Loading services/core/java/com/android/server/notification/ZenModeHelper.java +9 −6 Original line number Diff line number Diff line Loading @@ -961,14 +961,17 @@ public class ZenModeHelper { if (origin == ORIGIN_USER_IN_SYSTEMUI && condition != null && condition.source == SOURCE_USER_ACTION) { // Apply as override, instead of actual condition. // If the new override is the reverse of a previous (still active) override, try // removing the previous override, as long as the resulting state, based on the // previous owner-provided condition, is the desired one (active or inactive). // This allows the rule owner to resume controlling the rule after // snoozing-unsnoozing or activating-stopping. if (condition.state == STATE_TRUE) { // Manually turn on a rule -> Apply override. rule.resetConditionOverride(); if (!rule.isAutomaticActive()) { rule.setConditionOverride(OVERRIDE_ACTIVATE); } } else if (condition.state == STATE_FALSE) { // Manually turn off a rule. If the rule was manually activated before, reset // override -- but only if this will not result in the rule turning on // immediately because of a previously snoozed condition! In that case, apply // deactivate-override. rule.resetConditionOverride(); if (rule.isAutomaticActive()) { rule.setConditionOverride(OVERRIDE_DEACTIVATE); Loading services/tests/uiservicestests/src/com/android/server/notification/ZenModeHelperTest.java +55 −2 Original line number Diff line number Diff line Loading @@ -4972,7 +4972,7 @@ public class ZenModeHelperTest extends UiServiceTestCase { mZenModeHelper.setAutomaticZenRuleState(createdId, new Condition(zenRule.getConditionId(), "", STATE_FALSE), ORIGIN_APP, SYSTEM_UID); ORIGIN_APP, CUSTOM_PKG_UID); assertTrue(latch.await(500, TimeUnit.MILLISECONDS)); if (CompatChanges.isChangeEnabled(ZenModeHelper.SEND_ACTIVATION_AZR_STATUSES)) { Loading Loading @@ -6491,6 +6491,8 @@ public class ZenModeHelperTest extends UiServiceTestCase { .build(); String ruleId = mZenModeHelper.addAutomaticZenRule(mPkg, rule, ORIGIN_APP, "adding", CUSTOM_PKG_UID); Condition autoOn = new Condition(rule.getConditionId(), "auto-on", STATE_TRUE, SOURCE_CONTEXT); ZenRule zenRule; mZenModeHelper.setAutomaticZenRuleState(ruleId, Loading @@ -6508,6 +6510,57 @@ public class ZenModeHelperTest extends UiServiceTestCase { assertThat(zenRule.isAutomaticActive()).isFalse(); assertThat(zenRule.getConditionOverride()).isEqualTo(OVERRIDE_NONE); assertThat(zenRule.condition).isNull(); // Bonus check: app has resumed control over the rule and can now turn it on. mZenModeHelper.setAutomaticZenRuleState(ruleId, autoOn, ORIGIN_APP, CUSTOM_PKG_UID); zenRule = mZenModeHelper.mConfig.automaticRules.get(ruleId); assertThat(zenRule.isAutomaticActive()).isTrue(); assertThat(zenRule.getConditionOverride()).isEqualTo(OVERRIDE_NONE); assertThat(zenRule.condition).isEqualTo(autoOn); } @Test @EnableFlags({FLAG_MODES_API, FLAG_MODES_UI}) public void setAutomaticZenRuleState_manualDeactivationAndThenReactivation_removesOverride() { AutomaticZenRule rule = new AutomaticZenRule.Builder("Rule", Uri.parse("cond")) .setPackage(mPkg) .build(); String ruleId = mZenModeHelper.addAutomaticZenRule(mPkg, rule, ORIGIN_APP, "adding", CUSTOM_PKG_UID); Condition autoOn = new Condition(rule.getConditionId(), "auto-on", STATE_TRUE, SOURCE_CONTEXT); Condition autoOff = new Condition(rule.getConditionId(), "auto-off", STATE_FALSE, SOURCE_CONTEXT); ZenRule zenRule; mZenModeHelper.setAutomaticZenRuleState(ruleId, autoOn, ORIGIN_APP, CUSTOM_PKG_UID); zenRule = mZenModeHelper.mConfig.automaticRules.get(ruleId); assertThat(zenRule.isAutomaticActive()).isTrue(); assertThat(zenRule.getConditionOverride()).isEqualTo(OVERRIDE_NONE); assertThat(zenRule.condition).isEqualTo(autoOn); mZenModeHelper.setAutomaticZenRuleState(ruleId, new Condition(rule.getConditionId(), "manual-off", STATE_FALSE, SOURCE_USER_ACTION), ORIGIN_USER_IN_SYSTEMUI, SYSTEM_UID); zenRule = mZenModeHelper.mConfig.automaticRules.get(ruleId); assertThat(zenRule.isAutomaticActive()).isFalse(); assertThat(zenRule.getConditionOverride()).isEqualTo(OVERRIDE_DEACTIVATE); assertThat(zenRule.condition).isEqualTo(autoOn); mZenModeHelper.setAutomaticZenRuleState(ruleId, new Condition(rule.getConditionId(), "manual-on", STATE_TRUE, SOURCE_USER_ACTION), ORIGIN_USER_IN_SYSTEMUI, SYSTEM_UID); zenRule = mZenModeHelper.mConfig.automaticRules.get(ruleId); assertThat(zenRule.isAutomaticActive()).isTrue(); assertThat(zenRule.getConditionOverride()).isEqualTo(OVERRIDE_NONE); assertThat(zenRule.condition).isEqualTo(autoOn); // Bonus check: app has resumed control over the rule and can now turn it off. mZenModeHelper.setAutomaticZenRuleState(ruleId, autoOff, ORIGIN_APP, CUSTOM_PKG_UID); zenRule = mZenModeHelper.mConfig.automaticRules.get(ruleId); assertThat(zenRule.isAutomaticActive()).isFalse(); assertThat(zenRule.getConditionOverride()).isEqualTo(OVERRIDE_NONE); assertThat(zenRule.condition).isEqualTo(autoOff); } @Test Loading @@ -6521,7 +6574,7 @@ public class ZenModeHelperTest extends UiServiceTestCase { mZenModeHelper.setAutomaticZenRuleState(ruleId, new Condition(rule.getConditionId(), "auto-on", STATE_TRUE, SOURCE_CONTEXT), ORIGIN_APP, SYSTEM_UID); ORIGIN_APP, CUSTOM_PKG_UID); ZenRule zenRuleOn = mZenModeHelper.mConfig.automaticRules.get(ruleId); assertThat(zenRuleOn.isAutomaticActive()).isTrue(); assertThat(zenRuleOn.getConditionOverride()).isEqualTo(OVERRIDE_NONE); Loading Loading
services/core/java/com/android/server/notification/ZenModeHelper.java +9 −6 Original line number Diff line number Diff line Loading @@ -961,14 +961,17 @@ public class ZenModeHelper { if (origin == ORIGIN_USER_IN_SYSTEMUI && condition != null && condition.source == SOURCE_USER_ACTION) { // Apply as override, instead of actual condition. // If the new override is the reverse of a previous (still active) override, try // removing the previous override, as long as the resulting state, based on the // previous owner-provided condition, is the desired one (active or inactive). // This allows the rule owner to resume controlling the rule after // snoozing-unsnoozing or activating-stopping. if (condition.state == STATE_TRUE) { // Manually turn on a rule -> Apply override. rule.resetConditionOverride(); if (!rule.isAutomaticActive()) { rule.setConditionOverride(OVERRIDE_ACTIVATE); } } else if (condition.state == STATE_FALSE) { // Manually turn off a rule. If the rule was manually activated before, reset // override -- but only if this will not result in the rule turning on // immediately because of a previously snoozed condition! In that case, apply // deactivate-override. rule.resetConditionOverride(); if (rule.isAutomaticActive()) { rule.setConditionOverride(OVERRIDE_DEACTIVATE); Loading
services/tests/uiservicestests/src/com/android/server/notification/ZenModeHelperTest.java +55 −2 Original line number Diff line number Diff line Loading @@ -4972,7 +4972,7 @@ public class ZenModeHelperTest extends UiServiceTestCase { mZenModeHelper.setAutomaticZenRuleState(createdId, new Condition(zenRule.getConditionId(), "", STATE_FALSE), ORIGIN_APP, SYSTEM_UID); ORIGIN_APP, CUSTOM_PKG_UID); assertTrue(latch.await(500, TimeUnit.MILLISECONDS)); if (CompatChanges.isChangeEnabled(ZenModeHelper.SEND_ACTIVATION_AZR_STATUSES)) { Loading Loading @@ -6491,6 +6491,8 @@ public class ZenModeHelperTest extends UiServiceTestCase { .build(); String ruleId = mZenModeHelper.addAutomaticZenRule(mPkg, rule, ORIGIN_APP, "adding", CUSTOM_PKG_UID); Condition autoOn = new Condition(rule.getConditionId(), "auto-on", STATE_TRUE, SOURCE_CONTEXT); ZenRule zenRule; mZenModeHelper.setAutomaticZenRuleState(ruleId, Loading @@ -6508,6 +6510,57 @@ public class ZenModeHelperTest extends UiServiceTestCase { assertThat(zenRule.isAutomaticActive()).isFalse(); assertThat(zenRule.getConditionOverride()).isEqualTo(OVERRIDE_NONE); assertThat(zenRule.condition).isNull(); // Bonus check: app has resumed control over the rule and can now turn it on. mZenModeHelper.setAutomaticZenRuleState(ruleId, autoOn, ORIGIN_APP, CUSTOM_PKG_UID); zenRule = mZenModeHelper.mConfig.automaticRules.get(ruleId); assertThat(zenRule.isAutomaticActive()).isTrue(); assertThat(zenRule.getConditionOverride()).isEqualTo(OVERRIDE_NONE); assertThat(zenRule.condition).isEqualTo(autoOn); } @Test @EnableFlags({FLAG_MODES_API, FLAG_MODES_UI}) public void setAutomaticZenRuleState_manualDeactivationAndThenReactivation_removesOverride() { AutomaticZenRule rule = new AutomaticZenRule.Builder("Rule", Uri.parse("cond")) .setPackage(mPkg) .build(); String ruleId = mZenModeHelper.addAutomaticZenRule(mPkg, rule, ORIGIN_APP, "adding", CUSTOM_PKG_UID); Condition autoOn = new Condition(rule.getConditionId(), "auto-on", STATE_TRUE, SOURCE_CONTEXT); Condition autoOff = new Condition(rule.getConditionId(), "auto-off", STATE_FALSE, SOURCE_CONTEXT); ZenRule zenRule; mZenModeHelper.setAutomaticZenRuleState(ruleId, autoOn, ORIGIN_APP, CUSTOM_PKG_UID); zenRule = mZenModeHelper.mConfig.automaticRules.get(ruleId); assertThat(zenRule.isAutomaticActive()).isTrue(); assertThat(zenRule.getConditionOverride()).isEqualTo(OVERRIDE_NONE); assertThat(zenRule.condition).isEqualTo(autoOn); mZenModeHelper.setAutomaticZenRuleState(ruleId, new Condition(rule.getConditionId(), "manual-off", STATE_FALSE, SOURCE_USER_ACTION), ORIGIN_USER_IN_SYSTEMUI, SYSTEM_UID); zenRule = mZenModeHelper.mConfig.automaticRules.get(ruleId); assertThat(zenRule.isAutomaticActive()).isFalse(); assertThat(zenRule.getConditionOverride()).isEqualTo(OVERRIDE_DEACTIVATE); assertThat(zenRule.condition).isEqualTo(autoOn); mZenModeHelper.setAutomaticZenRuleState(ruleId, new Condition(rule.getConditionId(), "manual-on", STATE_TRUE, SOURCE_USER_ACTION), ORIGIN_USER_IN_SYSTEMUI, SYSTEM_UID); zenRule = mZenModeHelper.mConfig.automaticRules.get(ruleId); assertThat(zenRule.isAutomaticActive()).isTrue(); assertThat(zenRule.getConditionOverride()).isEqualTo(OVERRIDE_NONE); assertThat(zenRule.condition).isEqualTo(autoOn); // Bonus check: app has resumed control over the rule and can now turn it off. mZenModeHelper.setAutomaticZenRuleState(ruleId, autoOff, ORIGIN_APP, CUSTOM_PKG_UID); zenRule = mZenModeHelper.mConfig.automaticRules.get(ruleId); assertThat(zenRule.isAutomaticActive()).isFalse(); assertThat(zenRule.getConditionOverride()).isEqualTo(OVERRIDE_NONE); assertThat(zenRule.condition).isEqualTo(autoOff); } @Test Loading @@ -6521,7 +6574,7 @@ public class ZenModeHelperTest extends UiServiceTestCase { mZenModeHelper.setAutomaticZenRuleState(ruleId, new Condition(rule.getConditionId(), "auto-on", STATE_TRUE, SOURCE_CONTEXT), ORIGIN_APP, SYSTEM_UID); ORIGIN_APP, CUSTOM_PKG_UID); ZenRule zenRuleOn = mZenModeHelper.mConfig.automaticRules.get(ruleId); assertThat(zenRuleOn.isAutomaticActive()).isTrue(); assertThat(zenRuleOn.getConditionOverride()).isEqualTo(OVERRIDE_NONE); Loading