Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d2e7a97b authored by Brad Stenning's avatar Brad Stenning
Browse files

Don't autogroup critical notifications

Bug: 115353049
Test: JUnit and manual
Change-Id: Icf44d01252342f97e3ee1b9199546049742ec86e
(cherry picked from commit ddf2e87ae8e397c1f04e28d2608a46bb2df17400)
parent 2aba342b
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -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() {
@@ -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.
     */
+20 −0
Original line number Diff line number Diff line
@@ -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);