Closed Wes1324 closed 1 month ago
It's also worth noting that the paired device disappears from the list of paired devices in my phone's settings after this call to removeBond()
, despite the exception that is thrown from the library. Further evidence that the OS has actually successfully removed the bond.
I'm facing the same issue on version 1.33.4
, is there a fix?
is your device supposed to disconnect when you remove the bond?
it seems android updates the connectionState stream before the bondState stream
the best solution i can think of is to try to get it to either:
a simple fix is to just remove the fbpEnsureDeviceIsConnected
line
Thanks for the replies @chipweinberger.
is your device supposed to disconnect when you remove the bond?
That was the question I had. I was surprised to see that calling removeBond()
disconnects the device too. I guess it kind of makes sense that Android would do this but I wasn't expecting it because I didn't see that behaviour documented anywhere.
it seems android updates the connectionState stream before the bondState stream
Yeh, I agree. That seems to be the root cause here.
a simple fix is to just remove the fbpEnsureDeviceIsConnected line
I think that would fix it (I can test and confirm tomorrow)... but can you foresee any issues in doing that? Do you remember why it was thought to be necessary to continuously monitor the connection state when removing the bond?
it's possible your ble peripheral initiated the disconnection, not android
you should log the disconnectionReason
Do you remember why it was thought to be necessary to continuously monitor the connection state when removing the bond?
I added that line because if the device disconnects, it would (usually) be a waste of time to wait until the full timeout
perhaps just put this change behind a flag. removeBond(ensureConnection:false)
perhaps just put this change behind a flag. removeBond(ensureConnection:false)
This seems like a good idea!
however, you should confirm why the device is disconnecting.
check your peripheral's firmware logs.
We have decided that we are not going to call removeBond
anymore so this is no longer an issue for us. Thanks for your help.
Requirements
Have you checked this problem on the example app?
Yes
FlutterBluePlus Version
1.32.12. Also tried with 1.33.4
Flutter Version
3.19.3
What OS?
Android
OS Version
Android 12
Bluetooth Module
Unsure
What is your problem?
When
removeBond()
is invoked, a FlutterBluePlusException saying "Device is disconnected" is thrown.I've debugged the code and the
changed
variable on this line istrue
, which makes me think the Android java code has completed successfully.However, I can see that the listener that is set up here receives an event that the device is disconnected before the parent future completes.
What could be causing the device to become disconnected before the call to
removeBond()
completes?There is no call to removeBond() in the example app so I couldn't try reproducing this in the example app.
Logs