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

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

Merge "Split ORIGIN_USER into "user from systemui" and "user from app"" into main

parents a2a899e5 6770f367
Loading
Loading
Loading
Loading
+1 −3
Original line number Original line Diff line number Diff line
@@ -16,8 +16,6 @@


package android.service.notification;
package android.service.notification;


import android.service.notification.ZenModeConfig.ConfigChangeOrigin;

/**
/**
 * Responsible for making any service calls needed to apply the set of {@link ZenDeviceEffects} that
 * Responsible for making any service calls needed to apply the set of {@link ZenDeviceEffects} that
 * make sense for the current platform.
 * make sense for the current platform.
@@ -43,5 +41,5 @@ public interface DeviceEffectsApplier {
     *               changing as a result of an explicit user action, then it makes sense to
     *               changing as a result of an explicit user action, then it makes sense to
     *               apply them immediately regardless.
     *               apply them immediately regardless.
     */
     */
    void apply(ZenDeviceEffects effects, @ConfigChangeOrigin int source);
    void apply(ZenDeviceEffects effects, @ZenModeConfig.ConfigOrigin int source);
}
}
+53 −37
Original line number Original line Diff line number Diff line
@@ -112,68 +112,83 @@ public class ZenModeConfig implements Parcelable {
    private static final String TAG = "ZenModeConfig";
    private static final String TAG = "ZenModeConfig";


    /**
    /**
     * The {@link ZenModeConfig} is being updated because of an unknown reason.
     * The {@link ZenModeConfig} is updated because of an unknown reason.
     */
     */
    public static final int UPDATE_ORIGIN_UNKNOWN = 0;
    public static final int ORIGIN_UNKNOWN = 0;


    /**
    /**
     * The {@link ZenModeConfig} is being updated because of system initialization (i.e. load from
     * The {@link ZenModeConfig} is updated because of system initialization (i.e. load from
     * storage, on device boot).
     * storage, on device boot).
     */
     */
    public static final int UPDATE_ORIGIN_INIT = 1;
    public static final int ORIGIN_INIT = 1;


    /** The {@link ZenModeConfig} is being updated (replaced) because of a user switch or unlock. */
    /** The {@link ZenModeConfig} is updated (replaced) because of a user switch or unlock. */
    public static final int UPDATE_ORIGIN_INIT_USER = 2;
    public static final int ORIGIN_INIT_USER = 2;


    /** The {@link ZenModeConfig} is being updated because of a user action, for example:
    /**
     * The {@link ZenModeConfig} is updated because of a <em>user action</em> performed from a
     * system surface, such as:
     * <ul>
     * <ul>
     *     <li>{@link NotificationManager#setAutomaticZenRuleState} with a
     *     <li>Adding, updating, or removing a rule from Settings.
     *     {@link Condition#source} equal to {@link Condition#SOURCE_USER_ACTION}.</li>
     *     <li>Activating or deactivating a rule through the System (e.g. from Settings/Modes).
     *     <li>Adding, updating, or removing a rule from Settings.</li>
     *     <li>Activating or deactivating a rule through SystemUi (e.g. with Quick Settings).
     *     <li>Directly activating or deactivating/snoozing a rule through some UI affordance (e.g.
     *     Quick Settings).</li>
     * </ul>
     * </ul>
     *
     * <p>This does <em>not</em> include user actions from apps ({@link #ORIGIN_USER_IN_APP} nor
     * non-user actions from the system ({@link #ORIGIN_SYSTEM}).
     */
     */
    public static final int UPDATE_ORIGIN_USER = 3;
    public static final int ORIGIN_USER_IN_SYSTEMUI = 3;


    /**
    /**
     * The {@link ZenModeConfig} is being "independently" updated by an app, and not as a result of
     * The {@link ZenModeConfig} is updated by an app, but (probably) not as a result of a user
     * a user's action inside that app (for example, activating an {@link AutomaticZenRule} based on
     * action (for example, activating an {@link AutomaticZenRule} based on a previously set
     * a previously set schedule).
     * schedule).
     *
     * <p>Note that {@code ORIGIN_APP} is the only option for all public APIs except
     * {@link NotificationManager#setAutomaticZenRuleState} -- apps cannot claim to be adding or
     * updating a rule on behalf of the user.
     */
     */
    public static final int UPDATE_ORIGIN_APP = 4;
    public static final int ORIGIN_APP = 4;


    /**
    /**
     * The {@link ZenModeConfig} is being updated by the System or SystemUI. Note that this only
     * The {@link ZenModeConfig} is updated by the System (or SystemUI). This only includes cases
     * includes cases where the call is coming from the System/SystemUI but the change is not due to
     * where the call is coming from the System/SystemUI but the change is not due to a user action
     * a user action (e.g. automatically activating a schedule-based rule). If the change is a
     * (e.g. automatically activating a schedule-based rule, or some service toggling Do Not
     * result of a user action (e.g. activating a rule by tapping on its QS tile) then
     * Disturb). See {@link #ORIGIN_USER_IN_SYSTEMUI}.
     * {@link #UPDATE_ORIGIN_USER} is used instead.
     */
     */
    public static final int UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI = 5;
    public static final int ORIGIN_SYSTEM = 5;


    /**
    /**
     * The {@link ZenModeConfig} is being updated (replaced) because the user's DND configuration
     * The {@link ZenModeConfig} is being updated (replaced) because the user's DND configuration
     * is being restored from a backup.
     * is being restored from a backup.
     */
     */
    public static final int UPDATE_ORIGIN_RESTORE_BACKUP = 6;
    public static final int ORIGIN_RESTORE_BACKUP = 6;


    @IntDef(prefix = { "UPDATE_ORIGIN_" }, value = {
    /**
            UPDATE_ORIGIN_UNKNOWN,
     * The {@link ZenModeConfig} is updated from an app, and the app reports it's the result
            UPDATE_ORIGIN_INIT,
     * of a user action (e.g. tapping a button in the Wellbeing App to start Bedtime Mode).
            UPDATE_ORIGIN_INIT_USER,
     * Corresponds to {@link NotificationManager#setAutomaticZenRuleState} with a
            UPDATE_ORIGIN_USER,
     * {@link Condition#source} equal to {@link Condition#SOURCE_USER_ACTION}.</li>
            UPDATE_ORIGIN_APP,
     */
            UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI,
    public static final int ORIGIN_USER_IN_APP = 7;
            UPDATE_ORIGIN_RESTORE_BACKUP

    @IntDef(prefix = { "ORIGIN_" }, value = {
            ORIGIN_UNKNOWN,
            ORIGIN_INIT,
            ORIGIN_INIT_USER,
            ORIGIN_USER_IN_SYSTEMUI,
            ORIGIN_APP,
            ORIGIN_SYSTEM,
            ORIGIN_RESTORE_BACKUP,
            ORIGIN_USER_IN_APP
    })
    })
    @Retention(RetentionPolicy.SOURCE)
    @Retention(RetentionPolicy.SOURCE)
    public @interface ConfigChangeOrigin {}
    public @interface ConfigOrigin {}


    public static final int SOURCE_ANYONE = Policy.PRIORITY_SENDERS_ANY;
    public static final int SOURCE_ANYONE = Policy.PRIORITY_SENDERS_ANY;
    public static final int SOURCE_CONTACT = Policy.PRIORITY_SENDERS_CONTACTS;
    public static final int SOURCE_CONTACT = Policy.PRIORITY_SENDERS_CONTACTS;
    public static final int SOURCE_STAR = Policy.PRIORITY_SENDERS_STARRED;
    public static final int SOURCE_STAR = Policy.PRIORITY_SENDERS_STARRED;
    public static final int MAX_SOURCE = SOURCE_STAR;
    private static final int MAX_SOURCE = SOURCE_STAR;
    private static final int DEFAULT_SOURCE = SOURCE_STAR;
    private static final int DEFAULT_SOURCE = SOURCE_STAR;
    private static final int DEFAULT_CALLS_SOURCE = SOURCE_STAR;
    private static final int DEFAULT_CALLS_SOURCE = SOURCE_STAR;


@@ -1174,7 +1189,7 @@ public class ZenModeConfig implements Parcelable {
            }
            }
            if (Flags.modesUi()) {
            if (Flags.modesUi()) {
                rt.disabledOrigin = safeInt(parser, RULE_ATT_DISABLED_ORIGIN,
                rt.disabledOrigin = safeInt(parser, RULE_ATT_DISABLED_ORIGIN,
                        UPDATE_ORIGIN_UNKNOWN);
                        ORIGIN_UNKNOWN);
                rt.legacySuppressedEffects = safeInt(parser,
                rt.legacySuppressedEffects = safeInt(parser,
                        RULE_ATT_LEGACY_SUPPRESSED_EFFECTS, 0);
                        RULE_ATT_LEGACY_SUPPRESSED_EFFECTS, 0);
            }
            }
