Commit 80927260 by tianyifeng Committed by Ian Baker

Handle the bitmap loading result with applicationHandler

Before this change, the bitmap loading result with mainHandler, in which we set the metadata to `MediaSessionCompat`. However, the `MediaSessionCompat` is not thread safe, all calls should be made from the same thread. In the other calls to `MediaSessionCompat`, we ensure that they are on the application thread (which may be or may not be main thread), so we should do the same for `setMetadata` when bitmap arrives.

Also removes a comment in `DefaultMediaNotificationProvider` as bitmap request caching is already moved to CacheBitmapLoader.

PiperOrigin-RevId: 490524209
parent 2693ca13
...@@ -244,8 +244,6 @@ public class DefaultMediaNotificationProvider implements MediaNotification.Provi ...@@ -244,8 +244,6 @@ public class DefaultMediaNotificationProvider implements MediaNotification.Provi
private final String channelId; private final String channelId;
@StringRes private final int channelNameResourceId; @StringRes private final int channelNameResourceId;
private final NotificationManager notificationManager; private final NotificationManager notificationManager;
// Cache the last bitmap load request to avoid reloading the bitmap again, particularly useful
// when showing a notification for the same item (e.g. when switching from playing to paused).
private final Handler mainHandler; private final Handler mainHandler;
private @MonotonicNonNull OnBitmapLoadedFutureCallback pendingOnBitmapLoadedFutureCallback; private @MonotonicNonNull OnBitmapLoadedFutureCallback pendingOnBitmapLoadedFutureCallback;
......
...@@ -118,7 +118,6 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; ...@@ -118,7 +118,6 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
private final MediaPlayPauseKeyHandler mediaPlayPauseKeyHandler; private final MediaPlayPauseKeyHandler mediaPlayPauseKeyHandler;
private final MediaSessionCompat sessionCompat; private final MediaSessionCompat sessionCompat;
@Nullable private VolumeProviderCompat volumeProviderCompat; @Nullable private VolumeProviderCompat volumeProviderCompat;
private final Handler mainHandler;
private volatile long connectionTimeoutMs; private volatile long connectionTimeoutMs;
@Nullable private FutureCallback<Bitmap> pendingBitmapLoadCallback; @Nullable private FutureCallback<Bitmap> pendingBitmapLoadCallback;
...@@ -162,7 +161,6 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; ...@@ -162,7 +161,6 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
@Initialized @Initialized
MediaSessionLegacyStub thisRef = this; MediaSessionLegacyStub thisRef = this;
sessionCompat.setCallback(thisRef, handler); sessionCompat.setCallback(thisRef, handler);
mainHandler = new Handler(Looper.getMainLooper());
} }
/** Starts to receive commands. */ /** Starts to receive commands. */
...@@ -1205,7 +1203,9 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; ...@@ -1205,7 +1203,9 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
} }
}; };
Futures.addCallback( Futures.addCallback(
bitmapFuture, pendingBitmapLoadCallback, /* executor= */ mainHandler::post); bitmapFuture,
pendingBitmapLoadCallback,
/* executor= */ sessionImpl.getApplicationHandler()::post);
} }
} }
setMetadata( setMetadata(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment