Skip to content

Commit

Permalink
Merge pull request #555 from kkkbird/fix-497-autoconnect
Browse files Browse the repository at this point in the history
fix: reset connected if DISCONNECTED is received between connect and initialize for autoconnected
  • Loading branch information
philips77 authored Apr 29, 2024
2 parents 6dd5bec + a393efe commit 577262c
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 577262c

Please sign in to comment.