Skip to content

Commit dc5c1f9

Browse files
committed
Fix race between media notification (controller) and legacy stub
1 parent 047d489 commit dc5c1f9

File tree

4 files changed

+73
-83
lines changed

4 files changed

+73
-83
lines changed

libraries/session/src/main/java/androidx/media3/session/MediaLibrarySessionImpl.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import android.app.PendingIntent;
2828
import android.content.Context;
2929
import android.os.Bundle;
30-
import android.os.RemoteException;
3130
import androidx.annotation.Nullable;
3231
import androidx.media3.common.MediaItem;
3332
import androidx.media3.common.MediaMetadata;
@@ -359,19 +358,6 @@ protected MediaSessionServiceLegacyStub createLegacyBrowserService(
359358
return stub;
360359
}
361360

362-
@Override
363-
protected void dispatchRemoteControllerTaskWithoutReturn(RemoteControllerTask task) {
364-
super.dispatchRemoteControllerTaskWithoutReturn(task);
365-
@Nullable MediaLibraryServiceLegacyStub legacyStub = getLegacyBrowserService();
366-
if (legacyStub != null) {
367-
try {
368-
task.run(legacyStub.getBrowserLegacyCbForBroadcast(), /* seq= */ 0);
369-
} catch (RemoteException e) {
370-
Log.e(TAG, "Exception in using media1 API", e);
371-
}
372-
}
373-
}
374-
375361
private void maybeUpdateLegacyErrorState(ControllerInfo browser, LibraryResult<?> result) {
376362
if (libraryErrorReplicationMode == MediaLibrarySession.LIBRARY_ERROR_REPLICATION_MODE_NONE
377363
|| browser.getControllerVersion() != ControllerInfo.LEGACY_CONTROLLER_VERSION) {

libraries/session/src/main/java/androidx/media3/session/MediaNotificationManager.java

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -406,20 +406,6 @@ public void onConnected(boolean shouldShowNotification) {
406406
}
407407
}
408408

409-
@Override
410-
public void onMediaButtonPreferencesChanged(
411-
MediaController controller, List<CommandButton> mediaButtonPreferences) {
412-
mediaSessionService.onUpdateNotificationInternal(
413-
session, /* startInForegroundWhenPaused= */ false);
414-
}
415-
416-
@Override
417-
public void onAvailableSessionCommandsChanged(
418-
MediaController controller, SessionCommands commands) {
419-
mediaSessionService.onUpdateNotificationInternal(
420-
session, /* startInForegroundWhenPaused= */ false);
421-
}
422-
423409
@Override
424410
public ListenableFuture<SessionResult> onCustomCommand(
425411
MediaController controller, SessionCommand command, Bundle args) {
@@ -440,20 +426,6 @@ public void onDisconnected(MediaController controller) {
440426
mediaSessionService.onUpdateNotificationInternal(
441427
session, /* startInForegroundWhenPaused= */ false);
442428
}
443-
444-
@Override
445-
public void onEvents(Player player, Player.Events events) {
446-
// We must limit the frequency of notification updates, otherwise the system may suppress
447-
// them.
448-
if (events.containsAny(
449-
Player.EVENT_PLAYBACK_STATE_CHANGED,
450-
Player.EVENT_PLAY_WHEN_READY_CHANGED,
451-
Player.EVENT_MEDIA_METADATA_CHANGED,
452-
Player.EVENT_TIMELINE_CHANGED)) {
453-
mediaSessionService.onUpdateNotificationInternal(
454-
session, /* startInForegroundWhenPaused= */ false);
455-
}
456-
}
457429
}
458430

459431
@SuppressLint("InlinedApi") // Using compile time constant FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK

libraries/session/src/main/java/androidx/media3/session/MediaSessionImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ public ListenableFuture<SessionResult> setCustomLayout(
508508
ControllerInfo controller, ImmutableList<CommandButton> customLayout) {
509509
if (isMediaNotificationController(controller)) {
510510
sessionLegacyStub.setPlatformCustomLayout(customLayout);
511-
sessionLegacyStub.updateLegacySessionPlaybackState(playerWrapper);
511+
sessionLegacyStub.updateLegacySessionPlaybackState(playerWrapper, true);
512512
}
513513
return dispatchRemoteControllerTask(
514514
controller, (controller1, seq) -> controller1.setCustomLayout(seq, customLayout));
@@ -533,7 +533,7 @@ public ListenableFuture<SessionResult> setMediaButtonPreferences(
533533
ControllerInfo controller, ImmutableList<CommandButton> mediaButtonPreferences) {
534534
if (isMediaNotificationController(controller)) {
535535
sessionLegacyStub.setPlatformMediaButtonPreferences(mediaButtonPreferences);
536-
sessionLegacyStub.updateLegacySessionPlaybackState(playerWrapper);
536+
sessionLegacyStub.updateLegacySessionPlaybackState(playerWrapper, true);
537537
}
538538
return dispatchRemoteControllerTask(
539539
controller,

0 commit comments

Comments
 (0)