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

Commit 1e14f9f9 authored by Brad Stenning's avatar Brad Stenning
Browse files

Bypass Zenmode filtering when the notification is marked as critical

Test: enable dnd and use test app to send Car_emergency
Bug: 111793232
Change-Id: I6492c1e48429c5f199680c76d53248da8072f4ff
parent 7c6ceb23
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -117,7 +117,8 @@ public class ZenModeFiltering {
    }

    public boolean shouldIntercept(int zen, ZenModeConfig config, NotificationRecord record) {
        if (zen == ZEN_MODE_OFF) {
        // Zen mode is ignored for critical notifications.
        if (zen == ZEN_MODE_OFF || isCritical(record)) {
            return false;
        }
        // Make an exception to policy for the notification saying that policy has changed
@@ -207,6 +208,19 @@ public class ZenModeFiltering {
        }
    }

    /**
     * Check if the notification is too critical to be suppressed.
     *
     * @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;
    }

    private static boolean shouldInterceptAudience(int source, NotificationRecord record) {
        if (!audienceMatches(source, record.getContactAffinity())) {
            ZenLog.traceIntercepted(record, "!audienceMatches");
+13 −0
Original line number Diff line number Diff line
@@ -171,4 +171,17 @@ public class ZenModeFilteringTest extends UiServiceTestCase {

        assertFalse(mZenModeFiltering.shouldIntercept(ZEN_MODE_OFF, config, r));
    }

    @Test
    public void testSuppressAnything_bypass_ZenModeOn() {
        NotificationRecord r = getNotificationRecord();
        r.setCriticality(CriticalNotificationExtractor.CRITICAL);
        when(r.sbn.getPackageName()).thenReturn("bananas");
        ZenModeConfig config = mock(ZenModeConfig.class);

        assertFalse(mZenModeFiltering.shouldIntercept(ZEN_MODE_NO_INTERRUPTIONS, config, r));

        r.setCriticality(CriticalNotificationExtractor.CRITICAL_LOW);
        assertFalse(mZenModeFiltering.shouldIntercept(ZEN_MODE_NO_INTERRUPTIONS, config, r));
    }
}