Skip to content

Commit f599ab8

Browse files
Beth Thibodeauandroid-build-team Robot
authored andcommitted
Increase maximum allowed size for status bar icons
The previous size was causing some apps to crash which otherwise worked fine. This more closely matches the hard limit in RecordingCanvas (which we need to stay below to prevent SystemUI from crashing). Fixes: 182891864 Fixes: 182232777 Bug: 169255797 Test: atest StatusBarIconViewTest Test: manual - posting notifications with different drawable sizes Change-Id: I8deacc651e05a202ec980eeb8bcdf4f92daea8eb (cherry picked from commit 5cd7976f7d2b702f803f0628f61f02491834cd41) (cherry picked from commit 001d4e6)
1 parent 78e5c3b commit f599ab8

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)