Loading services/core/java/com/android/server/notification/ZenModeHelper.java +18 −0 Original line number Diff line number Diff line Loading @@ -210,6 +210,9 @@ public class ZenModeHelper { mDefaultConfig = readDefaultConfig(mContext.getResources()); updateDefaultAutomaticRuleNames(); if (Flags.modesApi()) { updateDefaultAutomaticRulePolicies(); } mConfig = mDefaultConfig.copy(); synchronized (mConfigsArrayLock) { mConfigs.put(UserHandle.USER_SYSTEM, mConfig); Loading Loading @@ -1966,6 +1969,21 @@ public class ZenModeHelper { } } // Updates the policies in the default automatic rules (provided via default XML config) to // be fully filled in default values. private void updateDefaultAutomaticRulePolicies() { if (!Flags.modesApi()) { // Should be checked before calling, but just in case. return; } ZenPolicy defaultPolicy = mDefaultConfig.toZenPolicy(); for (ZenRule rule : mDefaultConfig.automaticRules.values()) { if (ZenModeConfig.DEFAULT_RULE_IDS.contains(rule.id) && rule.zenPolicy == null) { rule.zenPolicy = defaultPolicy.copy(); } } } @VisibleForTesting protected void applyRestrictions() { final boolean zenOn = mZenMode != Global.ZEN_MODE_OFF; Loading services/tests/uiservicestests/src/com/android/server/notification/ZenModeHelperTest.java +19 −0 Original line number Diff line number Diff line Loading @@ -2122,6 +2122,25 @@ public class ZenModeHelperTest extends UiServiceTestCase { assertFalse(Objects.equals(defaultRuleName, ruleAfterUpdating.name)); // update name } @Test @EnableFlags(Flags.FLAG_MODES_API) public void testDefaultRulesFromConfig_modesApi_getPolicies() { // After mZenModeHelper was created, set some things in the policy so it's changed from // default. setupZenConfig(); // Find default rules; check they have non-null policies; check that they match the default // and not whatever has been set up in setupZenConfig. ArrayMap<String, ZenModeConfig.ZenRule> rules = mZenModeHelper.mConfig.automaticRules; for (String defaultId : ZenModeConfig.DEFAULT_RULE_IDS) { assertThat(rules).containsKey(defaultId); ZenRule rule = rules.get(defaultId); assertThat(rule.zenPolicy).isNotNull(); assertThat(rule.zenPolicy).isEqualTo(mZenModeHelper.getDefaultZenPolicy()); } } @Test public void testAddAutomaticZenRule_beyondSystemLimit() { for (int i = 0; i < RULE_LIMIT_PER_PACKAGE; i++) { Loading Loading
services/core/java/com/android/server/notification/ZenModeHelper.java +18 −0 Original line number Diff line number Diff line Loading @@ -210,6 +210,9 @@ public class ZenModeHelper { mDefaultConfig = readDefaultConfig(mContext.getResources()); updateDefaultAutomaticRuleNames(); if (Flags.modesApi()) { updateDefaultAutomaticRulePolicies(); } mConfig = mDefaultConfig.copy(); synchronized (mConfigsArrayLock) { mConfigs.put(UserHandle.USER_SYSTEM, mConfig); Loading Loading @@ -1966,6 +1969,21 @@ public class ZenModeHelper { } } // Updates the policies in the default automatic rules (provided via default XML config) to // be fully filled in default values. private void updateDefaultAutomaticRulePolicies() { if (!Flags.modesApi()) { // Should be checked before calling, but just in case. return; } ZenPolicy defaultPolicy = mDefaultConfig.toZenPolicy(); for (ZenRule rule : mDefaultConfig.automaticRules.values()) { if (ZenModeConfig.DEFAULT_RULE_IDS.contains(rule.id) && rule.zenPolicy == null) { rule.zenPolicy = defaultPolicy.copy(); } } } @VisibleForTesting protected void applyRestrictions() { final boolean zenOn = mZenMode != Global.ZEN_MODE_OFF; Loading
services/tests/uiservicestests/src/com/android/server/notification/ZenModeHelperTest.java +19 −0 Original line number Diff line number Diff line Loading @@ -2122,6 +2122,25 @@ public class ZenModeHelperTest extends UiServiceTestCase { assertFalse(Objects.equals(defaultRuleName, ruleAfterUpdating.name)); // update name } @Test @EnableFlags(Flags.FLAG_MODES_API) public void testDefaultRulesFromConfig_modesApi_getPolicies() { // After mZenModeHelper was created, set some things in the policy so it's changed from // default. setupZenConfig(); // Find default rules; check they have non-null policies; check that they match the default // and not whatever has been set up in setupZenConfig. ArrayMap<String, ZenModeConfig.ZenRule> rules = mZenModeHelper.mConfig.automaticRules; for (String defaultId : ZenModeConfig.DEFAULT_RULE_IDS) { assertThat(rules).containsKey(defaultId); ZenRule rule = rules.get(defaultId); assertThat(rule.zenPolicy).isNotNull(); assertThat(rule.zenPolicy).isEqualTo(mZenModeHelper.getDefaultZenPolicy()); } } @Test public void testAddAutomaticZenRule_beyondSystemLimit() { for (int i = 0; i < RULE_LIMIT_PER_PACKAGE; i++) { Loading