Callback onConnectionStateChange after disconnect can put BleManager in inconsistent state
See original GitHub issueI am seeing a situation where onConnectionStateChangeSafe
in BleManager
gets called with newState == BluetoothProfile.STATE_CONNECTED
after I do a disconnect (call BleManager.disconnect()
).
This causes mConnected
to be set to true, but mBluetoothDevice
is null. This makes both connect do nothing (since mConnected
is true) and disconnect to nothing (since mBluetoothDevice
is null), so the BleManager is no longer of much use.
Some more rough details on what I’m doing:
- Connecting (calling
BleManager.connect()
). - Enabling notifications for a couple of characteristics. Reading and writing some characteristics.
- Disconnecting.
- Repeat.
This is not done in quick succession - between the disconnect and the next connect for instance there is a pause several seconds long.
This works fine most of the time, but sometimes, there is a call to onConnectionStateChangeSafe
after the disconnect, which causes the problem described above.
Side note: The purpose for this is to implement a communications protocol where characteristics are used to transfer data, and the error handling is specified as disconnecting, reconnecting, and starting over.
I have been using version 2.0-beta10.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
I have now, the fix seems to have solved the problem. I have run the same test with the new code 50 times, no issues, connection works beautifully. Thanks again!
By any chance, did you try the version from referenced PR?