Loading packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java +31 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading @@ -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 { Loading Loading @@ -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; Loading @@ -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); Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationDataTest.java +39 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); Loading Loading
packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java +31 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading @@ -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 { Loading Loading @@ -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; Loading @@ -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); Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationDataTest.java +39 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); Loading