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

Commit d4094185 authored by Matías Hernández's avatar Matías Hernández Committed by Android (Google) Code Review
Browse files

Merge "Never disable the manual rule (and fix it on read if it was disabled)" into main

parents bec6352c 86af2cbb
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -1046,6 +1046,8 @@ public class ZenModeConfig implements Parcelable {
                            DEFAULT_SUPPRESSED_VISUAL_EFFECTS);
                } else if (MANUAL_TAG.equals(tag)) {
                    rt.manualRule = readRuleXml(parser);
                    // manualRule.enabled can never be false, but it was broken in some builds.
                    rt.manualRule.enabled = true;
                    // 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.
+1 −1
Original line number Diff line number Diff line
@@ -157,7 +157,7 @@ public class ZenModeConditions implements ConditionProviders.Callback {
        }
        // empty rule? disable and bail early
        if (rule.component == null && rule.enabler == null) {
            if (!android.app.Flags.modesUi() || (android.app.Flags.modesUi() && !isManual)) {
            if (!isManual) {
                Log.w(TAG, "No component found for automatic rule: " + rule.conditionId);
                rule.enabled = false;
            }
+18 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import static android.service.notification.Condition.STATE_FALSE;
import static android.service.notification.Condition.STATE_TRUE;
import static android.service.notification.NotificationListenerService.SUPPRESSED_EFFECT_SCREEN_ON;
import static android.service.notification.ZenModeConfig.XML_VERSION_MODES_API;
import static android.service.notification.ZenModeConfig.XML_VERSION_MODES_UI;
import static android.service.notification.ZenModeConfig.ZEN_TAG;
import static android.service.notification.ZenModeConfig.ZenRule.OVERRIDE_DEACTIVATE;
import static android.service.notification.ZenModeConfig.ZenRule.OVERRIDE_NONE;
@@ -1169,6 +1170,23 @@ public class ZenModeConfigTest extends UiServiceTestCase {
        assertThat(suppressedEffectsOf(result)).isEqualTo(suppressedEffectsOf(policy));
    }

    @Test
    public void readXml_fixesWronglyDisabledManualRule() throws Exception {
        ZenModeConfig config = getCustomConfig();
        if (!Flags.modesUi()) {
            config.manualRule = new ZenModeConfig.ZenRule();
            config.manualRule.zenMode = ZEN_MODE_IMPORTANT_INTERRUPTIONS;
        }
        config.manualRule.enabled = false;

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        writeConfigXml(config, XML_VERSION_MODES_UI, /* forBackup= */ false, baos);
        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
        ZenModeConfig fromXml = readConfigXml(bais);

        assertThat(fromXml.manualRule.enabled).isTrue();
    }

    private static String suppressedEffectsOf(Policy policy) {
        return suppressedEffectsToString(policy.suppressedVisualEffects) + "("
                + policy.suppressedVisualEffects + ")";