summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Brad Stenning <stenning@google.com> 2018-08-10 14:39:26 -0700
committer Brad Stenning <stenning@google.com> 2018-08-16 13:51:57 +0000
commit1e14f9f92a35e61c24ec53410740e588e4ba8b39 (patch)
treeedb1272ca9028529427741e2d625ba2203ad1dce
parent7c6ceb23dbbd6c6e8be4d593ed22ff1b491648cf (diff)
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
-rw-r--r--services/core/java/com/android/server/notification/ZenModeFiltering.java16
-rw-r--r--services/tests/uiservicestests/src/com/android/server/notification/ZenModeFilteringTest.java13
2 files changed, 28 insertions, 1 deletions
diff --git a/services/core/java/com/android/server/notification/ZenModeFiltering.java b/services/core/java/com/android/server/notification/ZenModeFiltering.java
index 71cee052d9a1..28cee7ac4dda 100644
--- a/services/core/java/com/android/server/notification/ZenModeFiltering.java
+++ b/services/core/java/com/android/server/notification/ZenModeFiltering.java
@@ -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");
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/ZenModeFilteringTest.java b/services/tests/uiservicestests/src/com/android/server/notification/ZenModeFilteringTest.java
index c0bd7ccf6bf4..d3354502f40b 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/ZenModeFilteringTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/ZenModeFilteringTest.java
@@ -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));
+ }
}