Skip to content

Commit 4fdf4a5

Browse files
Beth ThibodeauAndroid (Google) Code Review
authored andcommitted
Merge "Increase maximum allowed size for status bar icons" into rvc-dev
2 parents 637a90a + 001d4e6 commit 4fdf4a5

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import android.graphics.ColorMatrixColorFilter;
3434
import android.graphics.Paint;
3535
import android.graphics.Rect;
36+
import android.graphics.drawable.BitmapDrawable;
3637
import android.graphics.drawable.Drawable;
3738
import android.graphics.drawable.Icon;
3839
import android.os.Parcelable;
@@ -83,8 +84,15 @@ public class StatusBarIconView extends AnimatedImageView implements StatusIconDi
8384
public static final int STATE_DOT = 1;
8485
public static final int STATE_HIDDEN = 2;
8586

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;
8896

8997
private static final String TAG = "StatusBarIconView";
9098
private static final Property<StatusBarIconView, Float> ICON_APPEAR_AMOUNT
@@ -382,9 +390,18 @@ private boolean updateDrawable(boolean withClear) {
382390
return false;
383391
}
384392

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
386401
|| 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);
388405
return false;
389406
}
390407

packages/SystemUI/tests/src/com/android/systemui/statusbar/StatusBarIconViewTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public void testGetContrastedStaticDrawableColor() {
127127

128128
@Test
129129
public void testGiantImageNotAllowed() {
130-
Bitmap largeBitmap = Bitmap.createBitmap(1000, 1000, Bitmap.Config.ARGB_8888);
130+
Bitmap largeBitmap = Bitmap.createBitmap(6000, 6000, Bitmap.Config.ARGB_8888);
131131
Icon icon = Icon.createWithBitmap(largeBitmap);
132132
StatusBarIcon largeIcon = new StatusBarIcon(UserHandle.ALL, "mockPackage",
133133
icon, 0, 0, "");

0 commit comments

Comments
 (0)