From a287408a7a0d92828dfcaa25292746d2a73d26f5 Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Thu, 18 Oct 2018 09:40:32 -0700 Subject: [PATCH] Only start the screen lock timeout when the app is backgrounded. --- .../securesms/service/KeyCachingService.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/org/thoughtcrime/securesms/service/KeyCachingService.java b/src/org/thoughtcrime/securesms/service/KeyCachingService.java index 152cbe7f3e..9fbbb94d7c 100644 --- a/src/org/thoughtcrime/securesms/service/KeyCachingService.java +++ b/src/org/thoughtcrime/securesms/service/KeyCachingService.java @@ -32,6 +32,8 @@ import android.os.SystemClock; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.NotificationCompat; + +import org.thoughtcrime.securesms.ApplicationContext; import org.thoughtcrime.securesms.logging.Log; import android.widget.RemoteViews; @@ -220,13 +222,16 @@ public class KeyCachingService extends Service { } private static void startTimeoutIfAppropriate(@NonNull Context context) { - boolean timeoutEnabled = TextSecurePreferences.isPassphraseTimeoutEnabled(context); - long screenTimeout = TextSecurePreferences.getScreenLockTimeout(context); + boolean appVisible = ApplicationContext.getInstance(context).isAppVisible(); + boolean secretSet = KeyCachingService.masterSecret != null; - if ((KeyCachingService.masterSecret != null) && - (timeoutEnabled && !TextSecurePreferences.isPasswordDisabled(context)) || - (screenTimeout >= 60 && TextSecurePreferences.isScreenLockEnabled(context))) - { + boolean timeoutEnabled = TextSecurePreferences.isPassphraseTimeoutEnabled(context); + boolean passLockActive = timeoutEnabled && !TextSecurePreferences.isPasswordDisabled(context); + + long screenTimeout = TextSecurePreferences.getScreenLockTimeout(context); + boolean screenLockActive = screenTimeout >= 60 && TextSecurePreferences.isScreenLockEnabled(context); + + if (!appVisible && secretSet && (passLockActive || screenLockActive)) { long passphraseTimeoutMinutes = TextSecurePreferences.getPassphraseTimeoutInterval(context); long screenLockTimeoutSeconds = TextSecurePreferences.getScreenLockTimeout(context);