Pre-P target SDK can't silence alarms/media in dnd
In P, users can toggle alarms and media to bypass priority
mode DND. As a result, apps targetting pre-P, will not be able to
silence alarms or media (cannot disallow alarms/media from bypassing
DND).
Bug: 70662324
Test: make cts-verifier -j40, Notification Attention Management Test
Change-Id: I3d97530bfd2009863c69aa6adfc706551633fcff
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index cf01400..50986fb 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -2917,12 +2917,34 @@
}
}
+ /**
+ * 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}
+ */
@Override
public void setNotificationPolicy(String pkg, Policy policy) {
enforcePolicyAccess(pkg, "setNotificationPolicy");
final long identity = Binder.clearCallingIdentity();
try {
+ final ApplicationInfo applicationInfo = mPackageManager.getApplicationInfo(pkg,
+ 0, UserHandle.getUserId(MY_UID));
+
+ 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);
+ policy = new Policy(priorityCategories,
+ policy.priorityCallSenders, policy.priorityMessageSenders,
+ policy.suppressedVisualEffects);
+ }
+
mZenModeHelper.setNotificationPolicy(policy);
+ } catch (RemoteException e) {
} finally {
Binder.restoreCallingIdentity(identity);
}