diff options
author | timhypeng <timhypeng@google.com> | 2020-12-08 06:31:03 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-12-08 06:31:03 +0000 |
commit | 9d07cfff0b7635b55d9c4d49ce5439770f57f209 (patch) | |
tree | 783989093eee480fc1ab3beab18c7a4475a5b0f6 | |
parent | a06d339f9156fc947759262d406cb9f2788e9e70 (diff) | |
parent | 083c989950420d47458072646adf173a4f4bb024 (diff) |
Fix NPE when notification icon is empty am: 083c989950
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/13118157
MUST ONLY BE SUBMITTED BY AUTOMERGER
Change-Id: I9655067ea1343dbcab3e1410a171fae5df6ab4de
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java | 11 | ||||
-rw-r--r-- | packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputControllerTest.java | 19 |
2 files changed, 28 insertions, 2 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java index 80928d6da978..451bd42bd053 100644 --- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java +++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java @@ -16,10 +16,12 @@ package com.android.systemui.media.dialog; +import android.app.Notification; import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.drawable.Drawable; +import android.graphics.drawable.Icon; import android.media.MediaMetadata; import android.media.MediaRoute2Info; import android.media.RoutingSessionInfo; @@ -221,9 +223,14 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback { } for (NotificationEntry entry : mNotificationEntryManager.getActiveNotificationsForCurrentUser()) { - if (entry.getSbn().getNotification().hasMediaSession() + final Notification notification = entry.getSbn().getNotification(); + if (notification.hasMediaSession() && TextUtils.equals(entry.getSbn().getPackageName(), mPackageName)) { - return IconCompat.createFromIcon(entry.getSbn().getNotification().getLargeIcon()); + final Icon icon = notification.getLargeIcon(); + if (icon == null) { + break; + } + return IconCompat.createFromIcon(icon); } } return null; diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputControllerTest.java index 6ceac131ed4b..0d352c1b42d9 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputControllerTest.java @@ -447,6 +447,25 @@ public class MediaOutputControllerTest extends SysuiTestCase { } @Test + public void getNotificationLargeIcon_withoutLargeIcon_returnsNull() { + final List<NotificationEntry> entryList = new ArrayList<>(); + final NotificationEntry entry = mock(NotificationEntry.class); + final StatusBarNotification sbn = mock(StatusBarNotification.class); + final Notification notification = mock(Notification.class); + entryList.add(entry); + + when(mNotificationEntryManager.getActiveNotificationsForCurrentUser()) + .thenReturn(entryList); + when(entry.getSbn()).thenReturn(sbn); + when(sbn.getNotification()).thenReturn(notification); + when(sbn.getPackageName()).thenReturn(TEST_PACKAGE_NAME); + when(notification.hasMediaSession()).thenReturn(true); + when(notification.getLargeIcon()).thenReturn(null); + + assertThat(mMediaOutputController.getNotificationIcon()).isNull(); + } + + @Test public void getNotificationLargeIcon_withPackageNameAndMediaSession_returnsIconCompat() { final List<NotificationEntry> entryList = new ArrayList<>(); final NotificationEntry entry = mock(NotificationEntry.class); |