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

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

Never disable the manual rule (and fix it on read if it was disabled)

ZenModeConditions could potentially do this if you flipped modes_ui from true to false.

This would manifest as the DND mode refusing to activate (from any surface) when modes_ui was flipped to true again.

Fixes: 366451998
Test: atest ZenModeConfigTest
Flag: EXEMPT Bugfix for modes_ui
Change-Id: I63f51568ae4d556c4536d5620fc70988af8a9570
parent c7c82ca0
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -1045,6 +1045,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 + ")";