Loading services/core/java/com/android/server/notification/ZenModeHelper.java +7 −3 Original line number Diff line number Diff line Loading @@ -1493,11 +1493,15 @@ public class ZenModeHelper { newConfig = mConfig.copy(); if (zenMode == Global.ZEN_MODE_OFF) { newConfig.manualRule = null; if (!Flags.modesUi() || origin != UPDATE_ORIGIN_USER) { // User deactivation of DND means just turning off the manual DND rule. // For API calls (different origin) keep old behavior of snoozing all rules. for (ZenRule automaticRule : newConfig.automaticRules.values()) { if (automaticRule.isAutomaticActive()) { automaticRule.snoozing = true; } } } } else { final ZenRule newRule = new ZenRule(); newRule.enabled = true; Loading services/tests/uiservicestests/src/com/android/server/notification/ZenModeHelperTest.java +87 −0 Original line number Diff line number Diff line Loading @@ -322,6 +322,27 @@ public class ZenModeHelperTest extends UiServiceTestCase { mZenModeEventLogger.reset(); } private enum ChangeOrigin { ORIGIN_UNKNOWN(ZenModeConfig.UPDATE_ORIGIN_UNKNOWN), ORIGIN_INIT(ZenModeConfig.UPDATE_ORIGIN_INIT), ORIGIN_INIT_USER(ZenModeConfig.UPDATE_ORIGIN_INIT_USER), ORIGIN_USER(ZenModeConfig.UPDATE_ORIGIN_USER), ORIGIN_APP(ZenModeConfig.UPDATE_ORIGIN_APP), ORIGIN_SYSTEM_OR_SYSTEMUI(ZenModeConfig.UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI), ORIGIN_RESTORE_BACKUP(ZenModeConfig.UPDATE_ORIGIN_RESTORE_BACKUP); private final int mValue; ChangeOrigin(@ZenModeConfig.ConfigChangeOrigin int value) { mValue = value; } @ZenModeConfig.ConfigChangeOrigin public int value() { return mValue; } } private XmlResourceParser getDefaultConfigParser() throws IOException, XmlPullParserException { String xml = "<zen version=\"10\">\n" + "<allow alarms=\"true\" media=\"true\" system=\"false\" calls=\"true\" " Loading Loading @@ -2897,6 +2918,72 @@ public class ZenModeHelperTest extends UiServiceTestCase { assertEquals(Global.ZEN_MODE_OFF, mZenModeHelper.mZenMode); } @Test @EnableFlags(Flags.FLAG_MODES_API) @DisableFlags(Flags.FLAG_MODES_UI) public void setManualZenMode_off_snoozesActiveRules(@TestParameter ChangeOrigin setZenOrigin) { // Start with an active rule and an inactive rule. mZenModeHelper.mConfig.automaticRules.clear(); AutomaticZenRule activeRule = new AutomaticZenRule.Builder("Test", CONDITION_ID) .setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY) .build(); String activeRuleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), activeRule, UPDATE_ORIGIN_APP, "add it", CUSTOM_PKG_UID); mZenModeHelper.setAutomaticZenRuleState(activeRuleId, CONDITION_TRUE, UPDATE_ORIGIN_APP, CUSTOM_PKG_UID); AutomaticZenRule inactiveRule = new AutomaticZenRule.Builder("Test", CONDITION_ID) .setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY) .build(); String inactiveRuleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), inactiveRule, UPDATE_ORIGIN_APP, "add it", CUSTOM_PKG_UID); assertThat(mZenModeHelper.getZenMode()).isEqualTo(ZEN_MODE_IMPORTANT_INTERRUPTIONS); // User turns DND off. mZenModeHelper.setManualZenMode(ZEN_MODE_OFF, null, setZenOrigin.value(), "snoozing", "systemui", Process.SYSTEM_UID); assertThat(mZenModeHelper.getZenMode()).isEqualTo(ZEN_MODE_OFF); assertThat(mZenModeHelper.mConfig.automaticRules.get(activeRuleId).snoozing).isTrue(); assertThat(mZenModeHelper.mConfig.automaticRules.get(inactiveRuleId).snoozing).isFalse(); } @Test @EnableFlags({Flags.FLAG_MODES_API, Flags.FLAG_MODES_UI}) public void setManualZenMode_off_doesNotSnoozeRulesIfFromUser( @TestParameter ChangeOrigin setZenOrigin) { // Start with an active rule and an inactive rule mZenModeHelper.mConfig.automaticRules.clear(); AutomaticZenRule activeRule = new AutomaticZenRule.Builder("Test", CONDITION_ID) .setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY) .build(); String activeRuleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), activeRule, UPDATE_ORIGIN_APP, "add it", CUSTOM_PKG_UID); mZenModeHelper.setAutomaticZenRuleState(activeRuleId, CONDITION_TRUE, UPDATE_ORIGIN_APP, CUSTOM_PKG_UID); AutomaticZenRule inactiveRule = new AutomaticZenRule.Builder("Test", CONDITION_ID) .setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY) .build(); String inactiveRuleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), inactiveRule, UPDATE_ORIGIN_APP, "add it", CUSTOM_PKG_UID); assertThat(mZenModeHelper.getZenMode()).isEqualTo(ZEN_MODE_IMPORTANT_INTERRUPTIONS); // User turns DND off. mZenModeHelper.setManualZenMode(ZEN_MODE_OFF, null, setZenOrigin.value(), "snoozing", "systemui", Process.SYSTEM_UID); ZenModeConfig config = mZenModeHelper.mConfig; if (setZenOrigin == ChangeOrigin.ORIGIN_USER) { // Other rule was unaffected. assertThat(mZenModeHelper.getZenMode()).isEqualTo(ZEN_MODE_IMPORTANT_INTERRUPTIONS); assertThat(config.automaticRules.get(activeRuleId).snoozing).isFalse(); assertThat(config.automaticRules.get(inactiveRuleId).snoozing).isFalse(); } else { assertThat(mZenModeHelper.getZenMode()).isEqualTo(ZEN_MODE_OFF); assertThat(config.automaticRules.get(activeRuleId).snoozing).isTrue(); assertThat(config.automaticRules.get(inactiveRuleId).snoozing).isFalse(); } } @Test public void testSetManualZenMode_legacy() { setupZenConfig(); Loading Loading
services/core/java/com/android/server/notification/ZenModeHelper.java +7 −3 Original line number Diff line number Diff line Loading @@ -1493,11 +1493,15 @@ public class ZenModeHelper { newConfig = mConfig.copy(); if (zenMode == Global.ZEN_MODE_OFF) { newConfig.manualRule = null; if (!Flags.modesUi() || origin != UPDATE_ORIGIN_USER) { // User deactivation of DND means just turning off the manual DND rule. // For API calls (different origin) keep old behavior of snoozing all rules. for (ZenRule automaticRule : newConfig.automaticRules.values()) { if (automaticRule.isAutomaticActive()) { automaticRule.snoozing = true; } } } } else { final ZenRule newRule = new ZenRule(); newRule.enabled = true; Loading
services/tests/uiservicestests/src/com/android/server/notification/ZenModeHelperTest.java +87 −0 Original line number Diff line number Diff line Loading @@ -322,6 +322,27 @@ public class ZenModeHelperTest extends UiServiceTestCase { mZenModeEventLogger.reset(); } private enum ChangeOrigin { ORIGIN_UNKNOWN(ZenModeConfig.UPDATE_ORIGIN_UNKNOWN), ORIGIN_INIT(ZenModeConfig.UPDATE_ORIGIN_INIT), ORIGIN_INIT_USER(ZenModeConfig.UPDATE_ORIGIN_INIT_USER), ORIGIN_USER(ZenModeConfig.UPDATE_ORIGIN_USER), ORIGIN_APP(ZenModeConfig.UPDATE_ORIGIN_APP), ORIGIN_SYSTEM_OR_SYSTEMUI(ZenModeConfig.UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI), ORIGIN_RESTORE_BACKUP(ZenModeConfig.UPDATE_ORIGIN_RESTORE_BACKUP); private final int mValue; ChangeOrigin(@ZenModeConfig.ConfigChangeOrigin int value) { mValue = value; } @ZenModeConfig.ConfigChangeOrigin public int value() { return mValue; } } private XmlResourceParser getDefaultConfigParser() throws IOException, XmlPullParserException { String xml = "<zen version=\"10\">\n" + "<allow alarms=\"true\" media=\"true\" system=\"false\" calls=\"true\" " Loading Loading @@ -2897,6 +2918,72 @@ public class ZenModeHelperTest extends UiServiceTestCase { assertEquals(Global.ZEN_MODE_OFF, mZenModeHelper.mZenMode); } @Test @EnableFlags(Flags.FLAG_MODES_API) @DisableFlags(Flags.FLAG_MODES_UI) public void setManualZenMode_off_snoozesActiveRules(@TestParameter ChangeOrigin setZenOrigin) { // Start with an active rule and an inactive rule. mZenModeHelper.mConfig.automaticRules.clear(); AutomaticZenRule activeRule = new AutomaticZenRule.Builder("Test", CONDITION_ID) .setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY) .build(); String activeRuleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), activeRule, UPDATE_ORIGIN_APP, "add it", CUSTOM_PKG_UID); mZenModeHelper.setAutomaticZenRuleState(activeRuleId, CONDITION_TRUE, UPDATE_ORIGIN_APP, CUSTOM_PKG_UID); AutomaticZenRule inactiveRule = new AutomaticZenRule.Builder("Test", CONDITION_ID) .setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY) .build(); String inactiveRuleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), inactiveRule, UPDATE_ORIGIN_APP, "add it", CUSTOM_PKG_UID); assertThat(mZenModeHelper.getZenMode()).isEqualTo(ZEN_MODE_IMPORTANT_INTERRUPTIONS); // User turns DND off. mZenModeHelper.setManualZenMode(ZEN_MODE_OFF, null, setZenOrigin.value(), "snoozing", "systemui", Process.SYSTEM_UID); assertThat(mZenModeHelper.getZenMode()).isEqualTo(ZEN_MODE_OFF); assertThat(mZenModeHelper.mConfig.automaticRules.get(activeRuleId).snoozing).isTrue(); assertThat(mZenModeHelper.mConfig.automaticRules.get(inactiveRuleId).snoozing).isFalse(); } @Test @EnableFlags({Flags.FLAG_MODES_API, Flags.FLAG_MODES_UI}) public void setManualZenMode_off_doesNotSnoozeRulesIfFromUser( @TestParameter ChangeOrigin setZenOrigin) { // Start with an active rule and an inactive rule mZenModeHelper.mConfig.automaticRules.clear(); AutomaticZenRule activeRule = new AutomaticZenRule.Builder("Test", CONDITION_ID) .setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY) .build(); String activeRuleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), activeRule, UPDATE_ORIGIN_APP, "add it", CUSTOM_PKG_UID); mZenModeHelper.setAutomaticZenRuleState(activeRuleId, CONDITION_TRUE, UPDATE_ORIGIN_APP, CUSTOM_PKG_UID); AutomaticZenRule inactiveRule = new AutomaticZenRule.Builder("Test", CONDITION_ID) .setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY) .build(); String inactiveRuleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), inactiveRule, UPDATE_ORIGIN_APP, "add it", CUSTOM_PKG_UID); assertThat(mZenModeHelper.getZenMode()).isEqualTo(ZEN_MODE_IMPORTANT_INTERRUPTIONS); // User turns DND off. mZenModeHelper.setManualZenMode(ZEN_MODE_OFF, null, setZenOrigin.value(), "snoozing", "systemui", Process.SYSTEM_UID); ZenModeConfig config = mZenModeHelper.mConfig; if (setZenOrigin == ChangeOrigin.ORIGIN_USER) { // Other rule was unaffected. assertThat(mZenModeHelper.getZenMode()).isEqualTo(ZEN_MODE_IMPORTANT_INTERRUPTIONS); assertThat(config.automaticRules.get(activeRuleId).snoozing).isFalse(); assertThat(config.automaticRules.get(inactiveRuleId).snoozing).isFalse(); } else { assertThat(mZenModeHelper.getZenMode()).isEqualTo(ZEN_MODE_OFF); assertThat(config.automaticRules.get(activeRuleId).snoozing).isTrue(); assertThat(config.automaticRules.get(inactiveRuleId).snoozing).isFalse(); } } @Test public void testSetManualZenMode_legacy() { setupZenConfig(); Loading