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

Commit 2078cfd9 authored by Matías Hernández's avatar Matías Hernández
Browse files

Only consider Settings/SystemUI for tracking last manual activation

Although including calls with ORIGIN_USER from an app could be theoretically correct, it runs counter to the desired usage -- e.g. snoozing and then resuming Bedtime from its notification will cause that mode to become the "last manually activated".

Bug: 405988332
Test: atest ZenModeHelperTest
Flag: android.app.modes_ui_tile_reactivates_last
Change-Id: Ic2bd507d2e18a339b6261123d3327bb118c5b251
parent 088ae231
Loading
Loading
Loading
Loading
+6 −8
Original line number Diff line number Diff line
@@ -2658,10 +2658,9 @@ public class ZenModeConfig implements Parcelable {
        public Instant lastActivation;

        /**
         * Last time at which the rule was manually activated (whether as a user action in
         * Settings or SystemUI, or from the owner package with
         * {@link Condition#SOURCE_USER_ACTION}). If {@code null}, the rule has never been manually
         * activated since its creation.
         * Last time at which the rule was manually activated (as a user action in Settings or
         * SystemUI). If {@code null}, the rule has never been manually activated since its
         * creation.
         *
         * <p>Note that this was previously untracked, so it will also be {@code null} for rules
         * created before we started tracking and never activated since.
@@ -2680,10 +2679,9 @@ public class ZenModeConfig implements Parcelable {
        public Instant lastDeactivation;

        /**
         * Last time at which the rule was manually deactivated (whether as a user action in
         * Settings or SystemUI, or from the owner package with
         * {@link Condition#SOURCE_USER_ACTION}). If {@code null}, the rule has never been manually
         * deactivated since its creation.
         * Last time at which the rule was manually deactivated (as a user action in Settings or
         * SystemUI). If {@code null}, the rule has never been manually deactivated since its
         * creation.
         *
         * <p>Note that this was previously untracked, so it will also be {@code null} for rules
         * created before we started tracking and never deactivated since.
+1 −2
Original line number Diff line number Diff line
@@ -2115,8 +2115,7 @@ public class ZenModeHelper {

            // Update last activation for rules that are being activated.
            Instant now = mClock.instant();
            boolean isManualOrigin =
                    origin == ORIGIN_USER_IN_SYSTEMUI || origin == ORIGIN_USER_IN_APP;
            boolean isManualOrigin = origin == ORIGIN_USER_IN_SYSTEMUI;
            if (Flags.modesUi()
                    && (Flags.modesCleanupImplicit() || Flags.modesUiTileReactivatesLast())) {
                if (!mConfig.isManualActive() && config.isManualActive()) {
+0 −49
Original line number Diff line number Diff line
@@ -7453,55 +7453,6 @@ public class ZenModeHelperTest extends UiServiceTestCase {
        assertThat(getZenRule(ruleTwo).lastManualDeactivation).isNull();
    }

    @Test
    @EnableFlags({FLAG_MODES_UI, FLAG_MODES_CLEANUP_IMPLICIT, FLAG_MODES_UI_TILE_REACTIVATES_LAST})
    public void setAutomaticZenRuleState_manualFromApp_updatesLastManualActivation() {
        String rule = mZenModeHelper.addAutomaticZenRule(UserHandle.CURRENT, mPkg,
                new AutomaticZenRule.Builder("rule", CONDITION_ID)
                        .setConfigurationActivity(new ComponentName(mPkg, "cls"))
                        .setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
                        .build(),
                ORIGIN_APP, "reason", CUSTOM_PKG_UID);

        assertThat(getZenRule(rule).lastManualActivation).isNull();
        assertThat(getZenRule(rule).lastManualDeactivation).isNull();

        Instant manualOn = Instant.ofEpochMilli(100);
        mTestClock.setNow(manualOn);
        mZenModeHelper.setAutomaticZenRuleState(UserHandle.CURRENT, rule,
                new Condition(CONDITION_ID, "on", STATE_TRUE, SOURCE_USER_ACTION),
                ORIGIN_USER_IN_APP, CUSTOM_PKG_UID);

        assertThat(getZenRule(rule).lastManualActivation).isEqualTo(manualOn);
        assertThat(getZenRule(rule).lastManualDeactivation).isNull();

        Instant manualOff = Instant.ofEpochMilli(200);
        mTestClock.setNow(manualOff);
        mZenModeHelper.setAutomaticZenRuleState(UserHandle.CURRENT, rule,
                new Condition(CONDITION_ID, "off", STATE_FALSE, SOURCE_USER_ACTION),
                ORIGIN_USER_IN_APP, CUSTOM_PKG_UID);

        assertThat(getZenRule(rule).lastManualActivation).isEqualTo(manualOn);
        assertThat(getZenRule(rule).lastManualDeactivation).isEqualTo(manualOff);

        Instant autoOn = Instant.ofEpochMilli(300);
        mTestClock.setNow(autoOn);
        mZenModeHelper.setAutomaticZenRuleState(UserHandle.CURRENT, rule,
                new Condition(CONDITION_ID, "auto on", STATE_TRUE, SOURCE_CONTEXT),
                ORIGIN_APP, CUSTOM_PKG_UID);
        Instant autoOff = Instant.ofEpochMilli(400);
        mTestClock.setNow(autoOff);
        mZenModeHelper.setAutomaticZenRuleState(UserHandle.CURRENT, rule,
                new Condition(CONDITION_ID, "auto off", STATE_FALSE, SOURCE_CONTEXT),
                ORIGIN_APP, CUSTOM_PKG_UID);

        assertThat(getZenRule(rule).lastManualActivation).isEqualTo(manualOn);
        assertThat(getZenRule(rule).lastManualDeactivation).isEqualTo(manualOff);

        assertThat(getZenRule(rule).lastActivation).isEqualTo(autoOn);
        assertThat(getZenRule(rule).lastDeactivation).isEqualTo(autoOff);
    }

    @Test
    @EnableFlags({FLAG_MODES_UI, FLAG_MODES_CLEANUP_IMPLICIT, FLAG_MODES_UI_TILE_REACTIVATES_LAST})
    public void setManualZenMode_updatesLastActivation() {