mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 22:29:53 +01:00
Merge branch '1142-wakeful-lifecycle' into 'master'
Hold a wake lock during app startup and shutdown See merge request briar/briar!1271
This commit is contained in:
@@ -24,4 +24,15 @@ public interface AndroidWakeLockManager {
|
|||||||
* thrown while submitting or running the task.
|
* thrown while submitting or running the task.
|
||||||
*/
|
*/
|
||||||
void executeWakefully(Runnable r, Executor executor, String tag);
|
void executeWakefully(Runnable r, Executor executor, String tag);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts a dedicated thread to run the given task asynchronously. A wake
|
||||||
|
* lock is acquired before starting the thread and released when the task
|
||||||
|
* completes, or if an exception is thrown while starting the thread or
|
||||||
|
* running the task.
|
||||||
|
* <p>
|
||||||
|
* This method should only be used for lifecycle management tasks that
|
||||||
|
* can't be run on an executor.
|
||||||
|
*/
|
||||||
|
void executeWakefully(Runnable r, String tag);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,6 +86,24 @@ class AndroidWakeLockManagerImpl implements AndroidWakeLockManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void executeWakefully(Runnable r, String tag) {
|
||||||
|
AndroidWakeLock wakeLock = createWakeLock(tag);
|
||||||
|
wakeLock.acquire();
|
||||||
|
try {
|
||||||
|
new Thread(() -> {
|
||||||
|
try {
|
||||||
|
r.run();
|
||||||
|
} finally {
|
||||||
|
wakeLock.release();
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
} catch (Exception e) {
|
||||||
|
wakeLock.release();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private String getWakeLockTag(Context ctx) {
|
private String getWakeLockTag(Context ctx) {
|
||||||
PackageManager pm = ctx.getPackageManager();
|
PackageManager pm = ctx.getPackageManager();
|
||||||
for (PackageInfo info : pm.getInstalledPackages(0)) {
|
for (PackageInfo info : pm.getInstalledPackages(0)) {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import org.briarproject.bramble.api.db.DatabaseComponent;
|
|||||||
import org.briarproject.bramble.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.db.Transaction;
|
import org.briarproject.bramble.api.db.Transaction;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.system.Wakeful;
|
||||||
|
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
|
||||||
@@ -65,6 +66,7 @@ public interface LifecycleManager {
|
|||||||
* Opens the {@link DatabaseComponent} using the given key and starts any
|
* Opens the {@link DatabaseComponent} using the given key and starts any
|
||||||
* registered {@link Service Services}.
|
* registered {@link Service Services}.
|
||||||
*/
|
*/
|
||||||
|
@Wakeful
|
||||||
StartResult startServices(SecretKey dbKey);
|
StartResult startServices(SecretKey dbKey);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -72,6 +74,7 @@ public interface LifecycleManager {
|
|||||||
* registered {@link ExecutorService ExecutorServices}, and closes the
|
* registered {@link ExecutorService ExecutorServices}, and closes the
|
||||||
* {@link DatabaseComponent}.
|
* {@link DatabaseComponent}.
|
||||||
*/
|
*/
|
||||||
|
@Wakeful
|
||||||
void stopServices();
|
void stopServices();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -104,6 +107,7 @@ public interface LifecycleManager {
|
|||||||
*
|
*
|
||||||
* @param txn A read-write transaction
|
* @param txn A read-write transaction
|
||||||
*/
|
*/
|
||||||
|
@Wakeful
|
||||||
void onDatabaseOpened(Transaction txn) throws DbException;
|
void onDatabaseOpened(Transaction txn) throws DbException;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,16 +1,20 @@
|
|||||||
package org.briarproject.bramble.api.lifecycle;
|
package org.briarproject.bramble.api.lifecycle;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.system.Wakeful;
|
||||||
|
|
||||||
public interface Service {
|
public interface Service {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts the service.This method must not be called concurrently with
|
* Starts the service. This method must not be called concurrently with
|
||||||
* {@link #stopService()}.
|
* {@link #stopService()}.
|
||||||
*/
|
*/
|
||||||
|
@Wakeful
|
||||||
void startService() throws ServiceException;
|
void startService() throws ServiceException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stops the service. This method must not be called concurrently with
|
* Stops the service. This method must not be called concurrently with
|
||||||
* {@link #startService()}.
|
* {@link #startService()}.
|
||||||
*/
|
*/
|
||||||
|
@Wakeful
|
||||||
void stopService() throws ServiceException;
|
void stopService() throws ServiceException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import org.briarproject.bramble.api.Pair;
|
|||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.properties.TransportProperties;
|
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||||
import org.briarproject.bramble.api.settings.SettingsManager;
|
import org.briarproject.bramble.api.settings.SettingsManager;
|
||||||
|
import org.briarproject.bramble.api.system.Wakeful;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
@@ -70,11 +71,13 @@ public interface Plugin {
|
|||||||
/**
|
/**
|
||||||
* Starts the plugin.
|
* Starts the plugin.
|
||||||
*/
|
*/
|
||||||
|
@Wakeful
|
||||||
void start() throws PluginException;
|
void start() throws PluginException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stops the plugin.
|
* Stops the plugin.
|
||||||
*/
|
*/
|
||||||
|
@Wakeful
|
||||||
void stop() throws PluginException;
|
void stop() throws PluginException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -106,6 +109,7 @@ public interface Plugin {
|
|||||||
* Attempts to create connections using the given transport properties,
|
* Attempts to create connections using the given transport properties,
|
||||||
* passing any created connections to the corresponding handlers.
|
* passing any created connections to the corresponding handlers.
|
||||||
*/
|
*/
|
||||||
|
@Wakeful
|
||||||
void poll(Collection<Pair<TransportProperties, ConnectionHandler>>
|
void poll(Collection<Pair<TransportProperties, ConnectionHandler>>
|
||||||
properties);
|
properties);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import org.briarproject.bramble.api.plugin.Plugin;
|
|||||||
import org.briarproject.bramble.api.properties.TransportProperties;
|
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||||
import org.briarproject.bramble.api.rendezvous.KeyMaterialSource;
|
import org.briarproject.bramble.api.rendezvous.KeyMaterialSource;
|
||||||
import org.briarproject.bramble.api.rendezvous.RendezvousEndpoint;
|
import org.briarproject.bramble.api.rendezvous.RendezvousEndpoint;
|
||||||
|
import org.briarproject.bramble.api.system.Wakeful;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
@@ -21,6 +22,7 @@ public interface DuplexPlugin extends Plugin {
|
|||||||
* Attempts to create and return a connection using the given transport
|
* Attempts to create and return a connection using the given transport
|
||||||
* properties. Returns null if a connection cannot be created.
|
* properties. Returns null if a connection cannot be created.
|
||||||
*/
|
*/
|
||||||
|
@Wakeful
|
||||||
@Nullable
|
@Nullable
|
||||||
DuplexTransportConnection createConnection(TransportProperties p);
|
DuplexTransportConnection createConnection(TransportProperties p);
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import org.briarproject.bramble.api.plugin.Plugin;
|
|||||||
import org.briarproject.bramble.api.plugin.TransportConnectionReader;
|
import org.briarproject.bramble.api.plugin.TransportConnectionReader;
|
||||||
import org.briarproject.bramble.api.plugin.TransportConnectionWriter;
|
import org.briarproject.bramble.api.plugin.TransportConnectionWriter;
|
||||||
import org.briarproject.bramble.api.properties.TransportProperties;
|
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||||
|
import org.briarproject.bramble.api.system.Wakeful;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
@@ -18,6 +19,7 @@ public interface SimplexPlugin extends Plugin {
|
|||||||
* Attempts to create and return a reader for the given transport
|
* Attempts to create and return a reader for the given transport
|
||||||
* properties. Returns null if a reader cannot be created.
|
* properties. Returns null if a reader cannot be created.
|
||||||
*/
|
*/
|
||||||
|
@Wakeful
|
||||||
@Nullable
|
@Nullable
|
||||||
TransportConnectionReader createReader(TransportProperties p);
|
TransportConnectionReader createReader(TransportProperties p);
|
||||||
|
|
||||||
@@ -25,6 +27,7 @@ public interface SimplexPlugin extends Plugin {
|
|||||||
* Attempts to create and return a writer for the given transport
|
* Attempts to create and return a writer for the given transport
|
||||||
* properties. Returns null if a writer cannot be created.
|
* properties. Returns null if a writer cannot be created.
|
||||||
*/
|
*/
|
||||||
|
@Wakeful
|
||||||
@Nullable
|
@Nullable
|
||||||
TransportConnectionWriter createWriter(TransportProperties p);
|
TransportConnectionWriter createWriter(TransportProperties p);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ public interface TaskScheduler {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Submits the given task to the given executor after the given delay.
|
* Submits the given task to the given executor after the given delay.
|
||||||
|
* <p>
|
||||||
|
* If the platform supports wake locks, a wake lock will be held while
|
||||||
|
* submitting and running the task.
|
||||||
*/
|
*/
|
||||||
Future<?> schedule(Runnable task, Executor executor, long delay,
|
Future<?> schedule(Runnable task, Executor executor, long delay,
|
||||||
TimeUnit unit);
|
TimeUnit unit);
|
||||||
@@ -22,6 +25,9 @@ public interface TaskScheduler {
|
|||||||
* Submits the given task to the given executor after the given delay,
|
* Submits the given task to the given executor after the given delay,
|
||||||
* and then repeatedly with the given interval between executions
|
* and then repeatedly with the given interval between executions
|
||||||
* (measured from the end of one execution to the beginning of the next).
|
* (measured from the end of one execution to the beginning of the next).
|
||||||
|
* <p>
|
||||||
|
* If the platform supports wake locks, a wake lock will be held while
|
||||||
|
* submitting and running the task.
|
||||||
*/
|
*/
|
||||||
Future<?> scheduleWithFixedDelay(Runnable task, Executor executor,
|
Future<?> scheduleWithFixedDelay(Runnable task, Executor executor,
|
||||||
long delay, long interval, TimeUnit unit);
|
long delay, long interval, TimeUnit unit);
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package org.briarproject.bramble.api.system;
|
||||||
|
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
import javax.inject.Qualifier;
|
||||||
|
|
||||||
|
import static java.lang.annotation.ElementType.METHOD;
|
||||||
|
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Annotation for methods that must be called while holding a wake lock, if
|
||||||
|
* the platform supports wake locks.
|
||||||
|
*/
|
||||||
|
@Qualifier
|
||||||
|
@Target(METHOD)
|
||||||
|
@Retention(RUNTIME)
|
||||||
|
public @interface Wakeful {
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ import org.briarproject.bramble.api.io.TimeoutMonitor;
|
|||||||
import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.bramble.api.system.TaskScheduler;
|
import org.briarproject.bramble.api.system.TaskScheduler;
|
||||||
|
import org.briarproject.bramble.api.system.Wakeful;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@@ -75,6 +76,7 @@ class TimeoutMonitorImpl implements TimeoutMonitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@IoExecutor
|
@IoExecutor
|
||||||
|
@Wakeful
|
||||||
private void checkTimeouts() {
|
private void checkTimeouts() {
|
||||||
List<TimeoutInputStream> snapshot;
|
List<TimeoutInputStream> snapshot;
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import org.briarproject.bramble.api.properties.TransportProperties;
|
|||||||
import org.briarproject.bramble.api.properties.TransportPropertyManager;
|
import org.briarproject.bramble.api.properties.TransportPropertyManager;
|
||||||
import org.briarproject.bramble.api.settings.Settings;
|
import org.briarproject.bramble.api.settings.Settings;
|
||||||
import org.briarproject.bramble.api.settings.SettingsManager;
|
import org.briarproject.bramble.api.settings.SettingsManager;
|
||||||
|
import org.briarproject.bramble.api.system.WakefulIoExecutor;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -64,7 +65,7 @@ class PluginManagerImpl implements PluginManager, Service {
|
|||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
getLogger(PluginManagerImpl.class.getName());
|
getLogger(PluginManagerImpl.class.getName());
|
||||||
|
|
||||||
private final Executor ioExecutor;
|
private final Executor ioExecutor, wakefulIoExecutor;
|
||||||
private final EventBus eventBus;
|
private final EventBus eventBus;
|
||||||
private final PluginConfig pluginConfig;
|
private final PluginConfig pluginConfig;
|
||||||
private final ConnectionManager connectionManager;
|
private final ConnectionManager connectionManager;
|
||||||
@@ -77,11 +78,15 @@ class PluginManagerImpl implements PluginManager, Service {
|
|||||||
private final AtomicBoolean used = new AtomicBoolean(false);
|
private final AtomicBoolean used = new AtomicBoolean(false);
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
PluginManagerImpl(@IoExecutor Executor ioExecutor, EventBus eventBus,
|
PluginManagerImpl(@IoExecutor Executor ioExecutor,
|
||||||
PluginConfig pluginConfig, ConnectionManager connectionManager,
|
@WakefulIoExecutor Executor wakefulIoExecutor,
|
||||||
|
EventBus eventBus,
|
||||||
|
PluginConfig pluginConfig,
|
||||||
|
ConnectionManager connectionManager,
|
||||||
SettingsManager settingsManager,
|
SettingsManager settingsManager,
|
||||||
TransportPropertyManager transportPropertyManager) {
|
TransportPropertyManager transportPropertyManager) {
|
||||||
this.ioExecutor = ioExecutor;
|
this.ioExecutor = ioExecutor;
|
||||||
|
this.wakefulIoExecutor = wakefulIoExecutor;
|
||||||
this.eventBus = eventBus;
|
this.eventBus = eventBus;
|
||||||
this.pluginConfig = pluginConfig;
|
this.pluginConfig = pluginConfig;
|
||||||
this.connectionManager = connectionManager;
|
this.connectionManager = connectionManager;
|
||||||
@@ -109,7 +114,7 @@ class PluginManagerImpl implements PluginManager, Service {
|
|||||||
simplexPlugins.add(s);
|
simplexPlugins.add(s);
|
||||||
CountDownLatch startLatch = new CountDownLatch(1);
|
CountDownLatch startLatch = new CountDownLatch(1);
|
||||||
startLatches.put(t, startLatch);
|
startLatches.put(t, startLatch);
|
||||||
ioExecutor.execute(new PluginStarter(s, startLatch));
|
wakefulIoExecutor.execute(new PluginStarter(s, startLatch));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Instantiate the duplex plugins and start them asynchronously
|
// Instantiate the duplex plugins and start them asynchronously
|
||||||
@@ -125,7 +130,7 @@ class PluginManagerImpl implements PluginManager, Service {
|
|||||||
duplexPlugins.add(d);
|
duplexPlugins.add(d);
|
||||||
CountDownLatch startLatch = new CountDownLatch(1);
|
CountDownLatch startLatch = new CountDownLatch(1);
|
||||||
startLatches.put(t, startLatch);
|
startLatches.put(t, startLatch);
|
||||||
ioExecutor.execute(new PluginStarter(d, startLatch));
|
wakefulIoExecutor.execute(new PluginStarter(d, startLatch));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -137,12 +142,16 @@ class PluginManagerImpl implements PluginManager, Service {
|
|||||||
LOG.info("Stopping simplex plugins");
|
LOG.info("Stopping simplex plugins");
|
||||||
for (SimplexPlugin s : simplexPlugins) {
|
for (SimplexPlugin s : simplexPlugins) {
|
||||||
CountDownLatch startLatch = startLatches.get(s.getId());
|
CountDownLatch startLatch = startLatches.get(s.getId());
|
||||||
|
// Don't need the wakeful executor here as we wait for the plugin
|
||||||
|
// to stop before returning
|
||||||
ioExecutor.execute(new PluginStopper(s, startLatch, stopLatch));
|
ioExecutor.execute(new PluginStopper(s, startLatch, stopLatch));
|
||||||
}
|
}
|
||||||
// Stop the duplex plugins
|
// Stop the duplex plugins
|
||||||
LOG.info("Stopping duplex plugins");
|
LOG.info("Stopping duplex plugins");
|
||||||
for (DuplexPlugin d : duplexPlugins) {
|
for (DuplexPlugin d : duplexPlugins) {
|
||||||
CountDownLatch startLatch = startLatches.get(d.getId());
|
CountDownLatch startLatch = startLatches.get(d.getId());
|
||||||
|
// Don't need the wakeful executor here as we wait for the plugin
|
||||||
|
// to stop before returning
|
||||||
ioExecutor.execute(new PluginStopper(d, startLatch, stopLatch));
|
ioExecutor.execute(new PluginStopper(d, startLatch, stopLatch));
|
||||||
}
|
}
|
||||||
// Wait for all the plugins to stop
|
// Wait for all the plugins to stop
|
||||||
@@ -205,7 +214,7 @@ class PluginManagerImpl implements PluginManager, Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class PluginStarter implements Runnable {
|
private static class PluginStarter implements Runnable {
|
||||||
|
|
||||||
private final Plugin plugin;
|
private final Plugin plugin;
|
||||||
private final CountDownLatch startLatch;
|
private final CountDownLatch startLatch;
|
||||||
@@ -235,7 +244,7 @@ class PluginManagerImpl implements PluginManager, Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class PluginStopper implements Runnable {
|
private static class PluginStopper implements Runnable {
|
||||||
|
|
||||||
private final Plugin plugin;
|
private final Plugin plugin;
|
||||||
private final CountDownLatch startLatch, stopLatch;
|
private final CountDownLatch startLatch, stopLatch;
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import org.briarproject.bramble.api.properties.TransportProperties;
|
|||||||
import org.briarproject.bramble.api.properties.TransportPropertyManager;
|
import org.briarproject.bramble.api.properties.TransportPropertyManager;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.bramble.api.system.TaskScheduler;
|
import org.briarproject.bramble.api.system.TaskScheduler;
|
||||||
|
import org.briarproject.bramble.api.system.Wakeful;
|
||||||
import org.briarproject.bramble.api.system.WakefulIoExecutor;
|
import org.briarproject.bramble.api.system.WakefulIoExecutor;
|
||||||
|
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
@@ -57,7 +58,7 @@ class PollerImpl implements Poller, EventListener {
|
|||||||
|
|
||||||
private static final Logger LOG = getLogger(PollerImpl.class.getName());
|
private static final Logger LOG = getLogger(PollerImpl.class.getName());
|
||||||
|
|
||||||
private final Executor wakefulIoExecutor;
|
private final Executor ioExecutor, wakefulIoExecutor;
|
||||||
private final TaskScheduler scheduler;
|
private final TaskScheduler scheduler;
|
||||||
private final ConnectionManager connectionManager;
|
private final ConnectionManager connectionManager;
|
||||||
private final ConnectionRegistry connectionRegistry;
|
private final ConnectionRegistry connectionRegistry;
|
||||||
@@ -70,7 +71,8 @@ class PollerImpl implements Poller, EventListener {
|
|||||||
private final Map<TransportId, ScheduledPollTask> tasks;
|
private final Map<TransportId, ScheduledPollTask> tasks;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
PollerImpl(@WakefulIoExecutor Executor wakefulIoExecutor,
|
PollerImpl(@IoExecutor Executor ioExecutor,
|
||||||
|
@WakefulIoExecutor Executor wakefulIoExecutor,
|
||||||
TaskScheduler scheduler,
|
TaskScheduler scheduler,
|
||||||
ConnectionManager connectionManager,
|
ConnectionManager connectionManager,
|
||||||
ConnectionRegistry connectionRegistry,
|
ConnectionRegistry connectionRegistry,
|
||||||
@@ -78,6 +80,7 @@ class PollerImpl implements Poller, EventListener {
|
|||||||
TransportPropertyManager transportPropertyManager,
|
TransportPropertyManager transportPropertyManager,
|
||||||
SecureRandom random,
|
SecureRandom random,
|
||||||
Clock clock) {
|
Clock clock) {
|
||||||
|
this.ioExecutor = ioExecutor;
|
||||||
this.wakefulIoExecutor = wakefulIoExecutor;
|
this.wakefulIoExecutor = wakefulIoExecutor;
|
||||||
this.scheduler = scheduler;
|
this.scheduler = scheduler;
|
||||||
this.connectionManager = connectionManager;
|
this.connectionManager = connectionManager;
|
||||||
@@ -190,8 +193,8 @@ class PollerImpl implements Poller, EventListener {
|
|||||||
// it will abort safely when it finds it's been replaced
|
// it will abort safely when it finds it's been replaced
|
||||||
if (scheduled != null) scheduled.future.cancel(false);
|
if (scheduled != null) scheduled.future.cancel(false);
|
||||||
PollTask task = new PollTask(p, due, randomiseNext);
|
PollTask task = new PollTask(p, due, randomiseNext);
|
||||||
Future<?> future = scheduler.schedule(task, wakefulIoExecutor,
|
Future<?> future = scheduler.schedule(task, ioExecutor, delay,
|
||||||
delay, MILLISECONDS);
|
MILLISECONDS);
|
||||||
tasks.put(t, new ScheduledPollTask(task, future));
|
tasks.put(t, new ScheduledPollTask(task, future));
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@@ -256,6 +259,7 @@ class PollerImpl implements Poller, EventListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@IoExecutor
|
@IoExecutor
|
||||||
|
@Wakeful
|
||||||
public void run() {
|
public void run() {
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ import org.briarproject.bramble.api.rendezvous.event.RendezvousConnectionOpenedE
|
|||||||
import org.briarproject.bramble.api.rendezvous.event.RendezvousPollEvent;
|
import org.briarproject.bramble.api.rendezvous.event.RendezvousPollEvent;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.bramble.api.system.TaskScheduler;
|
import org.briarproject.bramble.api.system.TaskScheduler;
|
||||||
|
import org.briarproject.bramble.api.system.Wakeful;
|
||||||
|
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -205,6 +206,7 @@ class RendezvousPollerImpl implements RendezvousPoller, Service, EventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Worker
|
// Worker
|
||||||
|
@Wakeful
|
||||||
private void poll() {
|
private void poll() {
|
||||||
removeExpiredPendingContacts();
|
removeExpiredPendingContacts();
|
||||||
for (PluginState ps : pluginStates.values()) poll(ps);
|
for (PluginState ps : pluginStates.values()) poll(ps);
|
||||||
@@ -235,6 +237,7 @@ class RendezvousPollerImpl implements RendezvousPoller, Service, EventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Worker
|
// Worker
|
||||||
|
@Wakeful
|
||||||
private void poll(PluginState ps) {
|
private void poll(PluginState ps) {
|
||||||
if (ps.endpoints.isEmpty()) return;
|
if (ps.endpoints.isEmpty()) return;
|
||||||
TransportId t = ps.plugin.getId();
|
TransportId t = ps.plugin.getId();
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
|||||||
import org.briarproject.bramble.api.plugin.TransportId;
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.bramble.api.system.TaskScheduler;
|
import org.briarproject.bramble.api.system.TaskScheduler;
|
||||||
|
import org.briarproject.bramble.api.system.Wakeful;
|
||||||
import org.briarproject.bramble.api.transport.KeySetId;
|
import org.briarproject.bramble.api.transport.KeySetId;
|
||||||
import org.briarproject.bramble.api.transport.StreamContext;
|
import org.briarproject.bramble.api.transport.StreamContext;
|
||||||
import org.briarproject.bramble.api.transport.TransportKeySet;
|
import org.briarproject.bramble.api.transport.TransportKeySet;
|
||||||
@@ -203,6 +204,7 @@ class TransportKeyManagerImpl implements TransportKeyManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@DatabaseExecutor
|
@DatabaseExecutor
|
||||||
|
@Wakeful
|
||||||
private void updateKeys() {
|
private void updateKeys() {
|
||||||
try {
|
try {
|
||||||
db.transaction(false, this::updateKeys);
|
db.transaction(false, this::updateKeys);
|
||||||
@@ -441,6 +443,8 @@ class TransportKeyManagerImpl implements TransportKeyManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DatabaseExecutor
|
||||||
|
@Wakeful
|
||||||
private void updateKeys(Transaction txn) throws DbException {
|
private void updateKeys(Transaction txn) throws DbException {
|
||||||
long now = clock.currentTimeMillis();
|
long now = clock.currentTimeMillis();
|
||||||
lock.lock();
|
lock.lock();
|
||||||
|
|||||||
@@ -109,8 +109,8 @@ public class PluginManagerImplTest extends BrambleTestCase {
|
|||||||
oneOf(duplexPlugin).stop();
|
oneOf(duplexPlugin).stop();
|
||||||
}});
|
}});
|
||||||
|
|
||||||
PluginManagerImpl p = new PluginManagerImpl(ioExecutor, eventBus,
|
PluginManagerImpl p = new PluginManagerImpl(ioExecutor, ioExecutor,
|
||||||
pluginConfig, connectionManager, settingsManager,
|
eventBus, pluginConfig, connectionManager, settingsManager,
|
||||||
transportPropertyManager);
|
transportPropertyManager);
|
||||||
|
|
||||||
// Two plugins should be started and stopped
|
// Two plugins should be started and stopped
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ public class PollerImplTest extends BrambleMockTestCase {
|
|||||||
private final Future<?> future = context.mock(Future.class);
|
private final Future<?> future = context.mock(Future.class);
|
||||||
private final SecureRandom random;
|
private final SecureRandom random;
|
||||||
|
|
||||||
|
private final Executor ioExecutor = new ImmediateExecutor();
|
||||||
private final Executor wakefulIoExecutor = new ImmediateExecutor();
|
private final Executor wakefulIoExecutor = new ImmediateExecutor();
|
||||||
private final TransportId transportId = getTransportId();
|
private final TransportId transportId = getTransportId();
|
||||||
private final ContactId contactId = getContactId();
|
private final ContactId contactId = getContactId();
|
||||||
@@ -74,9 +75,9 @@ public class PollerImplTest extends BrambleMockTestCase {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
poller = new PollerImpl(wakefulIoExecutor, scheduler, connectionManager,
|
poller = new PollerImpl(ioExecutor, wakefulIoExecutor, scheduler,
|
||||||
connectionRegistry, pluginManager, transportPropertyManager,
|
connectionManager, connectionRegistry, pluginManager,
|
||||||
random, clock);
|
transportPropertyManager, random, clock);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -234,7 +235,7 @@ public class PollerImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(clock).currentTimeMillis();
|
oneOf(clock).currentTimeMillis();
|
||||||
will(returnValue(now));
|
will(returnValue(now));
|
||||||
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
||||||
with(wakefulIoExecutor), with((long) pollingInterval),
|
with(ioExecutor), with((long) pollingInterval),
|
||||||
with(MILLISECONDS));
|
with(MILLISECONDS));
|
||||||
will(returnValue(future));
|
will(returnValue(future));
|
||||||
}});
|
}});
|
||||||
@@ -263,7 +264,7 @@ public class PollerImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(clock).currentTimeMillis();
|
oneOf(clock).currentTimeMillis();
|
||||||
will(returnValue(now));
|
will(returnValue(now));
|
||||||
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
||||||
with(wakefulIoExecutor), with((long) pollingInterval),
|
with(ioExecutor), with((long) pollingInterval),
|
||||||
with(MILLISECONDS));
|
with(MILLISECONDS));
|
||||||
will(returnValue(future));
|
will(returnValue(future));
|
||||||
// Second event
|
// Second event
|
||||||
@@ -306,7 +307,7 @@ public class PollerImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(clock).currentTimeMillis();
|
oneOf(clock).currentTimeMillis();
|
||||||
will(returnValue(now));
|
will(returnValue(now));
|
||||||
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
||||||
with(wakefulIoExecutor), with((long) pollingInterval),
|
with(ioExecutor), with((long) pollingInterval),
|
||||||
with(MILLISECONDS));
|
with(MILLISECONDS));
|
||||||
will(returnValue(future));
|
will(returnValue(future));
|
||||||
// Second event
|
// Second event
|
||||||
@@ -323,7 +324,7 @@ public class PollerImplTest extends BrambleMockTestCase {
|
|||||||
will(returnValue(now + 1));
|
will(returnValue(now + 1));
|
||||||
oneOf(future).cancel(false);
|
oneOf(future).cancel(false);
|
||||||
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
||||||
with(wakefulIoExecutor), with((long) pollingInterval - 2),
|
with(ioExecutor), with((long) pollingInterval - 2),
|
||||||
with(MILLISECONDS));
|
with(MILLISECONDS));
|
||||||
}});
|
}});
|
||||||
|
|
||||||
@@ -350,7 +351,7 @@ public class PollerImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(clock).currentTimeMillis();
|
oneOf(clock).currentTimeMillis();
|
||||||
will(returnValue(now));
|
will(returnValue(now));
|
||||||
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
||||||
with(wakefulIoExecutor), with(0L), with(MILLISECONDS));
|
with(ioExecutor), with(0L), with(MILLISECONDS));
|
||||||
will(returnValue(future));
|
will(returnValue(future));
|
||||||
will(new RunAction());
|
will(new RunAction());
|
||||||
// Running the polling task schedules the next polling task
|
// Running the polling task schedules the next polling task
|
||||||
@@ -361,7 +362,7 @@ public class PollerImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(clock).currentTimeMillis();
|
oneOf(clock).currentTimeMillis();
|
||||||
will(returnValue(now));
|
will(returnValue(now));
|
||||||
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
||||||
with(wakefulIoExecutor), with((long) (pollingInterval * 0.5)),
|
with(ioExecutor), with((long) (pollingInterval * 0.5)),
|
||||||
with(MILLISECONDS));
|
with(MILLISECONDS));
|
||||||
will(returnValue(future));
|
will(returnValue(future));
|
||||||
// Get the transport properties and connected contacts
|
// Get the transport properties and connected contacts
|
||||||
@@ -394,7 +395,7 @@ public class PollerImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(clock).currentTimeMillis();
|
oneOf(clock).currentTimeMillis();
|
||||||
will(returnValue(now));
|
will(returnValue(now));
|
||||||
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
||||||
with(wakefulIoExecutor), with(0L), with(MILLISECONDS));
|
with(ioExecutor), with(0L), with(MILLISECONDS));
|
||||||
will(returnValue(future));
|
will(returnValue(future));
|
||||||
will(new RunAction());
|
will(new RunAction());
|
||||||
// Running the polling task schedules the next polling task
|
// Running the polling task schedules the next polling task
|
||||||
@@ -405,7 +406,7 @@ public class PollerImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(clock).currentTimeMillis();
|
oneOf(clock).currentTimeMillis();
|
||||||
will(returnValue(now));
|
will(returnValue(now));
|
||||||
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
||||||
with(wakefulIoExecutor), with((long) (pollingInterval * 0.5)),
|
with(ioExecutor), with((long) (pollingInterval * 0.5)),
|
||||||
with(MILLISECONDS));
|
with(MILLISECONDS));
|
||||||
will(returnValue(future));
|
will(returnValue(future));
|
||||||
// Get the transport properties and connected contacts
|
// Get the transport properties and connected contacts
|
||||||
@@ -436,7 +437,7 @@ public class PollerImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(clock).currentTimeMillis();
|
oneOf(clock).currentTimeMillis();
|
||||||
will(returnValue(now));
|
will(returnValue(now));
|
||||||
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
||||||
with(wakefulIoExecutor), with(0L), with(MILLISECONDS));
|
with(ioExecutor), with(0L), with(MILLISECONDS));
|
||||||
will(returnValue(future));
|
will(returnValue(future));
|
||||||
// The plugin is deactivated before the task runs - cancel the task
|
// The plugin is deactivated before the task runs - cancel the task
|
||||||
oneOf(future).cancel(false);
|
oneOf(future).cancel(false);
|
||||||
@@ -460,7 +461,7 @@ public class PollerImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(clock).currentTimeMillis();
|
oneOf(clock).currentTimeMillis();
|
||||||
will(returnValue(now));
|
will(returnValue(now));
|
||||||
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
||||||
with(wakefulIoExecutor), with((long) pollingInterval),
|
with(ioExecutor), with((long) pollingInterval),
|
||||||
with(MILLISECONDS));
|
with(MILLISECONDS));
|
||||||
will(returnValue(future));
|
will(returnValue(future));
|
||||||
}});
|
}});
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
|||||||
import org.briarproject.bramble.api.plugin.PluginManager;
|
import org.briarproject.bramble.api.plugin.PluginManager;
|
||||||
import org.briarproject.bramble.api.settings.SettingsManager;
|
import org.briarproject.bramble.api.settings.SettingsManager;
|
||||||
import org.briarproject.bramble.api.system.AndroidExecutor;
|
import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||||
|
import org.briarproject.bramble.api.system.AndroidWakeLockManager;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.bramble.api.system.LocationUtils;
|
import org.briarproject.bramble.api.system.LocationUtils;
|
||||||
import org.briarproject.bramble.plugin.tor.CircumventionProvider;
|
import org.briarproject.bramble.plugin.tor.CircumventionProvider;
|
||||||
@@ -166,6 +167,8 @@ public interface AndroidComponent
|
|||||||
|
|
||||||
FeatureFlags featureFlags();
|
FeatureFlags featureFlags();
|
||||||
|
|
||||||
|
AndroidWakeLockManager wakeLockManager();
|
||||||
|
|
||||||
void inject(SignInReminderReceiver briarService);
|
void inject(SignInReminderReceiver briarService);
|
||||||
|
|
||||||
void inject(BriarService briarService);
|
void inject(BriarService briarService);
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import org.briarproject.bramble.api.crypto.SecretKey;
|
|||||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager.StartResult;
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager.StartResult;
|
||||||
import org.briarproject.bramble.api.system.AndroidExecutor;
|
import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||||
|
import org.briarproject.bramble.api.system.AndroidWakeLockManager;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.logout.HideUiActivity;
|
import org.briarproject.briar.android.logout.HideUiActivity;
|
||||||
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
||||||
@@ -48,6 +49,7 @@ import static java.util.logging.Level.INFO;
|
|||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static org.briarproject.bramble.api.lifecycle.LifecycleManager.StartResult.ALREADY_RUNNING;
|
import static org.briarproject.bramble.api.lifecycle.LifecycleManager.StartResult.ALREADY_RUNNING;
|
||||||
import static org.briarproject.bramble.api.lifecycle.LifecycleManager.StartResult.SUCCESS;
|
import static org.briarproject.bramble.api.lifecycle.LifecycleManager.StartResult.SUCCESS;
|
||||||
|
import static org.briarproject.bramble.api.nullsafety.NullSafety.requireNonNull;
|
||||||
import static org.briarproject.briar.android.BriarApplication.ENTRY_ACTIVITY;
|
import static org.briarproject.briar.android.BriarApplication.ENTRY_ACTIVITY;
|
||||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.FAILURE_CHANNEL_ID;
|
import static org.briarproject.briar.api.android.AndroidNotificationManager.FAILURE_CHANNEL_ID;
|
||||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.FAILURE_NOTIFICATION_ID;
|
import static org.briarproject.briar.api.android.AndroidNotificationManager.FAILURE_NOTIFICATION_ID;
|
||||||
@@ -80,6 +82,8 @@ public class BriarService extends Service {
|
|||||||
AccountManager accountManager;
|
AccountManager accountManager;
|
||||||
@Inject
|
@Inject
|
||||||
LockManager lockManager;
|
LockManager lockManager;
|
||||||
|
@Inject
|
||||||
|
AndroidWakeLockManager wakeLockManager;
|
||||||
|
|
||||||
// Fields that are accessed from background threads must be volatile
|
// Fields that are accessed from background threads must be volatile
|
||||||
@Inject
|
@Inject
|
||||||
@@ -108,54 +112,57 @@ public class BriarService extends Service {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create notification channels
|
// Hold a wake lock during startup
|
||||||
if (SDK_INT >= 26) {
|
wakeLockManager.runWakefully(() -> {
|
||||||
NotificationManager nm = (NotificationManager)
|
// Create notification channels
|
||||||
getSystemService(NOTIFICATION_SERVICE);
|
if (SDK_INT >= 26) {
|
||||||
NotificationChannel ongoingChannel = new NotificationChannel(
|
NotificationManager nm = (NotificationManager)
|
||||||
ONGOING_CHANNEL_ID,
|
requireNonNull(getSystemService(NOTIFICATION_SERVICE));
|
||||||
getString(R.string.ongoing_notification_title),
|
NotificationChannel ongoingChannel = new NotificationChannel(
|
||||||
IMPORTANCE_NONE);
|
ONGOING_CHANNEL_ID,
|
||||||
ongoingChannel.setLockscreenVisibility(VISIBILITY_SECRET);
|
getString(R.string.ongoing_notification_title),
|
||||||
nm.createNotificationChannel(ongoingChannel);
|
IMPORTANCE_NONE);
|
||||||
NotificationChannel failureChannel = new NotificationChannel(
|
ongoingChannel.setLockscreenVisibility(VISIBILITY_SECRET);
|
||||||
FAILURE_CHANNEL_ID,
|
nm.createNotificationChannel(ongoingChannel);
|
||||||
getString(R.string.startup_failed_notification_title),
|
NotificationChannel failureChannel = new NotificationChannel(
|
||||||
IMPORTANCE_DEFAULT);
|
FAILURE_CHANNEL_ID,
|
||||||
failureChannel.setLockscreenVisibility(VISIBILITY_SECRET);
|
getString(R.string.startup_failed_notification_title),
|
||||||
nm.createNotificationChannel(failureChannel);
|
IMPORTANCE_DEFAULT);
|
||||||
}
|
failureChannel.setLockscreenVisibility(VISIBILITY_SECRET);
|
||||||
Notification foregroundNotification =
|
nm.createNotificationChannel(failureChannel);
|
||||||
notificationManager.getForegroundNotification();
|
|
||||||
startForeground(ONGOING_NOTIFICATION_ID, foregroundNotification);
|
|
||||||
// Start the services in a background thread
|
|
||||||
new Thread(() -> {
|
|
||||||
StartResult result = lifecycleManager.startServices(dbKey);
|
|
||||||
if (result == SUCCESS) {
|
|
||||||
started = true;
|
|
||||||
} else if (result == ALREADY_RUNNING) {
|
|
||||||
LOG.info("Already running");
|
|
||||||
stopSelf();
|
|
||||||
} else {
|
|
||||||
if (LOG.isLoggable(WARNING))
|
|
||||||
LOG.warning("Startup failed: " + result);
|
|
||||||
showStartupFailureNotification(result);
|
|
||||||
stopSelf();
|
|
||||||
}
|
}
|
||||||
}).start();
|
Notification foregroundNotification =
|
||||||
// Register for device shutdown broadcasts
|
notificationManager.getForegroundNotification();
|
||||||
receiver = new BroadcastReceiver() {
|
startForeground(ONGOING_NOTIFICATION_ID, foregroundNotification);
|
||||||
@Override
|
// Start the services in a background thread
|
||||||
public void onReceive(Context context, Intent intent) {
|
wakeLockManager.executeWakefully(() -> {
|
||||||
LOG.info("Device is shutting down");
|
StartResult result = lifecycleManager.startServices(dbKey);
|
||||||
shutdownFromBackground();
|
if (result == SUCCESS) {
|
||||||
}
|
started = true;
|
||||||
};
|
} else if (result == ALREADY_RUNNING) {
|
||||||
IntentFilter filter = new IntentFilter();
|
LOG.info("Already running");
|
||||||
filter.addAction(ACTION_SHUTDOWN);
|
stopSelf();
|
||||||
filter.addAction("android.intent.action.QUICKBOOT_POWEROFF");
|
} else {
|
||||||
filter.addAction("com.htc.intent.action.QUICKBOOT_POWEROFF");
|
if (LOG.isLoggable(WARNING))
|
||||||
registerReceiver(receiver, filter);
|
LOG.warning("Startup failed: " + result);
|
||||||
|
showStartupFailureNotification(result);
|
||||||
|
stopSelf();
|
||||||
|
}
|
||||||
|
}, "LifecycleStartup");
|
||||||
|
// 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);
|
||||||
|
}, "LifecycleStartup");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -179,8 +186,8 @@ public class BriarService extends Service {
|
|||||||
i.putExtra(EXTRA_NOTIFICATION_ID, FAILURE_NOTIFICATION_ID);
|
i.putExtra(EXTRA_NOTIFICATION_ID, FAILURE_NOTIFICATION_ID);
|
||||||
b.setContentIntent(PendingIntent.getActivity(BriarService.this,
|
b.setContentIntent(PendingIntent.getActivity(BriarService.this,
|
||||||
0, i, FLAG_UPDATE_CURRENT));
|
0, i, FLAG_UPDATE_CURRENT));
|
||||||
Object o = getSystemService(NOTIFICATION_SERVICE);
|
NotificationManager nm = (NotificationManager)
|
||||||
NotificationManager nm = (NotificationManager) o;
|
requireNonNull(getSystemService(NOTIFICATION_SERVICE));
|
||||||
nm.notify(FAILURE_NOTIFICATION_ID, b.build());
|
nm.notify(FAILURE_NOTIFICATION_ID, b.build());
|
||||||
// Bring the dashboard to the front to clear the back stack
|
// Bring the dashboard to the front to clear the back stack
|
||||||
i = new Intent(BriarService.this, ENTRY_ACTIVITY);
|
i = new Intent(BriarService.this, ENTRY_ACTIVITY);
|
||||||
@@ -205,14 +212,17 @@ public class BriarService extends Service {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
super.onDestroy();
|
// Hold a wake lock during shutdown
|
||||||
LOG.info("Destroyed");
|
wakeLockManager.runWakefully(() -> {
|
||||||
stopForeground(true);
|
super.onDestroy();
|
||||||
if (receiver != null) unregisterReceiver(receiver);
|
LOG.info("Destroyed");
|
||||||
// Stop the services in a background thread
|
stopForeground(true);
|
||||||
new Thread(() -> {
|
if (receiver != null) unregisterReceiver(receiver);
|
||||||
if (started) lifecycleManager.stopServices();
|
// Stop the services in a background thread
|
||||||
}).start();
|
wakeLockManager.executeWakefully(() -> {
|
||||||
|
if (started) lifecycleManager.stopServices();
|
||||||
|
}, "LifecycleShutdown");
|
||||||
|
}, "LifecycleShutdown");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -257,20 +267,23 @@ public class BriarService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void shutdownFromBackground() {
|
private void shutdownFromBackground() {
|
||||||
// Stop the service
|
// Hold a wake lock during shutdown
|
||||||
stopSelf();
|
wakeLockManager.runWakefully(() -> {
|
||||||
// Hide the UI
|
// Stop the service
|
||||||
hideUi();
|
stopSelf();
|
||||||
// Wait for shutdown to complete, then exit
|
// Hide the UI
|
||||||
new Thread(() -> {
|
hideUi();
|
||||||
try {
|
// Wait for shutdown to complete, then exit
|
||||||
if (started) lifecycleManager.waitForShutdown();
|
wakeLockManager.executeWakefully(() -> {
|
||||||
} catch (InterruptedException e) {
|
try {
|
||||||
LOG.info("Interrupted while waiting for shutdown");
|
if (started) lifecycleManager.waitForShutdown();
|
||||||
}
|
} catch (InterruptedException e) {
|
||||||
LOG.info("Exiting");
|
LOG.info("Interrupted while waiting for shutdown");
|
||||||
System.exit(0);
|
}
|
||||||
}).start();
|
LOG.info("Exiting");
|
||||||
|
System.exit(0);
|
||||||
|
}, "BackgroundShutdown");
|
||||||
|
}, "BackgroundShutdown");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -82,13 +82,19 @@ import org.briarproject.briar.android.test.TestDataActivity;
|
|||||||
import dagger.Component;
|
import dagger.Component;
|
||||||
|
|
||||||
@ActivityScope
|
@ActivityScope
|
||||||
@Component(
|
@Component(modules = {
|
||||||
modules = {ActivityModule.class, ForumModule.class, SharingModule.class,
|
ActivityModule.class,
|
||||||
BlogModule.class, ContactModule.class, GroupListModule.class,
|
BlogModule.class,
|
||||||
CreateGroupModule.class, GroupInvitationModule.class,
|
ContactModule.class,
|
||||||
GroupConversationModule.class, GroupMemberModule.class,
|
CreateGroupModule.class,
|
||||||
GroupRevealModule.class},
|
ForumModule.class,
|
||||||
dependencies = AndroidComponent.class)
|
GroupInvitationModule.class,
|
||||||
|
GroupConversationModule.class,
|
||||||
|
GroupListModule.class,
|
||||||
|
GroupMemberModule.class,
|
||||||
|
GroupRevealModule.class,
|
||||||
|
SharingModule.class
|
||||||
|
}, dependencies = AndroidComponent.class)
|
||||||
public interface ActivityComponent {
|
public interface ActivityComponent {
|
||||||
|
|
||||||
Activity activity();
|
Activity activity();
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import android.widget.CheckBox;
|
|||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.system.AndroidWakeLockManager;
|
||||||
|
import org.briarproject.bramble.api.system.Wakeful;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.account.UnlockActivity;
|
import org.briarproject.briar.android.account.UnlockActivity;
|
||||||
import org.briarproject.briar.android.controller.BriarController;
|
import org.briarproject.briar.android.controller.BriarController;
|
||||||
@@ -32,6 +34,7 @@ import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
|
|||||||
import static android.content.Intent.FLAG_ACTIVITY_NO_ANIMATION;
|
import static android.content.Intent.FLAG_ACTIVITY_NO_ANIMATION;
|
||||||
import static android.os.Build.VERSION.SDK_INT;
|
import static android.os.Build.VERSION.SDK_INT;
|
||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
|
import static java.util.logging.Logger.getLogger;
|
||||||
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_DOZE_WHITELISTING;
|
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_DOZE_WHITELISTING;
|
||||||
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_PASSWORD;
|
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_PASSWORD;
|
||||||
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_UNLOCK;
|
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_UNLOCK;
|
||||||
@@ -47,7 +50,7 @@ public abstract class BriarActivity extends BaseActivity {
|
|||||||
public static final String GROUP_NAME = "briar.GROUP_NAME";
|
public static final String GROUP_NAME = "briar.GROUP_NAME";
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(BriarActivity.class.getName());
|
getLogger(BriarActivity.class.getName());
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
BriarController briarController;
|
BriarController briarController;
|
||||||
@@ -56,6 +59,8 @@ public abstract class BriarActivity extends BaseActivity {
|
|||||||
DbController dbController;
|
DbController dbController;
|
||||||
@Inject
|
@Inject
|
||||||
protected LockManager lockManager;
|
protected LockManager lockManager;
|
||||||
|
@Inject
|
||||||
|
AndroidWakeLockManager wakeLockManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
@@ -130,6 +135,7 @@ public abstract class BriarActivity extends BaseActivity {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the transition animations.
|
* Sets the transition animations.
|
||||||
|
*
|
||||||
* @param enterTransition used to move views into initial positions
|
* @param enterTransition used to move views into initial positions
|
||||||
* @param exitTransition used to move views out when starting a <b>new</b> activity.
|
* @param exitTransition used to move views out when starting a <b>new</b> activity.
|
||||||
* @param returnTransition used when window is closing, because the activity is finishing.
|
* @param returnTransition used when window is closing, because the activity is finishing.
|
||||||
@@ -197,22 +203,30 @@ public abstract class BriarActivity extends BaseActivity {
|
|||||||
|
|
||||||
protected void signOut(boolean removeFromRecentApps,
|
protected void signOut(boolean removeFromRecentApps,
|
||||||
boolean deleteAccount) {
|
boolean deleteAccount) {
|
||||||
if (briarController.accountSignedIn()) {
|
// Hold a wake lock to ensure we exit before the device goes to sleep
|
||||||
// Don't use UiResultHandler because we want the result even if
|
wakeLockManager.runWakefully(() -> {
|
||||||
// this activity has been destroyed
|
if (briarController.accountSignedIn()) {
|
||||||
briarController.signOut(result -> runOnUiThread(
|
// Don't use UiResultHandler because we want the result even if
|
||||||
() -> exit(removeFromRecentApps)), deleteAccount);
|
// this activity has been destroyed
|
||||||
} else {
|
briarController.signOut(result -> {
|
||||||
if (deleteAccount) briarController.deleteAccount();
|
Runnable exit = () -> exit(removeFromRecentApps);
|
||||||
exit(removeFromRecentApps);
|
wakeLockManager.executeWakefully(exit,
|
||||||
}
|
this::runOnUiThread, "SignOut");
|
||||||
|
}, deleteAccount);
|
||||||
|
} else {
|
||||||
|
if (deleteAccount) briarController.deleteAccount();
|
||||||
|
exit(removeFromRecentApps);
|
||||||
|
}
|
||||||
|
}, "SignOut");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Wakeful
|
||||||
private void exit(boolean removeFromRecentApps) {
|
private void exit(boolean removeFromRecentApps) {
|
||||||
if (removeFromRecentApps) startExitActivity();
|
if (removeFromRecentApps) startExitActivity();
|
||||||
else finishAndExit();
|
else finishAndExit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Wakeful
|
||||||
private void startExitActivity() {
|
private void startExitActivity() {
|
||||||
Intent i = new Intent(this, ExitActivity.class);
|
Intent i = new Intent(this, ExitActivity.class);
|
||||||
i.addFlags(FLAG_ACTIVITY_NEW_TASK
|
i.addFlags(FLAG_ACTIVITY_NEW_TASK
|
||||||
@@ -222,6 +236,7 @@ public abstract class BriarActivity extends BaseActivity {
|
|||||||
startActivity(i);
|
startActivity(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Wakeful
|
||||||
private void finishAndExit() {
|
private void finishAndExit() {
|
||||||
if (SDK_INT >= 21) finishAndRemoveTask();
|
if (SDK_INT >= 21) finishAndRemoveTask();
|
||||||
else supportFinishAfterTransition();
|
else supportFinishAfterTransition();
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
package org.briarproject.briar.android.controller;
|
package org.briarproject.briar.android.controller;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.system.Wakeful;
|
||||||
import org.briarproject.briar.android.controller.handler.ResultHandler;
|
import org.briarproject.briar.android.controller.handler.ResultHandler;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
public interface BriarController extends ActivityLifecycleController {
|
public interface BriarController extends ActivityLifecycleController {
|
||||||
|
|
||||||
void startAndBindService();
|
void startAndBindService();
|
||||||
@@ -16,7 +19,8 @@ public interface BriarController extends ActivityLifecycleController {
|
|||||||
|
|
||||||
void doNotAskAgainForDozeWhiteListing();
|
void doNotAskAgainForDozeWhiteListing();
|
||||||
|
|
||||||
void signOut(ResultHandler<Void> eventHandler, boolean deleteAccount);
|
@Wakeful
|
||||||
|
void signOut(ResultHandler<Void> handler, boolean deleteAccount);
|
||||||
|
|
||||||
void deleteAccount();
|
void deleteAccount();
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,10 @@ import org.briarproject.bramble.api.account.AccountManager;
|
|||||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.settings.Settings;
|
import org.briarproject.bramble.api.settings.Settings;
|
||||||
import org.briarproject.bramble.api.settings.SettingsManager;
|
import org.briarproject.bramble.api.settings.SettingsManager;
|
||||||
|
import org.briarproject.bramble.api.system.AndroidWakeLockManager;
|
||||||
import org.briarproject.briar.android.BriarService;
|
import org.briarproject.briar.android.BriarService;
|
||||||
import org.briarproject.briar.android.BriarService.BriarServiceConnection;
|
import org.briarproject.briar.android.BriarService.BriarServiceConnection;
|
||||||
import org.briarproject.briar.android.controller.handler.ResultHandler;
|
import org.briarproject.briar.android.controller.handler.ResultHandler;
|
||||||
@@ -23,15 +25,17 @@ import javax.inject.Inject;
|
|||||||
import androidx.annotation.CallSuper;
|
import androidx.annotation.CallSuper;
|
||||||
|
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
|
import static java.util.logging.Logger.getLogger;
|
||||||
import static org.briarproject.bramble.api.lifecycle.LifecycleManager.LifecycleState.STARTING_SERVICES;
|
import static org.briarproject.bramble.api.lifecycle.LifecycleManager.LifecycleState.STARTING_SERVICES;
|
||||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
import static org.briarproject.briar.android.settings.SettingsFragment.SETTINGS_NAMESPACE;
|
import static org.briarproject.briar.android.settings.SettingsFragment.SETTINGS_NAMESPACE;
|
||||||
import static org.briarproject.briar.android.util.UiUtils.needsDozeWhitelisting;
|
import static org.briarproject.briar.android.util.UiUtils.needsDozeWhitelisting;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
public class BriarControllerImpl implements BriarController {
|
public class BriarControllerImpl implements BriarController {
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(BriarControllerImpl.class.getName());
|
getLogger(BriarControllerImpl.class.getName());
|
||||||
|
|
||||||
public static final String DOZE_ASK_AGAIN = "dozeAskAgain";
|
public static final String DOZE_ASK_AGAIN = "dozeAskAgain";
|
||||||
|
|
||||||
@@ -41,6 +45,7 @@ public class BriarControllerImpl implements BriarController {
|
|||||||
private final Executor databaseExecutor;
|
private final Executor databaseExecutor;
|
||||||
private final SettingsManager settingsManager;
|
private final SettingsManager settingsManager;
|
||||||
private final DozeWatchdog dozeWatchdog;
|
private final DozeWatchdog dozeWatchdog;
|
||||||
|
private final AndroidWakeLockManager wakeLockManager;
|
||||||
private final Activity activity;
|
private final Activity activity;
|
||||||
|
|
||||||
private boolean bound = false;
|
private boolean bound = false;
|
||||||
@@ -50,7 +55,9 @@ public class BriarControllerImpl implements BriarController {
|
|||||||
AccountManager accountManager,
|
AccountManager accountManager,
|
||||||
LifecycleManager lifecycleManager,
|
LifecycleManager lifecycleManager,
|
||||||
@DatabaseExecutor Executor databaseExecutor,
|
@DatabaseExecutor Executor databaseExecutor,
|
||||||
SettingsManager settingsManager, DozeWatchdog dozeWatchdog,
|
SettingsManager settingsManager,
|
||||||
|
DozeWatchdog dozeWatchdog,
|
||||||
|
AndroidWakeLockManager wakeLockManager,
|
||||||
Activity activity) {
|
Activity activity) {
|
||||||
this.serviceConnection = serviceConnection;
|
this.serviceConnection = serviceConnection;
|
||||||
this.accountManager = accountManager;
|
this.accountManager = accountManager;
|
||||||
@@ -58,6 +65,7 @@ public class BriarControllerImpl implements BriarController {
|
|||||||
this.databaseExecutor = databaseExecutor;
|
this.databaseExecutor = databaseExecutor;
|
||||||
this.settingsManager = settingsManager;
|
this.settingsManager = settingsManager;
|
||||||
this.dozeWatchdog = dozeWatchdog;
|
this.dozeWatchdog = dozeWatchdog;
|
||||||
|
this.wakeLockManager = wakeLockManager;
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,9 +135,8 @@ public class BriarControllerImpl implements BriarController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void signOut(ResultHandler<Void> eventHandler,
|
public void signOut(ResultHandler<Void> handler, boolean deleteAccount) {
|
||||||
boolean deleteAccount) {
|
wakeLockManager.executeWakefully(() -> {
|
||||||
new Thread(() -> {
|
|
||||||
try {
|
try {
|
||||||
// Wait for the service to finish starting up
|
// Wait for the service to finish starting up
|
||||||
IBinder binder = serviceConnection.waitForBinder();
|
IBinder binder = serviceConnection.waitForBinder();
|
||||||
@@ -145,8 +152,8 @@ public class BriarControllerImpl implements BriarController {
|
|||||||
} finally {
|
} finally {
|
||||||
if (deleteAccount) accountManager.deleteAccount();
|
if (deleteAccount) accountManager.deleteAccount();
|
||||||
}
|
}
|
||||||
eventHandler.onResult(null);
|
handler.onResult(null);
|
||||||
}).start();
|
}, "SignOut");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -4,17 +4,14 @@ import android.content.Intent;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
|
||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.system.AndroidExecutor;
|
|
||||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||||
import org.briarproject.briar.android.activity.BriarActivity;
|
import org.briarproject.briar.android.activity.BriarActivity;
|
||||||
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import androidx.preference.PreferenceManager;
|
import androidx.preference.PreferenceManager;
|
||||||
import info.guardianproject.GuardianProjectRSA4096;
|
import info.guardianproject.GuardianProjectRSA4096;
|
||||||
@@ -23,6 +20,7 @@ import info.guardianproject.panic.PanicResponder;
|
|||||||
import info.guardianproject.trustedintents.TrustedIntents;
|
import info.guardianproject.trustedintents.TrustedIntents;
|
||||||
|
|
||||||
import static android.os.Build.VERSION.SDK_INT;
|
import static android.os.Build.VERSION.SDK_INT;
|
||||||
|
import static java.util.logging.Logger.getLogger;
|
||||||
import static org.briarproject.briar.android.panic.PanicPreferencesFragment.KEY_LOCK;
|
import static org.briarproject.briar.android.panic.PanicPreferencesFragment.KEY_LOCK;
|
||||||
import static org.briarproject.briar.android.panic.PanicPreferencesFragment.KEY_PURGE;
|
import static org.briarproject.briar.android.panic.PanicPreferencesFragment.KEY_PURGE;
|
||||||
|
|
||||||
@@ -31,12 +29,7 @@ import static org.briarproject.briar.android.panic.PanicPreferencesFragment.KEY_
|
|||||||
public class PanicResponderActivity extends BriarActivity {
|
public class PanicResponderActivity extends BriarActivity {
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(PanicResponderActivity.class.getName());
|
getLogger(PanicResponderActivity.class.getName());
|
||||||
|
|
||||||
@Inject
|
|
||||||
protected LifecycleManager lifecycleManager;
|
|
||||||
@Inject
|
|
||||||
protected AndroidExecutor androidExecutor;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
@@ -63,13 +56,20 @@ public class PanicResponderActivity extends BriarActivity {
|
|||||||
// Performing panic responses
|
// Performing panic responses
|
||||||
if (sharedPref.getBoolean(KEY_PURGE, false)) {
|
if (sharedPref.getBoolean(KEY_PURGE, false)) {
|
||||||
LOG.info("Purging all data...");
|
LOG.info("Purging all data...");
|
||||||
deleteAllData();
|
signOut(true, true);
|
||||||
|
} else if (sharedPref.getBoolean(KEY_LOCK, true)) {
|
||||||
|
LOG.info("Signing out...");
|
||||||
|
signOut(true, false);
|
||||||
|
} else {
|
||||||
|
LOG.info("Configured not to purge or lock");
|
||||||
}
|
}
|
||||||
}
|
} else if (sharedPref.getBoolean(KEY_LOCK, true)) {
|
||||||
// non-destructive actions are allowed by non-connected trusted apps
|
// non-destructive actions are allowed by non-connected
|
||||||
if (sharedPref.getBoolean(KEY_LOCK, true)) {
|
// trusted apps
|
||||||
LOG.info("Signing out...");
|
LOG.info("Signing out...");
|
||||||
signOut(true, false);
|
signOut(true, false);
|
||||||
|
} else {
|
||||||
|
LOG.info("Configured not to lock");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -85,11 +85,4 @@ public class PanicResponderActivity extends BriarActivity {
|
|||||||
public void injectActivity(ActivityComponent component) {
|
public void injectActivity(ActivityComponent component) {
|
||||||
component.inject(this);
|
component.inject(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteAllData() {
|
|
||||||
androidExecutor.runOnBackgroundThread(() -> {
|
|
||||||
LOG.info("Signing out...");
|
|
||||||
signOut(true, true);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import org.briarproject.bramble.api.sync.Group;
|
|||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.bramble.api.system.TaskScheduler;
|
import org.briarproject.bramble.api.system.TaskScheduler;
|
||||||
|
import org.briarproject.bramble.api.system.Wakeful;
|
||||||
import org.briarproject.bramble.util.StringUtils;
|
import org.briarproject.bramble.util.StringUtils;
|
||||||
import org.briarproject.briar.api.blog.Blog;
|
import org.briarproject.briar.api.blog.Blog;
|
||||||
import org.briarproject.briar.api.blog.BlogManager;
|
import org.briarproject.briar.api.blog.BlogManager;
|
||||||
@@ -284,7 +285,7 @@ class FeedManagerImpl implements FeedManager, EventListener, OpenDatabaseHook,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is called periodically from a background service.
|
* This method is called periodically by the task scheduler.
|
||||||
* It fetches all available feeds and posts new entries to the respective
|
* It fetches all available feeds and posts new entries to the respective
|
||||||
* blog.
|
* blog.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -292,6 +293,7 @@ class FeedManagerImpl implements FeedManager, EventListener, OpenDatabaseHook,
|
|||||||
* because fetching can take a long time
|
* because fetching can take a long time
|
||||||
* and we can not block the database that long.
|
* and we can not block the database that long.
|
||||||
*/
|
*/
|
||||||
|
@Wakeful
|
||||||
void fetchFeeds() {
|
void fetchFeeds() {
|
||||||
if (!torActive) return;
|
if (!torActive) return;
|
||||||
LOG.info("Updating RSS feeds...");
|
LOG.info("Updating RSS feeds...");
|
||||||
|
|||||||
Reference in New Issue
Block a user