diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java index 72c4ce8afe9b5..0fb6ea669458b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java @@ -427,15 +427,17 @@ public class StatusBarIconView extends AnimatedImageView implements StatusIconDi typedValue, true); float scaleFactor = typedValue.getFloat(); - // We downscale the loaded drawable to reasonable size to protect against applications - // using too much memory. The size can be tweaked in config.xml. Drawables - // that are already sized properly won't be touched. - boolean isLowRamDevice = ActivityManager.isLowRamDeviceStatic(); - Resources res = sysuiContext.getResources(); - int maxIconSize = res.getDimensionPixelSize(isLowRamDevice - ? com.android.internal.R.dimen.notification_small_icon_size_low_ram - : com.android.internal.R.dimen.notification_small_icon_size); - icon = DrawableSize.downscaleToSize(res, icon, maxIconSize, maxIconSize); + if (icon != null) { + // We downscale the loaded drawable to reasonable size to protect against applications + // using too much memory. The size can be tweaked in config.xml. Drawables that are + // already sized properly won't be touched. + boolean isLowRamDevice = ActivityManager.isLowRamDeviceStatic(); + Resources res = sysuiContext.getResources(); + int maxIconSize = res.getDimensionPixelSize(isLowRamDevice + ? com.android.internal.R.dimen.notification_small_icon_size_low_ram + : com.android.internal.R.dimen.notification_small_icon_size); + icon = DrawableSize.downscaleToSize(res, icon, maxIconSize, maxIconSize); + } // No need to scale the icon, so return it as is. if (scaleFactor == 1.f) { 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 d13451dc4769f..03c22b32b8f68 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/StatusBarIconViewTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/StatusBarIconViewTest.java @@ -155,4 +155,19 @@ public class StatusBarIconViewTest extends SysuiTestCase { mIconView.getIcon(largeIcon); // no crash? good } -} \ No newline at end of file + + @Test + public void testNullIcon() { + Icon mockIcon = mock(Icon.class); + when(mockIcon.loadDrawableAsUser(any(), anyInt())).thenReturn(null); + mStatusBarIcon.icon = mockIcon; + mIconView.set(mStatusBarIcon); + + Bitmap bitmap = Bitmap.createBitmap(60, 60, Bitmap.Config.ARGB_8888); + Icon icon = Icon.createWithBitmap(bitmap); + StatusBarIcon largeIcon = new StatusBarIcon(UserHandle.ALL, "mockPackage", + icon, 0, 0, ""); + mIconView.getIcon(largeIcon); + // No crash? good + } +}