Skip to content

fix for AOAP negotiation - #52

Open
tomlohave wants to merge 5 commits into
MaKi983:developmentfrom
tomlohave:devel
Open

fix for AOAP negotiation#52
tomlohave wants to merge 5 commits into
MaKi983:developmentfrom
tomlohave:devel

Conversation

@tomlohave

@tomlohave tomlohave commented Aug 16, 2026

Copy link
Copy Markdown

Correction of the index where Version/URI/Serial are sent.

controlTransfer(ACC_REQ_SEND_STRING, ...) with a per-field index — but all
three used index 0, colliding with each other (and with Manufacturer,
which correctly uses 0). Only Manufacturer/Model/Desc (indices 0/1/2) were
ever correctly received. Fixed to 3/4/5, matching the existing convention.
Found by decompiling the old closed-source build (still reliable with the
same phone/cable) and comparing against the current USB init sequence.
Without this it blocks with : Execution failed for task ':app:minifyReleaseWithR8'.
Three related changes:
  a) Tolerate up to 3 consecutive transient USB errors (native code 1 or 2)
     in onChannelError() before actually tearing down the session; counter
     resets on a successful ping/pong.
  b) isQuitting_ is now std::atomic<bool>, set via exchange() in
     triggerQuit()/triggerQuitOnError(), so only one shutdown path runs if
     both the ping watchdog and a channel error fire near-simultaneously.
  c) 300ms delay before the very first send (VersionRequest) after claiming
     the AOAP interface. Tested in the field: no measurable effect on the
     connection issue. Kept because harmless
ISteeringMenuService.registerCallbackEx() can throw IllegalStateException
("beginBroadcast() called while already in a broadcast") — a server-side
bug in the head unit firmware. This doesn't extend RemoteException, so the
existing catch missed it, crashing the whole app and forcing a full USB
renegotiation. Added catch (RuntimeException) on all three IPC calls;
logs and continues instead of crashing.
This fix produced the biggest visible drop in restart-loop frequency.
@tomlohave

tomlohave commented Aug 23, 2026

Copy link
Copy Markdown
Author

Added 3 more patchs with the help of Claude AI and now, no more problem with USB.
It should solved #13, #33 and maybe #44

@MaKi983 MaKi983 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two questions:

  1. What benefits does StartupSettleTimer provide? Have you verified that in some cases sendVersionRequest fails?
  2. Are you sure that handling the errors by simply ignoring them works? Errors 1 and 2 can also be native Android Auto errors, in which case I believe the phone itself disconnects. Have you verified that ignoring them actually works?

@tomlohave

Copy link
Copy Markdown
Author

On the StartupSettleTimer (300ms delay):
I have not observed or confirmed a case in which sendVersionRequest fails. The delay was added as a precautionary measure rather than in response to a verified failure. Field testing showed no measurable effect on the connection issue. I retained it on the grounds that it is harmless, but I can remove it if you'd prefer not to keep code without a demonstrated benefit.

On tolerating errors 1/2:
That's a valid concern. In my testing, tolerating up to three consecutive transient errors (with the counter resetting upon the next successful ping/pong) produced the largest observed reduction in restart-loop frequency, so it has proven effective for my setup (with Nokia 8.3 5G). However, you're correct that error codes 1 and 2 could also indicate a genuine Android Auto-side disconnect. In that scenario, this change would not resolve the underlying issue, it would simply delay detection by up to three error occurrences. The practical risk is a marginally longer delay before a clean reconnection, rather than a silent failure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants