Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to discover services despite initial bonding failure #351

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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