From 25926af53740667b215457bbde0bda679b400078 Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Tue, 1 May 2018 17:05:33 -0400 Subject: [PATCH] Hide some previously exempt notifications Some notifications are exempt from DND visual suppression, like foreground services. If a notification is tagged as a category that's explicitly mentioned in DND settings (like calls), exempt that notification from DND exemption, or, hide it. Test: atest SystemUITests Change-Id: I661e6d99d09adcb381aef04cccdf93c9810d19b2 Fixes: 78908945 --- .../systemui/statusbar/NotificationData.java | 31 +++++++++++++++++ .../systemui/statusbar/NotificationDataTest.java | 39 ++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java index b442bb4d8572..419e262bbc6f 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java @@ -16,6 +16,11 @@ package com.android.systemui.statusbar; +import static android.app.Notification.CATEGORY_ALARM; +import static android.app.Notification.CATEGORY_CALL; +import static android.app.Notification.CATEGORY_EVENT; +import static android.app.Notification.CATEGORY_MESSAGE; +import static android.app.Notification.CATEGORY_REMINDER; import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_AMBIENT; import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_FULL_SCREEN_INTENT; import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_NOTIFICATION_LIST; @@ -52,6 +57,7 @@ import com.android.systemui.statusbar.notification.InflationException; import com.android.systemui.statusbar.phone.NotificationGroupManager; import com.android.systemui.statusbar.phone.StatusBar; import com.android.systemui.statusbar.policy.HeadsUpManager; +import com.android.systemui.statusbar.policy.ZenModeController; import java.io.PrintWriter; import java.util.ArrayList; @@ -68,6 +74,7 @@ public class NotificationData { private final Environment mEnvironment; private HeadsUpManager mHeadsUpManager; + final ZenModeController mZen = Dependency.get(ZenModeController.class); final ForegroundServiceController mFsc = Dependency.get(ForegroundServiceController.class); public static final class Entry { @@ -474,6 +481,10 @@ public class NotificationData { } protected boolean isExemptFromDndVisualSuppression(Entry entry) { + if (isNotificationBlockedByPolicy(entry.notification.getNotification())) { + return false; + } + if ((entry.notification.getNotification().flags & Notification.FLAG_FOREGROUND_SERVICE) != 0) { return true; @@ -487,6 +498,26 @@ public class NotificationData { return false; } + /** + * Categories that are explicitly called out on DND settings screens are always blocked, if + * DND has flagged them, even if they are foreground or system notifications that might + * otherwise visually bypass DND. + */ + protected boolean isNotificationBlockedByPolicy(Notification n) { + if (isCategory(CATEGORY_CALL, n) + || isCategory(CATEGORY_MESSAGE, n) + || isCategory(CATEGORY_ALARM, n) + || isCategory(CATEGORY_EVENT, n) + || isCategory(CATEGORY_REMINDER, n)) { + return true; + } + return false; + } + + private boolean isCategory(String category, Notification n) { + return Objects.equals(n.category, category); + } + public int getImportance(String key) { if (mRankingMap != null) { getRanking(key, mTmpRanking); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationDataTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationDataTest.java index d3c3746761aa..8bdaff942736 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationDataTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationDataTest.java @@ -18,6 +18,11 @@ package com.android.systemui.statusbar; import static android.app.AppOpsManager.OP_ACCEPT_HANDOVER; import static android.app.AppOpsManager.OP_CAMERA; +import static android.app.Notification.CATEGORY_ALARM; +import static android.app.Notification.CATEGORY_CALL; +import static android.app.Notification.CATEGORY_EVENT; +import static android.app.Notification.CATEGORY_MESSAGE; +import static android.app.Notification.CATEGORY_REMINDER; import static junit.framework.Assert.assertEquals; @@ -312,6 +317,40 @@ public class NotificationDataTest extends SysuiTestCase { assertFalse(mNotificationData.shouldSuppressAmbient(entry)); } + @Test + public void testIsNotExemptFromDndVisualSuppression_hiddenCategories() { + initStatusBarNotification(false); + when(mMockStatusBarNotification.getKey()).thenReturn( + TEST_EXEMPT_DND_VISUAL_SUPPRESSION_KEY); + NotificationData.Entry entry = new NotificationData.Entry(mMockStatusBarNotification); + entry.mIsSystemNotification = true; + when(mMockStatusBarNotification.getNotification()).thenReturn( + new Notification.Builder(mContext, "").setCategory(CATEGORY_CALL).build()); + + assertFalse(mNotificationData.isExemptFromDndVisualSuppression(entry)); + assertTrue(mNotificationData.shouldSuppressAmbient(entry)); + + when(mMockStatusBarNotification.getNotification()).thenReturn( + new Notification.Builder(mContext, "").setCategory(CATEGORY_REMINDER).build()); + + assertFalse(mNotificationData.isExemptFromDndVisualSuppression(entry)); + + when(mMockStatusBarNotification.getNotification()).thenReturn( + new Notification.Builder(mContext, "").setCategory(CATEGORY_ALARM).build()); + + assertFalse(mNotificationData.isExemptFromDndVisualSuppression(entry)); + + when(mMockStatusBarNotification.getNotification()).thenReturn( + new Notification.Builder(mContext, "").setCategory(CATEGORY_EVENT).build()); + + assertFalse(mNotificationData.isExemptFromDndVisualSuppression(entry)); + + when(mMockStatusBarNotification.getNotification()).thenReturn( + new Notification.Builder(mContext, "").setCategory(CATEGORY_MESSAGE).build()); + + assertFalse(mNotificationData.isExemptFromDndVisualSuppression(entry)); + } + private void initStatusBarNotification(boolean allowDuringSetup) { Bundle bundle = new Bundle(); bundle.putBoolean(Notification.EXTRA_ALLOW_DURING_SETUP, allowDuringSetup); -- 2.11.0