Skip to content
Snippets Groups Projects
Commit f489da1a authored by akwizgran's avatar akwizgran
Browse files

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.
parent 6745bbf9
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment