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

Commit 3e45c4be authored by Yuri Lin's avatar Yuri Lin Committed by Android (Google) Code Review
Browse files

Merge "Fill in policies for default zen rules." into main

parents 24676604 0324a22a
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -210,6 +210,9 @@ public class ZenModeHelper {

        mDefaultConfig = readDefaultConfig(mContext.getResources());
        updateDefaultAutomaticRuleNames();
        if (Flags.modesApi()) {
            updateDefaultAutomaticRulePolicies();
        }
        mConfig = mDefaultConfig.copy();
        synchronized (mConfigsArrayLock) {
            mConfigs.put(UserHandle.USER_SYSTEM, mConfig);
@@ -1966,6 +1969,21 @@ public class ZenModeHelper {
        }
    }

    // Updates the policies in the default automatic rules (provided via default XML config) to
    // be fully filled in default values.
    private void updateDefaultAutomaticRulePolicies() {
        if (!Flags.modesApi()) {
            // Should be checked before calling, but just in case.
            return;
        }
        ZenPolicy defaultPolicy = mDefaultConfig.toZenPolicy();
        for (ZenRule rule : mDefaultConfig.automaticRules.values()) {
            if (ZenModeConfig.DEFAULT_RULE_IDS.contains(rule.id) && rule.zenPolicy == null) {
                rule.zenPolicy = defaultPolicy.copy();
            }
        }
    }

    @VisibleForTesting
    protected void applyRestrictions() {
        final boolean zenOn = mZenMode != Global.ZEN_MODE_OFF;
+19 −0
Original line number Diff line number Diff line
@@ -2122,6 +2122,25 @@ public class ZenModeHelperTest extends UiServiceTestCase {
        assertFalse(Objects.equals(defaultRuleName, ruleAfterUpdating.name)); // update name
    }

    @Test
    @EnableFlags(Flags.FLAG_MODES_API)
    public void testDefaultRulesFromConfig_modesApi_getPolicies() {
        // After mZenModeHelper was created, set some things in the policy so it's changed from
        // default.
        setupZenConfig();

        // Find default rules; check they have non-null policies; check that they match the default
        // and not whatever has been set up in setupZenConfig.
        ArrayMap<String, ZenModeConfig.ZenRule> rules = mZenModeHelper.mConfig.automaticRules;
        for (String defaultId : ZenModeConfig.DEFAULT_RULE_IDS) {
            assertThat(rules).containsKey(defaultId);
            ZenRule rule = rules.get(defaultId);
            assertThat(rule.zenPolicy).isNotNull();

            assertThat(rule.zenPolicy).isEqualTo(mZenModeHelper.getDefaultZenPolicy());
        }
    }

    @Test
    public void testAddAutomaticZenRule_beyondSystemLimit() {
        for (int i = 0; i < RULE_LIMIT_PER_PACKAGE; i++) {