Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ca169170 authored by Matías Hernández's avatar Matías Hernández
Browse files

Don't fail to deserialize a ZenRule if it has an invalid filter value

This was the only case where readRuleXml() returned null. Making it NonNull simplifies callers (and removes a possible exception when the manual rule is involved).

Fixes: 357902620
Test: atest ZenModeConfigTest ZenModeHelperTest
Flag: EXEMPT trivial fix
Change-Id: Ibe1884e6b286d32f845de143ef526ac3ec38fa8f
parent ee215211
Loading
Loading
Loading
Loading
+11 −18
Original line number Diff line number Diff line
@@ -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.
@@ -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);
@@ -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);
+13 −0
Original line number Diff line number Diff line
@@ -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();