From 98ef61b549fbb881acce264eb66230e21c2da4c6 Mon Sep 17 00:00:00 2001 From: Beverly Date: Thu, 15 Feb 2018 10:36:28 -0500 Subject: [PATCH] Pre-P cannot change alarms/media dnd policy Test: runtest --path cts/tests/app/src/android/app/cts/NotifiationManagerTest.java Bug: 70662324 Change-Id: I063c9b0c6c7282c0ea6969fa2f27f42879d84185 --- .../NotificationManagerService.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 3800017f0a080..74d9284ff679a 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -3017,9 +3017,9 @@ public class NotificationManagerService extends SystemService { /** * Sets the notification policy. Apps that target API levels below - * {@link android.os.Build.VERSION_CODES#P} cannot make DND silence - * {@link Policy#PRIORITY_CATEGORY_ALARMS} or - * {@link Policy#PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER} + * {@link android.os.Build.VERSION_CODES#P} cannot change user-designated values to + * allow or disallow {@link Policy#PRIORITY_CATEGORY_ALARMS} and + * {@link Policy#PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER} from bypassing dnd */ @Override public void setNotificationPolicy(String pkg, Policy policy) { @@ -3032,10 +3032,14 @@ public class NotificationManagerService extends SystemService { if (applicationInfo.targetSdkVersion <= Build.VERSION_CODES.O_MR1) { Policy currPolicy = mZenModeHelper.getNotificationPolicy(); - int priorityCategories = policy.priorityCategories - | (currPolicy.priorityCategories & Policy.PRIORITY_CATEGORY_ALARMS) - | (currPolicy.priorityCategories & - Policy.PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER); + int priorityCategories = policy.priorityCategories; + // ignore alarm and media values from new policy + priorityCategories &= ~Policy.PRIORITY_CATEGORY_ALARMS; + priorityCategories &= ~Policy.PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER; + // use user-designated values + priorityCategories |= currPolicy.PRIORITY_CATEGORY_ALARMS; + priorityCategories |= currPolicy.PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER; + policy = new Policy(priorityCategories, policy.priorityCallSenders, policy.priorityMessageSenders, policy.suppressedVisualEffects);