Skip to content

Commit

Permalink
Check whether a session is still managed before removing
Browse files Browse the repository at this point in the history
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
  • Loading branch information
marcbaechinger authored and copybara-github committed Oct 11, 2023
1 parent cef85be commit 7fdc5b2
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,9 @@ public void onAvailableSessionCommandsChanged(

@Override
public void onDisconnected(MediaController controller) {
mediaSessionService.removeSession(session);
if (mediaSessionService.isSessionAdded(session)) {
mediaSessionService.removeSession(session);
}
// We may need to hide the notification.
mediaSessionService.onUpdateNotificationInternal(
session, /* startInForegroundWhenPaused= */ false);
Expand Down

0 comments on commit 7fdc5b2

Please sign in to comment.