Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Julian Dehm
briar
Commits
825ed451
Verified
Commit
825ed451
authored
Aug 14, 2018
by
Torsten Grote
Browse files
Screen lock: Add a fallback in case alarm manager didn't run during sleep
parent
bffd78d4
Changes
1
Hide whitespace changes
Inline
Side-by-side
briar-android/src/main/java/org/briarproject/briar/android/account/LockManagerImpl.java
View file @
825ed451
...
...
@@ -63,6 +63,7 @@ public class LockManagerImpl implements LockManager, Service, EventListener {
private
volatile
boolean
lockableSetting
=
false
;
private
volatile
int
timeoutMinutes
;
private
int
activitiesRunning
=
0
;
private
long
idleTime
;
private
final
MutableLiveData
<
Boolean
>
lockable
=
new
MutableLiveData
<>();
@Inject
...
...
@@ -101,6 +102,11 @@ public class LockManagerImpl implements LockManager, Service, EventListener {
@UiThread
@Override
public
void
onActivityStart
()
{
if
(!
locked
&&
activitiesRunning
==
0
&&
timeoutEnabled
()
&&
timedOut
())
{
// lock the app in case the alarm wasn't run during sleep
setLocked
(
true
);
}
activitiesRunning
++;
alarmManager
.
cancel
(
lockIntent
);
}
...
...
@@ -109,12 +115,14 @@ public class LockManagerImpl implements LockManager, Service, EventListener {
@Override
public
void
onActivityStop
()
{
activitiesRunning
--;
if
(
activitiesRunning
==
0
&&
!
locked
&&
timeoutMinutes
!=
timeoutNever
&&
lockable
.
getValue
())
{
alarmManager
.
cancel
(
lockIntent
);
long
triggerAt
=
elapsedRealtime
()
+
MINUTES
.
toMillis
(
timeoutMinutes
);
alarmManager
.
set
(
ELAPSED_REALTIME
,
triggerAt
,
lockIntent
);
if
(
activitiesRunning
==
0
)
{
idleTime
=
elapsedRealtime
();
if
(!
locked
&&
timeoutEnabled
())
{
alarmManager
.
cancel
(
lockIntent
);
long
triggerAt
=
elapsedRealtime
()
+
MINUTES
.
toMillis
(
timeoutMinutes
);
alarmManager
.
set
(
ELAPSED_REALTIME
,
triggerAt
,
lockIntent
);
}
}
}
...
...
@@ -138,6 +146,8 @@ public class LockManagerImpl implements LockManager, Service, EventListener {
if
(
locked
&&
!
hasScreenLock
(
appContext
))
{
lockable
.
postValue
(
false
);
locked
=
false
;
}
else
if
(!
locked
&&
activitiesRunning
==
0
&&
timeoutEnabled
())
{
setLocked
(
true
);
}
return
locked
;
}
...
...
@@ -179,4 +189,12 @@ public class LockManagerImpl implements LockManager, Service, EventListener {
});
}
private
boolean
timeoutEnabled
()
{
return
timeoutMinutes
!=
timeoutNever
&&
lockable
.
getValue
();
}
private
boolean
timedOut
()
{
return
elapsedRealtime
()
-
idleTime
>
MINUTES
.
toMillis
(
timeoutMinutes
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment