Loading services/core/java/com/android/server/notification/NotificationManagerService.java +15 −1 Original line number Diff line number Diff line Loading @@ -4732,7 +4732,8 @@ public class NotificationManagerService extends SystemService { if (notification.getSmallIcon() != null) { StatusBarNotification oldSbn = (old != null) ? old.sbn : null; mListeners.notifyPostedLocked(r, old); if (oldSbn == null || !Objects.equals(oldSbn.getGroup(), n.getGroup())) { if ((oldSbn == null || !Objects.equals(oldSbn.getGroup(), n.getGroup())) && !isCritical(r)) { mHandler.post(new Runnable() { @Override public void run() { Loading Loading @@ -4901,6 +4902,19 @@ public class NotificationManagerService extends SystemService { return false; } /** * Check if the notification is classified as critical. * * @param record the record to test for criticality * @return {@code true} if notification is considered critical * * @see CriticalNotificationExtractor for criteria */ private boolean isCritical(NotificationRecord record) { // 0 is the most critical return record.getCriticality() < CriticalNotificationExtractor.NORMAL; } /** * Keeps the last 5 packages that have notified, by user. */ Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +20 −0 Original line number Diff line number Diff line Loading @@ -2191,6 +2191,26 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { verify(mGroupHelper, never()).onNotificationPosted(any(), anyBoolean()); } @Test public void testDontAutogroupIfCritical() throws Exception { NotificationRecord r = generateNotificationRecord(mTestNotificationChannel, 0, null, false); r.setCriticality(CriticalNotificationExtractor.CRITICAL_LOW); mService.addEnqueuedNotification(r); NotificationManagerService.PostNotificationRunnable runnable = mService.new PostNotificationRunnable(r.getKey()); runnable.run(); r = generateNotificationRecord(mTestNotificationChannel, 1, null, false); r.setCriticality(CriticalNotificationExtractor.CRITICAL); runnable = mService.new PostNotificationRunnable(r.getKey()); mService.addEnqueuedNotification(r); runnable.run(); waitForIdle(); verify(mGroupHelper, never()).onNotificationPosted(any(), anyBoolean()); } @Test public void testNoFakeColorizedPermission() throws Exception { when(mPackageManagerClient.checkPermission(any(), any())).thenReturn(PERMISSION_DENIED); Loading Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +15 −1 Original line number Diff line number Diff line Loading @@ -4732,7 +4732,8 @@ public class NotificationManagerService extends SystemService { if (notification.getSmallIcon() != null) { StatusBarNotification oldSbn = (old != null) ? old.sbn : null; mListeners.notifyPostedLocked(r, old); if (oldSbn == null || !Objects.equals(oldSbn.getGroup(), n.getGroup())) { if ((oldSbn == null || !Objects.equals(oldSbn.getGroup(), n.getGroup())) && !isCritical(r)) { mHandler.post(new Runnable() { @Override public void run() { Loading Loading @@ -4901,6 +4902,19 @@ public class NotificationManagerService extends SystemService { return false; } /** * Check if the notification is classified as critical. * * @param record the record to test for criticality * @return {@code true} if notification is considered critical * * @see CriticalNotificationExtractor for criteria */ private boolean isCritical(NotificationRecord record) { // 0 is the most critical return record.getCriticality() < CriticalNotificationExtractor.NORMAL; } /** * Keeps the last 5 packages that have notified, by user. */ Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +20 −0 Original line number Diff line number Diff line Loading @@ -2191,6 +2191,26 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { verify(mGroupHelper, never()).onNotificationPosted(any(), anyBoolean()); } @Test public void testDontAutogroupIfCritical() throws Exception { NotificationRecord r = generateNotificationRecord(mTestNotificationChannel, 0, null, false); r.setCriticality(CriticalNotificationExtractor.CRITICAL_LOW); mService.addEnqueuedNotification(r); NotificationManagerService.PostNotificationRunnable runnable = mService.new PostNotificationRunnable(r.getKey()); runnable.run(); r = generateNotificationRecord(mTestNotificationChannel, 1, null, false); r.setCriticality(CriticalNotificationExtractor.CRITICAL); runnable = mService.new PostNotificationRunnable(r.getKey()); mService.addEnqueuedNotification(r); runnable.run(); waitForIdle(); verify(mGroupHelper, never()).onNotificationPosted(any(), anyBoolean()); } @Test public void testNoFakeColorizedPermission() throws Exception { when(mPackageManagerClient.checkPermission(any(), any())).thenReturn(PERMISSION_DENIED); Loading