Skip to content

Commit

Permalink
fix: reset connected if DISCONNECTED is received between connect and …
Browse files Browse the repository at this point in the history
…initialize for autoconnected
  • Loading branch information
kkkbird committed Apr 16, 2024
1 parent 6dd5bec commit a393efe
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2217,7 +2217,15 @@ public void onConnectionStateChange(@NonNull final BluetoothGatt gatt,

if (cr != null && cr.shouldAutoConnect() && initialConnection
&& gatt.getDevice().getBondState() == BluetoothDevice.BOND_BONDED) {
log(Log.DEBUG, () -> "autoConnect = false called failed; retrying with autoConnect = true");
log(Log.DEBUG, () -> "autoConnect = false called failed; retrying with autoConnect = true" + (connected ? "; reset connected to false" : ""));

// fix:https://github.com/NordicSemiconductor/Android-BLE-Library/issues/497
// if DISCONNECTED is received between connect and initialize, need to reset connected to make internalConnect work
if (connected) {
connected = false;
connectionState = BluetoothGatt.STATE_DISCONNECTED;
}

post(() -> internalConnect(gatt.getDevice(), cr));
return;
}
Expand Down

0 comments on commit a393efe

Please sign in to comment.