Commit 6ad3a303 authored by akwizgran's avatar akwizgran

Hold a wifi lock to prevent sleep from affecting wifi speed.

parent fadb253a
......@@ -10,6 +10,7 @@
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission-sdk-23 android:name="android.permission.ACCESS_COARSE_LOCATION" />
......
......@@ -9,6 +9,8 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiManager.WifiLock;
import android.os.Bundle;
import android.util.Log;
......@@ -38,6 +40,8 @@ import static android.bluetooth.BluetoothAdapter.ACTION_STATE_CHANGED;
import static android.bluetooth.BluetoothAdapter.EXTRA_STATE;
import static android.bluetooth.BluetoothAdapter.STATE_OFF;
import static android.bluetooth.BluetoothAdapter.STATE_ON;
import static android.content.Context.WIFI_SERVICE;
import static android.net.wifi.WifiManager.WIFI_MODE_FULL_HIGH_PERF;
import static java.util.concurrent.Executors.newCachedThreadPool;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.briarproject.interferometer.MainViewModel.ConnectionState.DISCONNECTED;
......@@ -117,9 +121,18 @@ public class MainViewModel extends AndroidViewModel {
if (hostPort == null) return INVALID_ADDRESS;
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if (adapter == null) return NO_BLUETOOTH;
Log.i(TAG, "Starting test");
task = executorService.submit(() -> {
WifiLock wifiLock = null;
try {
WifiManager wifiManager = (WifiManager)
getApplication().getApplicationContext().getSystemService(WIFI_SERVICE);
if (wifiManager != null) {
wifiLock = wifiManager.createWifiLock(WIFI_MODE_FULL_HIGH_PERF, TAG);
wifiLock.acquire();
}
if (!disableBluetooth(adapter)) {
Log.w(TAG, "Failed to disable Bluetooth");
return;
......@@ -166,7 +179,6 @@ public class MainViewModel extends AndroidViewModel {
adapter.disable();
}
Log.i(TAG, "Test finished");
Bundle b = new Bundle();
b.putDouble(DOWNLOAD_DISABLED, mean(downloadDisabled));
......@@ -180,6 +192,7 @@ public class MainViewModel extends AndroidViewModel {
b.putBoolean(CONSUMED, false);
results.postValue(b);
} finally {
if (wifiLock != null) wifiLock.release();
testPhase.postValue(READY);
}
});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment