Skip to content

Commit

Permalink
Merge pull request #351 from NordicSemiconductor/improvement/service-…
Browse files Browse the repository at this point in the history
…discovery-with-failed-bonding

Trying to discover services despite initial bonding failure
  • Loading branch information
philips77 committed Feb 2, 2022
2 parents 9e77c41 + 3e66f99 commit cbccbed
Showing 1 changed file with 14 additions and 1 deletion.
Expand Up @@ -317,10 +317,23 @@ public void onReceive(final Context context, final Intent intent) {
postCallback(c -> c.onBondingFailed(device));
postBondingStateChange(o -> o.onBondingFailed(device));
log(Log.WARN, () -> "Bonding failed");
if (request != null) { // CREATE_BOND request
if (request != null && request.type == Request.Type.CREATE_BOND) {
request.notifyFail(device, FailCallback.REASON_REQUEST_FAILED);
request = null;
}
// If the device started to pair just after the connection was
// established the services were not discovered. We may try to discover services
// despite the fail bonding process.
// See: https://github.com/NordicSemiconductor/Android-BLE-Library/issues/335
if (!servicesDiscovered && !serviceDiscoveryRequested) {
post(() -> {
serviceDiscoveryRequested = true;
log(Log.VERBOSE, () -> "Discovering services...");
log(Log.DEBUG, () -> "gatt.discoverServices()");
bluetoothGatt.discoverServices();
});
return;
}
} else if (previousBondState == BluetoothDevice.BOND_BONDED) {
if (request != null && request.type == Request.Type.REMOVE_BOND) {
// The device has already disconnected by now.
Expand Down

0 comments on commit cbccbed

Please sign in to comment.