@@ -2537,7 +2552,8 @@ public class ZenModeConfig implements Parcelable {
        @ZenDeviceEffects.ModifiableField public int zenDeviceEffectsUserModifiedFields;
        @ZenDeviceEffects.ModifiableField public int zenDeviceEffectsUserModifiedFields;
        @Nullable public Instant deletionInstant; // Only set on deleted rules.
        @Nullable public Instant deletionInstant; // Only set on deleted rules.
        @FlaggedApi(Flags.FLAG_MODES_UI)
        @FlaggedApi(Flags.FLAG_MODES_UI)
        @ConfigChangeOrigin public int disabledOrigin = UPDATE_ORIGIN_UNKNOWN;
        @ConfigOrigin
        public int disabledOrigin = ORIGIN_UNKNOWN;
        // The obsolete suppressed effects in NM.Policy (SCREEN_ON, SCREEN_OFF) cannot be put in a
        // The obsolete suppressed effects in NM.Policy (SCREEN_ON, SCREEN_OFF) cannot be put in a
        // ZenPolicy, so we store them here, only for the manual rule.
        // ZenPolicy, so we store them here, only for the manual rule.
        @FlaggedApi(Flags.FLAG_MODES_UI)
        @FlaggedApi(Flags.FLAG_MODES_UI)
+3 −3
Original line number Original line Diff line number Diff line
@@ -16,8 +16,8 @@


package com.android.settingslib.notification.modes;
package com.android.settingslib.notification.modes;


import static android.service.notification.ZenModeConfig.UPDATE_ORIGIN_UNKNOWN;
import static android.service.notification.ZenModeConfig.ORIGIN_UNKNOWN;
import static android.service.notification.ZenModeConfig.UPDATE_ORIGIN_USER;
import static android.service.notification.ZenModeConfig.ORIGIN_USER_IN_SYSTEMUI;


import android.app.AutomaticZenRule;
import android.app.AutomaticZenRule;
import android.app.NotificationManager;
import android.app.NotificationManager;
@@ -154,7 +154,7 @@ public class TestModeBuilder {
        mRule.setEnabled(enabled);
        mRule.setEnabled(enabled);
        mConfigZenRule.enabled = enabled;
        mConfigZenRule.enabled = enabled;
        if (!enabled) {
        if (!enabled) {
            mConfigZenRule.disabledOrigin = byUser ? UPDATE_ORIGIN_USER : UPDATE_ORIGIN_UNKNOWN;
            mConfigZenRule.disabledOrigin = byUser ? ORIGIN_USER_IN_SYSTEMUI : ORIGIN_UNKNOWN;
        }
        }
        return this;
        return this;
    }
    }
