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

Merge branch '226-bluetooth-logic' into 'master'

Don't disable Bluetooth unless we enabled it. #226

Fixes #226

See merge request !71
parents 6bb4d45f 124a4380
No related branches found
No related tags found
No related merge requests found
......@@ -72,7 +72,7 @@ class DroidtoothPlugin implements DuplexPlugin {
private final int maxLatency, pollingInterval;
private volatile boolean running = false;
private volatile boolean wasDisabled = false;
private volatile boolean wasEnabledByUs = false;
private volatile BluetoothStateReceiver receiver = null;
private volatile BluetoothServerSocket socket = null;
......@@ -132,12 +132,13 @@ class DroidtoothPlugin implements DuplexPlugin {
filter.addAction(ACTION_SCAN_MODE_CHANGED);
receiver = new BluetoothStateReceiver();
appContext.registerReceiver(receiver, filter);
// If Bluetooth is enabled, bind a socket - otherwise enable it
// If Bluetooth is enabled, bind a socket
if (adapter.isEnabled()) {
bind();
} else {
wasDisabled = true;
// Enable Bluetooth if settings allow
if (callback.getSettings().getBoolean("enable", false)) {
wasEnabledByUs = true;
if (adapter.enable()) LOG.info("Enabling Bluetooth");
else LOG.info("Could not enable Bluetooth");
} else {
......@@ -228,7 +229,7 @@ class DroidtoothPlugin implements DuplexPlugin {
if (receiver != null) appContext.unregisterReceiver(receiver);
tryToClose(socket);
// Disable Bluetooth if we enabled it and it's still enabled
if (wasDisabled && adapter.isEnabled()) {
if (wasEnabledByUs && adapter.isEnabled()) {
if (adapter.disable()) LOG.info("Disabling Bluetooth");
else LOG.info("Could not disable Bluetooth");
}
......
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