Repository navigation
Handle already-connected BLE devices gracefully - #928
Conversation
Detect and surface a clear, actionable error when RxAndroidBle already holds a connection that the plugin does not track (e.g. after a hot restart). - ReactiveBleClient.establishConnection: if the underlying RxBleDevice is CONNECTED but no DeviceConnector is tracked, return an EstablishConnectionFailure Observable with a helpful message instead of triggering BleAlreadyConnectedException. - PluginController: map discover-services errors and return a "device_already_connected" code and detailed message when the underlying error indicates an already-connected device. - Tests: adjust connectionState stubbing and add a unit test verifying the actionable error is surfaced for untracked OS-level connections. This avoids confusing BleAlreadyConnected exceptions and guides callers to disconnect the device (or restart Bluetooth) before retrying.
|
@werediver hello, could you please take a look at this? It's meant for an overall improvement to exception handling. If you are okay on reviewing this, I'll make the necessary commits to improve it. Thanks for your time. |
|
@utkuvrs My expertise is primarily iOS & Flutter, but I poked some relevant people who may want to look at this p/r. In fact, they said "looks good" while I was typing this. I will approve and integrate, if the CI validation passes, but a new release will happen later, can't give a timeline on this. |
Detect and surface a clear, actionable error when RxAndroidBle already holds a connection that the plugin does not track (e.g. after a hot restart). - ReactiveBleClient.establishConnection: if the underlying RxBleDevice is CONNECTED but no DeviceConnector is tracked, return an EstablishConnectionFailure Observable with a helpful message instead of triggering BleAlreadyConnectedException. - PluginController: map discover-services errors and return a "device_already_connected" code and detailed message when the underlying error indicates an already-connected device. - Tests: adjust connectionState stubbing and add a unit test verifying the actionable error is surfaced for untracked OS-level connections. This avoids confusing BleAlreadyConnected exceptions and guides callers to disconnect the device (or restart Bluetooth) before retrying.
|
Thanks a lot @werediver I appreciate it. Please do let me know if there's anything that requires any changes on my end. |
|
@werediver thank you for your time regarding this PR, is it ready for merge I'm unable to see the contents of the workflow. Please do let me know if there is anything I can fix regarding this. If not, should I close the PR? |
|
@PieterAelse I think you're comparatively active here. Is the CI broken permanently and we don't care anymore or is it something someone can fix? We have a p/r with an improvement here (mostly development experience), but the CI doesn't validate it. |
|
@werediver / @utkuvrs (thanks for your PR!) I've ran the tests/build and it came back with (link) one (stupid?)
Which is due to 2 new returns added for method
I'm all fine for 1, but I think 2 narrows the scope so is better (and 3 is not needed IMO). (sorry for closing/reopening, I mispressed 🥲) |
|
@utkuvrs I've discussed internally, could you update the PR to add option 2 (if there's such an annotation) |
Thank you I will start implementing this and I will get back with updates. Have a good day for now. |
|
I've also ran the tests on my local with Gradle 9.8.2 here are the results: Test resultsCommand (run from Result: BUILD SUCCESSFUL in 2m 59s (29 actionable tasks executed). detekt
Unit tests (
|
|
@PieterAelse sorry for the late reply. I've applied the 2nd option and also included unit tests. |
|
Thanks @utkuvrs ! Everything was now green so I've (squashed and) merged it 🎉 thanks for you contribution. |
Detect and surface a clear, actionable error when RxAndroidBle already holds a connection that the plugin does not track (e.g. after a hot restart).
This avoids confusing BleAlreadyConnected exceptions and guides callers to disconnect the device (or restart Bluetooth) before retrying.