diff options
author | Beth Thibodeau <ethibodeau@google.com> | 2021-03-25 17:19:30 -0400 |
---|---|---|
committer | Beth Thibodeau <ethibodeau@google.com> | 2021-04-01 18:16:52 +0000 |
commit | 001d4e68bbebc14132a13b21c38c5fb6af9034a3 (patch) | |
tree | 589b17d525120e3bab2dd783dbdca1ac741a43af | |
parent | 65eb4a433260f1a28e0f2aced9bd551ec6657de7 (diff) | |
download | base-001d4e68bbebc14132a13b21c38c5fb6af9034a3.tar.gz |
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)
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java | 25 | ||||
-rw-r--r-- | packages/SystemUI/tests/src/com/android/systemui/statusbar/StatusBarIconViewTest.java | 2 |
2 files changed, 22 insertions, 5 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java index 25ae5c2dadef..db9afd6ea799 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java @@ -33,6 +33,7 @@ import android.graphics.Color; import android.graphics.ColorMatrixColorFilter; import android.graphics.Paint; import android.graphics.Rect; +import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.Icon; import android.os.Parcelable; @@ -83,8 +84,15 @@ public class StatusBarIconView extends AnimatedImageView implements StatusIconDi public static final int STATE_DOT = 1; public static final int STATE_HIDDEN = 2; - /** Maximum allowed width or height for an icon drawable */ - private static final int MAX_IMAGE_SIZE = 500; + /** + * Maximum allowed byte count for an icon bitmap + * @see android.graphics.RecordingCanvas.MAX_BITMAP_SIZE + */ + private static final int MAX_BITMAP_SIZE = 100 * 1024 * 1024; // 100 MB + /** + * Maximum allowed width or height for an icon drawable, if we can't get byte count + */ + private static final int MAX_IMAGE_SIZE = 5000; private static final String TAG = "StatusBarIconView"; private static final Property<StatusBarIconView, Float> ICON_APPEAR_AMOUNT @@ -382,9 +390,18 @@ public class StatusBarIconView extends AnimatedImageView implements StatusIconDi return false; } - if (drawable.getIntrinsicWidth() > MAX_IMAGE_SIZE + if (drawable instanceof BitmapDrawable && ((BitmapDrawable) drawable).getBitmap() != null) { + // If it's a bitmap we can check the size directly + int byteCount = ((BitmapDrawable) drawable).getBitmap().getByteCount(); + if (byteCount > MAX_BITMAP_SIZE) { + Log.w(TAG, "Drawable is too large (" + byteCount + " bytes) " + mIcon); + return false; + } + } else if (drawable.getIntrinsicWidth() > MAX_IMAGE_SIZE || drawable.getIntrinsicHeight() > MAX_IMAGE_SIZE) { - Log.w(TAG, "Drawable is too large " + mIcon); + // Otherwise, check dimensions + Log.w(TAG, "Drawable is too large (" + drawable.getIntrinsicWidth() + "x" + + drawable.getIntrinsicHeight() + ") " + mIcon); return false; } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/StatusBarIconViewTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/StatusBarIconViewTest.java index daa805a8f6e6..edafa6549027 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/StatusBarIconViewTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/StatusBarIconViewTest.java @@ -127,7 +127,7 @@ public class StatusBarIconViewTest extends SysuiTestCase { @Test public void testGiantImageNotAllowed() { - Bitmap largeBitmap = Bitmap.createBitmap(1000, 1000, Bitmap.Config.ARGB_8888); + Bitmap largeBitmap = Bitmap.createBitmap(6000, 6000, Bitmap.Config.ARGB_8888); Icon icon = Icon.createWithBitmap(largeBitmap); StatusBarIcon largeIcon = new StatusBarIcon(UserHandle.ALL, "mockPackage", icon, 0, 0, ""); |