Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
briar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julian Dehm
briar
Commits
4f732c39
Verified
Commit
4f732c39
authored
7 years ago
by
akwizgran
Browse files
Options
Downloads
Patches
Plain Diff
Acquire wake lock with a timeout.
parent
74cfd313
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bramble-android/src/main/java/org/briarproject/bramble/util/RenewableWakeLock.java
+13
-8
13 additions, 8 deletions
...java/org/briarproject/bramble/util/RenewableWakeLock.java
with
13 additions
and
8 deletions
bramble-android/src/main/java/org/briarproject/bramble/util/RenewableWakeLock.java
+
13
−
8
View file @
4f732c39
...
@@ -7,6 +7,7 @@ import java.util.concurrent.ScheduledFuture;
...
@@ -7,6 +7,7 @@ import java.util.concurrent.ScheduledFuture;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
import
java.util.logging.Logger
;
import
java.util.logging.Logger
;
import
static
java
.
util
.
concurrent
.
TimeUnit
.
MILLISECONDS
;
import
static
java
.
util
.
logging
.
Level
.
INFO
;
import
static
java
.
util
.
logging
.
Level
.
INFO
;
public
class
RenewableWakeLock
{
public
class
RenewableWakeLock
{
...
@@ -14,12 +15,17 @@ public class RenewableWakeLock {
...
@@ -14,12 +15,17 @@ public class RenewableWakeLock {
private
static
final
Logger
LOG
=
private
static
final
Logger
LOG
=
Logger
.
getLogger
(
RenewableWakeLock
.
class
.
getName
());
Logger
.
getLogger
(
RenewableWakeLock
.
class
.
getName
());
/**
* Automatically release the lock this many milliseconds after it's due
* to have been replaced and released.
*/
private
static
final
int
SAFETY_MARGIN_MS
=
10_000
;
private
final
PowerManager
powerManager
;
private
final
PowerManager
powerManager
;
private
final
ScheduledExecutorService
scheduler
;
private
final
ScheduledExecutorService
scheduler
;
private
final
int
levelAndFlags
;
private
final
int
levelAndFlags
;
private
final
String
tag
;
private
final
String
tag
;
private
final
long
duration
;
private
final
long
durationMs
;
private
final
TimeUnit
timeUnit
;
private
final
Runnable
renewTask
;
private
final
Runnable
renewTask
;
private
final
Object
lock
=
new
Object
();
private
final
Object
lock
=
new
Object
();
...
@@ -33,8 +39,7 @@ public class RenewableWakeLock {
...
@@ -33,8 +39,7 @@ public class RenewableWakeLock {
this
.
scheduler
=
scheduler
;
this
.
scheduler
=
scheduler
;
this
.
levelAndFlags
=
levelAndFlags
;
this
.
levelAndFlags
=
levelAndFlags
;
this
.
tag
=
tag
;
this
.
tag
=
tag
;
this
.
duration
=
duration
;
durationMs
=
MILLISECONDS
.
convert
(
duration
,
timeUnit
);
this
.
timeUnit
=
timeUnit
;
renewTask
=
this
::
renew
;
renewTask
=
this
::
renew
;
}
}
...
@@ -47,8 +52,8 @@ public class RenewableWakeLock {
...
@@ -47,8 +52,8 @@ public class RenewableWakeLock {
}
}
wakeLock
=
powerManager
.
newWakeLock
(
levelAndFlags
,
tag
);
wakeLock
=
powerManager
.
newWakeLock
(
levelAndFlags
,
tag
);
wakeLock
.
setReferenceCounted
(
false
);
wakeLock
.
setReferenceCounted
(
false
);
wakeLock
.
acquire
();
wakeLock
.
acquire
(
durationMs
+
SAFETY_MARGIN_MS
);
future
=
scheduler
.
schedule
(
renewTask
,
duration
,
timeUnit
);
future
=
scheduler
.
schedule
(
renewTask
,
duration
Ms
,
MILLISECONDS
);
}
}
}
}
...
@@ -62,9 +67,9 @@ public class RenewableWakeLock {
...
@@ -62,9 +67,9 @@ public class RenewableWakeLock {
PowerManager
.
WakeLock
oldWakeLock
=
wakeLock
;
PowerManager
.
WakeLock
oldWakeLock
=
wakeLock
;
wakeLock
=
powerManager
.
newWakeLock
(
levelAndFlags
,
tag
);
wakeLock
=
powerManager
.
newWakeLock
(
levelAndFlags
,
tag
);
wakeLock
.
setReferenceCounted
(
false
);
wakeLock
.
setReferenceCounted
(
false
);
wakeLock
.
acquire
();
wakeLock
.
acquire
(
durationMs
+
SAFETY_MARGIN_MS
);
oldWakeLock
.
release
();
oldWakeLock
.
release
();
future
=
scheduler
.
schedule
(
renewTask
,
duration
,
timeUnit
);
future
=
scheduler
.
schedule
(
renewTask
,
duration
Ms
,
MILLISECONDS
);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment