Fix crash extracting wallpaper color
When extracting background color, copy the bitmap first
if it's a Config.HARDWARE bitmap (and recycle immediately
after that).
Fixes: 136195242
Change-Id: I815230895b9b57daa730a94905a30e1901f90c0c
(cherry picked from commit dfb59e8ec287a9650489d6d5040fc2b085f343a1)
diff --git a/src/com/android/customization/picker/theme/ThemeFragment.java b/src/com/android/customization/picker/theme/ThemeFragment.java
index cb78ea6..f584dec 100644
--- a/src/com/android/customization/picker/theme/ThemeFragment.java
+++ b/src/com/android/customization/picker/theme/ThemeFragment.java
@@ -22,6 +22,7 @@
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.Bitmap;
+import android.graphics.Bitmap.Config;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
@@ -568,7 +569,15 @@
}
view.findViewById(R.id.theme_preview_card_background).setBackground(background);
if (mScrim == null && !mIsTranslucent) {
+ boolean shouldRecycle = false;
+ if (bitmap.getConfig() == Config.HARDWARE) {
+ bitmap = bitmap.copy(Config.ARGB_8888, false);
+ shouldRecycle = true;
+ }
int colorsHint = WallpaperColors.fromBitmap(bitmap).getColorHints();
+ if (shouldRecycle) {
+ bitmap.recycle();
+ }
TextView header = view.findViewById(R.id.theme_preview_card_header);
if ((colorsHint & WallpaperColors.HINT_SUPPORTS_DARK_TEXT) == 0) {
int colorLight = res.getColor(R.color.text_color_light, null);