+2 −2
Original line number Original line Diff line number Diff line
@@ -66,7 +66,7 @@ public class ZenMode implements Parcelable {


    private static final String TAG = "ZenMode";
    private static final String TAG = "ZenMode";


    static final String MANUAL_DND_MODE_ID = "manual_dnd";
    static final String MANUAL_DND_MODE_ID = ZenModeConfig.MANUAL_RULE_ID;
    static final String TEMP_NEW_MODE_ID = "temp_new_mode";
    static final String TEMP_NEW_MODE_ID = "temp_new_mode";


    // Must match com.android.server.notification.ZenModeHelper#applyCustomPolicy.
    // Must match com.android.server.notification.ZenModeHelper#applyCustomPolicy.
@@ -119,7 +119,7 @@ public class ZenMode implements Parcelable {
                return Status.ENABLED;
                return Status.ENABLED;
            }
            }
        } else {
        } else {
            if (zenRuleExtraData.disabledOrigin == ZenModeConfig.UPDATE_ORIGIN_USER) {
            if (zenRuleExtraData.disabledOrigin == ZenModeConfig.ORIGIN_USER_IN_SYSTEMUI) {
                return Status.DISABLED_BY_USER;
                return Status.DISABLED_BY_USER;
            } else {
            } else {
                return Status.DISABLED_BY_OTHER; // by APP, SYSTEM, UNKNOWN.
                return Status.DISABLED_BY_OTHER; // by APP, SYSTEM, UNKNOWN.
+2 −2
Original line number Original line Diff line number Diff line
@@ -93,7 +93,7 @@ public class ZenModeTest {
    public void constructor_disabledRuleByUser_statusDisabledByUser() {
    public void constructor_disabledRuleByUser_statusDisabledByUser() {
        AutomaticZenRule azr = new AutomaticZenRule.Builder(ZEN_RULE).setEnabled(false).build();
        AutomaticZenRule azr = new AutomaticZenRule.Builder(ZEN_RULE).setEnabled(false).build();
        ZenModeConfig.ZenRule configZenRule = zenConfigRuleFor(azr, false);
        ZenModeConfig.ZenRule configZenRule = zenConfigRuleFor(azr, false);
        configZenRule.disabledOrigin = ZenModeConfig.UPDATE_ORIGIN_USER;
        configZenRule.disabledOrigin = ZenModeConfig.ORIGIN_USER_IN_SYSTEMUI;


        ZenMode mode = new ZenMode("id", azr, configZenRule);
        ZenMode mode = new ZenMode("id", azr, configZenRule);
        assertThat(mode.getStatus()).isEqualTo(ZenMode.Status.DISABLED_BY_USER);
        assertThat(mode.getStatus()).isEqualTo(ZenMode.Status.DISABLED_BY_USER);
@@ -103,7 +103,7 @@ public class ZenModeTest {
    public void constructor_disabledRuleByOther_statusDisabledByOther() {
    public void constructor_disabledRuleByOther_statusDisabledByOther() {
        AutomaticZenRule azr = new AutomaticZenRule.Builder(ZEN_RULE).setEnabled(false).build();
        AutomaticZenRule azr = new AutomaticZenRule.Builder(ZEN_RULE).setEnabled(false).build();
        ZenModeConfig.ZenRule configZenRule = zenConfigRuleFor(azr, false);
        ZenModeConfig.ZenRule configZenRule = zenConfigRuleFor(azr, false);
        configZenRule.disabledOrigin = ZenModeConfig.UPDATE_ORIGIN_APP;
        configZenRule.disabledOrigin = ZenModeConfig.ORIGIN_APP;


        ZenMode mode = new ZenMode("id", azr, configZenRule);
        ZenMode mode = new ZenMode("id", azr, configZenRule);
        assertThat(mode.getStatus()).isEqualTo(ZenMode.Status.DISABLED_BY_OTHER);
        assertThat(mode.getStatus()).isEqualTo(ZenMode.Status.DISABLED_BY_OTHER);
Loading