Skip to content

Lockscreen / Quick-Settings media tile only shows 2 of 5 controls for audiobooks #12

Closed

Description

@libravault-xyz

Summary

On Android 13+ the lockscreen "Live notifications" media card and the Quick-Settings media output panel only show 2 of the 5 controls that the in-app player exposes. The system tile shows [<<, ▶/||] (and sometimes [<<, ▶] while paused); the in-app expanded notification correctly shows all 5 ([Prev | −seek | Play/Pause | +seek | Next]).

This has been worked on in three commits, all of which fixed a different problem than the one that turned out to be the real cause. The current state on dev is the b60e925 build (commit 27d1772 reverted a later broken attempt). Notification has 5 controls, system tile has 2.

Symptoms

  • Lockscreen "Live notifications" card: [<<, ▶] only (no Prev, no +seek, no Next).
  • Quick-Settings media output panel: same.
  • Expanded notification: all 5 buttons, working.
  • In-app reader/library mini-player: all 5 buttons, working.
  • Tapping play/pause on the system tile works correctly (the system ACTION_PLAY_PAUSE is honored).

Environment

  • androidx.media3:media3-session:1.3.1 (per gradle/libs.versions.toml).
  • Android 13+ (system surface changed; on older Android the notification itself is the surface, so 5 controls appear).
  • Affected surfaces: lockscreen media card, Quick-Settings media output panel.

What has been tried

  1. PR fix(player): expand lockscreen & in-app media tile to 5 controls, honor skip-duration setting #11 / c82fc24 "expand lockscreen & in-app media tile to 5 controls" — fixed the expanded notification to render 5 actions. Did not address the system tile. The notification-side fix is correct and stays. The system tile was not affected because the system tile does not read the notification's compact-view indices.

  2. b60e925 "publish 5-button customLayout to MediaSession" — added MediaSession.Builder.setCustomLayout(...) in PlaybackService.onCreate with 5 CommandButtons using Player.COMMAND_* shortcuts. This did not change the system tile because PlayerWrapper.createPlaybackStateCompat (verified against the AAR via javap of media3-session-1.3.1.aar) only adds a button to PlaybackStateCompat.customActions when the button's sessionCommand.commandCode == COMMAND_CODE_CUSTOM (value 0). Player.COMMAND_* buttons are silently dropped at that filter.

  3. 7d54659 "use custom SessionCommands so 5 buttons actually appear on lockscreen/QS tile" — replaced Player.COMMAND_* with custom SessionCommands and added a MediaSession.Callback that dispatches the four unique actions (Prev/Next/PlayPause/SEEK_BY) in onCustomCommand. After install + force-stop, the user got "Playback service unavailable." in the in-app reader. Reverted in 27d1772 because the failure mode wasn't diagnosed and shipping unverified code had broken the service. No logcat was captured at the time.

Hypothesis (unverified)

The fix in 7d54659 is the right shape: use CommandButton.setSessionCommand(SessionCommand(action, extras)) with COMMAND_CODE_CUSTOM so the buttons survive PlayerWrapper.createPlaybackStateCompat's filter, and handle the dispatch in a MediaSession.Callback.onCustomCommand. What made it throw on device isn't known yet — the most likely candidates are:

  • A Hilt injection or annotation-processor issue (callback inner class, generics).
  • A MediaSession.ConnectionResult.AcceptedResultBuilder API misuse in 1.3.1.
  • Something specific to the user's PlaybackState configuration (e.g. setMediaNotificationProvider called before MediaSession.Builder).

The bytecode of MediaSession.Builder.build() and MediaSessionImpl.<init> (Media3 1.3.1) shows no checkNotNull or checkArgument on the inputs we pass (customLayout, callback, player), so a build-time throw from those is unlikely. The throw is more likely in Media3's MediaSessionLegacyStub.<init> or a later step (e.g. notification controller connect), neither of which has been ruled out yet.

Diagnostic logging to land next

To find the actual exception, PlaybackService.onCreate and the callback are being instrumented with android.util.Log calls. After the next build, the user will install + force-stop + open a book, then run:

adb logcat -d -s LibravaultPlayback:V AndroidRuntime:E *:S

The logcat output should pin down which step in onCreate is throwing and why. Once the real cause is known, the fix can be done with confidence and a Robolectric or instrumented test added so the regression can't happen again.

