NordicSemiconductor / Android-BLE-Library

A library that makes working with Bluetooth LE on Android a pleasure. Seriously.
BSD 3-Clause "New" or "Revised" License
2.04k stars 419 forks source link

Pairing dialog displayed twice when bonding two Android devices #430

Closed DominikRidjic closed 2 years ago

DominikRidjic commented 2 years ago

I'm having this issue running the current version 2.5.1 of your library.

Both Android devices are running my app (with your library) where one is acting as GATT service and the other as client.

The device running the GATT service will have the service started as soon as the app is started as foreground service, the device acting as client will only on demand scan, connect and bond

Bonding flow on client:

a) User scans and picks a device to connect to b) connect (using your lib) c) in BleManagerGattCallback.initialise() set MTU size, set connection priority, enable notifications and so on d) when connection is successful check if bonded, if not -> createBondInsecure() e) Pairing dialog is displayed twice, one of these without passkey (the first), the second with a passkey f) in Android OS settings I now have two pairings to the server, with two different MAC

Flow on server:

a) on app start GATT service is started and advertised (using your lib as well) b) once a client connects the server will connect back to the client (but not bond) as described in your docs c) Pairing dialog is displayed only once f) in Android OS settings I have only one pairing to the client

I have tried this with multiple different devices and all show the same behaviour. I also tried using device.createBond() from Android APIs directly and the behaviour is identical. I suspect it might have to do with the fact that the GATT service device is connecting back to the client, which is only a requirement in your lib and not on Android OS, causing the Android OS to behave weirdly...

Please let me know if you need more information, I could surely provide you with some logs from both sides

Thanks!

DominikRidjic commented 2 years ago

Additional Info: devices are all Android 10-12

philips77 commented 2 years ago

Hello, No, this is "normal" Android behavior. For some reason Android shows the request twice, which is very anoying. If you'd try with a nRF5 DK, insterad of a second phone, even one that doesn't do discovery on the client, the behavior would be the same. As far as I remember, on the firmware side it is possible to comment out some line of code to make it happen just once, but I don't remember which one. When 2 Android phones... well. Nothing can be done other than reporting to Google, as bonding is handled internally by Android. The BLE lib just receives broadcasts when bonding is complete or failed.

DominikRidjic commented 2 years ago

Hi!

Thank you for your quick reply! I fear you are right about this because I did try bonding with Android APIs after all. :/ I will still check how Google does it internally in their settings app but I doubt I'll find a solution there that we can use.

Thanks!