From 57eafc6f90a1ce2dd97079dd82b4b2f8dcd9e00f Mon Sep 17 00:00:00 2001 From: sergeyv Date: Mon, 19 Dec 2016 11:52:06 -0800 Subject: [PATCH] Throw exception if getPixel(s) is called on a hardware bitmap Test: android.graphics.cts.BitmapTest#testHardwareGetPixel bug:30999911 Change-Id: Ifa5a80d048c44c91122e9e7c79ca3ef9ecab963e --- graphics/java/android/graphics/Bitmap.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java index cd75fe95121ae..eb69dead5f166 100644 --- a/graphics/java/android/graphics/Bitmap.java +++ b/graphics/java/android/graphics/Bitmap.java @@ -1402,10 +1402,14 @@ public final class Bitmap implements Parcelable { * @param y The y coordinate (0...height-1) of the pixel to return * @return The argb {@link Color} at the specified coordinate * @throws IllegalArgumentException if x, y exceed the bitmap's bounds + * @throws IllegalStateException if the bitmap's config is {@link Config#HARDWARE} */ @ColorInt public int getPixel(int x, int y) { checkRecycled("Can't call getPixel() on a recycled bitmap"); + if (getConfig() == Config.HARDWARE) { + throw new IllegalStateException("Can't access pixels in hardware Bitmaps"); + } checkPixelAccess(x, y); return nativeGetPixel(mNativePtr, x, y); } @@ -1432,10 +1436,14 @@ public final class Bitmap implements Parcelable { * bounds of the bitmap, or if abs(stride) < width. * @throws ArrayIndexOutOfBoundsException if the pixels array is too small * to receive the specified number of pixels. + * @throws IllegalStateException if the bitmap's config is {@link Config#HARDWARE} */ public void getPixels(@ColorInt int[] pixels, int offset, int stride, int x, int y, int width, int height) { checkRecycled("Can't call getPixels() on a recycled bitmap"); + if (getConfig() == Config.HARDWARE) { + throw new IllegalStateException("Can't access pixels in hardware Bitmaps"); + } if (width == 0 || height == 0) { return; // nothing to do }