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

Commit 3f77dcd6 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix reading of ZenModeConfig.manualRule in MODES_UI transition" into main

parents 54e01db2 38de1a3f
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -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;
+34 −1
Original line number Diff line number Diff line
@@ -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();