Loading core/java/android/service/notification/ZenModeConfig.java +11 −18 Original line number Diff line number Diff line Loading @@ -1044,10 +1044,7 @@ 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; 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. Loading @@ -1055,12 +1052,11 @@ public class ZenModeConfig implements Parcelable { 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); if (id != null) { final ZenRule automaticRule = readRuleXml(parser); if (id != null && automaticRule != null) { automaticRule.id = id; if (Flags.modesApi() && AUTOMATIC_DELETED_TAG.equals(tag)) { String deletedRuleKey = deletedRuleKey(automaticRule); Loading Loading @@ -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); Loading services/tests/uiservicestests/src/com/android/server/notification/ZenModeConfigTest.java +13 −0 Original line number Diff line number Diff line Loading @@ -787,6 +787,19 @@ public class ZenModeConfigTest extends UiServiceTestCase { assertEquals(rule.zenMode, fromXml.zenMode); } @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(); Loading Loading
core/java/android/service/notification/ZenModeConfig.java +11 −18 Original line number Diff line number Diff line Loading @@ -1044,10 +1044,7 @@ 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; 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. Loading @@ -1055,12 +1052,11 @@ public class ZenModeConfig implements Parcelable { 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); if (id != null) { final ZenRule automaticRule = readRuleXml(parser); if (id != null && automaticRule != null) { automaticRule.id = id; if (Flags.modesApi() && AUTOMATIC_DELETED_TAG.equals(tag)) { String deletedRuleKey = deletedRuleKey(automaticRule); Loading Loading @@ -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); Loading
services/tests/uiservicestests/src/com/android/server/notification/ZenModeConfigTest.java +13 −0 Original line number Diff line number Diff line Loading @@ -787,6 +787,19 @@ public class ZenModeConfigTest extends UiServiceTestCase { assertEquals(rule.zenMode, fromXml.zenMode); } @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(); Loading