Hold wake lock while polling.

This commit is contained in:
akwizgran
2020-08-06 15:54:23 +01:00
parent b5341700be
commit 086c10abc0
24 changed files with 239 additions and 118 deletions

View File

@@ -79,6 +79,7 @@ class AndroidBluetoothPlugin
AndroidBluetoothPlugin(BluetoothConnectionLimiter connectionLimiter,
BluetoothConnectionFactory<BluetoothSocket> connectionFactory,
Executor ioExecutor,
Executor wakefulIoExecutor,
SecureRandom secureRandom,
AndroidExecutor androidExecutor,
Context appContext,
@@ -87,8 +88,9 @@ class AndroidBluetoothPlugin
PluginCallback callback,
int maxLatency,
int maxIdleTime) {
super(connectionLimiter, connectionFactory, ioExecutor, secureRandom,
backoff, callback, maxLatency, maxIdleTime);
super(connectionLimiter, connectionFactory, ioExecutor,
wakefulIoExecutor, secureRandom, backoff, callback,
maxLatency, maxIdleTime);
this.androidExecutor = androidExecutor;
this.appContext = appContext;
this.clock = clock;

View File

@@ -33,7 +33,7 @@ public class AndroidBluetoothPluginFactory implements DuplexPluginFactory {
private static final int MAX_POLLING_INTERVAL = 10 * 60 * 1000; // 10 mins
private static final double BACKOFF_BASE = 1.2;
private final Executor ioExecutor;
private final Executor ioExecutor, wakefulIoExecutor;
private final AndroidExecutor androidExecutor;
private final AndroidWakeLockManager wakeLockManager;
private final Context appContext;
@@ -44,6 +44,7 @@ public class AndroidBluetoothPluginFactory implements DuplexPluginFactory {
private final BackoffFactory backoffFactory;
public AndroidBluetoothPluginFactory(Executor ioExecutor,
Executor wakefulIoExecutor,
AndroidExecutor androidExecutor,
AndroidWakeLockManager wakeLockManager,
Context appContext,
@@ -53,6 +54,7 @@ public class AndroidBluetoothPluginFactory implements DuplexPluginFactory {
TimeoutMonitor timeoutMonitor,
BackoffFactory backoffFactory) {
this.ioExecutor = ioExecutor;
this.wakefulIoExecutor = wakefulIoExecutor;
this.androidExecutor = androidExecutor;
this.wakeLockManager = wakeLockManager;
this.appContext = appContext;
@@ -83,9 +85,9 @@ public class AndroidBluetoothPluginFactory implements DuplexPluginFactory {
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
MAX_POLLING_INTERVAL, BACKOFF_BASE);
AndroidBluetoothPlugin plugin = new AndroidBluetoothPlugin(
connectionLimiter, connectionFactory, ioExecutor, secureRandom,
androidExecutor, appContext, clock, backoff, callback,
MAX_LATENCY, MAX_IDLE_TIME);
connectionLimiter, connectionFactory, ioExecutor,
wakefulIoExecutor, secureRandom, androidExecutor, appContext,
clock, backoff, callback, MAX_LATENCY, MAX_IDLE_TIME);
eventBus.addListener(plugin);
return plugin;
}

View File

@@ -61,11 +61,16 @@ class AndroidLanTcpPlugin extends LanTcpPlugin {
private volatile SocketFactory socketFactory;
AndroidLanTcpPlugin(Executor ioExecutor, Context appContext,
Backoff backoff, PluginCallback callback, int maxLatency,
int maxIdleTime, int connectionTimeout) {
super(ioExecutor, backoff, callback, maxLatency, maxIdleTime,
connectionTimeout);
AndroidLanTcpPlugin(Executor ioExecutor,
Executor wakefulIoExecutor,
Context appContext,
Backoff backoff,
PluginCallback callback,
int maxLatency,
int maxIdleTime,
int connectionTimeout) {
super(ioExecutor, wakefulIoExecutor, backoff, callback, maxLatency,
maxIdleTime, connectionTimeout);
// Don't execute more than one connection status check at a time
connectionStatusExecutor =
new PoliteExecutor("AndroidLanTcpPlugin", ioExecutor, 1);

View File

@@ -28,14 +28,18 @@ public class AndroidLanTcpPluginFactory implements DuplexPluginFactory {
private static final int MAX_POLLING_INTERVAL = 600_000; // 10 mins
private static final double BACKOFF_BASE = 1.2;
private final Executor ioExecutor;
private final Executor ioExecutor, wakefulIoExecutor;
private final EventBus eventBus;
private final BackoffFactory backoffFactory;
private final Context appContext;
public AndroidLanTcpPluginFactory(Executor ioExecutor, EventBus eventBus,
BackoffFactory backoffFactory, Context appContext) {
public AndroidLanTcpPluginFactory(Executor ioExecutor,
Executor wakefulIoExecutor,
EventBus eventBus,
BackoffFactory backoffFactory,
Context appContext) {
this.ioExecutor = ioExecutor;
this.wakefulIoExecutor = wakefulIoExecutor;
this.eventBus = eventBus;
this.backoffFactory = backoffFactory;
this.appContext = appContext;
@@ -56,8 +60,8 @@ public class AndroidLanTcpPluginFactory implements DuplexPluginFactory {
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
MAX_POLLING_INTERVAL, BACKOFF_BASE);
AndroidLanTcpPlugin plugin = new AndroidLanTcpPlugin(ioExecutor,
appContext, backoff, callback, MAX_LATENCY, MAX_IDLE_TIME,
CONNECTION_TIMEOUT);
wakefulIoExecutor, appContext, backoff, callback,
MAX_LATENCY, MAX_IDLE_TIME, CONNECTION_TIMEOUT);
eventBus.addListener(plugin);
return plugin;
}

View File

@@ -32,6 +32,7 @@ class AndroidTorPlugin extends TorPlugin {
private final AndroidWakeLock wakeLock;
AndroidTorPlugin(Executor ioExecutor,
Executor wakefulIoExecutor,
Context appContext,
NetworkManager networkManager,
LocationUtils locationUtils,
@@ -47,11 +48,11 @@ class AndroidTorPlugin extends TorPlugin {
String architecture,
int maxLatency,
int maxIdleTime) {
super(ioExecutor, networkManager, locationUtils, torSocketFactory,
clock, resourceProvider, circumventionProvider, batteryManager,
backoff, torRendezvousCrypto, callback, architecture,
maxLatency, maxIdleTime,
appContext.getDir("tor", MODE_PRIVATE));
super(ioExecutor, wakefulIoExecutor, networkManager, locationUtils,
torSocketFactory, clock, resourceProvider,
circumventionProvider, batteryManager, backoff,
torRendezvousCrypto, callback, architecture, maxLatency,
maxIdleTime, appContext.getDir("tor", MODE_PRIVATE));
this.appContext = appContext;
wakeLock = wakeLockManager.createWakeLock("TorPlugin");
}

View File

@@ -38,7 +38,7 @@ public class AndroidTorPluginFactory implements DuplexPluginFactory {
private static final int MAX_POLLING_INTERVAL = 10 * 60 * 1000; // 10 mins
private static final double BACKOFF_BASE = 1.2;
private final Executor ioExecutor;
private final Executor ioExecutor, wakefulIoExecutor;
private final Context appContext;
private final NetworkManager networkManager;
private final LocationUtils locationUtils;
@@ -52,6 +52,7 @@ public class AndroidTorPluginFactory implements DuplexPluginFactory {
private final Clock clock;
public AndroidTorPluginFactory(Executor ioExecutor,
Executor wakefulIoExecutor,
Context appContext,
NetworkManager networkManager,
LocationUtils locationUtils,
@@ -64,6 +65,7 @@ public class AndroidTorPluginFactory implements DuplexPluginFactory {
AndroidWakeLockManager wakeLockManager,
Clock clock) {
this.ioExecutor = ioExecutor;
this.wakefulIoExecutor = wakefulIoExecutor;
this.appContext = appContext;
this.networkManager = networkManager;
this.locationUtils = locationUtils;
@@ -118,10 +120,11 @@ public class AndroidTorPluginFactory implements DuplexPluginFactory {
MAX_POLLING_INTERVAL, BACKOFF_BASE);
TorRendezvousCrypto torRendezvousCrypto = new TorRendezvousCryptoImpl();
AndroidTorPlugin plugin = new AndroidTorPlugin(ioExecutor,
appContext, networkManager, locationUtils, torSocketFactory,
clock, resourceProvider, circumventionProvider, batteryManager,
wakeLockManager, backoff, torRendezvousCrypto, callback,
architecture, MAX_LATENCY, MAX_IDLE_TIME);
wakefulIoExecutor, appContext, networkManager, locationUtils,
torSocketFactory, clock, resourceProvider,
circumventionProvider, batteryManager, wakeLockManager,
backoff, torRendezvousCrypto, callback, architecture,
MAX_LATENCY, MAX_IDLE_TIME);
eventBus.addListener(plugin);
return plugin;
}