From 2ffc804b4b690270fb84820b29322064f10e9e5b Mon Sep 17 00:00:00 2001 From: Chris Thornton Date: Sat, 22 Feb 2025 15:26:42 -0800 Subject: [PATCH] Trigger service discovery if interrupted in `onConnectionUpdated` It appears that when a service discovery is in progress and `onConnectionUpdated` is called, the service discovery callback `onServicesDiscovered` is never invoked. By checking to see `serviceDiscoverRequested` is set, we can restart the service discovery and get a result back. This may potentially fix #536, but I was seeing this behaviour consistently when connecting to another BLE device --- .../java/no/nordicsemi/android/ble/BleManagerHandler.java | 5 +++++ 1 file changed, 5 insertions(+) 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 3cdfe377..de61e433 100644 --- a/ble/src/main/java/no/nordicsemi/android/ble/BleManagerHandler.java +++ b/ble/src/main/java/no/nordicsemi/android/ble/BleManagerHandler.java @@ -2907,6 +2907,11 @@ public void onConnectionUpdated(@NonNull final BluetoothGatt gatt, cpr.notifyConnectionPriorityChanged(gatt.getDevice(), interval, latency, timeout); cpr.notifySuccess(gatt.getDevice()); } + if (serviceDiscoveryRequested) { + log(Log.VERBOSE, () -> "Discovering services..."); + log(Log.DEBUG, () -> "gatt.discoverServices()"); + bluetoothGatt.discoverServices(); + } } else if (status == 0x3b) { // HCI_ERR_UNACCEPT_CONN_INTERVAL Log.e(TAG, "onConnectionUpdated received status: Unacceptable connection interval, " + "interval: " + interval + ", latency: " + latency + ", timeout: " + timeout);