Keep the skips in the phone notification when no car is connected #38
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Reported by the owner on 2026-09-08 after GitHub #78: "I didn't get that car and headset was in the notifications too, is it possible to show seek when not in the car?"
Fair, and it was under-communicated. GitHub #78 gave Car and Headset the two app-claimable primary slots at the owner's request — "I need them more than seek forward and back" — which was asked and answered about the car's compact bar. The phone notification taking the same change was a consequence, mentioned once and not made prominent enough before the decision.
Why it happened
Android Auto and API-33+ System UI read the same single media-button layout. Both
setMediaButtonPreferencesoverloads write the sameMediaSessionLegacyStub.mediaButtonPreferencesfield, and the legacy stub's connection callback never readsConnectionResult.mediaButtonPreferencesat all — so no ordering of calls produces two layouts at the same time. That much is measured and is not worth re-testing.But they do not have to be simultaneous
The phone and the car are not both in use at the same moment. The layout can simply follow whether a car is bound, and the machinery for that already exists:
CarConnections.isConnected()already tracks bound car controllers, counted rather than flagged so two controllers do not confuse it.PlaybackService.onConnectandonDisconnectedboth already callrepublishOutputButtons(), so the layout is already recomputed at exactly the two moments that matter.So the proposal is:
SLOT_BACKSLOT_FORWARDThe driver gets what they asked for in the car. The phone keeps its skips the rest of the time — which is almost all of the time, and is the surface where skipping is done by looking rather than by feel.
While a car is connected the phone notification also shows Car and Headset. That is acceptable: the phone is in a pocket or a cradle and the head unit is the surface in use.
Implementation sketch
MediaButtonLayout.inPriorityOrdercurrently always puts the output actions first. Give it the car state and swap the two groups:Both groups already declare their primary slot with
SLOT_OVERFLOWas the fallback, so whichever loses is relocated rather than dropped — no other change is needed to the buttons themselves.carBoundhas to be plumbed in. Note thatOutputButtons.showCaris not the right signal: it iscarConnected || car(outputs) != null, so it is also true for a car audio device that is merely present with no controller bound. UsecarConnections.isConnected()directly, or add a distinct field.The invariant still has to hold
Some button must occupy
SLOT_BACKin every state, in both modes. If it is ever vacated, Media3 stops clearingACTION_SKIP_TO_PREVIOUS, nothing in this app intercepts it, and a head unit's previous reachesPlayer.seekToPreviousand restarts a thirty-four-hour book.MediaButtonLayoutTestalready asserts this across the four show/hide combinations; the test must be extended to cover both car states, not just re-run.Not the answer
Subclassing
DefaultMediaNotificationProviderand overridinggetMediaButtons(...)genuinely does give the notification its own layout — but only on API 26–32. On API 33+ System UI derives its buttons from the session rather than from the notification's actions, so it would leave most phones unchanged while adding a second layout path to maintain. Do not start there.Acceptance
SLOT_BACKis occupied in every combination of car state and shown output actions, asserted by a test that fails when it is not.Related
docs/risks.mdR-109 — the original trade and what it costMediaButtonLayout,MediaButtonLayoutTest,MediaButtonSlotConversionTest