bluetooth-le
bluetooth-le copied to clipboard
Android: `startNotifications()` hangs when pairing prompt is canceled
Describe the bug
I have an app where I connect to a device and then enable notifications. If Androids OS prompt to pair the device is aborted, the library is stuck, as onDescriptorWrite is never called, and thus the startNotifications function never resolves, so the queue in the plugin is stuck.
To Reproduce Steps to reproduce the behavior:
- Connect to a device
- Call
startNotifications - If Android prompts to pair the device, press 'Cancel'
- See error
Expected behavior The plugin should not be stuck if a user presses 'Cancel' in the OS prompt.
So I would expect the plugin to have a timeout when waiting for onDescriptorWrite (similar as in createBond). (Or detect if the pairing prompt is cancelled. I think this could be done by listening on bond‐state changes BOND_BONDING → BOND_NONE, bit I don't know how reliable this will work).
Plugin version:
- @capacitor-community/bluetooth-le: 6.1.0
Smartphone (please complete the following information):
- Device: different devices (Samsung, Pixel,...)
- OS: different OS versions
Additional context
-
Calling
BleClient.disableQueue()fixes this issue. (But I am currently afraid using that in production, as we are not sure, that we don't call somewhere some commands in paralell). -
I could imagine, that this is also the source or related to #734.
-
We probably work around this issue by manually trigger createBond before calling
startNotifications. createBond has proper timeout and handling of canceling the propmpt, so in our case this can solve the issue.
I am not sure, what solution (timeout vs listening on bonding changes vs just better document the behaviour) is the preferred way to continue. If we agree on a way, I can provide a PR to change it as agreed.
Thanks for the report @gion-andri
I'll try and get around to giving you some feedback and a direction tomorrow 🙂
Please bear with me!
@peitschie Did u find some time to have a look at this?
As we found some issues with manual bond creation (just on our side), I will probably start tomorrow implementing a patch for our app and then opening a PR with those changes.
Apologies, I have not yet had a chance 😔