OSDN Git Service

Limit persistent ashmem backed fds to a minimum of 128kB.
authorRiley Andrews <riandrews@android.com>
Mon, 2 Nov 2015 07:36:04 +0000 (23:36 -0800)
committerRiley Andrews <riandrews@google.com>
Tue, 3 Nov 2015 17:46:15 +0000 (17:46 +0000)
Bug 25256717

Change-Id: Ieb356006df0a6545b89de44d3d8fd4b46312b3b8
Signed-off-by: Riley Andrews <riandrews@google.com>
core/java/android/app/Notification.java
core/jni/android/graphics/Bitmap.cpp
graphics/java/android/graphics/drawable/Icon.java

index f3f2428..a2e8fd1 100644 (file)
@@ -3969,7 +3969,9 @@ public class Notification implements Parcelable
         @Override
         public void purgeResources() {
             super.purgeResources();
-            if (mPicture != null && mPicture.isMutable()) {
+            if (mPicture != null &&
+                mPicture.isMutable() &&
+                mPicture.getAllocationByteCount() >= (128 * (1 << 10))) {
                 mPicture = mPicture.createAshmemBitmap();
             }
             if (mBigLargeIcon != null) {
index fbe3ece..6cbdeaa 100755 (executable)
@@ -28,6 +28,7 @@
 #include <cutils/ashmem.h>
 
 #define DEBUG_PARCEL 0
+#define ASHMEM_BITMAP_MIN_SIZE (128 * (1 << 10))
 
 namespace android {
 
@@ -993,7 +994,7 @@ static jobject Bitmap_createFromParcel(JNIEnv* env, jobject, jobject parcel) {
 
     // Map the bitmap in place from the ashmem region if possible otherwise copy.
     Bitmap* nativeBitmap;
-    if (blob.fd() >= 0 && (blob.isMutable() || !isMutable)) {
+    if (blob.fd() >= 0 && (blob.isMutable() || !isMutable) && (size >= ASHMEM_BITMAP_MIN_SIZE)) {
 #if DEBUG_PARCEL
         ALOGD("Bitmap.createFromParcel: mapped contents of %s bitmap from %s blob "
                 "(fds %s)",
index 26232a9..44d7530 100644 (file)
@@ -382,7 +382,9 @@ public final class Icon implements Parcelable {
      * @hide
      */
     public void convertToAshmem() {
-        if (mType == TYPE_BITMAP && getBitmap().isMutable()) {
+        if (mType == TYPE_BITMAP &&
+            getBitmap().isMutable() &&
+            getBitmap().getAllocationByteCount() >= (128 * (1 << 10))) {
             setBitmap(getBitmap().createAshmemBitmap());
         }
     }