Loading core/java/android/service/notification/NotificationListenerService.java +9 −3 Original line number Diff line number Diff line Loading @@ -807,7 +807,8 @@ public abstract class NotificationListenerService extends Service { * @return An array of active notifications, sorted in natural order. */ public StatusBarNotification[] getActiveNotifications() { return getActiveNotifications(null, TRIM_FULL); StatusBarNotification[] activeNotifications = getActiveNotifications(null, TRIM_FULL); return activeNotifications != null ? activeNotifications : new StatusBarNotification[0]; } /** Loading Loading @@ -842,7 +843,8 @@ public abstract class NotificationListenerService extends Service { */ @SystemApi public StatusBarNotification[] getActiveNotifications(int trim) { return getActiveNotifications(null, trim); StatusBarNotification[] activeNotifications = getActiveNotifications(null, trim); return activeNotifications != null ? activeNotifications : new StatusBarNotification[0]; } /** Loading @@ -858,7 +860,8 @@ public abstract class NotificationListenerService extends Service { * same order as the key list. */ public StatusBarNotification[] getActiveNotifications(String[] keys) { return getActiveNotifications(keys, TRIM_FULL); StatusBarNotification[] activeNotifications = getActiveNotifications(keys, TRIM_FULL); return activeNotifications != null ? activeNotifications : new StatusBarNotification[0]; } /** Loading Loading @@ -890,6 +893,9 @@ public abstract class NotificationListenerService extends Service { private StatusBarNotification[] cleanUpNotificationList( ParceledListSlice<StatusBarNotification> parceledList) { if (parceledList == null || parceledList.getList() == null) { return new StatusBarNotification[0]; } List<StatusBarNotification> list = parceledList.getList(); ArrayList<StatusBarNotification> corruptNotifications = null; int N = list.size(); Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationListenerServiceTest.java +25 −0 Original line number Diff line number Diff line Loading @@ -24,7 +24,13 @@ import static android.service.notification.NotificationListenerService.Ranking .USER_SENTIMENT_POSITIVE; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import android.app.INotificationManager; import android.app.NotificationChannel; import android.content.Intent; import android.os.Binder; Loading @@ -34,6 +40,7 @@ import android.service.notification.NotificationListenerService; import android.service.notification.NotificationListenerService.Ranking; import android.service.notification.NotificationRankingUpdate; import android.service.notification.SnoozeCriterion; import android.service.notification.StatusBarNotification; import android.support.test.runner.AndroidJUnit4; import android.test.suitebuilder.annotation.SmallTest; Loading @@ -51,6 +58,19 @@ public class NotificationListenerServiceTest extends UiServiceTestCase { private String[] mKeys = new String[] { "key", "key1", "key2", "key3"}; @Test public void testGetActiveNotifications_notNull() throws Exception { TestListenerService service = new TestListenerService(); INotificationManager noMan = service.getNoMan(); when(noMan.getActiveNotificationsFromListener(any(), any(), anyInt())).thenReturn(null); assertNotNull(service.getActiveNotifications()); assertNotNull(service.getActiveNotifications(NotificationListenerService.TRIM_FULL)); assertNotNull(service.getActiveNotifications(new String[0])); assertNotNull(service.getActiveNotifications( new String[0], NotificationListenerService.TRIM_LIGHT)); } @Test public void testRanking() throws Exception { TestListenerService service = new TestListenerService(); Loading Loading @@ -180,7 +200,12 @@ public class NotificationListenerServiceTest extends UiServiceTestCase { private final IBinder binder = new LocalBinder(); public TestListenerService() { mWrapper = mock(NotificationListenerWrapper.class); mNoMan = mock(INotificationManager.class); } INotificationManager getNoMan() { return mNoMan; } @Override Loading Loading
core/java/android/service/notification/NotificationListenerService.java +9 −3 Original line number Diff line number Diff line Loading @@ -807,7 +807,8 @@ public abstract class NotificationListenerService extends Service { * @return An array of active notifications, sorted in natural order. */ public StatusBarNotification[] getActiveNotifications() { return getActiveNotifications(null, TRIM_FULL); StatusBarNotification[] activeNotifications = getActiveNotifications(null, TRIM_FULL); return activeNotifications != null ? activeNotifications : new StatusBarNotification[0]; } /** Loading Loading @@ -842,7 +843,8 @@ public abstract class NotificationListenerService extends Service { */ @SystemApi public StatusBarNotification[] getActiveNotifications(int trim) { return getActiveNotifications(null, trim); StatusBarNotification[] activeNotifications = getActiveNotifications(null, trim); return activeNotifications != null ? activeNotifications : new StatusBarNotification[0]; } /** Loading @@ -858,7 +860,8 @@ public abstract class NotificationListenerService extends Service { * same order as the key list. */ public StatusBarNotification[] getActiveNotifications(String[] keys) { return getActiveNotifications(keys, TRIM_FULL); StatusBarNotification[] activeNotifications = getActiveNotifications(keys, TRIM_FULL); return activeNotifications != null ? activeNotifications : new StatusBarNotification[0]; } /** Loading Loading @@ -890,6 +893,9 @@ public abstract class NotificationListenerService extends Service { private StatusBarNotification[] cleanUpNotificationList( ParceledListSlice<StatusBarNotification> parceledList) { if (parceledList == null || parceledList.getList() == null) { return new StatusBarNotification[0]; } List<StatusBarNotification> list = parceledList.getList(); ArrayList<StatusBarNotification> corruptNotifications = null; int N = list.size(); Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationListenerServiceTest.java +25 −0 Original line number Diff line number Diff line Loading @@ -24,7 +24,13 @@ import static android.service.notification.NotificationListenerService.Ranking .USER_SENTIMENT_POSITIVE; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import android.app.INotificationManager; import android.app.NotificationChannel; import android.content.Intent; import android.os.Binder; Loading @@ -34,6 +40,7 @@ import android.service.notification.NotificationListenerService; import android.service.notification.NotificationListenerService.Ranking; import android.service.notification.NotificationRankingUpdate; import android.service.notification.SnoozeCriterion; import android.service.notification.StatusBarNotification; import android.support.test.runner.AndroidJUnit4; import android.test.suitebuilder.annotation.SmallTest; Loading @@ -51,6 +58,19 @@ public class NotificationListenerServiceTest extends UiServiceTestCase { private String[] mKeys = new String[] { "key", "key1", "key2", "key3"}; @Test public void testGetActiveNotifications_notNull() throws Exception { TestListenerService service = new TestListenerService(); INotificationManager noMan = service.getNoMan(); when(noMan.getActiveNotificationsFromListener(any(), any(), anyInt())).thenReturn(null); assertNotNull(service.getActiveNotifications()); assertNotNull(service.getActiveNotifications(NotificationListenerService.TRIM_FULL)); assertNotNull(service.getActiveNotifications(new String[0])); assertNotNull(service.getActiveNotifications( new String[0], NotificationListenerService.TRIM_LIGHT)); } @Test public void testRanking() throws Exception { TestListenerService service = new TestListenerService(); Loading Loading @@ -180,7 +200,12 @@ public class NotificationListenerServiceTest extends UiServiceTestCase { private final IBinder binder = new LocalBinder(); public TestListenerService() { mWrapper = mock(NotificationListenerWrapper.class); mNoMan = mock(INotificationManager.class); } INotificationManager getNoMan() { return mNoMan; } @Override Loading