Repository navigation
"Downscaling oversized MediaMetadata Bitmap" strict mode violations #2829
Description
Version
Media3 1.8.0
More version details
No response
Devices that reproduce the issue
- Pixel 7a running Android 16 (build number BP3A.250905.014)
Devices that do not reproduce the issue
No response
Reproducible in the demo app?
Not tested
Reproduction steps
- Create a
MediaItemwith an artwork URI corresponding to a 1024x1024 image. - Use the item in a
SimpleBasePlayerimplementation's playlist.
Expected result
No strict mode violations.
Actual result
I receive a bunch of strict mode violations like the following:
10-04 08:22:32.260 E NupApplication$onCreate android.os.strictmode.CustomViolation: Downscaling oversized MediaMetadata Bitmap
at android.os.StrictMode$AndroidBlockGuardPolicy.onCustomSlowCall(StrictMode.java:1731)
at android.os.StrictMode.noteSlowCall(StrictMode.java:2966)
at android.media.MediaMetadata$Builder.scaleBitmap(MediaMetadata.java:995)
at android.media.MediaMetadata$Builder.build(MediaMetadata.java:980)
at android.media.session.MediaSession.setMetadata(MediaSession.java:513)
at androidx.media3.session.legacy.MediaSessionCompat$MediaSessionImplApi21.setMetadata(MediaSessionCompat.java:2069)
at androidx.media3.session.legacy.MediaSessionCompat.setMetadata(MediaSessionCompat.java:538)
at androidx.media3.session.MediaSessionLegacyStub.setMetadata(MediaSessionLegacyStub.java:1171)
at androidx.media3.session.MediaSessionLegacyStub.access$1700(MediaSessionLegacyStub.java:118)
at androidx.media3.session.MediaSessionLegacyStub$ControllerLegacyCbForBroadcast$1.onSuccess(MediaSessionLegacyStub.java:1675)
at androidx.media3.session.MediaSessionLegacyStub$ControllerLegacyCbForBroadcast$1.onSuccess(MediaSessionLegacyStub.java:1669)
at com.google.common.util.concurrent.Futures$CallbackListener.run(Futures.java:1102)
at android.os.Handler.handleCallback(Handler.java:1041)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.dispatchMessage(Looper.java:315)
at android.os.Looper.loopOnce(Looper.java:251)
at android.os.Looper.loop(Looper.java:349)
at android.app.ActivityThread.main(ActivityThread.java:9041)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:593)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:929)
I'm also seeing this slightly different violation:
10-04 08:22:32.262 E NupApplication$onCreate android.os.strictmode.CustomViolation: Downscaling oversized Icon Bitmap
at android.os.StrictMode$AndroidBlockGuardPolicy.onCustomSlowCall(StrictMode.java:1731)
at android.os.StrictMode.noteSlowCall(StrictMode.java:2966)
at android.graphics.drawable.Icon.scaleDownIfNecessary(Icon.java:1162)
at android.graphics.drawable.Icon.scaleDownIfNecessary(Icon.java:1184)
at android.app.Notification.reduceImageSizes(Notification.java:8080)
at android.app.Notification$Builder.build(Notification.java:7741)
at androidx.core.app.NotificationCompatBuilder.buildInternal(NotificationCompatBuilder.java:428)
at androidx.core.app.NotificationCompatBuilder.build(NotificationCompatBuilder.java:338)
at androidx.core.app.NotificationCompat$Builder.build(NotificationCompat.java:2528)
at androidx.media3.session.DefaultMediaNotificationProvider.createNotification(DefaultMediaNotificationProvider.java:389)
at androidx.media3.session.MediaNotificationManager.$r8$lambda$buumm_xVh6KuEzVTNi7Lz3qTH48(MediaNotificationManager.java:188)
at androidx.media3.session.MediaNotificationManager$$ExternalSyntheticLambda2.run(R8$$SyntheticClass:0)
at androidx.media3.common.util.Util.postOrRun(Util.java:802)
at androidx.media3.session.MediaNotificationManager.updateNotification(MediaNotificationManager.java:184)
at androidx.media3.session.MediaSessionService.onUpdateNotification(MediaSessionService.java:677)
at androidx.media3.session.MediaSessionService.onUpdateNotificationInternal(MediaSessionService.java:712)
at androidx.media3.session.MediaSessionService$MediaSessionListener.onNotificationRefreshRequired(MediaSessionService.java:784)
at androidx.media3.session.MediaSessionImpl.$r8$lambda$LbaJMA-nvOZMx4M1Mvj1WGuv1Lc(MediaSessionImpl.java:1078)
at androidx.media3.session.MediaSessionImpl$$ExternalSyntheticLambda20.run(R8$$SyntheticClass:0)
at androidx.media3.common.util.Util.postOrRun(Util.java:802)
at androidx.media3.session.MediaSessionImpl.onNotificationRefreshRequired(MediaSessionImpl.java:1074)
at androidx.media3.session.MediaSessionLegacyStub$ControllerLegacyCbForBroadcast$1.onSuccess(MediaSessionLegacyStub.java:1683)
at androidx.media3.session.MediaSessionLegacyStub$ControllerLegacyCbForBroadcast$1.onSuccess(MediaSessionLegacyStub.java:1669)
at com.google.common.util.concurrent.Futures$CallbackListener.run(Futures.java:1102)
at android.os.Handler.handleCallback(Handler.java:1041)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.dispatchMessage(Looper.java:315)
at android.os.Looper.loopOnce(Looper.java:251)
at android.os.Looper.loop(Looper.java:349)
at android.app.ActivityThread.main(ActivityThread.java:9041)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:593)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:929)
My code is currently calling MediaMetadata.Builder().setArtworkUri() with URIs corresponding to a ContentProvider that provides 1024x1024 AVIF images. I don't think it's practical for me to use smaller images on my end, since my activity actually makes use of the full resolution.
This just started after my phone applied a system update for build number BP3A.250905.014, so I suspect it was caused by a framework change -- I didn't see any violations using whichever build of Android 16 that I was on before.
I haven't spent much time looking at the framework code yet, but I wonder if this from https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/values/config.xml is related:
<!-- The maximum bitmap size that can be written to a MediaMetadata object. This value
is the max width/height allowed in dips.-->
<dimen name="config_mediaMetadataBitmapMaxSize">320dp</dimen>Media
Not applicable
Bug Report
- You will email the zip file produced by
adb bugreportto android-media-github@google.com after filing this issue.
Activity
marcbaechinger commentedon Oct 14, 2025
Thanks for you report.
I think what was added in the framework, is the line that actually reports the strict mode:
What was added to the framework on line 995 is a call to
StrictMode.noteSlowCall()which now triggers the violation you are seeing.The violation as a such was there before, but it wasn't reported.
The line was added in
android.graphics.drawable.Icon.scaleDownIfNecessarythat you see as a violation now as well.That's the right expectation in any case. On the Media3 library side, there is a counterpart that should take care of that with the next version (1.9).
for the metadata bitmap,
DataSourceBitmapLoaderis automatically scaling down you bitmap to the max allowed dimension if needed. Media3 does this not on the main thread and then when the bitmap is passed down to the framework it is scaled already.the same is true for the the notification if an app does not set a custom
BitmapLoaderonMediaSession.Builder.If in either of the above cases, an app is using its own
BitmapLoader, the app may want to wrap its version in aSizeLimitedBitmapLoaderbefore setting it to the session. This way the wrapper does the scaling. There is also aCacheBitmapLoaderin case an app is doing their own thing and wants to avoid to load, decode and scale the same thing multiple times.derat commentedon Oct 14, 2025
Thanks for the detailed reply! It sounds like 1.9 should fix this for me, as I'm not setting a custom
BitmapLoaderin my service'sMediaLibrarySession.Builder. I've updated my app to not report these violations in the meantime.I'm currently using
DataSourceBitmapLoaderto decode the full 1024x1024 bitmaps in my activity. Will I need to change that in 1.9 to continue getting bitmaps at their original size, based on this:?
marcbaechinger commentedon Oct 14, 2025
You're fine If you use the same constructor as you do now, you are using the default which is LENGTH_UNSET [1] that is passed to
BitmapUtil.decode(byte[] data, int length, @Nullable BitmapFactory.Options options, int maximumOutputDimension)[2] for which JavaDoc says:[1] https://github.com/androidx/media/blob/main/libraries/datasource/src/main/java/androidx/media3/datasource/DataSourceBitmapLoader.java#L105
[2]
media/libraries/datasource/src/main/java/androidx/media3/datasource/BitmapUtil.java
Line 45 in bfe5930
Add inline comment for const default
Add inline comment for const default
derat commentedon Dec 24, 2025
Hi again, thanks for looking into this earlier! I just upgraded my app to Media3 1.9.0, and it looks like these violations are still occurring:
My
MediaSessionis still getting built without a customBitmapLoader:Any ideas about why the violations are still occurring?
tonihei commentedon Jan 6, 2026
I can't see this happening in the session demo app even after enabling strict mode. Could you provide more details on how to reproduce exactly? (for example, which Bitmap and how you set it on the session/player)
derat commentedon Jan 6, 2026
@tonihei, thanks for investigating!
Here's an example from my logs of several violations occurring when displaying
4e178435-9e38-4877-891b-68efb6942085.jpg, a 1034x1024 WebP (despite the extension) cover image (attached here):This is where I'm creating my
MediaLibrarySession.This is where I'm setting it as the artwork URI on my
MediaMetadata.tonihei commentedon Jan 7, 2026
I strangely can't trigger the warning myself even if strict mode is enabled (I can see other warnings though). I can see the additional downscaling is happening nonetheless because the notification applies a much lower bitmap size limit (48dp) than the media session code (320dp). This means we should add additional downscaling for the notification icon specifically.
9 remaining items
Enable strict mode for session and ExoPlayer demo apps
Add additional bitmap scaling for large notification icon
Add additional bitmap scaling for large notification icon
Enable strict mode for session and ExoPlayer demo apps
Add additional bitmap scaling for large notification icon
Add additional bitmap scaling for large notification icon
Enable strict mode for session and ExoPlayer demo apps
Add additional bitmap scaling for large notification icon
Enable strict mode for session and ExoPlayer demo apps
Add additional bitmap scaling for large notification icon
derat commentedon Jan 26, 2026
I can confirm that I no longer see any strict mode violations related to downscaling bitmaps after upgrading to 1.9.1. Thanks again!
tonihei commentedon Jan 29, 2026
Great, thanks for confirming!
Enable strict mode for session and ExoPlayer demo apps
Add additional bitmap scaling for large notification icon