diff options
| author | 2021-07-09 13:05:29 -0400 | |
|---|---|---|
| committer | 2021-07-09 14:03:59 -0400 | |
| commit | eb505a200cf04c9459ccd45caadffaad560bc0ea (patch) | |
| tree | 3ed74f8a78749fb2304e9d6c068a5deb6f546cec | |
| parent | f36c575bee6e45d274ebdb3cb931028695d613d9 (diff) | |
Guard against NPE
Test: atest; manually ensure that icons still work when
using SystemUI's context
Fixes: 192575971
Change-Id: I3c93d4898a6995148606b15fc8bd98d465741c0a
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java | 10 | ||||
| -rw-r--r-- | packages/SystemUI/tests/src/com/android/systemui/statusbar/StatusBarIconViewTest.java | 16 |
2 files changed, 22 insertions, 4 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java index a00d01427ebc..5302188ccb31 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java @@ -416,10 +416,12 @@ public class StatusBarIconView extends AnimatedImageView implements StatusIconDi return mIcon.icon; } - private Drawable getIcon(StatusBarIcon icon) { - Context notifContext = mNotification != null ? - mNotification.getPackageContext(getContext()) : getContext(); - return getIcon(getContext(), notifContext, icon); + Drawable getIcon(StatusBarIcon icon) { + Context notifContext = getContext(); + if (mNotification != null) { + notifContext = mNotification.getPackageContext(getContext()); + } + return getIcon(getContext(), notifContext != null ? notifContext : getContext(), icon); } /** 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 7c819f5c5ba4..85ea52b6af6a 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/StatusBarIconViewTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/StatusBarIconViewTest.java @@ -39,6 +39,7 @@ import android.graphics.Bitmap; import android.graphics.Color; import android.graphics.drawable.Icon; import android.os.UserHandle; +import android.service.notification.StatusBarNotification; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; @@ -131,4 +132,19 @@ public class StatusBarIconViewTest extends SysuiTestCase { icon, 0, 0, ""); assertFalse(mIconView.set(largeIcon)); } + + @Test + public void testNullNotifInfo() { + 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.setNotification(mock(StatusBarNotification.class)); + mIconView.getIcon(largeIcon); + // no crash? good + + mIconView.setNotification(null); + mIconView.getIcon(largeIcon); + // no crash? good + } }
\ No newline at end of file |