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
196cf15e
Verified
Commit
196cf15e
authored
7 years ago
by
akwizgran
Browse files
Options
Downloads
Patches
Plain Diff
Shut down cleanly when device shuts down.
parent
6ff0f317
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
briar-android/src/main/java/org/briarproject/briar/android/BriarService.java
+22
-0
22 additions, 0 deletions
...ain/java/org/briarproject/briar/android/BriarService.java
with
22 additions
and
0 deletions
briar-android/src/main/java/org/briarproject/briar/android/BriarService.java
+
22
−
0
View file @
196cf15e
...
@@ -4,8 +4,11 @@ import android.app.NotificationChannel;
...
@@ -4,8 +4,11 @@ import android.app.NotificationChannel;
import
android.app.NotificationManager
;
import
android.app.NotificationManager
;
import
android.app.PendingIntent
;
import
android.app.PendingIntent
;
import
android.app.Service
;
import
android.app.Service
;
import
android.content.BroadcastReceiver
;
import
android.content.ComponentName
;
import
android.content.ComponentName
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.content.IntentFilter
;
import
android.content.ServiceConnection
;
import
android.content.ServiceConnection
;
import
android.os.Binder
;
import
android.os.Binder
;
import
android.os.IBinder
;
import
android.os.IBinder
;
...
@@ -24,11 +27,13 @@ import java.util.concurrent.CountDownLatch;
...
@@ -24,11 +27,13 @@ import java.util.concurrent.CountDownLatch;
import
java.util.concurrent.atomic.AtomicBoolean
;
import
java.util.concurrent.atomic.AtomicBoolean
;
import
java.util.logging.Logger
;
import
java.util.logging.Logger
;
import
javax.annotation.Nullable
;
import
javax.inject.Inject
;
import
javax.inject.Inject
;
import
static
android
.
app
.
NotificationManager
.
IMPORTANCE_DEFAULT
;
import
static
android
.
app
.
NotificationManager
.
IMPORTANCE_DEFAULT
;
import
static
android
.
app
.
NotificationManager
.
IMPORTANCE_NONE
;
import
static
android
.
app
.
NotificationManager
.
IMPORTANCE_NONE
;
import
static
android
.
app
.
PendingIntent
.
FLAG_UPDATE_CURRENT
;
import
static
android
.
app
.
PendingIntent
.
FLAG_UPDATE_CURRENT
;
import
static
android
.
content
.
Intent
.
ACTION_SHUTDOWN
;
import
static
android
.
content
.
Intent
.
FLAG_ACTIVITY_CLEAR_TASK
;
import
static
android
.
content
.
Intent
.
FLAG_ACTIVITY_CLEAR_TASK
;
import
static
android
.
content
.
Intent
.
FLAG_ACTIVITY_CLEAR_TOP
;
import
static
android
.
content
.
Intent
.
FLAG_ACTIVITY_CLEAR_TOP
;
import
static
android
.
content
.
Intent
.
FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
;
import
static
android
.
content
.
Intent
.
FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
;
...
@@ -65,6 +70,9 @@ public class BriarService extends Service {
...
@@ -65,6 +70,9 @@ public class BriarService extends Service {
private
final
AtomicBoolean
created
=
new
AtomicBoolean
(
false
);
private
final
AtomicBoolean
created
=
new
AtomicBoolean
(
false
);
private
final
Binder
binder
=
new
BriarBinder
();
private
final
Binder
binder
=
new
BriarBinder
();
@Nullable
private
BroadcastReceiver
receiver
=
null
;
@Inject
@Inject
protected
DatabaseConfig
databaseConfig
;
protected
DatabaseConfig
databaseConfig
;
// Fields that are accessed from background threads must be volatile
// Fields that are accessed from background threads must be volatile
...
@@ -144,6 +152,19 @@ public class BriarService extends Service {
...
@@ -144,6 +152,19 @@ public class BriarService extends Service {
stopSelf
();
stopSelf
();
}
}
}).
start
();
}).
start
();
// Register for device shutdown broadcasts
receiver
=
new
BroadcastReceiver
()
{
@Override
public
void
onReceive
(
Context
context
,
Intent
intent
)
{
LOG
.
info
(
"Device is shutting down"
);
shutdownFromBackground
();
}
};
IntentFilter
filter
=
new
IntentFilter
();
filter
.
addAction
(
ACTION_SHUTDOWN
);
filter
.
addAction
(
"android.intent.action.QUICKBOOT_POWEROFF"
);
filter
.
addAction
(
"com.htc.intent.action.QUICKBOOT_POWEROFF"
);
registerReceiver
(
receiver
,
filter
);
}
}
private
void
showStartupFailureNotification
(
StartResult
result
)
{
private
void
showStartupFailureNotification
(
StartResult
result
)
{
...
@@ -188,6 +209,7 @@ public class BriarService extends Service {
...
@@ -188,6 +209,7 @@ public class BriarService extends Service {
super
.
onDestroy
();
super
.
onDestroy
();
LOG
.
info
(
"Destroyed"
);
LOG
.
info
(
"Destroyed"
);
stopForeground
(
true
);
stopForeground
(
true
);
if
(
receiver
!=
null
)
unregisterReceiver
(
receiver
);
// Stop the services in a background thread
// Stop the services in a background thread
new
Thread
(()
->
{
new
Thread
(()
->
{
if
(
started
)
lifecycleManager
.
stopServices
();
if
(
started
)
lifecycleManager
.
stopServices
();
...
...
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