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

Commit ed7ef7ad authored by Garvit Narang's avatar Garvit Narang Committed by Android (Google) Code Review
Browse files

Merge "Don't reset AZR condition when user updates a rule for watch" into main

parents 04606353 0bea26e4
Loading
Loading
Loading
Loading
+12 −5
Original line number Diff line number Diff line
@@ -1159,10 +1159,17 @@ public class ZenModeHelper {
                rule.conditionId = azr.getConditionId();
                modified = true;
            }
            boolean shouldPreserveCondition = Flags.modesApi() && Flags.modesUi()
                    && !isNew && origin == UPDATE_ORIGIN_USER
            // This can be removed when {@link Flags#modesUi} is fully ramped up
            final boolean isWatch =
                    mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH);
            boolean shouldPreserveCondition =
                    Flags.modesApi()
                            && (Flags.modesUi() || isWatch)
                            && !isNew
                            && origin == UPDATE_ORIGIN_USER
                            && rule.enabled == azr.isEnabled()
                    && rule.conditionId != null && rule.condition != null
                            && rule.conditionId != null
                            && rule.condition != null
                            && rule.conditionId.equals(rule.condition.id);
            if (!shouldPreserveCondition) {
                // Do not update 'modified'. If only this changes we treat it as a no-op updateAZR.
+31 −3
Original line number Diff line number Diff line
@@ -186,6 +186,9 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.xmlpull.v1.XmlPullParserException;

import platform.test.runner.parameterized.ParameterizedAndroidJunit4;
import platform.test.runner.parameterized.Parameters;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
@@ -205,9 +208,6 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import platform.test.runner.parameterized.ParameterizedAndroidJunit4;
import platform.test.runner.parameterized.Parameters;

@SmallTest
@SuppressLint("GuardedBy") // It's ok for this test to access guarded methods from the service.
@RunWith(ParameterizedAndroidJunit4.class)
@@ -5021,6 +5021,34 @@ public class ZenModeHelperTest extends UiServiceTestCase {
                CONDITION_TRUE);
    }

    @Test
    @EnableFlags(FLAG_MODES_API)
    public void updateAutomaticZenRule_ruleChangedByUser_doesNotDeactivateRule_forWatch() {
        when(mContext.getPackageManager()).thenReturn(mPackageManager);
        when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_WATCH)).thenReturn(true);
        assertThat(mZenModeHelper.getZenMode()).isEqualTo(ZEN_MODE_OFF);
        AutomaticZenRule rule =
                new AutomaticZenRule.Builder("rule", CONDITION_ID)
                        .setConfigurationActivity(new ComponentName(mPkg, "cls"))
                        .setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
                        .build();
        String ruleId =
                mZenModeHelper.addAutomaticZenRule(
                        mPkg, rule, UPDATE_ORIGIN_APP, "reason", CUSTOM_PKG_UID);
        mZenModeHelper.setAutomaticZenRuleState(
                ruleId, CONDITION_TRUE, UPDATE_ORIGIN_APP, CUSTOM_PKG_UID);
        assertThat(mZenModeHelper.getZenMode()).isEqualTo(ZEN_MODE_IMPORTANT_INTERRUPTIONS);

        AutomaticZenRule updateWithDiff =
                new AutomaticZenRule.Builder(rule).setTriggerDescription("Whenever").build();
        mZenModeHelper.updateAutomaticZenRule(ruleId, updateWithDiff, UPDATE_ORIGIN_USER, "reason",
                CUSTOM_PKG_UID);

        assertThat(mZenModeHelper.getZenMode()).isEqualTo(ZEN_MODE_IMPORTANT_INTERRUPTIONS);
        assertThat(mZenModeHelper.mConfig.automaticRules.get(ruleId).condition).isEqualTo(
                CONDITION_TRUE);
    }

    @Test
    @EnableFlags({FLAG_MODES_API, FLAG_MODES_UI})
    public void updateAutomaticZenRule_ruleDisabledByUser_doesNotReactivateOnReenable() {