Loading services/core/java/com/android/server/notification/ZenModeHelper.java +3 −2 Original line number Diff line number Diff line Loading @@ -1358,7 +1358,8 @@ public class ZenModeHelper { if (isNew) { // Newly created rule with no provided policy; fill in with the default. zenRule.zenPolicy = Flags.modesUi() ? mDefaultConfig.getZenPolicy() : mConfig.getZenPolicy(); (Flags.modesUi() ? mDefaultConfig.getZenPolicy() : mConfig.getZenPolicy()) .copy(); return true; } // Otherwise, a null policy means no policy changes, so we can stop here. Loading Loading @@ -1773,7 +1774,7 @@ public class ZenModeHelper { // definition cannot have a rule with TYPE_BEDTIME (or any other type). config.automaticRules = new ArrayMap<>(); for (ZenRule rule : mDefaultConfig.automaticRules.values()) { config.automaticRules.put(rule.id, rule); config.automaticRules.put(rule.id, rule.copy()); } reason += ", reset to default rules"; } Loading services/tests/uiservicestests/src/com/android/server/notification/ZenModeHelperTest.java +16 −0 Original line number Diff line number Diff line Loading @@ -6992,6 +6992,22 @@ public class ZenModeHelperTest extends UiServiceTestCase { assertThat(zenRule.condition).isNotNull(); } @Test @EnableFlags(FLAG_MODES_API) public void addAutomaticZenRule_withoutPolicy_getsItsOwnInstanceOfDefaultPolicy() { // Add a rule without policy -> uses default config AutomaticZenRule azr = new AutomaticZenRule.Builder("Rule", Uri.parse("cond")) .setPackage(mPkg) .build(); String ruleId = mZenModeHelper.addAutomaticZenRule(mPkg, azr, ORIGIN_APP, "adding", CUSTOM_PKG_UID); ZenRule zenRule = checkNotNull(mZenModeHelper.mConfig.automaticRules.get(ruleId)); assertThat(zenRule.zenPolicy).isEqualTo(mZenModeHelper.getDefaultZenPolicy()); assertThat(zenRule.zenPolicy).isNotSameInstanceAs(mZenModeHelper.getDefaultZenPolicy()); } private static void addZenRule(ZenModeConfig config, String id, String ownerPkg, int zenMode, @Nullable ZenPolicy zenPolicy) { ZenRule rule = new ZenRule(); Loading Loading
services/core/java/com/android/server/notification/ZenModeHelper.java +3 −2 Original line number Diff line number Diff line Loading @@ -1358,7 +1358,8 @@ public class ZenModeHelper { if (isNew) { // Newly created rule with no provided policy; fill in with the default. zenRule.zenPolicy = Flags.modesUi() ? mDefaultConfig.getZenPolicy() : mConfig.getZenPolicy(); (Flags.modesUi() ? mDefaultConfig.getZenPolicy() : mConfig.getZenPolicy()) .copy(); return true; } // Otherwise, a null policy means no policy changes, so we can stop here. Loading Loading @@ -1773,7 +1774,7 @@ public class ZenModeHelper { // definition cannot have a rule with TYPE_BEDTIME (or any other type). config.automaticRules = new ArrayMap<>(); for (ZenRule rule : mDefaultConfig.automaticRules.values()) { config.automaticRules.put(rule.id, rule); config.automaticRules.put(rule.id, rule.copy()); } reason += ", reset to default rules"; } Loading
services/tests/uiservicestests/src/com/android/server/notification/ZenModeHelperTest.java +16 −0 Original line number Diff line number Diff line Loading @@ -6992,6 +6992,22 @@ public class ZenModeHelperTest extends UiServiceTestCase { assertThat(zenRule.condition).isNotNull(); } @Test @EnableFlags(FLAG_MODES_API) public void addAutomaticZenRule_withoutPolicy_getsItsOwnInstanceOfDefaultPolicy() { // Add a rule without policy -> uses default config AutomaticZenRule azr = new AutomaticZenRule.Builder("Rule", Uri.parse("cond")) .setPackage(mPkg) .build(); String ruleId = mZenModeHelper.addAutomaticZenRule(mPkg, azr, ORIGIN_APP, "adding", CUSTOM_PKG_UID); ZenRule zenRule = checkNotNull(mZenModeHelper.mConfig.automaticRules.get(ruleId)); assertThat(zenRule.zenPolicy).isEqualTo(mZenModeHelper.getDefaultZenPolicy()); assertThat(zenRule.zenPolicy).isNotSameInstanceAs(mZenModeHelper.getDefaultZenPolicy()); } private static void addZenRule(ZenModeConfig config, String id, String ownerPkg, int zenMode, @Nullable ZenPolicy zenPolicy) { ZenRule rule = new ZenRule(); Loading