fix(ble): Stop transport connect after failed bonding#5973
Merged
jamesarich merged 1 commit intoJun 27, 2026
Merged
Conversation
When BleRadioTransport bonds before connecting and bond() throws, re-check the final bonded state before continuing into GATT setup. Successful bonding continues unchanged. A thrown bond call with a final bonded state continues so late or flaky terminal bond signals do not strand the connection. A thrown bond call with the device still unbonded now fails fast with RadioNotConnectedException so BleReconnectPolicy owns retry/backoff instead of entering GATT setup and surfacing cryptic status 5 or 133 failures later. CancellationException is rethrown before the generic failure path, and the bond preflight is kept in a helper so attemptConnection does not need a broader ThrowsCount suppression. Tests cover the successful bond path, late bonded-after-error path, failed-unbonded path, and cancellation propagation. The cancellation test advances far enough to detect an unintended reconnect retry.
This was referenced Jun 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This pull request stops the BLE transport from continuing into GATT setup after transport-side bonding fails and Android still reports the device as not bonded.
This is the third change in the related BLE bonding cleanup. #5967 made Android bonding waits finite and re-checked final bond state before failing. #5969 changed the user-facing pairing path so failed pairing waits for an explicit retry instead of immediately arming the transport. This PR handles the remaining transport-side case.
If
bond()fails but Android now reports the device as bonded, the transport still continues. That preserves the late or flaky terminal-bond case where Android recorded the bond even though the app-side bond call reported an error.If
bond()fails and Android still reports the device as not bonded, the transport now stops that connection attempt before callingconnectAndAwait(). The existing reconnect policy remains responsible for any later retry/backoff.Key Changes
isBonded(address)after transport-sidebond()failure.RadioNotConnectedException.Testing
connectAndAwait().connectAndAwait()when Android still reports not bonded.CancellationExceptionfrom bonding cancels rather than becoming a retryable generic failure.Migration Notes