diff options
| -rw-r--r-- | core/java/android/service/notification/ZenModeConfig.java | 29 | ||||
| -rw-r--r-- | services/tests/uiservicestests/src/com/android/server/notification/ZenModeConfigTest.java | 13 |
2 files changed, 24 insertions, 18 deletions
diff --git a/core/java/android/service/notification/ZenModeConfig.java b/core/java/android/service/notification/ZenModeConfig.java index 918e591069fb..ba647864a4f1 100644 --- a/core/java/android/service/notification/ZenModeConfig.java +++ b/core/java/android/service/notification/ZenModeConfig.java @@ -1044,23 +1044,19 @@ public class ZenModeConfig implements Parcelable { rt.suppressedVisualEffects = safeInt(parser, DISALLOW_ATT_VISUAL_EFFECTS, DEFAULT_SUPPRESSED_VISUAL_EFFECTS); } else if (MANUAL_TAG.equals(tag)) { - ZenRule manualRule = readRuleXml(parser); - if (manualRule != null) { - rt.manualRule = manualRule; - - // Manual rule may be present prior to modes_ui if it were on, but in that - // case it would not have a set policy, so make note of the need to set - // it up later. - readManualRule = true; - if (rt.manualRule.zenPolicy == null) { - readManualRuleWithoutPolicy = true; - } + rt.manualRule = readRuleXml(parser); + // Manual rule may be present prior to modes_ui if it were on, but in that + // case it would not have a set policy, so make note of the need to set + // it up later. + readManualRule = true; + if (rt.manualRule.zenPolicy == null) { + readManualRuleWithoutPolicy = true; } } else if (AUTOMATIC_TAG.equals(tag) || (Flags.modesApi() && AUTOMATIC_DELETED_TAG.equals(tag))) { final String id = parser.getAttributeValue(null, RULE_ATT_ID); - final ZenRule automaticRule = readRuleXml(parser); - if (id != null && automaticRule != null) { + if (id != null) { + final ZenRule automaticRule = readRuleXml(parser); automaticRule.id = id; if (Flags.modesApi() && AUTOMATIC_DELETED_TAG.equals(tag)) { String deletedRuleKey = deletedRuleKey(automaticRule); @@ -1177,16 +1173,13 @@ public class ZenModeConfig implements Parcelable { out.endTag(null, ZEN_TAG); } + @NonNull public static ZenRule readRuleXml(TypedXmlPullParser parser) { final ZenRule rt = new ZenRule(); rt.enabled = safeBoolean(parser, RULE_ATT_ENABLED, true); rt.name = parser.getAttributeValue(null, RULE_ATT_NAME); final String zen = parser.getAttributeValue(null, RULE_ATT_ZEN); - rt.zenMode = tryParseZenMode(zen, -1); - if (rt.zenMode == -1) { - Slog.w(TAG, "Bad zen mode in rule xml:" + zen); - return null; - } + rt.zenMode = tryParseZenMode(zen, ZEN_MODE_IMPORTANT_INTERRUPTIONS); rt.conditionId = safeUri(parser, RULE_ATT_CONDITION_ID); rt.component = safeComponentName(parser, RULE_ATT_COMPONENT); rt.configurationActivity = safeComponentName(parser, RULE_ATT_CONFIG_ACTIVITY); 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 e70ed5f256bf..f8ff1f45e89c 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/ZenModeConfigTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/ZenModeConfigTest.java @@ -788,6 +788,19 @@ public class ZenModeConfigTest extends UiServiceTestCase { } @Test + public void testRuleXml_invalidInterruptionFilter_readsDefault() throws Exception { + ZenModeConfig.ZenRule rule = new ZenModeConfig.ZenRule(); + rule.zenMode = 1979; + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + writeRuleXml(rule, baos); + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + ZenModeConfig.ZenRule fromXml = readRuleXml(bais); + + assertThat(fromXml.zenMode).isEqualTo(ZEN_MODE_IMPORTANT_INTERRUPTIONS); + } + + @Test public void testZenPolicyXml_allUnset() throws Exception { ZenPolicy policy = new ZenPolicy.Builder().build(); |