Keep the skips in the phone notification when no car is connected #38

Closed
opened 2026-09-18 08:47:54 +02:00 by alexander · 0 comments
Owner

Migrated from GitHub issue #130. Forgejo issue: #38. GitHub source content synchronized on 2026-09-19. Migrated issue references below use Forgejo numbers where an equivalent issue exists; historical references without a Forgejo counterpart remain explicit GitHub links.

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 setMediaButtonPreferences overloads write the same MediaSessionLegacyStub.mediaButtonPreferences field, and the legacy stub's connection callback never reads ConnectionResult.mediaButtonPreferences at 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.onConnect and onDisconnected both already call republishOutputButtons(), so the layout is already recomputed at exactly the two moments that matter.

So the proposal is:

State SLOT_BACK SLOT_FORWARD Overflow
No car bound skip back skip forward Car, Headset, sleep timer
Car bound Car Headset skip back, skip forward, sleep timer

The 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.inPriorityOrder currently always puts the output actions first. Give it the car state and swap the two groups:

fun inPriorityOrder(
    outputActions: List<CommandButton>,
    skipActions: List<CommandButton>,
    overflowActions: List<CommandButton>,
    carBound: Boolean,
): List<CommandButton> =
    if (carBound) outputActions + skipActions + overflowActions
    else skipActions + outputActions + overflowActions

Both groups already declare their primary slot with SLOT_OVERFLOW as the fallback, so whichever loses is relocated rather than dropped — no other change is needed to the buttons themselves.

carBound has to be plumbed in. Note that OutputButtons.showCar is not the right signal: it is carConnected || car(outputs) != null, so it is also true for a car audio device that is merely present with no controller bound. Use carConnections.isConnected() directly, or add a distinct field.

The invariant still has to hold

Some button must occupy SLOT_BACK in every state, in both modes. If it is ever vacated, Media3 stops clearing ACTION_SKIP_TO_PREVIOUS, nothing in this app intercepts it, and a head unit's previous reaches Player.seekToPrevious and restarts a thirty-four-hour book. MediaButtonLayoutTest already 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 DefaultMediaNotificationProvider and overriding getMediaButtons(...) 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

  • With no car connected, the phone's compact media control shows skip back and skip forward.
  • With a car connected, the car's control bar shows Car and Headset.
  • Connecting and disconnecting a car switches the layout without a republish storm and without interrupting playback.
  • SLOT_BACK is occupied in every combination of car state and shown output actions, asserted by a test that fails when it is not.
  • GitHub #78, docs/risks.md R-109 — the original trade and what it cost
  • ADR-0029 §8
  • MediaButtonLayout, MediaButtonLayoutTest, MediaButtonSlotConversionTest
> Migrated from [GitHub issue #130](https://github.com/AlexanderWilhelmsenBerg/Audiobookshelf-Manager-Claude/issues/130). Forgejo issue: #38. GitHub source content synchronized on 2026-09-19. Migrated issue references below use Forgejo numbers where an equivalent issue exists; historical references without a Forgejo counterpart remain explicit GitHub links. Reported by the owner on 2026-09-08 after [GitHub #78](https://github.com/AlexanderWilhelmsenBerg/Audiobookshelf-Manager-Claude/issues/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](https://github.com/AlexanderWilhelmsenBerg/Audiobookshelf-Manager-Claude/issues/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 `setMediaButtonPreferences` overloads write the same `MediaSessionLegacyStub.mediaButtonPreferences` field, and the legacy stub's connection callback never reads `ConnectionResult.mediaButtonPreferences` at 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.onConnect` **and** `onDisconnected` both already call `republishOutputButtons()`, so the layout is already recomputed at exactly the two moments that matter. So the proposal is: | State | `SLOT_BACK` | `SLOT_FORWARD` | Overflow | |---|---|---|---| | **No car bound** | skip back | skip forward | Car, Headset, sleep timer | | **Car bound** | Car | Headset | skip back, skip forward, sleep timer | The 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.inPriorityOrder` currently always puts the output actions first. Give it the car state and swap the two groups: ```kotlin fun inPriorityOrder( outputActions: List<CommandButton>, skipActions: List<CommandButton>, overflowActions: List<CommandButton>, carBound: Boolean, ): List<CommandButton> = if (carBound) outputActions + skipActions + overflowActions else skipActions + outputActions + overflowActions ``` Both groups already declare their primary slot with `SLOT_OVERFLOW` as the fallback, so whichever loses is relocated rather than dropped — no other change is needed to the buttons themselves. `carBound` has to be plumbed in. Note that `OutputButtons.showCar` is **not** the right signal: it is `carConnected || car(outputs) != null`, so it is also true for a car audio device that is merely present with no controller bound. Use `carConnections.isConnected()` directly, or add a distinct field. ## The invariant still has to hold **Some button must occupy `SLOT_BACK` in every state, in both modes.** If it is ever vacated, Media3 stops clearing `ACTION_SKIP_TO_PREVIOUS`, nothing in this app intercepts it, and a head unit's *previous* reaches `Player.seekToPrevious` and restarts a thirty-four-hour book. `MediaButtonLayoutTest` already 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 `DefaultMediaNotificationProvider` and overriding `getMediaButtons(...)` 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 - With no car connected, the phone's compact media control shows skip back and skip forward. - With a car connected, the car's control bar shows Car and Headset. - Connecting and disconnecting a car switches the layout without a republish storm and without interrupting playback. - `SLOT_BACK` is occupied in every combination of car state and shown output actions, asserted by a test that fails when it is not. ## Related - [GitHub #78](https://github.com/AlexanderWilhelmsenBerg/Audiobookshelf-Manager-Claude/issues/78), `docs/risks.md` R-109 — the original trade and what it cost - ADR-0029 §8 - `MediaButtonLayout`, `MediaButtonLayoutTest`, `MediaButtonSlotConversionTest`
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
alexander/Audiobookshelf-Manager-Claude#38
No description provided.