Screen Lock Timeout: Address review comments

parent 825ed451
......@@ -63,11 +63,15 @@ public class LockManagerImpl implements LockManager, Service, EventListener {
private volatile boolean lockableSetting = false;
private volatile int timeoutMinutes;
private int activitiesRunning = 0;
private boolean alarmSet = false;
// This is to ensure that we don't start unlocked after a timeout and thus
// is set to the elapsed real time when no more activities are running.
// Its value is only relevant as long as no activity is running.
private long idleTime;
private final MutableLiveData<Boolean> lockable = new MutableLiveData<>();
@Inject
public LockManagerImpl(Application app, SettingsManager settingsManager,
LockManagerImpl(Application app, SettingsManager settingsManager,
AndroidNotificationManager notificationManager,
@DatabaseExecutor Executor dbExecutor) {
this.appContext = app.getApplicationContext();
......@@ -108,7 +112,10 @@ public class LockManagerImpl implements LockManager, Service, EventListener {
setLocked(true);
}
activitiesRunning++;
alarmManager.cancel(lockIntent);
if (alarmSet) {
alarmManager.cancel(lockIntent);
alarmSet = false;
}
}
@UiThread
......@@ -118,10 +125,11 @@ public class LockManagerImpl implements LockManager, Service, EventListener {
if (activitiesRunning == 0) {
idleTime = elapsedRealtime();
if (!locked && timeoutEnabled()) {
alarmManager.cancel(lockIntent);
if (alarmSet) alarmManager.cancel(lockIntent);
long triggerAt =
elapsedRealtime() + MINUTES.toMillis(timeoutMinutes);
alarmManager.set(ELAPSED_REALTIME, triggerAt, lockIntent);
alarmSet = true;
}
}
}
......@@ -146,7 +154,8 @@ public class LockManagerImpl implements LockManager, Service, EventListener {
if (locked && !hasScreenLock(appContext)) {
lockable.postValue(false);
locked = false;
} else if (!locked && activitiesRunning == 0 && timeoutEnabled()) {
} else if (!locked && activitiesRunning == 0 && timeoutEnabled() &&
timedOut()) {
setLocked(true);
}
return locked;
......
......@@ -62,6 +62,7 @@
<string name="groups_button">Private Groups</string>
<string name="forums_button">Forums</string>
<string name="blogs_button">Blogs</string>
<!-- This is part of the main menu. The app will be locked when this is tapped. -->
<string name="lock_button">Lock App</string>
<string name="settings_button">Settings</string>
<string name="sign_out_button">Sign Out</string>
......@@ -357,18 +358,23 @@
<!-- Settings Security and Panic -->
<string name="security_settings_title">Security</string>
<string name="pref_lock_title">Screen Lock</string>
<string name="pref_lock_title">Screen lock</string>
<string name="pref_lock_summary">Use the device\'s screen lock to protect Briar while signed in</string>
<string name="pref_lock_disabled_summary">Set up a screen lock for your device to protect Briar while signed in</string>
<string name="pref_lock_timeout_title">Screen Lock Inactivity Timeout</string>
<!-- The %s placeholder is replaces with the following time spans, e.g. after 5 Minutes -->
<string name="pref_lock_timeout_summary">When not using Briar, automatically lock it %s</string>
<string name="pref_lock_timeout_1">after 1 Minute</string>
<string name="pref_lock_timeout_5">after 5 Minutes</string>
<string name="pref_lock_timeout_15">after 15 Minutes</string>
<string name="pref_lock_timeout_30">after 30 Minutes</string>
<string name="pref_lock_timeout_60">after 1 Hour</string>
<string name="pref_lock_timeout_never">never</string>
<string name="pref_lock_disabled_summary">To use this feature, set up a screen lock for your device</string>
<string name="pref_lock_timeout_title">Screen lock inactivity timeout</string>
<!-- The %s placeholder is replaced with the following time spans, e.g. 5 Minutes, 1 Hour -->
<string name="pref_lock_timeout_summary">When not using Briar, automatically lock it after %s</string>
<!-- Will be shown in a list of lock times. Should fit into the %s of "automatically lock it after %s" -->
<string name="pref_lock_timeout_1">1 minute</string>
<!-- Will be shown in a list of lock times. Should fit into the %s of "automatically lock it after %s" -->
<string name="pref_lock_timeout_5">5 minutes</string>
<!-- Will be shown in a list of lock times. Should fit into the %s of "automatically lock it after %s" -->
<string name="pref_lock_timeout_15">15 minutes</string>
<!-- Will be shown in a list of lock times. Should fit into the %s of "automatically lock it after %s" -->
<string name="pref_lock_timeout_30">30 minutes</string>
<!-- Will be shown in a list of lock times. Should fit into the %s of "automatically lock it after %s" -->
<string name="pref_lock_timeout_60">1 hour</string>
<string name="pref_lock_timeout_never">Never</string>
<string name="pref_lock_timeout_never_summary">Never lock Briar automatically</string>
<string name="change_password">Change password</string>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment