Skip to content

Serialize audio capability callbacks on receiver handler - #3388

Open
ajay-jg wants to merge 3 commits into
androidx:mainfrom
ajay-jg:fix-audio-capabilities-callback-thread
Open

Serialize audio capability callbacks on receiver handler#3388
ajay-jg wants to merge 3 commits into
androidx:mainfrom
ajay-jg:fix-audio-capabilities-callback-thread

Conversation

@ajay-jg

@ajay-jg ajay-jg commented Aug 20, 2026

Copy link
Copy Markdown

Fixes #3386.

Context

Some Android devices invoke AudioDeviceCallback from an OEM thread instead of the Handler supplied during registration. This violates the AudioManager callback contract and can notify DefaultAudioSink off its playback looper.

The resulting crash is:

IllegalStateException: Current looper (null) is not the playback looper

Change

This change reposts audio-device capability updates to the AudioCapabilitiesReceiver handler only for the confirmed affected device cohort.

The workaround is enabled only when all of the following are true:

  • MediaLibraryInfo.enableWorkarounds() is enabled.
  • SDK_INT < 38.
  • The device matches the narrow static manufacturer/model list.

All other devices retain the existing direct callback path. The API 38 gate allows this workaround to retire where CTS verifies that AudioManager invokes callbacks on the supplied handler thread.

For removed devices, routed-device invalidation and capability recalculation run in the same handler task, preserving receiver state ordering.

Testing

  • Added and removed callbacks are invoked from a looper-less thread.
  • Listener delivery is verified on the receiver handler for an affected device.
  • The workaround is verified disabled when MediaLibraryInfo.enableWorkarounds() is false.
  • ./gradlew :lib-exoplayer:testDebugUnitTest --tests androidx.media3.exoplayer.audio.AudioCapabilitiesReceiverWrongThreadTest --no-daemon passes.

@ajay-jg
ajay-jg marked this pull request as ready for review September 12, 2026 05:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant