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

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

Merge "Always make copies of objects from mDefaultConfig" into main

parents e116ca15 1cca7e88
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -1358,7 +1358,8 @@ public class ZenModeHelper {
            if (isNew) {
                // Newly created rule with no provided policy; fill in with the default.
                zenRule.zenPolicy =
                        Flags.modesUi() ? mDefaultConfig.getZenPolicy() : mConfig.getZenPolicy();
                        (Flags.modesUi() ? mDefaultConfig.getZenPolicy() : mConfig.getZenPolicy())
                                .copy();
                return true;
            }
            // Otherwise, a null policy means no policy changes, so we can stop here.
@@ -1773,7 +1774,7 @@ public class ZenModeHelper {
                // definition cannot have a rule with TYPE_BEDTIME (or any other type).
                config.automaticRules = new ArrayMap<>();
                for (ZenRule rule : mDefaultConfig.automaticRules.values()) {
                    config.automaticRules.put(rule.id, rule);
                    config.automaticRules.put(rule.id, rule.copy());
                }
                reason += ", reset to default rules";
            }
+16 −0
Original line number Diff line number Diff line
@@ -6992,6 +6992,22 @@ public class ZenModeHelperTest extends UiServiceTestCase {
        assertThat(zenRule.condition).isNotNull();
    }

    @Test
    @EnableFlags(FLAG_MODES_API)
    public void addAutomaticZenRule_withoutPolicy_getsItsOwnInstanceOfDefaultPolicy() {
        // Add a rule without policy -> uses default config
        AutomaticZenRule azr = new AutomaticZenRule.Builder("Rule", Uri.parse("cond"))
                .setPackage(mPkg)
                .build();
        String ruleId = mZenModeHelper.addAutomaticZenRule(mPkg, azr, ORIGIN_APP, "adding",
                CUSTOM_PKG_UID);

        ZenRule zenRule = checkNotNull(mZenModeHelper.mConfig.automaticRules.get(ruleId));

        assertThat(zenRule.zenPolicy).isEqualTo(mZenModeHelper.getDefaultZenPolicy());
        assertThat(zenRule.zenPolicy).isNotSameInstanceAs(mZenModeHelper.getDefaultZenPolicy());
    }

    private static void addZenRule(ZenModeConfig config, String id, String ownerPkg, int zenMode,
            @Nullable ZenPolicy zenPolicy) {
        ZenRule rule = new ZenRule();