From 5c50b27e8fce878bc24852498ae42298613d5ad2 Mon Sep 17 00:00:00 2001 From: bachinger Date: Thu, 4 Jan 2024 07:31:42 -0800 Subject: [PATCH] Return null if media notification controller Future is not done When the media notification controller is requested for a session with `getConnectedControllerForSession` and the `Future` is not null but not yet completed, the `Future` was returned either way. This was reported as creating a race condition between the notification being requested for update the very first time, and the media notification controller having completed connecting to the session. Returning null from `getConnectedControllerForSession` when the `Future` is available but not yet done fixes the problem. This is safe because for the case when a notification update is dropped, the media notification controller will trigger the update as soon as the connection completes. Issue: androidx/media#917 #minor-release PiperOrigin-RevId: 595699929 --- RELEASENOTES.md | 3 +++ .../java/androidx/media3/session/MediaNotificationManager.java | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 4b754f3037..7980e4e0f1 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -123,6 +123,9 @@ * Fix a bug where setting a negative time for a disabled `setWhen` timer of the notification caused a crash on some devices ([#903](https://github.com/androidx/media/issues/903)). + * Fix `IllegalStateException` when the media notification controller + hasn't completed connecting when the first notification update is + requested ([#917](https://github.com/androidx/media/issues/917)). * UI: * Fix issue where forward and rewind buttons are not visible when used with Material Design in a BottomSheetDialogFragment diff --git a/libraries/session/src/main/java/androidx/media3/session/MediaNotificationManager.java b/libraries/session/src/main/java/androidx/media3/session/MediaNotificationManager.java index b8ad16d4de..98a5833776 100644 --- a/libraries/session/src/main/java/androidx/media3/session/MediaNotificationManager.java +++ b/libraries/session/src/main/java/androidx/media3/session/MediaNotificationManager.java @@ -260,7 +260,7 @@ import java.util.concurrent.TimeoutException; @Nullable private MediaController getConnectedControllerForSession(MediaSession session) { ListenableFuture controller = controllerMap.get(session); - if (controller == null) { + if (controller == null || !controller.isDone()) { return null; } try {