fix(ble): the radio's word is the only report; Bluetooth off clears what it ended - #1023
Merged
Merged
Conversation
…hat it ended BleCoordinator reported advertising and scanning started without asking the radio: startAdvertising and startScanning discarded the advertiser's and scanner's answers, then sent the started event and returned true. The advertiser's own confirmation and failure callbacks were wired to nobody. Advertising is now reported started when the stack confirms the set and stopped when it confirms the stop; a refused start returns false and reports nothing; a scan is reported started only when it started, stopped only when a running scan stopped, and stopped when the stack fails it afterwards. Nothing handled Bluetooth going off. The advertiser kept its STARTED state, the scanner its scanning flag and the GATT server its registration, so the STATE_ON refresh found everything "running" and started nothing. The coordinator now listens for the adapter for the life of the process and, on TURNING_OFF/OFF, clears all three on the lifecycle lane; the next start opens a new server and requests a new set and scan. GattServerHost.stop also forgets a registration in flight, and a late onServiceAdded for a closed server is ignored. MainActivity publishes the session facts when Bluetooth turns on or off, so pairing follows it. Radio events go through an injected sink (production relays to Rust), so the unit tests can observe them; success is still derived only from the radio.
Review of the previous commit: onRadioOff closed the GATT server but left each peer that was connected to it marked as a live, subscribed server client. The closed server can no longer report those disconnects, so after Bluetooth came back a send to such a peer took the server-notify path and failed until the peer reconnected. The reset now clears every peer's client and server links and drops peers left with nothing. Tests pin BleAdvertiser.radioOff's answer when nothing was on the air, and the coordinator test checks no peer is left reachable. §6.29 records the change, its tests, mutation controls and device run, and the pre-existing radio issues the review found (recorded Open, not changed here).
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.
The BLE coordinator reported advertising and scanning as started without asking the radio, and nothing handled Bluetooth going off. So after an off/on toggle, advertising never came back while the logs said it had. Both were found while mapping #1021's device run; this fixes them.
What changed
startAdvertisingandstartScanningused to discard the advertiser's and scanner's answers, then send the started event and return true.GattServerHost.stopnow also forgets a registration in flight. A lateonServiceAddedfor a closed server is ignored.Radio events go through an injected sink; production relays them to Rust. Success is still derived only from the radio, so the sink is not a bypass.
Verification
BleCoordinatorRadioTest7/0 andBleRadioComponentsTest4/0 (framework simulated at its boundary); Android unit suite 263/0radioOffkeeping state or always answering on-air; advertiser not reporting the stack's start; scanner keeping its scanAdvertising set started. Bluetooth off clears the set and GATT server and reports stopped once; the stack's late stop is ignored as stale. Bluetooth on opens a new server, registers the service and starts a new set (id=2); before, nothing started. Session facts published on both.Not covered
GattServerHost's registration reset is exercised only on the device, because Robolectric'saddServiceanswers false.onServiceAddedbranch is not exercised anywhere.Still open (recorded in §6.29), all older than this change:
PairingConfirmWrittenhandler's 15 s wait on its own dispatcher;resumePairingScanscanning in the background;onScanFailed's unframed error envelope;BlePermissionsGatereceiver;