mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 13:49:53 +01:00
Don't allow BriarService to restart automatically without a DB key.
Fixes bug #7. The service is restarted after a crash even if onStartCommand() returns START_NOT_STICKY, but after restarting the DB key is not restored and so the app can't usefully proceed.
This commit is contained in:
@@ -11,6 +11,7 @@ import javax.inject.Inject;
|
|||||||
|
|
||||||
import net.sf.briar.R;
|
import net.sf.briar.R;
|
||||||
import net.sf.briar.api.android.AndroidExecutor;
|
import net.sf.briar.api.android.AndroidExecutor;
|
||||||
|
import net.sf.briar.api.db.DatabaseConfig;
|
||||||
import net.sf.briar.api.lifecycle.LifecycleManager;
|
import net.sf.briar.api.lifecycle.LifecycleManager;
|
||||||
import roboguice.service.RoboService;
|
import roboguice.service.RoboService;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
@@ -28,6 +29,9 @@ public class BriarService extends RoboService {
|
|||||||
|
|
||||||
private final Binder binder = new BriarBinder();
|
private final Binder binder = new BriarBinder();
|
||||||
|
|
||||||
|
@Inject private DatabaseConfig databaseConfig;
|
||||||
|
private boolean started = false;
|
||||||
|
|
||||||
// Fields that are accessed from background threads must be volatile
|
// Fields that are accessed from background threads must be volatile
|
||||||
@Inject private volatile LifecycleManager lifecycleManager;
|
@Inject private volatile LifecycleManager lifecycleManager;
|
||||||
@Inject private volatile AndroidExecutor androidExecutor;
|
@Inject private volatile AndroidExecutor androidExecutor;
|
||||||
@@ -36,6 +40,11 @@ public class BriarService extends RoboService {
|
|||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
if(LOG.isLoggable(INFO)) LOG.info("Created");
|
if(LOG.isLoggable(INFO)) LOG.info("Created");
|
||||||
|
if(databaseConfig.getEncryptionKey() == null) {
|
||||||
|
if(LOG.isLoggable(INFO)) LOG.info("No database key");
|
||||||
|
stopSelf();
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Show an ongoing notification that the service is running
|
// Show an ongoing notification that the service is running
|
||||||
NotificationCompat.Builder b = new NotificationCompat.Builder(this);
|
NotificationCompat.Builder b = new NotificationCompat.Builder(this);
|
||||||
b.setSmallIcon(R.drawable.notification_icon);
|
b.setSmallIcon(R.drawable.notification_icon);
|
||||||
@@ -56,6 +65,7 @@ public class BriarService extends RoboService {
|
|||||||
lifecycleManager.startServices();
|
lifecycleManager.startServices();
|
||||||
}
|
}
|
||||||
}.start();
|
}.start();
|
||||||
|
started = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -74,7 +84,7 @@ public class BriarService extends RoboService {
|
|||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
if(LOG.isLoggable(INFO)) LOG.info("Destroyed");
|
if(LOG.isLoggable(INFO)) LOG.info("Destroyed");
|
||||||
// Stop the services in a background thread
|
// Stop the services in a background thread
|
||||||
new Thread() {
|
if(started) new Thread() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
androidExecutor.shutdown();
|
androidExecutor.shutdown();
|
||||||
|
|||||||
Reference in New Issue
Block a user