Loading core/java/android/app/WallpaperColors.java +8 −3 Original line number Diff line number Diff line Loading @@ -136,12 +136,12 @@ public final class WallpaperColors implements Parcelable { } final int bitmapArea = bitmap.getWidth() * bitmap.getHeight(); boolean shouldRecycle = false; if (bitmapArea > MAX_WALLPAPER_EXTRACTION_AREA) { shouldRecycle = true; Size optimalSize = calculateOptimalSize(bitmap.getWidth(), bitmap.getHeight()); Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, optimalSize.getWidth(), bitmap = Bitmap.createScaledBitmap(bitmap, optimalSize.getWidth(), optimalSize.getHeight(), true /* filter */); bitmap.recycle(); bitmap = scaledBitmap; } final Palette palette = Palette Loading Loading @@ -181,6 +181,11 @@ public final class WallpaperColors implements Parcelable { } int hints = calculateHints(bitmap); if (shouldRecycle) { bitmap.recycle(); } return new WallpaperColors(primary, secondary, tertiary, hints); } Loading tests/Internal/src/android/app/WallpaperColorsTest.java +12 −0 Original line number Diff line number Diff line Loading @@ -77,4 +77,16 @@ public class WallpaperColorsTest { Assert.assertFalse("Light surface shouldn't support dark text " + "when it contains dark pixels", supportsDarkText); } /** * WallpaperColors should not recycle bitmaps that it didn't create. */ @Test public void wallpaperRecycleBitmapTest() { Bitmap image = Bitmap.createBitmap(300, 300, Bitmap.Config.ARGB_8888); WallpaperColors.fromBitmap(image); Canvas canvas = new Canvas(); // This would crash: canvas.drawBitmap(image, 0, 0, new Paint()); } } Loading
core/java/android/app/WallpaperColors.java +8 −3 Original line number Diff line number Diff line Loading @@ -136,12 +136,12 @@ public final class WallpaperColors implements Parcelable { } final int bitmapArea = bitmap.getWidth() * bitmap.getHeight(); boolean shouldRecycle = false; if (bitmapArea > MAX_WALLPAPER_EXTRACTION_AREA) { shouldRecycle = true; Size optimalSize = calculateOptimalSize(bitmap.getWidth(), bitmap.getHeight()); Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, optimalSize.getWidth(), bitmap = Bitmap.createScaledBitmap(bitmap, optimalSize.getWidth(), optimalSize.getHeight(), true /* filter */); bitmap.recycle(); bitmap = scaledBitmap; } final Palette palette = Palette Loading Loading @@ -181,6 +181,11 @@ public final class WallpaperColors implements Parcelable { } int hints = calculateHints(bitmap); if (shouldRecycle) { bitmap.recycle(); } return new WallpaperColors(primary, secondary, tertiary, hints); } Loading
tests/Internal/src/android/app/WallpaperColorsTest.java +12 −0 Original line number Diff line number Diff line Loading @@ -77,4 +77,16 @@ public class WallpaperColorsTest { Assert.assertFalse("Light surface shouldn't support dark text " + "when it contains dark pixels", supportsDarkText); } /** * WallpaperColors should not recycle bitmaps that it didn't create. */ @Test public void wallpaperRecycleBitmapTest() { Bitmap image = Bitmap.createBitmap(300, 300, Bitmap.Config.ARGB_8888); WallpaperColors.fromBitmap(image); Canvas canvas = new Canvas(); // This would crash: canvas.drawBitmap(image, 0, 0, new Paint()); } }