Add a recycle bitmap check before extracting wallpaper color

Makes sure we don't call WallpaperColors.fromBitmap if the bitmap of the
icon is recycled.

Bug: 269079356
Test: atest MediaControlPanelTest
Change-Id: Ia57b6f190853bbfeaf588c64f31c88469fb8a807
This commit is contained in:
Michael Mikhail
2023-03-01 19:00:08 +00:00
parent 7ef14ecb39
commit 2f4d0ea966
2 changed files with 20 additions and 4 deletions

View File

@@ -928,13 +928,16 @@ public class MediaControlPanel {
if (artworkIcon.getType() == Icon.TYPE_BITMAP
|| artworkIcon.getType() == Icon.TYPE_ADAPTIVE_BITMAP) {
// Avoids extra processing if this is already a valid bitmap
return WallpaperColors
.fromBitmap(artworkIcon.getBitmap());
Bitmap artworkBitmap = artworkIcon.getBitmap();
if (artworkBitmap.isRecycled()) {
Log.d(TAG, "Cannot load wallpaper color from a recycled bitmap");
return null;
}
return WallpaperColors.fromBitmap(artworkBitmap);
} else {
Drawable artworkDrawable = artworkIcon.loadDrawable(mContext);
if (artworkDrawable != null) {
return WallpaperColors
.fromDrawable(artworkIcon.loadDrawable(mContext));
return WallpaperColors.fromDrawable(artworkDrawable);
}
}
}

View File

@@ -730,6 +730,19 @@ public class MediaControlPanelTest : SysuiTestCase() {
.isNotEqualTo(greenArtwork.getDrawable(1).constantState)
}
@Test
fun getWallpaperColor_recycledBitmap_notCrashing() {
// Setup redArt icon.
val redBmp = Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888)
val redArt = Icon.createWithBitmap(redBmp)
// Recycle bitmap of redArt icon.
redArt.bitmap.recycle()
// get wallpaperColor without illegal exception.
player.getWallpaperColor(redArt)
}
@Test
fun bind_seekBarDisabled_hasActions_seekBarVisibilityIsSetToInvisible() {
useRealConstraintSets()