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

Commit 2648a2a9 authored by Fabian Kozynski's avatar Fabian Kozynski
Browse files

Prevent NPE in CustomTile

The icon is passed by the TileService, so it could null when retrieving
the drawable. Check for null before doing operations on it.

Test: atest CustomTileTest
Fixes: 140479361
Change-Id: I0ee11806c0047e0e524f5201d369bee51beba451
Merged-In: I0ee11806c0047e0e524f5201d369bee51beba451
(cherry picked from commit cfdd8d40)
parent 0b66590f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -327,6 +327,7 @@ public class CustomTile extends QSTileImpl<State> implements TileChangeListener

        final Drawable drawableF = drawable;
        state.iconSupplier = () -> {
            if (drawableF == null) return null;
            Drawable.ConstantState cs = drawableF.getConstantState();
            if (cs != null) {
                return new DrawableIcon(cs.newDrawable());
+8 −0
Original line number Diff line number Diff line
@@ -125,4 +125,12 @@ class CustomTileTest : SysuiTestCase() {
        customTile.handleUpdateState(state, null)
        assertFalse(state.value)
    }

    @Test
    fun testNoCrashOnNullDrawable() {
        customTile.qsTile.icon = mock(Icon::class.java)
        `when`(customTile.qsTile.icon.loadDrawable(any(Context::class.java)))
                .thenReturn(null)
        customTile.handleUpdateState(customTile.newTileState(), null)
    }
}
 No newline at end of file