From 124a4380d35229177458d3d51226e9e13642e01f Mon Sep 17 00:00:00 2001 From: akwizgran <akwizgran@users.sourceforge.net> Date: Wed, 20 Jan 2016 16:55:01 +0000 Subject: [PATCH] Don't disable Bluetooth unless we enabled it. #226 --- .../plugins/droidtooth/DroidtoothPlugin.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/briar-android/src/org/briarproject/plugins/droidtooth/DroidtoothPlugin.java b/briar-android/src/org/briarproject/plugins/droidtooth/DroidtoothPlugin.java index 0d622ef779..7bbbe7a15e 100644 --- a/briar-android/src/org/briarproject/plugins/droidtooth/DroidtoothPlugin.java +++ b/briar-android/src/org/briarproject/plugins/droidtooth/DroidtoothPlugin.java @@ -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"); } -- GitLab