diff options
5 files changed, 72 insertions, 33 deletions
diff --git a/core/java/android/service/notification/ZenPolicy.java b/core/java/android/service/notification/ZenPolicy.java index 2669391b4d45..be0d7b3a72f2 100644 --- a/core/java/android/service/notification/ZenPolicy.java +++ b/core/java/android/service/notification/ZenPolicy.java @@ -393,6 +393,46 @@ public final class ZenPolicy implements Parcelable { } /** + * Base Zen Policy used when {@link android.app.NotificationManager#setInterruptionFilter} is + * called with {@link android.app.NotificationManager#INTERRUPTION_FILTER_ALARMS} or an + * {@link android.app.AutomaticZenRule} specifies said filter. + * + * <p>Note that <em>visual effects</em> for filtered notifications are unset in this base + * policy, so should be merged on top of the default policy's visual effects (see + * {@link #overwrittenWith(ZenPolicy)}). + * + * @hide + */ + @FlaggedApi(Flags.FLAG_MODES_API) + public static ZenPolicy getBasePolicyInterruptionFilterAlarms() { + return new ZenPolicy.Builder() + .disallowAllSounds() + .allowAlarms(true) + .allowMedia(true) + .allowPriorityChannels(false) + .build(); + } + + /** + * Base Zen Policy used when {@link android.app.NotificationManager#setInterruptionFilter} is + * called with {@link android.app.NotificationManager#INTERRUPTION_FILTER_NONE} or an + * {@link android.app.AutomaticZenRule} specifies said filter. + * + * <p>Note that <em>visual effects</em> for filtered notifications are unset in this base + * policy, so it should be merged on top of the device default policy's visual effects (see + * {@link #overwrittenWith(ZenPolicy)}). + * + * @hide + */ + @FlaggedApi(Flags.FLAG_MODES_API) + public static ZenPolicy getBasePolicyInterruptionFilterNone() { + return new ZenPolicy.Builder() + .disallowAllSounds() + .allowPriorityChannels(false) + .build(); + } + + /** * Conversation type that can bypass DND. * @return {@link #CONVERSATION_SENDERS_UNSET}, {@link #CONVERSATION_SENDERS_ANYONE}, * {@link #CONVERSATION_SENDERS_IMPORTANT}, {@link #CONVERSATION_SENDERS_NONE}. diff --git a/packages/SettingsLib/src/com/android/settingslib/notification/modes/ZenMode.java b/packages/SettingsLib/src/com/android/settingslib/notification/modes/ZenMode.java index d0661fa4dee4..7b2a284803a2 100644 --- a/packages/SettingsLib/src/com/android/settingslib/notification/modes/ZenMode.java +++ b/packages/SettingsLib/src/com/android/settingslib/notification/modes/ZenMode.java @@ -69,23 +69,6 @@ public class ZenMode implements Parcelable { static final String MANUAL_DND_MODE_ID = ZenModeConfig.MANUAL_RULE_ID; static final String TEMP_NEW_MODE_ID = "temp_new_mode"; - // Must match com.android.server.notification.ZenModeHelper#applyCustomPolicy. - static final ZenPolicy POLICY_INTERRUPTION_FILTER_ALARMS = - new ZenPolicy.Builder() - .disallowAllSounds() - .allowAlarms(true) - .allowMedia(true) - .allowPriorityChannels(false) - .build(); - - // Must match com.android.server.notification.ZenModeHelper#applyCustomPolicy. - static final ZenPolicy POLICY_INTERRUPTION_FILTER_NONE = - new ZenPolicy.Builder() - .disallowAllSounds() - .hideAllVisualEffects() - .allowPriorityChannels(false) - .build(); - private static final Comparator<Integer> PRIORITIZED_TYPE_COMPARATOR = new Comparator<>() { private static final ImmutableList</* @AutomaticZenRule.Type */ Integer> @@ -320,10 +303,12 @@ public class ZenMode implements Parcelable { return requireNonNull(mRule.getZenPolicy()); case NotificationManager.INTERRUPTION_FILTER_ALARMS: - return POLICY_INTERRUPTION_FILTER_ALARMS; + return new ZenPolicy.Builder(ZenModeConfig.getDefaultZenPolicy()).build() + .overwrittenWith(ZenPolicy.getBasePolicyInterruptionFilterAlarms()); case NotificationManager.INTERRUPTION_FILTER_NONE: - return POLICY_INTERRUPTION_FILTER_NONE; + return new ZenPolicy.Builder(ZenModeConfig.getDefaultZenPolicy()).build() + .overwrittenWith(ZenPolicy.getBasePolicyInterruptionFilterNone()); case NotificationManager.INTERRUPTION_FILTER_UNKNOWN: default: diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/notification/modes/ZenModeTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/notification/modes/ZenModeTest.java index a30613d6274c..d08d91d18b27 100644 --- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/notification/modes/ZenModeTest.java +++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/notification/modes/ZenModeTest.java @@ -213,7 +213,7 @@ public class ZenModeTest { ZenMode zenMode = new ZenMode("id", azr, zenConfigRuleFor(azr, false)); assertThat(zenMode.getPolicy()).isEqualTo( - new ZenPolicy.Builder() + new ZenPolicy.Builder(ZenModeConfig.getDefaultZenPolicy()) .disallowAllSounds() .allowAlarms(true) .allowMedia(true) @@ -230,9 +230,8 @@ public class ZenModeTest { ZenMode zenMode = new ZenMode("id", azr, zenConfigRuleFor(azr, false)); assertThat(zenMode.getPolicy()).isEqualTo( - new ZenPolicy.Builder() + new ZenPolicy.Builder(ZenModeConfig.getDefaultZenPolicy()) .disallowAllSounds() - .hideAllVisualEffects() .allowPriorityChannels(false) .build()); } diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/notification/modes/ZenModesBackendTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/notification/modes/ZenModesBackendTest.java index ff028dd6bbdc..aae72b338c8c 100644 --- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/notification/modes/ZenModesBackendTest.java +++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/notification/modes/ZenModesBackendTest.java @@ -238,9 +238,16 @@ public class ZenModesBackendTest { assertThat(mode.isManualDnd()).isTrue(); assertThat(mode.isEnabled()).isTrue(); assertThat(mode.isActive()).isTrue(); + // Mode itself has a special fixed policy, different to the rule. assertThat(mode.canEditPolicy()).isFalse(); - assertThat(mode.getPolicy()).isEqualTo(ZenMode.POLICY_INTERRUPTION_FILTER_ALARMS); + assertThat(mode.getPolicy()).isEqualTo( + new ZenPolicy.Builder(ZenModeConfig.getDefaultZenPolicy()) + .disallowAllSounds() + .allowAlarms(true) + .allowMedia(true) + .allowPriorityChannels(false) + .build()); } @Test diff --git a/services/core/java/com/android/server/notification/ZenModeHelper.java b/services/core/java/com/android/server/notification/ZenModeHelper.java index 333b3e25cbfa..2ada9ae4790d 100644 --- a/services/core/java/com/android/server/notification/ZenModeHelper.java +++ b/services/core/java/com/android/server/notification/ZenModeHelper.java @@ -2125,17 +2125,25 @@ public class ZenModeHelper { @GuardedBy("mConfigLock") private void applyCustomPolicy(ZenPolicy policy, ZenRule rule, boolean useManualConfig) { if (rule.zenMode == Global.ZEN_MODE_NO_INTERRUPTIONS) { - policy.apply(new ZenPolicy.Builder() - .disallowAllSounds() - .allowPriorityChannels(false) - .build()); + if (Flags.modesApi() && Flags.modesUi()) { + policy.apply(ZenPolicy.getBasePolicyInterruptionFilterNone()); + } else { + policy.apply(new ZenPolicy.Builder() + .disallowAllSounds() + .allowPriorityChannels(false) + .build()); + } } else if (rule.zenMode == Global.ZEN_MODE_ALARMS) { - policy.apply(new ZenPolicy.Builder() - .disallowAllSounds() - .allowAlarms(true) - .allowMedia(true) - .allowPriorityChannels(false) - .build()); + if (Flags.modesApi() && Flags.modesUi()) { + policy.apply(ZenPolicy.getBasePolicyInterruptionFilterAlarms()); + } else { + policy.apply(new ZenPolicy.Builder() + .disallowAllSounds() + .allowAlarms(true) + .allowMedia(true) + .allowPriorityChannels(false) + .build()); + } } else if (rule.zenPolicy != null) { policy.apply(rule.zenPolicy); } else { |