diff options
author | John Reck <jreck@google.com> | 2015-07-31 13:10:39 -0700 |
---|---|---|
committer | John Reck <jreck@google.com> | 2015-08-03 20:57:22 +0000 |
commit | 01a0af31d7d418f400ce5d3f752eba6a35aa00e2 (patch) | |
tree | 02b4cd30808726c61463464dd9c62959df5cb3f2 /graphics/java | |
parent | 3ba2bfa7b280bac76d4d60a7f548c5e06aaca569 (diff) | |
download | frameworks_base-01a0af31d7d418f400ce5d3f752eba6a35aa00e2.zip frameworks_base-01a0af31d7d418f400ce5d3f752eba6a35aa00e2.tar.gz frameworks_base-01a0af31d7d418f400ce5d3f752eba6a35aa00e2.tar.bz2 |
Yell loudly about undefined behind in Bitmap, but work anyway
Bug: 22214367
Previous releases would let the getters on a recycle()'d bitmap to still
work despite being firmly in undefined behavior per the documentation
on Bitmap#recycle().
As there are apps relying on this, yell very loudly about this behavior
in the log and give them a bit of time to fix it
Change-Id: I857be7e74cb217877973d9c6f03eb761d12fd056
Diffstat (limited to 'graphics/java')
-rw-r--r-- | graphics/java/android/graphics/Bitmap.java | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java index 8ad7c12..3e4d93b 100644 --- a/graphics/java/android/graphics/Bitmap.java +++ b/graphics/java/android/graphics/Bitmap.java @@ -23,6 +23,7 @@ import android.os.Parcel; import android.os.Parcelable; import android.os.Trace; import android.util.DisplayMetrics; +import android.util.Log; import dalvik.system.VMRuntime; @@ -33,6 +34,8 @@ import java.nio.IntBuffer; import java.nio.ShortBuffer; public final class Bitmap implements Parcelable { + private static final String TAG = "Bitmap"; + /** * Indicates that the bitmap was created for an unknown pixel density. * @@ -159,6 +162,9 @@ public final class Bitmap implements Parcelable { * @see #DENSITY_NONE */ public int getDensity() { + if (mRecycled) { + Log.w(TAG, "Called getDensity() on a recycle()'d bitmap! This is undefined behavior!"); + } return mDensity; } @@ -330,7 +336,9 @@ public final class Bitmap implements Parcelable { * @return The current generation ID for this bitmap. */ public int getGenerationId() { - if (mRecycled) return 0; + if (mRecycled) { + Log.w(TAG, "Called getGenerationId() on a recycle()'d bitmap! This is undefined behavior!"); + } return nativeGenerationId(mFinalizer.mNativeBitmap); } @@ -1057,7 +1065,9 @@ public final class Bitmap implements Parcelable { * @see BitmapFactory.Options#inPremultiplied */ public final boolean isPremultiplied() { - if (mRecycled) return false; + if (mRecycled) { + Log.w(TAG, "Called isPremultiplied() on a recycle()'d bitmap! This is undefined behavior!"); + } return nativeIsPremultiplied(mFinalizer.mNativeBitmap); } @@ -1089,11 +1099,17 @@ public final class Bitmap implements Parcelable { /** Returns the bitmap's width */ public final int getWidth() { + if (mRecycled) { + Log.w(TAG, "Called getWidth() on a recycle()'d bitmap! This is undefined behavior!"); + } return mWidth; } /** Returns the bitmap's height */ public final int getHeight() { + if (mRecycled) { + Log.w(TAG, "Called getHeight() on a recycle()'d bitmap! This is undefined behavior!"); + } return mHeight; } @@ -1176,7 +1192,9 @@ public final class Bitmap implements Parcelable { * @return number of bytes between rows of the native bitmap pixels. */ public final int getRowBytes() { - if (mRecycled) return 0; + if (mRecycled) { + Log.w(TAG, "Called getRowBytes() on a recycle()'d bitmap! This is undefined behavior!"); + } return nativeRowBytes(mFinalizer.mNativeBitmap); } @@ -1220,7 +1238,9 @@ public final class Bitmap implements Parcelable { * that config, otherwise return null. */ public final Config getConfig() { - if (mRecycled) return Config.ARGB_8888; + if (mRecycled) { + Log.w(TAG, "Called getConfig() on a recycle()'d bitmap! This is undefined behavior!"); + } return Config.nativeToConfig(nativeConfig(mFinalizer.mNativeBitmap)); } @@ -1233,7 +1253,9 @@ public final class Bitmap implements Parcelable { * it will return true by default. */ public final boolean hasAlpha() { - if (mRecycled) return false; + if (mRecycled) { + Log.w(TAG, "Called hasAlpha() on a recycle()'d bitmap! This is undefined behavior!"); + } return nativeHasAlpha(mFinalizer.mNativeBitmap); } @@ -1270,7 +1292,9 @@ public final class Bitmap implements Parcelable { * @see #setHasMipMap(boolean) */ public final boolean hasMipMap() { - if (mRecycled) return false; + if (mRecycled) { + Log.w(TAG, "Called hasMipMap() on a recycle()'d bitmap! This is undefined behavior!"); + } return nativeHasMipMap(mFinalizer.mNativeBitmap); } |