diff options
author | 2024-09-30 15:13:00 +0000 | |
---|---|---|
committer | 2024-09-30 15:13:00 +0000 | |
commit | 3f77dcd6b0dfacad76a0b775b2169aabc26ac8bc (patch) | |
tree | a4165342a548a53e6ad5189679ef774841999af2 | |
parent | 54e01db25ccff89be69f02c72ff727061256bdfb (diff) | |
parent | 38de1a3f76c189866a259d932ceac77b90e62836 (diff) |
Merge "Fix reading of ZenModeConfig.manualRule in MODES_UI transition" into main
-rw-r--r-- | core/java/android/service/notification/ZenModeConfig.java | 9 | ||||
-rw-r--r-- | services/tests/uiservicestests/src/com/android/server/notification/ZenModeConfigTest.java | 35 |
2 files changed, 40 insertions, 4 deletions
diff --git a/core/java/android/service/notification/ZenModeConfig.java b/core/java/android/service/notification/ZenModeConfig.java index 303197dfd82d..e1732559e262 100644 --- a/core/java/android/service/notification/ZenModeConfig.java +++ b/core/java/android/service/notification/ZenModeConfig.java @@ -1079,9 +1079,12 @@ public class ZenModeConfig implements Parcelable { // in ensureManualZenRule() and setManualZenMode(). rt.manualRule.pkg = PACKAGE_ANDROID; rt.manualRule.type = AutomaticZenRule.TYPE_OTHER; - rt.manualRule.condition = new Condition( - rt.manualRule.conditionId != null ? rt.manualRule.conditionId - : Uri.EMPTY, "", Condition.STATE_TRUE); + // conditionId in rule must match condition.id to pass isValidManualRule(). + if (rt.manualRule.conditionId == null) { + rt.manualRule.conditionId = Uri.EMPTY; + } + rt.manualRule.condition = new Condition(rt.manualRule.conditionId, "", + Condition.STATE_TRUE); } } return rt; diff --git a/services/tests/uiservicestests/src/com/android/server/notification/ZenModeConfigTest.java b/services/tests/uiservicestests/src/com/android/server/notification/ZenModeConfigTest.java index 84c4f620f394..5709d884d427 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/ZenModeConfigTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/ZenModeConfigTest.java @@ -1010,7 +1010,39 @@ public class ZenModeConfigTest extends UiServiceTestCase { @Test @EnableFlags(Flags.FLAG_MODES_UI) - public void testConfigXml_manualRule_upgradeWhenExisting() throws Exception { + public void testConfigXml_manualRuleWithoutCondition_upgradeWhenExisting() throws Exception { + // prior to modes_ui, it's possible to have a non-null manual rule that doesn't have much + // data on it because it's meant to indicate that the manual rule is on by merely existing. + ZenModeConfig config = new ZenModeConfig(); + config.manualRule = new ZenModeConfig.ZenRule(); + config.manualRule.enabled = true; + config.manualRule.pkg = "android"; + config.manualRule.zenMode = ZEN_MODE_IMPORTANT_INTERRUPTIONS; + config.manualRule.conditionId = null; + config.manualRule.enabler = "test"; + + // write out entire config xml + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + writeConfigXml(config, XML_VERSION_MODES_API, /* forBackup= */ false, baos); + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + ZenModeConfig fromXml = readConfigXml(bais); + + + // The result should be valid and contain a manual rule; the rule should have a non-null + // ZenPolicy and a condition whose state is true. The conditionId should be default. + assertThat(fromXml.isValid()).isTrue(); + assertThat(fromXml.manualRule).isNotNull(); + assertThat(fromXml.manualRule.zenPolicy).isNotNull(); + assertThat(fromXml.manualRule.condition).isNotNull(); + assertThat(fromXml.manualRule.condition.state).isEqualTo(STATE_TRUE); + assertThat(fromXml.manualRule.conditionId).isEqualTo(Uri.EMPTY); + assertThat(fromXml.manualRule.enabler).isEqualTo("test"); + assertThat(fromXml.isManualActive()).isTrue(); + } + + @Test + @EnableFlags(Flags.FLAG_MODES_UI) + public void testConfigXml_manualRuleWithCondition_upgradeWhenExisting() throws Exception { // prior to modes_ui, it's possible to have a non-null manual rule that doesn't have much // data on it because it's meant to indicate that the manual rule is on by merely existing. ZenModeConfig config = new ZenModeConfig(); @@ -1029,6 +1061,7 @@ public class ZenModeConfigTest extends UiServiceTestCase { // The result should have a manual rule; it should have a non-null ZenPolicy and a condition // whose state is true. The conditionId and enabler data should also be preserved. + assertThat(fromXml.isValid()).isTrue(); assertThat(fromXml.manualRule).isNotNull(); assertThat(fromXml.manualRule.zenPolicy).isNotNull(); assertThat(fromXml.manualRule.condition).isNotNull(); |