mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-23 16:53:04 +02:00
Synchronize BT disconnect method
Hopefully fixes the crash reported in #252.
This commit is contained in:
@@ -421,6 +421,7 @@ public abstract class BluetoothCommunication {
|
||||
* Disconnect from a Bluetooth device
|
||||
*/
|
||||
public void disconnect(boolean doCleanup) {
|
||||
synchronized (lock) {
|
||||
if (bluetoothGatt == null) {
|
||||
return;
|
||||
}
|
||||
@@ -432,17 +433,16 @@ public abstract class BluetoothCommunication {
|
||||
Timber.i("Disconnecting%s", doCleanup ? " (with cleanup)" : "");
|
||||
|
||||
if (doCleanup) {
|
||||
synchronized (lock) {
|
||||
if (btMachineState != BT_MACHINE_STATE.BT_CLEANUP_STATE) {
|
||||
setBtMachineState(BT_MACHINE_STATE.BT_CLEANUP_STATE);
|
||||
nextMachineStateStep();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bluetoothGatt.close();
|
||||
bluetoothGatt = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke next step for internal Bluetooth state machine.
|
||||
@@ -521,10 +521,12 @@ public abstract class BluetoothCommunication {
|
||||
Timber.d("onConnectionStateChange: status=%d, newState=%d", status, newState);
|
||||
|
||||
if (newState == BluetoothProfile.STATE_CONNECTED) {
|
||||
synchronized (lock) {
|
||||
if (leScanCallback != null) {
|
||||
btAdapter.stopLeScan(leScanCallback);
|
||||
leScanCallback = null;
|
||||
}
|
||||
}
|
||||
|
||||
connectionEstablished = true;
|
||||
setBtStatus(BT_STATUS_CODE.BT_CONNECTION_ESTABLISHED);
|
||||
|
Reference in New Issue
Block a user