summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Fabian Kozynski <kozynski@google.com> 2020-02-21 13:20:07 -0500
committer Fabian Kozynski <kozynski@google.com> 2020-02-26 20:23:35 +0000
commit2648a2a99ad9f12c279efbd563f9bc5447070108 (patch)
treeb7a699afcddf853e90edaff7d9150232c557e665
parent0b66590fbfae2acff4d937d95705dc5c34827f5f (diff)
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 cfdd8d40934d49ed0c07886d42cb09f84dfe4a71)
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/external/CustomTile.java1
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/qs/external/CustomTileTest.kt8
2 files changed, 9 insertions, 0 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/qs/external/CustomTile.java b/packages/SystemUI/src/com/android/systemui/qs/external/CustomTile.java
index 21a424c77a05..ef8a23df2cf9 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/external/CustomTile.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/external/CustomTile.java
@@ -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());
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/external/CustomTileTest.kt b/packages/SystemUI/tests/src/com/android/systemui/qs/external/CustomTileTest.kt
index 9fe2569177d7..c6715350d777 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/qs/external/CustomTileTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/external/CustomTileTest.kt
@@ -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