mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Wait for Bluetooth to be disabled before exiting.
This may have been the cause of Bluetooth not always being disabled at shutdown on the Sony Xperia Tipo.
This commit is contained in:
@@ -228,8 +228,18 @@ class DroidtoothPlugin implements DuplexPlugin {
|
||||
tryToClose(socket);
|
||||
// Disable Bluetooth if we enabled it and it's still enabled
|
||||
if(wasDisabled && adapter.isEnabled()) {
|
||||
if(adapter.disable()) LOG.info("Disabling Bluetooth");
|
||||
else LOG.info("Could not disable Bluetooth");
|
||||
// Try to disable the adapter and wait for the result
|
||||
LOG.info("Disabling Bluetooth");
|
||||
IntentFilter filter = new IntentFilter(ACTION_STATE_CHANGED);
|
||||
DisableBluetoothReceiver receiver = new DisableBluetoothReceiver();
|
||||
appContext.registerReceiver(receiver, filter);
|
||||
if(adapter.disable()) {
|
||||
LOG.info("Disabling Bluetooth");
|
||||
receiver.waitForStateChange();
|
||||
} else {
|
||||
LOG.info("Could not disable Bluetooth");
|
||||
}
|
||||
appContext.unregisterReceiver(receiver);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -382,6 +392,28 @@ class DroidtoothPlugin implements DuplexPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
private class DisableBluetoothReceiver extends BroadcastReceiver {
|
||||
|
||||
private final CountDownLatch latch = new CountDownLatch(1);
|
||||
|
||||
public void onReceive(Context ctx, Intent intent) {
|
||||
int state = intent.getIntExtra(EXTRA_STATE, 0);
|
||||
if(state == STATE_OFF) {
|
||||
LOG.info("Bluetooth disabled");
|
||||
latch.countDown();
|
||||
}
|
||||
}
|
||||
|
||||
private void waitForStateChange() {
|
||||
try {
|
||||
latch.await();
|
||||
} catch(InterruptedException e) {
|
||||
LOG.info("Interrupted while disabling Bluetooth");
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class DiscoveryThread extends Thread {
|
||||
|
||||
private final LatchedReference<BluetoothSocket> socketLatch;
|
||||
|
||||
Reference in New Issue
Block a user