Skip to content

Commit 7fdc5b2

Browse files
marcbaechingercopybara-github
authored andcommitted
Check whether a session is still managed before removing
When the controller of the `MediaNotificationManager` is disconnected, the session is removed from the service without checking whether the session hasn't already been removed. This caused flakiness in `MediaSessionServiceTest.addSession()`. Because there is a public API `MediaSessionService.removeSession()`, the controller can't make an assumption whether the session is still contained in the service when being disconnected. #minor-release PiperOrigin-RevId: 572568350
1 parent cef85be commit 7fdc5b2

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,9 @@ public void onAvailableSessionCommandsChanged(
392392

393393
@Override
394394
public void onDisconnected(MediaController controller) {
395-
mediaSessionService.removeSession(session);
395+
if (mediaSessionService.isSessionAdded(session)) {
396+
mediaSessionService.removeSession(session);
397+
}
396398
// We may need to hide the notification.
397399
mediaSessionService.onUpdateNotificationInternal(
398400
session, /* startInForegroundWhenPaused= */ false);

0 commit comments

Comments
 (0)