1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-25 03:16:51 +01:00

Always cleanup device and receiver in service when disconnecting

Fixes #1093

I have no idea why the code was like this, so the change might have some bad consequences...
This commit is contained in:
Andreas Shimokawa 2018-05-11 20:47:37 +02:00
parent 00ee9b6828
commit 3f421facab
2 changed files with 5 additions and 3 deletions

View File

@ -36,7 +36,7 @@ public class BluetoothStateChangeReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
if (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1) == BluetoothAdapter.STATE_ON) {
Intent refreshIntent = new Intent(DeviceManager.ACTION_REFRESH_DEVICELIST);
@ -50,6 +50,7 @@ public class BluetoothStateChangeReceiver extends BroadcastReceiver {
LOG.info("Bluetooth turned on => connecting...");
GBApplication.deviceService().connect();
} else if (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1) == BluetoothAdapter.STATE_OFF) {
LOG.info("Bluetooth turned off => disconnecting...");
GBApplication.deviceService().disconnect();
}
}

View File

@ -409,11 +409,12 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
}
case ACTION_DISCONNECT: {
mDeviceSupport.dispose();
if (mGBDevice != null && mGBDevice.getState() == GBDevice.State.WAITING_FOR_RECONNECT) {
setReceiversEnableState(false, false, null);
if (mGBDevice != null) {
mGBDevice.setState(GBDevice.State.NOT_CONNECTED);
mGBDevice.sendDeviceUpdateIntent(this);
}
setReceiversEnableState(false, false, null);
mGBDevice = null;
mDeviceSupport = null;
break;
}