mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-23 08:09:54 +01:00
Use a constant to enable the control condition.
This commit is contained in:
@@ -0,0 +1,8 @@
|
|||||||
|
package org.briarproject.bramble;
|
||||||
|
|
||||||
|
public interface PowerTestingConstants {
|
||||||
|
|
||||||
|
int WAKE_LOCK_DURATION = 5000;
|
||||||
|
int ALARM_DELAY = 5000;
|
||||||
|
boolean USE_TOR_WAKE_LOCK = true;
|
||||||
|
}
|
||||||
@@ -85,6 +85,7 @@ import static java.util.logging.Level.INFO;
|
|||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static net.freehaven.tor.control.TorControlCommands.HS_ADDRESS;
|
import static net.freehaven.tor.control.TorControlCommands.HS_ADDRESS;
|
||||||
import static net.freehaven.tor.control.TorControlCommands.HS_PRIVKEY;
|
import static net.freehaven.tor.control.TorControlCommands.HS_PRIVKEY;
|
||||||
|
import static org.briarproject.bramble.PowerTestingConstants.USE_TOR_WAKE_LOCK;
|
||||||
import static org.briarproject.bramble.api.plugin.TorConstants.CONTROL_PORT;
|
import static org.briarproject.bramble.api.plugin.TorConstants.CONTROL_PORT;
|
||||||
import static org.briarproject.bramble.api.plugin.TorConstants.ID;
|
import static org.briarproject.bramble.api.plugin.TorConstants.ID;
|
||||||
import static org.briarproject.bramble.api.plugin.TorConstants.PREF_TOR_NETWORK;
|
import static org.briarproject.bramble.api.plugin.TorConstants.PREF_TOR_NETWORK;
|
||||||
@@ -126,7 +127,7 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
private final ConnectionStatus connectionStatus;
|
private final ConnectionStatus connectionStatus;
|
||||||
private final File torDirectory, torFile, geoIpFile, configFile;
|
private final File torDirectory, torFile, geoIpFile, configFile;
|
||||||
private final File doneFile, cookieFile;
|
private final File doneFile, cookieFile;
|
||||||
//private final RenewableWakeLock wakeLock;
|
private final RenewableWakeLock wakeLock;
|
||||||
private final AtomicReference<Future<?>> connectivityCheck =
|
private final AtomicReference<Future<?>> connectivityCheck =
|
||||||
new AtomicReference<>();
|
new AtomicReference<>();
|
||||||
private final AtomicBoolean used = new AtomicBoolean(false);
|
private final AtomicBoolean used = new AtomicBoolean(false);
|
||||||
@@ -169,8 +170,8 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
ioExecutor, 1);
|
ioExecutor, 1);
|
||||||
PowerManager pm = (PowerManager)
|
PowerManager pm = (PowerManager)
|
||||||
appContext.getSystemService(POWER_SERVICE);
|
appContext.getSystemService(POWER_SERVICE);
|
||||||
//wakeLock = new RenewableWakeLock(pm, scheduler, PARTIAL_WAKE_LOCK,
|
wakeLock = new RenewableWakeLock(pm, scheduler, PARTIAL_WAKE_LOCK,
|
||||||
// WAKE_LOCK_TAG, 1, MINUTES);
|
WAKE_LOCK_TAG, 1, MINUTES);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -493,12 +494,12 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
|
|
||||||
private void enableNetwork(boolean enable) throws IOException {
|
private void enableNetwork(boolean enable) throws IOException {
|
||||||
if (!running) return;
|
if (!running) return;
|
||||||
//if (enable) wakeLock.acquire();
|
if (enable && USE_TOR_WAKE_LOCK) wakeLock.acquire();
|
||||||
connectionStatus.enableNetwork(enable);
|
connectionStatus.enableNetwork(enable);
|
||||||
controlConnection.setConf("DisableNetwork", enable ? "0" : "1");
|
controlConnection.setConf("DisableNetwork", enable ? "0" : "1");
|
||||||
if (!enable) {
|
if (!enable) {
|
||||||
callback.transportDisabled();
|
callback.transportDisabled();
|
||||||
// wakeLock.release();
|
if (USE_TOR_WAKE_LOCK) wakeLock.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -529,7 +530,7 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
logException(LOG, WARNING, e);
|
logException(LOG, WARNING, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//wakeLock.release();
|
if (USE_TOR_WAKE_LOCK) wakeLock.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -57,12 +57,11 @@ import static android.support.v4.app.NotificationCompat.PRIORITY_MIN;
|
|||||||
import static android.support.v4.app.NotificationCompat.VISIBILITY_SECRET;
|
import static android.support.v4.app.NotificationCompat.VISIBILITY_SECRET;
|
||||||
import static java.util.logging.Level.INFO;
|
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.PowerTestingConstants.ALARM_DELAY;
|
||||||
|
import static org.briarproject.bramble.PowerTestingConstants.USE_TOR_WAKE_LOCK;
|
||||||
|
import static org.briarproject.bramble.PowerTestingConstants.WAKE_LOCK_DURATION;
|
||||||
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.briar.android.TestingConstants.ACTION_ALARM;
|
|
||||||
import static org.briarproject.briar.android.TestingConstants.ALARM_DELAY;
|
|
||||||
import static org.briarproject.briar.android.TestingConstants.EXTRA_DUE_MILLIS;
|
|
||||||
import static org.briarproject.briar.android.TestingConstants.WAKE_LOCK_DURATION;
|
|
||||||
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;
|
||||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.ONGOING_CHANNEL_ID;
|
import static org.briarproject.briar.api.android.AndroidNotificationManager.ONGOING_CHANNEL_ID;
|
||||||
@@ -78,6 +77,11 @@ public class BriarService extends Service {
|
|||||||
public static String EXTRA_STARTUP_FAILED =
|
public static String EXTRA_STARTUP_FAILED =
|
||||||
"org.briarproject.briar.STARTUP_FAILED";
|
"org.briarproject.briar.STARTUP_FAILED";
|
||||||
|
|
||||||
|
private static final String ACTION_ALARM =
|
||||||
|
"org.briarproject.briar.android.ACTION_ALARM";
|
||||||
|
private static final String EXTRA_DUE_MILLIS =
|
||||||
|
"org.briarproject.briar.android.DUE_MILLIS";
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(BriarService.class.getName());
|
Logger.getLogger(BriarService.class.getName());
|
||||||
|
|
||||||
@@ -259,20 +263,24 @@ public class BriarService extends Service {
|
|||||||
long dueMillis = intent.getLongExtra(EXTRA_DUE_MILLIS, 0);
|
long dueMillis = intent.getLongExtra(EXTRA_DUE_MILLIS, 0);
|
||||||
long late = SystemClock.elapsedRealtime() - dueMillis;
|
long late = SystemClock.elapsedRealtime() - dueMillis;
|
||||||
Log.i("ALARM_TEST", "Alarm fired " + late + " ms late");
|
Log.i("ALARM_TEST", "Alarm fired " + late + " ms late");
|
||||||
//acquire wakelock
|
|
||||||
PowerManager powerManager = (PowerManager)
|
PowerManager powerManager = (PowerManager)
|
||||||
getApplicationContext().getSystemService(POWER_SERVICE);
|
getApplicationContext().getSystemService(POWER_SERVICE);
|
||||||
WakeLock wakeLock = powerManager.newWakeLock(PARTIAL_WAKE_LOCK,
|
WakeLock wakeLock = powerManager.newWakeLock(PARTIAL_WAKE_LOCK,
|
||||||
"briar:TestWakeLock");
|
"briar:TestWakeLock");
|
||||||
wakeLock.acquire();
|
if (!USE_TOR_WAKE_LOCK) {
|
||||||
Log.i("ALARM_TEST", "WakeLock acquired for "
|
//acquire wakelock
|
||||||
+ WAKE_LOCK_DURATION + " ms");
|
wakeLock.acquire();
|
||||||
|
Log.i("ALARM_TEST", "WakeLock acquired for "
|
||||||
|
+ WAKE_LOCK_DURATION + " ms");
|
||||||
|
}
|
||||||
new Handler().postDelayed(() -> {
|
new Handler().postDelayed(() -> {
|
||||||
//set alarm before releasing wake lock
|
//set alarm before releasing wake lock
|
||||||
setAlarm();
|
setAlarm();
|
||||||
//release wakelock
|
if (!USE_TOR_WAKE_LOCK) {
|
||||||
Log.i("ALARM_TEST", "Releasing WakeLock");
|
//release wakelock
|
||||||
wakeLock.release();
|
Log.i("ALARM_TEST", "Releasing WakeLock");
|
||||||
|
wakeLock.release();
|
||||||
|
}
|
||||||
}, WAKE_LOCK_DURATION);
|
}, WAKE_LOCK_DURATION);
|
||||||
}
|
}
|
||||||
return START_NOT_STICKY; // Don't restart automatically if killed
|
return START_NOT_STICKY; // Don't restart automatically if killed
|
||||||
|
|||||||
@@ -40,10 +40,4 @@ public interface TestingConstants {
|
|||||||
* Feature flag for enabling the sign-in reminder in release builds.
|
* Feature flag for enabling the sign-in reminder in release builds.
|
||||||
*/
|
*/
|
||||||
boolean FEATURE_FLAG_SIGN_IN_REMINDER = IS_DEBUG_BUILD;
|
boolean FEATURE_FLAG_SIGN_IN_REMINDER = IS_DEBUG_BUILD;
|
||||||
|
|
||||||
String ACTION_ALARM = "org.briarproject.briar.android.ACTION_ALARM";
|
|
||||||
String EXTRA_DUE_MILLIS = "org.briarproject.briar.android.DUE_MILLIS";
|
|
||||||
int WAKE_LOCK_DURATION = 5000;
|
|
||||||
int ALARM_DELAY = 15000;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user