Skip to content

Commit

Permalink
Return null if media notification controller Future is not done
Browse files Browse the repository at this point in the history
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
  • Loading branch information
marcbaechinger authored and Copybara-Service committed Jan 4, 2024
1 parent 1cb6865 commit 5c50b27
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ private boolean shouldShowNotification(MediaSession session) {
@Nullable
private MediaController getConnectedControllerForSession(MediaSession session) {
ListenableFuture<MediaController> controller = controllerMap.get(session);
if (controller == null) {
if (controller == null || !controller.isDone()) {
return null;
}
try {
Expand Down

0 comments on commit 5c50b27

Please sign in to comment.