Fix crash when loading album art by resource

When the album art is loaded from the notification largeIcon it may be a
resource rather than a bitmap, so it has to be loaded as a drawable.
Bitmaps are still loaded using `WallpaperColors.fromBitmap` to avoid
the extra steps needed by the `fromDrawable` method.

Fixes: 239368697
Test: manual
Test: atest MediaControlPanelTest
Change-Id: I0ba9a4b0f4d308cc360a785b68cbabdcb2480690
(cherry picked from commit ef53f601f2)
This commit is contained in:
Beth Thibodeau
2022-07-19 21:29:29 -05:00
parent e15951e5f2
commit d0c1f811af
2 changed files with 28 additions and 2 deletions

View File

@@ -631,9 +631,22 @@ public class MediaControlPanel {
Drawable artwork; Drawable artwork;
boolean isArtworkBound; boolean isArtworkBound;
Icon artworkIcon = data.getArtwork(); Icon artworkIcon = data.getArtwork();
WallpaperColors wallpaperColors = null;
if (artworkIcon != null) { if (artworkIcon != null) {
WallpaperColors wallpaperColors = WallpaperColors if (artworkIcon.getType() == Icon.TYPE_BITMAP
.fromBitmap(artworkIcon.getBitmap()); || artworkIcon.getType() == Icon.TYPE_ADAPTIVE_BITMAP) {
// Avoids extra processing if this is already a valid bitmap
wallpaperColors = WallpaperColors
.fromBitmap(artworkIcon.getBitmap());
} else {
Drawable artworkDrawable = artworkIcon.loadDrawable(mContext);
if (artworkDrawable != null) {
wallpaperColors = WallpaperColors
.fromDrawable(artworkIcon.loadDrawable(mContext));
}
}
}
if (wallpaperColors != null) {
mutableColorScheme = new ColorScheme(wallpaperColors, true, Style.CONTENT); mutableColorScheme = new ColorScheme(wallpaperColors, true, Style.CONTENT);
artwork = getScaledBackground(artworkIcon, width, height); artwork = getScaledBackground(artworkIcon, width, height);
isArtworkBound = true; isArtworkBound = true;

View File

@@ -546,6 +546,19 @@ public class MediaControlPanelTest : SysuiTestCase() {
verify(albumView).setLayerType(View.LAYER_TYPE_HARDWARE, null) verify(albumView).setLayerType(View.LAYER_TYPE_HARDWARE, null)
} }
@Test
fun bindAlbumView_artUsesResource() {
val albumArt = Icon.createWithResource(context, R.drawable.ic_android)
val state = mediaData.copy(artwork = albumArt)
player.attachPlayer(viewHolder)
player.bindPlayer(state, PACKAGE)
bgExecutor.runAllReady()
mainExecutor.runAllReady()
verify(albumView).setImageDrawable(any(Drawable::class.java))
}
@Test @Test
fun bindAlbumView_setAfterExecutors() { fun bindAlbumView_setAfterExecutors() {
val bmp = Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888) val bmp = Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888)