Skip to content

Commit 577262c

Browse files
authored
Merge pull request #555 from kkkbird/fix-497-autoconnect
fix: reset connected if DISCONNECTED is received between connect and initialize for autoconnected
2 parents 6dd5bec + a393efe commit 577262c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

ble/src/main/java/no/nordicsemi/android/ble/BleManagerHandler.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2217,7 +2217,15 @@ public void onConnectionStateChange(@NonNull final BluetoothGatt gatt,
22172217

22182218
if (cr != null && cr.shouldAutoConnect() && initialConnection
22192219
&& gatt.getDevice().getBondState() == BluetoothDevice.BOND_BONDED) {
2220-
log(Log.DEBUG, () -> "autoConnect = false called failed; retrying with autoConnect = true");
2220+
log(Log.DEBUG, () -> "autoConnect = false called failed; retrying with autoConnect = true" + (connected ? "; reset connected to false" : ""));
2221+
2222+
// fix:https://github.com/NordicSemiconductor/Android-BLE-Library/issues/497
2223+
// if DISCONNECTED is received between connect and initialize, need to reset connected to make internalConnect work
2224+
if (connected) {
2225+
connected = false;
2226+
connectionState = BluetoothGatt.STATE_DISCONNECTED;
2227+
}
2228+
22212229
post(() -> internalConnect(gatt.getDevice(), cr));
22222230
return;
22232231
}

0 commit comments

Comments
 (0)