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:
parent
00ee9b6828
commit
3f421facab
@ -36,7 +36,7 @@ public class BluetoothStateChangeReceiver extends BroadcastReceiver {
|
|||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
String action = intent.getAction();
|
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) {
|
if (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1) == BluetoothAdapter.STATE_ON) {
|
||||||
|
|
||||||
Intent refreshIntent = new Intent(DeviceManager.ACTION_REFRESH_DEVICELIST);
|
Intent refreshIntent = new Intent(DeviceManager.ACTION_REFRESH_DEVICELIST);
|
||||||
@ -50,6 +50,7 @@ public class BluetoothStateChangeReceiver extends BroadcastReceiver {
|
|||||||
LOG.info("Bluetooth turned on => connecting...");
|
LOG.info("Bluetooth turned on => connecting...");
|
||||||
GBApplication.deviceService().connect();
|
GBApplication.deviceService().connect();
|
||||||
} else if (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1) == BluetoothAdapter.STATE_OFF) {
|
} else if (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1) == BluetoothAdapter.STATE_OFF) {
|
||||||
|
LOG.info("Bluetooth turned off => disconnecting...");
|
||||||
GBApplication.deviceService().disconnect();
|
GBApplication.deviceService().disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -409,11 +409,12 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
|
|||||||
}
|
}
|
||||||
case ACTION_DISCONNECT: {
|
case ACTION_DISCONNECT: {
|
||||||
mDeviceSupport.dispose();
|
mDeviceSupport.dispose();
|
||||||
if (mGBDevice != null && mGBDevice.getState() == GBDevice.State.WAITING_FOR_RECONNECT) {
|
if (mGBDevice != null) {
|
||||||
setReceiversEnableState(false, false, null);
|
|
||||||
mGBDevice.setState(GBDevice.State.NOT_CONNECTED);
|
mGBDevice.setState(GBDevice.State.NOT_CONNECTED);
|
||||||
mGBDevice.sendDeviceUpdateIntent(this);
|
mGBDevice.sendDeviceUpdateIntent(this);
|
||||||
}
|
}
|
||||||
|
setReceiversEnableState(false, false, null);
|
||||||
|
mGBDevice = null;
|
||||||
mDeviceSupport = null;
|
mDeviceSupport = null;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user