Skip to content

Commit

Permalink
Merge pull request #2814 from dimagi/logs_session_expiration_copy
Browse files Browse the repository at this point in the history
Fixes Crash on App Resume after Session Expiration + Logs
  • Loading branch information
shubham1g5 authored Aug 19, 2024
2 parents 1d2f00b + 4e9ace9 commit 848eaa7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/src/org/commcare/activities/HomeButtons.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,14 @@ private static View.OnClickListener getSyncButtonSubTextListener(final StandardH

private static TextSetter getSyncButtonTextSetter(final StandardHomeActivity activity) {
return (cardDisplayData, squareButtonViewHolder, context, notificationText) -> {
SyncDetailCalculations.updateSubText(activity, squareButtonViewHolder, cardDisplayData, notificationText);
try {
SyncDetailCalculations.updateSubText(activity, squareButtonViewHolder, cardDisplayData,
notificationText);
} catch (SessionUnavailableException e) {
// stop button setup, since redirection to login is imminent
return;
}

squareButtonViewHolder.subTextView.setBackgroundColor(activity.getResources().getColor(cardDisplayData.subTextBgColor));
squareButtonViewHolder.textView.setTextColor(context.getResources().getColor(cardDisplayData.textColor));
squareButtonViewHolder.textView.setText(cardDisplayData.text);
Expand Down
7 changes: 7 additions & 0 deletions app/src/org/commcare/services/CommCareSessionService.java
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,14 @@ private void timeToExpireSession() {
// timeout then wrap-up the process.
if (logoutStartedAt != -1 &&
currentTime > (logoutStartedAt + LOGOUT_TIMEOUT)) {
Logger.log(LogTypes.TYPE_USER,
"Crossed threshold to save form session state during scheduled session expiration. Passed " + (
currentTime - logoutStartedAt) + "ms");
// Try and grab the logout lock, aborting if synchronization is in
// progress.
if (!CommCareSessionService.sessionAliveLock.tryLock()) {
Logger.log(LogTypes.TYPE_USER,
"Unabled to get session lock during scheduled session expiration");
return;
}
try {
Expand All @@ -371,6 +376,8 @@ private void timeToExpireSession() {
// Try and grab the logout lock, aborting if synchronization is in
// progress.
if (!CommCareSessionService.sessionAliveLock.tryLock()) {
Logger.log(LogTypes.TYPE_USER,
"Unabled to get session lock during scheduled session expiration");
return;
}

Expand Down

0 comments on commit 848eaa7

Please sign in to comment.