Skip to content

Commit 141f9b7

Browse files
marcbaechingermicrokatz
authored andcommitted
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: #917 #minor-release PiperOrigin-RevId: 595699929 (cherry picked from commit 5c50b27)
1 parent 77d220c commit 141f9b7

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

RELEASENOTES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@
6666
* Fix a bug where setting a negative time for a disabled `setWhen` timer
6767
of the notification caused a crash on some devices
6868
([#903](https://github.com/androidx/media/issues/903)).
69+
* Fix `IllegalStateException` when the media notification controller
70+
hasn't completed connecting when the first notification update is
71+
requested ([#917](https://github.com/androidx/media/issues/917)).
6972
* UI:
7073
* Fix issue where forward and rewind buttons are not visible when used
7174
with Material Design in a BottomSheetDialogFragment

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ private boolean shouldShowNotification(MediaSession session) {
262262
@Nullable
263263
private MediaController getConnectedControllerForSession(MediaSession session) {
264264
ListenableFuture<MediaController> controller = controllerMap.get(session);
265-
if (controller == null) {
265+
if (controller == null || !controller.isDone()) {
266266
return null;
267267
}
268268
try {

0 commit comments

Comments
 (0)