|
33 | 33 | import android.graphics.ColorMatrixColorFilter; |
34 | 34 | import android.graphics.Paint; |
35 | 35 | import android.graphics.Rect; |
| 36 | +import android.graphics.drawable.BitmapDrawable; |
36 | 37 | import android.graphics.drawable.Drawable; |
37 | 38 | import android.graphics.drawable.Icon; |
38 | 39 | import android.os.Parcelable; |
@@ -83,8 +84,15 @@ public class StatusBarIconView extends AnimatedImageView implements StatusIconDi |
83 | 84 | public static final int STATE_DOT = 1; |
84 | 85 | public static final int STATE_HIDDEN = 2; |
85 | 86 |
|
86 | | - /** Maximum allowed width or height for an icon drawable */ |
87 | | - private static final int MAX_IMAGE_SIZE = 500; |
| 87 | + /** |
| 88 | + * Maximum allowed byte count for an icon bitmap |
| 89 | + * @see android.graphics.RecordingCanvas.MAX_BITMAP_SIZE |
| 90 | + */ |
| 91 | + private static final int MAX_BITMAP_SIZE = 100 * 1024 * 1024; // 100 MB |
| 92 | + /** |
| 93 | + * Maximum allowed width or height for an icon drawable, if we can't get byte count |
| 94 | + */ |
| 95 | + private static final int MAX_IMAGE_SIZE = 5000; |
88 | 96 |
|
89 | 97 | private static final String TAG = "StatusBarIconView"; |
90 | 98 | private static final Property<StatusBarIconView, Float> ICON_APPEAR_AMOUNT |
@@ -382,9 +390,18 @@ private boolean updateDrawable(boolean withClear) { |
382 | 390 | return false; |
383 | 391 | } |
384 | 392 |
|
385 | | - if (drawable.getIntrinsicWidth() > MAX_IMAGE_SIZE |
| 393 | + if (drawable instanceof BitmapDrawable && ((BitmapDrawable) drawable).getBitmap() != null) { |
| 394 | + // If it's a bitmap we can check the size directly |
| 395 | + int byteCount = ((BitmapDrawable) drawable).getBitmap().getByteCount(); |
| 396 | + if (byteCount > MAX_BITMAP_SIZE) { |
| 397 | + Log.w(TAG, "Drawable is too large (" + byteCount + " bytes) " + mIcon); |
| 398 | + return false; |
| 399 | + } |
| 400 | + } else if (drawable.getIntrinsicWidth() > MAX_IMAGE_SIZE |
386 | 401 | || drawable.getIntrinsicHeight() > MAX_IMAGE_SIZE) { |
387 | | - Log.w(TAG, "Drawable is too large " + mIcon); |
| 402 | + // Otherwise, check dimensions |
| 403 | + Log.w(TAG, "Drawable is too large (" + drawable.getIntrinsicWidth() + "x" |
| 404 | + + drawable.getIntrinsicHeight() + ") " + mIcon); |
388 | 405 | return false; |
389 | 406 | } |
390 | 407 |
|
|
0 commit comments