Fix NPE when notification icon is empty
-Check notification icon before using Bug: 162998388 Test: atest MediaOutputControllerTest Change-Id: Ie3db32f3e6387f338c77faa741b2df54473a3675
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -446,6 +446,25 @@ public class MediaOutputControllerTest extends SysuiTestCase {
|
||||
assertThat(mMediaOutputController.getNotificationIcon()).isNull();
|
||||
}
|
||||
|
||||
@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<>();
|
||||
|
||||
Reference in New Issue
Block a user