Skip to content

How is Cup's native Android playback tested on the emulator and the Pixel? #426

Closed

Description

@patricktree

Question

How is Cup's native Android playback tested? Which behavior the mobile E2E suite (ADR 0018, loopback exempt from the network cut and freezer) covers on the emulator, which plugin logic gets unit tests, and what the physical-device protocol checks on the operator's Pixel 10 Pro.

Carried over for the protocol: a Pixel Bud out and back in (HCI snoop log shows the pause reaching Cup's session), a headphone disconnect, a call (also adb emu gsm call), another app taking focus, a ducking prompt (now a pause), a notification or earbud Play after the 10-minute grace, a call longer than the grace, swiping Cup from recents. New: a locked listen longer than an hour with positions saved, and the stop when the track URL expires.


Written by @patricktree's agent (Claude Code, Claude Opus 5.5).

Activity

  1. self-assigned this
    on Nov 16, 2026
  2. patricktree commented on Nov 16, 2026

    @patricktree
    CollaboratorAuthor

    Resolution

    Decided with the operator on 2026-11-16. The rule: automate everything the emulator can show, and leave only what needs real hardware or production networking to a manual check on the Pixel 10 Pro.

    Emulator: Android mobile E2E suite (deploy gate)

    These run against the test Worker. Each is a case in qa/mobile-e2e/test/android/ and extends what draft PR #401's media-session.test.ts already does.

    1. Play and the session. No notification exists before the first Play. After it, the service runs in the foreground with type mediaPlayback. dumpsys media_session shows Cup's session PLAYING, with the title, artwork present and the whole duration. The shade's progress text matches the position.
    2. System controls. KEYCODE_MEDIA_PAUSE and KEYCODE_MEDIA_PLAY, tapping the notification's back 15 and forward 15 buttons, and dragging the shade's seek bar all change the position. Each pause or seek saves it, which the Worker logs as a PUT /api/audiobooks/{id}/position?token=….
    3. Locked listen. Turn the screen off (KEYCODE_POWER, keyguard without PIN) and press HOME, then wait about 120 s, past the freezer's 60 to 90 s. Then check:
      • Cup's process has isFrozen=false.
      • The service is still in the foreground.
      • The position advanced.
      • Saves arrived at the save interval.
    4. Audio focus.
      • During adb emu gsm call, playback pauses, and it resumes after gsm cancel.
      • A transient focus request pauses and then resumes playback.
      • A duck request pauses playback.
    5. Failure paths.
      • Dropping adb reverse while playing pauses playback and shows "Press Play to try again".
      • A track URL that has expired or returns 403 stops the service and removes the notification. The next Play renews the URL and plays.
    6. Lifecycle.
      • Swiping Cup from recents keeps a playing session.
      • A relaunch adopts that session and shows the plugin's position.
      • Sign-out runs close("save"), which saves the position and stops the service.
      • With the shortened grace (seam c), the session leaves the foreground after the grace and the notification stays.
      • A notification Play after the grace works.
      • A call longer than the grace is covered.

    Debug-only test seams are passed the same way as cupTestApiOrigin:

    • (a) The test Worker issues short-lived track and position URLs, the way the sign-in test shortens the token lifetime.
    • (b) A debug-source-set FocusProbePlugin requests transient, duck or full audio focus on an adb command.
    • (c) A shortened Media3 foreground grace of about 10 s. If Media3 doesn't expose that timeout, the grace cases in item 6 move to the manual protocol.

    The suite can't reproduce the background network cut, because loopback is exempt. It only shows the unfrozen process state that keeps network access. If ExoPlayer doesn't advance under the emulator's -no-audio, the Android emulator starts with audio enabled, as the #373 probe did.

    The added runtime of about 3 to 5 minutes on Android is accepted. Android runs in parallel with iOS, and Turbo replays passes.

    Native unit tests (review gate)

    • The plugin's decision logic lives in plain Java classes with no Android imports:
      • position conversion (listeningPositionAt, mirroring the web player's cases)
      • the save rules and PlaybackSession's retry and ordering, with an injected clock
      • whether the track URL has expired
    • These classes are tested with JUnit 4 on the JVM, without Robolectric. ExoPlayer and MediaSessionService wiring is left to the E2E suite.
    • The code is Java, to match the existing Android code. This reverses the "port to Kotlin" remark in Who saves the listening position in Cup's Android app, and how does the page take over from the native player?.
    • apps/mobile-app gets a turbo:test that runs ./gradlew testDebugUnitTest, so the tests run in the review gate. The review gate therefore checks JDK 21 and the Android SDK as prerequisites, which only the deploy gate checks today.

    Web-side tests (Vitest, apps/web-app)

    • The navigator.mediaSession handlers and position state, for every platform.
    • Both createPlayer implementations behind the Player port. The native-backed one is tested against a fake plugin that emits state events and answers getState().
    • The page adopting or closing a running session at startup.
    • The save-rule tests in player-host.test.ts go through the Player port, so the browser implementation keeps the coverage it has today.

    Manual Pixel protocol

    The protocol is a checked-in checklist in qa/mobile-e2e/ (for example physical-device-protocol.md), linked from the README, so CUP-44 can grow it. During a run, the agent drives everything it can over adb: dumpsys, process state, the HCI snoop log, and the saved positions and Workers Logs. The operator does only the physical actions. The checks:

    1. A Pixel Bud taken out and put back in. The HCI snoop log shows the AVRCP pause reaching Cup's session.
    2. Both Buds put in the case, or a wired disconnect (AUDIO_BECOMING_NOISY).
    3. Another real app taking focus.
    4. An earbud Play after the grace.
    5. A locked listen longer than an hour against production. The evidence is the position the server saved at the end compared with the elapsed time, a spot check of the Workers Logs for regular writes, and dumpsys showing the service still in the foreground.
    6. A visual check of the lock screen's media controls and cover image.

    A real incoming call is dropped; the emulator's gsm call covers calls.

    The protocol runs once, as CUP-41's acceptance check before it moves to production QA. It runs again only when the plugin's native code, its Media3 version or the target Android version changes. Each run's result goes in that Linear comment. It is not a gate step.


    Written by @patricktree's agent (Claude Code, Claude Opus 5.5).

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions