fmetzger/android-sensorium

Scanning for Bluetooth devices even if the Bluetooth is off

Opened this issue · 4 comments

I have installed the latest version of the Sensorium from F-Droid (1.1.12) and installed it on Nexus 5, Nexus 6, and Galaxy S3. When I enable the Bluetooth sensor on the setting, the app shows the information about my phone Bluetooth status, discoverable devices, and paired devices, if the bluetooth is on. When I turn off the Bluetooth of the device, but the Bluetooth sensor of the sensorium is still enabled, the app keeps performing Bluetooth discovery (I can see the "restart bluetooth scanning" on the logCat every 10 seconds, which is the scan interval for Bluetooth sensor). I believe that the application should stop scanning for Bluetooth connections when the user turns of the Bluetooth on the device.

My suggestion to fix the problem:

in "at.univie.sensorium.sensors.BluetoothSensor", you stop scanning for Bluetooth connections only when the bluetooth sensor is disabled:
protected void _disable() { ... handler.removeCallbacks(scanTask); ... }

You can identify a broadcast receiver that listens to changes in the status of the device Bluetooth (with the "android.bluetooth.BluetoothAdapter.ACTION_STATE_CHANGED" intent filter). in the "OnReceive" method of this broadcast receiver, check if the Bluetooth is off or turning off. In either case, remove the callback that performs bluetooth discovery.

int state1 = android.bluetooth.BluetoothAdapter.STATE_OFF; int state2 = android.bluetooth.BluetoothAdapter.STATE_TURNING_OFF;
if(state1 || state2){ handler.removeCallbacks(scanTask); }

Thanks @ReyhanJB for your feedback! As far as I can see, Sensorium does not continue scanning when Bluetooth is turned off. (Essentially the OS keeps it from continuing to scan). However, it should definitely not spam the debug log with false notifications!

Do you want to submit a pull request that adds the broadcast receiver you propose?

@aaaaalbert: The method "_enable()" for the Bluetooth sensor will be called when the user enables it on the settings, right? When the Bluetooth is off at that time, the sensor won't start scanning. However, if the sensor is enabled by the user and she turns off the Bluetooth (for example, when the battery of the device is low), the scanTask callback will not be removed and keeps scanning. You can confirm this by looking at the logcat following the scenario I proposed (you should be able to see "restart bluetooth scanning" message on the logCat every 10 seconds, which is the scan interval for Bluetooth sensor).

Sure, I'll submit a pull request related to this issue.

@ReyhanJB, I agree with what you say; I'm trying to emphasize the difference between "Sensorium tries to scan" (i.e. the scan task is launched) and "this actually results in a Bluetooth scan" (for which the user turning on Bluetooth is a necessary precondition).

With Bluetooth turned off, Sensorium's scan task is spammy (as per the log), wastes computational and energy resources (though I would expect the numbers to be small), etc.

However, there are no privacy implications, because no actual Bluetooth scan is performed.

Looking forward to your patch, thanks!