Acceptance criteria

  • The system media tile (lockscreen + Quick-Settings) renders all 5 controls: Prev, −seek, Play/Pause, +seek, Next.
  • Tapping any of the 5 controls on the system tile actually drives the player.
  • PlaybackService starts without throwing in onCreate (no "Playback service unavailable." in the in-app reader).
  • A regression test exists in the repo that fails if this regresses (Robolectric or instrumented test that exercises the service start path).

Related

Activity

  1. libravault-xyz commented on Jul 16, 2026

    @libravault-xyz
    CollaboratorAuthor

    Update after bytecode analysis of media3-session-1.3.1.aar

    I decompiled the actual AAR (not just the source) and read the bytecode byte-for-byte. Here's what I now know with high confidence.

    What is certain (from bytecode)

    PlayerWrapper.createPlaybackStateCompat filters customLayout before adding anything to PlaybackStateCompat.customActions. Reading the bytecode at the for (i = 0; i < customLayout.size(); i++) loop:

       sessionCommand = button.sessionCommand;
       if (sessionCommand == null)              goto 423   // skip
       if (sessionCommand.commandCode != 0)      goto 423   // skip (0 == COMMAND_CODE_CUSTOM)
       if (!isEnabled(button, availableSessionCommands, availablePlayerCommands)) goto 423   // skip
       builder.addCustomAction(...);
    423: i++;
    

    So:

    • Player.COMMAND_* buttons (no sessionCommand) → skipped. My hypothesis was right.
    • SessionCommand with commandCode != COMMAND_CODE_CUSTOM → skipped.
    • SessionCommand with commandCode == COMMAND_CODE_CUSTOM but !isEnabled → skipped.

    CommandButton.isEnabled(button, availableSessionCommands, availablePlayerCommands) (also decompiled):

    • If button.sessionCommand != null: returns availableSessionCommands.contains(button.sessionCommand).
    • Else if button.playerCommand != COMMAND_INVALID: returns availablePlayerCommands.contains(button.playerCommand).
    • Else: false.

    MediaSessionImpl.<init> seeds playerWrapper.availableSessionCommands = EMPTY and playerWrapper.availablePlayerCommands = EMPTY. The PlayerWrapper ctor is called from MediaSessionImpl with the result of an AcceptedResultBuilder.build() that has no .setAvailableSessionCommands() / .setAvailablePlayerCommands() calls — so both fields default to EMPTY.

    MediaSessionImpl.onConnectOnHandler only writes back to playerWrapper via setAvailableFrameworkControllerCommands(sessionCmds, playerCmds) when the connecting controller is isMediaNotificationController(controller) — i.e. the app's own MediaController connecting back (package name matches app's, controllerVersion != 0, with the MediaNotificationManager connection hint). This sets isMediaNotificationControllerConnected = true. From that point on, systemui (com.android.systemui, controllerVersion == 0) hits the auto-accept branch (offset 0-59) and gets playerWrapper.getCustomLayout() / getAvailableSessionCommands() / getAvailablePlayerCommands().

    So the race to get the system tile to show 5 buttons is: the app's own MediaController (created by MediaNotificationManager) must connect first and return a ConnectionResult with availableSessionCommands containing the same custom session commands we publish in customLayout. Without a Callback.onConnect, no controller returns non-empty availableSessionCommands, so all session-command buttons fail isEnabled and get filtered out.

    What I'm still missing

    I cannot explain from the bytecode alone why the user's lockscreen currently shows 2 buttons (<< and ▶/PlayPause) rather than 0 or 5. The standard actions bitmask in createPlaybackStateCompat is computed as:

    actions = ACTION_SET_RATING
            | OR-over(convertCommandToPlaybackStateActions(cmd)
                       for cmd in intersect(availablePlayerCommands, player.availableCommands))
    

    If availablePlayerCommands == EMPTY, actions only contains ACTION_SET_RATING — i.e. the system should render no transport buttons at all. Yet the user sees << and ▶. So something IS populating availablePlayerCommands on the system controller's connection.

    The most likely possibilities I haven't ruled out:

    1. Samsung One UI's com.android.systemui (or com.samsung.android.app.spage/com.sec.android.app.launcher) connects as the media notification controller, not as systemui — i.e. Samsung routes the lockscreen surface through a different package that happens to satisfy isMediaNotificationController's packageName == context.packageName test under some other condition. That would explain why availablePlayerCommands is non-empty on first connect.
    2. Some vendor-specific OEM controller override that I haven't found in the AAR.
    3. My reading of the bytecode has an off-by-one or a missed branch.

    Without logcat from the user's device, I cannot tell which. The diagnostic-instrumentation commit 2d675ba (currently on dev HEAD) will surface the answer — install it, force-stop, open the book, then run:

    adb logcat -c
    adb logcat -d -s LibravaultPlayback:V AndroidRuntime:E *:S
    

    If logcat shows MediaButtonCallback.onConnect: pkg=com.android.systemui or pkg=com.samsung... then it's case #1 above and the architecture is fine — we just need Callback.onConnect to return the right commands for systemui. If it shows pkg=xyz.libravault.reader, then the app's own controller is the one populating things.

    What I will NOT do

    I will not push another 7d54659-style fix without logcat. That attempt was based on a partial read; the next one will be based on full evidence. The 2d675ba build is currently in ~/Downloads/libravault-dev-fdroid-debug.apk (md5 9070c554935f5e8b65c0034e4885e17c).

    What I'm now confident the right fix looks like

    Given the bytecode analysis, the fix is almost certainly a MediaSession.Callback.onConnect that returns a ConnectionResult.AcceptedResultBuilder(session).setAvailableSessionCommands(SessionCommands containing PREVIOUS, NEXT, PLAY_PAUSE, SEEK_BY).setAvailablePlayerCommands(<standard 5 Player.Command intents for the seek/play/preview set>).build() — for any connecting controller, including systemui. This populates the controller-side availableSessionCommands so isEnabled passes for session-command buttons in createPlaybackStateCompat, AND populates availablePlayerCommands (via the isMediaNotificationController branch) so the next systemui connect sees the proper commands in the auto-accept path.

    But I won't ship that without first seeing the logcat from 2d675ba to confirm exactly which controller (systemui or app-internal) is what populates availablePlayerCommands today.

  2. libravault-xyz commented on Jul 16, 2026

    @libravault-xyz
    CollaboratorAuthor

    Confirmed root cause: dev (b60e925 state, post-27d1772 revert) is still on the approach that point 2 in this issue already showed doesn't work — nothing regressed further, but nothing was fixed either.

    PlaybackService.onCreate calls builder.setCustomLayout(standardStrip) where standardStrip comes from LibravaultNotificationProvider.buildStandardStrip, and every button there is built with .setPlayerCommand(Player.COMMAND_SEEK_*...) — none has a sessionCommand.

    Two independent consumers of this:

    • Notification (getMediaButtons/addNotificationActions) builds RemoteViews actions straight from the CommandButton list — doesn't care about sessionCommand. This is why the expanded notification is fine.
    • System tile (Android 13+) reads PlaybackStateCompat, built via Media3's legacy bridge (PlayerWrapper.createPlaybackStateCompat). That bridge only forwards a customLayout entry into PlaybackStateCompat.customActions when sessionCommand?.commandCode == COMMAND_CODE_CUSTOM. Player-command buttons have sessionCommand == null, so all 5 get filtered out before the tile sees them.

    What the tile shows instead is the standard-actions bitmask, derived automatically from Player.Commands availability, independent of customLayout: ACTION_PLAY_PAUSE (always) + ACTION_REWIND (COMMAND_SEEK_BACK available) = [<<, ▶/||]. Prev/Next are disabled (single-item audiobook playlist), which is why they drop out too.

    So attempt 3 (7d54659) was the right shape — real SessionCommands with COMMAND_CODE_CUSTOM + MediaSession.Callback.onCustomCommand is the only path that populates customActions. It just crashed ("Playback service unavailable.") before the cause was captured. Recommend reapplying 7d54659 on a branch with the existing Log.i/Log.e instrumentation in PlaybackService.onCreate and actually grabbing:

    adb logcat -d -s LibravaultPlayback:V AndroidRuntime:E *:S
    

    before any further revert, so the real exception (DI, AcceptedResultBuilder misuse, or ordering with setMediaNotificationProvider) gets identified instead of guessed at again.

  3. added a commit that references this issue on Aug 2, 2026
    8f25d56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions