Skip to content

Harden media button event sequencing - #5646

Draft
joashrajin wants to merge 3 commits into
mainfrom
codex/serialize-media-button-events
Draft

Harden media button event sequencing#5646
joashrajin wants to merge 3 commits into
mainfrom
codex/serialize-media-button-events

Conversation

@joashrajin

@joashrajin joashrajin commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Description

Media-button callbacks currently launch queue work onto a shared multi-threaded
scope. MediaEventQueue stores its tap jobs and counter in unsynchronized mutable
state, so concurrent callbacks can create multiple tap windows or observe events
out of order.

This PR is the first, independently tested part of the #5645 stack:

  • Protect tap-window state and the tap counter with a mutex without holding the
    mutex across the 600 ms disambiguation window.
  • Introduce a shared MediaButtonEventHandler that owns key-code mapping, error
    handling, and ordered event registration.
  • Register each event before returning to the framework callback, while keeping
    resolved media actions asynchronous on the supplied scope.
  • Preserve Pixel Buds NEXT/PREVIOUS followed by spurious PLAY suppression.
  • Add eight-thread contention coverage plus focused handler behavior tests.

The follow-up PR #5645 wires this processor into the Media3 and legacy session
callbacks and contains the user-facing explicit-play behavior. Keeping the
processor and its unit tests here leaves both PRs below the 500-line review
threshold.

Related to #5631

Testing Instructions

  1. Run:

    ./gradlew :modules:services:repositories:testDebugUnitTest \
      --tests '*MediaEventQueueTest*' \
      --tests '*MediaButtonEventHandlerTest*'
  2. Confirm all 19 focused tests pass.

  3. Run ./gradlew :modules:services:repositories:testDebugUnitTest and confirm
    all 856 tests pass.

  4. Run ./gradlew spotlessCheck.

No manual playback verification is needed for this preparatory PR because the
handler is integrated into the application callbacks in #5645.

Screenshots or Screencast

Not applicable; there are no UI changes.

Checklist

  • If this is a user-facing change, I have added an entry in CHANGELOG.md — not user-facing on its own
  • Ensure the linter passes (./gradlew spotlessApply to automatically apply formatting/linting)
  • I have considered whether it makes sense to add tests for my changes
  • All strings that need to be localized are in modules/services/localization/src/main/res/values/strings.xml — no strings
  • Any jetpack compose components I added or changed are covered by compose previews — no UI
  • I have updated (or requested that someone edit) the Event Horizon schema to reflect any new or changed analytics — no analytics changes

I have tested any UI changes...

Not applicable; there are no UI changes.

@joashrajin joashrajin added [Type] Bug Not functioning as intended. [Area] Playback Episode playback issue labels Jul 25, 2026
@joashrajin joashrajin added this to the 8.18 milestone Jul 25, 2026
@claude

claude Bot commented Jul 25, 2026

Copy link
Copy Markdown

Claude Code is working…

I'll analyze this and get back to you.

View job run

@dangermattic

Copy link
Copy Markdown
Collaborator
1 Message
📖 This PR is still a Draft: some checks will be skipped.

Generated by 🚫 Danger

@wpmobilebot wpmobilebot modified the milestones: 8.18, 8.19 Aug 3, 2026
@wpmobilebot

Copy link
Copy Markdown
Collaborator

Version 8.18 has now entered code-freeze, so the milestone of this PR has been updated to 8.19.

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

Labels

[Area] Playback Episode playback issue [Type] Bug Not functioning as intended.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants