Merge "When disallowing all sounds, also turn off priority channels." into main
diff --git a/core/java/android/service/notification/ZenPolicy.java b/core/java/android/service/notification/ZenPolicy.java
index 786d768..aa47d3a 100644
--- a/core/java/android/service/notification/ZenPolicy.java
+++ b/core/java/android/service/notification/ZenPolicy.java
@@ -673,6 +673,10 @@
mZenPolicy.mPriorityMessages = PEOPLE_TYPE_NONE;
mZenPolicy.mPriorityCalls = PEOPLE_TYPE_NONE;
mZenPolicy.mConversationSenders = CONVERSATION_SENDERS_NONE;
+
+ if (Flags.modesApi()) {
+ mZenPolicy.mAllowChannels = CHANNEL_POLICY_NONE;
+ }
return this;
}
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/ZenModeHelperTest.java b/services/tests/uiservicestests/src/com/android/server/notification/ZenModeHelperTest.java
index f9ba33b..6e5c180 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/ZenModeHelperTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/ZenModeHelperTest.java
@@ -649,6 +649,74 @@
}
@Test
+ @EnableFlags(Flags.FLAG_MODES_API)
+ public void testTotalSilence_consolidatedPolicyDisallowsAll() {
+ // Start with zen mode off just to make sure global/manual mode isn't doing anything.
+ mZenModeHelper.mZenMode = ZEN_MODE_OFF;
+
+ // Create a zen rule that calls for total silence via zen mode, but does not specify any
+ // particular policy. This confirms that the application of the policy is based only on the
+ // actual zen mode setting.
+ AutomaticZenRule azr = new AutomaticZenRule.Builder("OriginalName", CONDITION_ID)
+ .setInterruptionFilter(INTERRUPTION_FILTER_NONE)
+ .build();
+ String ruleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(),
+ azr, UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "reason", Process.SYSTEM_UID);
+
+ // Enable rule
+ mZenModeHelper.setAutomaticZenRuleState(ruleId,
+ new Condition(azr.getConditionId(), "", STATE_TRUE),
+ UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI,
+ Process.SYSTEM_UID);
+
+ // Confirm that the consolidated policy doesn't allow anything
+ NotificationManager.Policy policy = mZenModeHelper.getConsolidatedNotificationPolicy();
+ assertThat(policy.allowAlarms()).isFalse();
+ assertThat(policy.allowMedia()).isFalse();
+ assertThat(policy.allowCalls()).isFalse();
+ assertThat(policy.allowMessages()).isFalse();
+ assertThat(policy.allowConversations()).isFalse();
+ assertThat(policy.allowEvents()).isFalse();
+ assertThat(policy.allowReminders()).isFalse();
+ assertThat(policy.allowRepeatCallers()).isFalse();
+ assertThat(policy.allowPriorityChannels()).isFalse();
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_MODES_API)
+ public void testAlarmsOnly_consolidatedPolicyOnlyAllowsAlarmsAndMedia() {
+ // Start with zen mode off just to make sure global/manual mode isn't doing anything.
+ mZenModeHelper.mZenMode = ZEN_MODE_OFF;
+
+ // Create a zen rule that calls for alarms only via zen mode, but does not specify any
+ // particular policy. This confirms that the application of the policy is based only on the
+ // actual zen mode setting.
+ AutomaticZenRule azr = new AutomaticZenRule.Builder("OriginalName", CONDITION_ID)
+ .setInterruptionFilter(INTERRUPTION_FILTER_ALARMS)
+ .build();
+ String ruleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(),
+ azr, UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "reason", Process.SYSTEM_UID);
+
+ // Enable rule
+ mZenModeHelper.setAutomaticZenRuleState(ruleId,
+ new Condition(azr.getConditionId(), "", STATE_TRUE),
+ UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI,
+ Process.SYSTEM_UID);
+
+ // Confirm that the consolidated policy allows only alarms and media and nothing else
+ NotificationManager.Policy policy = mZenModeHelper.getConsolidatedNotificationPolicy();
+ assertThat(policy.allowAlarms()).isTrue();
+ assertThat(policy.allowMedia()).isTrue();
+ assertThat(policy.allowCalls()).isFalse();
+ assertThat(policy.allowMessages()).isFalse();
+ assertThat(policy.allowConversations()).isFalse();
+ assertThat(policy.allowEvents()).isFalse();
+ assertThat(policy.allowReminders()).isFalse();
+ assertThat(policy.allowRepeatCallers()).isFalse();
+ assertThat(policy.allowPriorityChannels()).isFalse();
+ }
+
+ @Test
public void testZenUpgradeNotification() {
/**
* Commit a485ec65b5ba947d69158ad90905abf3310655cf disabled DND status change