Skip to content

commit dd8c4b8 seems to break Android 12(L) workaround by changing return value #3150

@nift4

Description

@nift4

Version

Media3 main branch

More version details

dd8c4b8

Devices that reproduce the issue

N/A

Devices that do not reproduce the issue

N/A

Reproducible in the demo app?

Not tested

Reproduction steps

This issue only affects Android 12(L). They previously had a workaround in place to catch ForegroundServiceStartNotAllowedException which would then return false from onPlayRequested and not start playback, as that could happen even in valid situations.

@Override
public boolean onPlayRequested(MediaSession session) {
if (SDK_INT < 31 || SDK_INT >= 33) {
return true;
}
// Check if service can start foreground successfully on Android 12 and 12L.
if (!getMediaNotificationManager().isStartedInForeground()) {
return onUpdateNotificationInternal(session, /* startInForegroundWhenPaused= */ true);
}
return true;
}

/* package */ void handleMediaControllerPlayRequest(
ControllerInfo controller, boolean callOnPlayerInteractionFinished) {
if (!onPlayRequested()) {
// Request denied, e.g. due to missing foreground service abilities.
return;

Expected result

Before the commit, if player was on main thread:

  1. onUpdateNotification() throws ForegroundServiceStartNotAllowedException
  2. It's caught in onUpdateNotificationInternal(), false is returned
  3. Thus false is returned by onPlayRequested(), and in MediaSessionImpl.handleMediaControllerPlayRequest(), playback is not started. onForegroundServiceStartNotAllowedException() is called to inform the app

Actual result

  1. onUpdateNotification() throws ForegroundServiceStartNotAllowedException
  2. It's caught, but onUpdateNotificationInternal() still returns true
  3. Thus, in MediaSessionImpl.handleMediaControllerPlayRequest(), playback IS started, onForegroundServiceStartNotAllowedException() is called anyway
  4. Service will attempt to start playing despite not being in foreground

Media

N/A

Bug Report

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions