Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 497fad03 authored by Steve Elliott's avatar Steve Elliott
Browse files

Fix NPE in StatusBarIconView#getIcon

The code to downscale the Icon drawables does not account for
potentially `null` Icons returned from `Icon#loadDrawableAsUser`.

Fixes: 218331554
Test: manual + atest
Change-Id: Iad1ef2975a0526a1fe129aa9693b6e9fe3d046b5
parent 865dc828
Loading
Loading
Loading
Loading
+11 −9
Original line number Diff line number Diff line
@@ -427,15 +427,17 @@ public class StatusBarIconView extends AnimatedImageView implements StatusIconDi
                typedValue, true);
        float scaleFactor = typedValue.getFloat();

        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.
            // 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) {
+16 −1
Original line number Diff line number Diff line
@@ -155,4 +155,19 @@ public class StatusBarIconViewTest extends SysuiTestCase {
        mIconView.getIcon(largeIcon);
        // no crash? good
    }

    @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
    }
}