diff --git a/ble/src/main/java/no/nordicsemi/android/ble/BleManagerHandler.java b/ble/src/main/java/no/nordicsemi/android/ble/BleManagerHandler.java index 1feb4e86..42693459 100644 --- a/ble/src/main/java/no/nordicsemi/android/ble/BleManagerHandler.java +++ b/ble/src/main/java/no/nordicsemi/android/ble/BleManagerHandler.java @@ -779,7 +779,7 @@ private boolean internalConnect(@NonNull final BluetoothDevice device, return true; } - private boolean internalDisconnect(final int reason) { + private void internalDisconnect(final int reason) { userDisconnected = true; initialConnection = false; ready = false; @@ -825,7 +825,6 @@ private boolean internalDisconnect(final int reason) { r.notifyInvalidRequest(); } nextRequest(true); - return true; } @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN) @@ -3589,6 +3588,10 @@ private synchronized void nextRequest(final boolean force) { } } + // At this point the bluetoothDevice is either null, and the request is a ConnectRequest, + // or not a null. + assert bluetoothDevice != null || request.type == Request.Type.CONNECT; + switch (request.type) { case CONNECT: { //noinspection DataFlowIssue @@ -3599,7 +3602,10 @@ private synchronized void nextRequest(final boolean force) { break; } case DISCONNECT: { - result = internalDisconnect(ConnectionObserver.REASON_SUCCESS); + internalDisconnect(ConnectionObserver.REASON_SUCCESS); + // If a disconnect request failed, it has already been notified at this point, + // therefore result is a success (true). + result = true; break; } case ENSURE_BOND: {