Repository navigation
CarLife USB: reopen the accessory after a session ends without a detach - #129
Merged
Merged
Conversation
A head unit can end the CarLife session and restart it on a cable that was never touched, and Android delivers the accessory attach intent only to a foreground activity. The lease stayed recorded after its streams had closed, so every later scan saw the same accessory as connected and never opened it again until the app restarted. - A lease is live only while its streams are open. When Stream closes them, the lease opened at that generation is released and usb_lease_lost is reported; a newer lease is never dropped. - While no lease is live, the inventory is swept every 3 s on the accessory worker. A lost lease waits for the next sweep, so a head unit that ends every session at once is retried at that interval. - ACCESSORY_ATTACHED is also registered on the receiver (usb_attached). - SecurityException from openAccessory, a grant revoked by a detach while the old entry is listed, is retried on the next sweep instead of stopping with usb_error. Tests end sessions explicitly through an attach seam and drive sweeps with a manual timer, so they stay deterministic.
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
What
usb_lease_lostis reported. Release is keyed by generation, so a late close never drops a newer lease.ACCESSORY_ATTACHEDis registered on the receiver as well (usb_attacheddiagnostic).SecurityExceptionfromopenAccessory()(grant revoked by a detach while the old entry is still listed) is reported asusb_permission_revokedand retried on the next sweep, instead of stopping reconciliation withusb_error.AccessoryStreams.close()no longer holds a monitor, because the reader thread can end the session during that teardown.Why
A community tester (OnePlus 7 Pro, CarLife 2.x head unit) reported that after a session ended the picture only came back after restarting the app. #127 already ends the lease on a matching detach. This covers the cases without a detach: a head unit that restarts CarLife on an untouched cable, and attach intents that only reach a foreground activity.
Tests
CarlifeUsbEventsTestnow attaches through a seam and ends sessions explicitly, with sweeps driven by a manual timer, so the tests stay deterministic. New cases: session end without detach reopens on the next sweep; closing a detached lease neither reports loss nor drops the next lease; sweeps run only while no lease is live; a revoked grant is retried; the attached broadcast rescans.AccessoryAttachmentTestcovers generation-keyed release.Tests and lint were not run locally; CI runs them. Not yet verified on a head unit.