Split ORIGIN_USER into "user from systemui" and "user from app"
In practice this applies to setAutomaticZenRuleState() only, since that call is the only one that allowed apps to claim to act on behalf of the user.
A follow-up will use this information to snooze rules that are turned off manually.
Bug: 333527800
Test: atest DefaultDeviceEffectsApplierTest NotificationManagerServiceTest ZenModeConfigTest ZenModeHelperTest
Flag: android.app.modes_ui
Change-Id: I7426315cd92c299327b73fcf0e992bfe5f1e4d43
diff --git a/core/java/android/service/notification/DeviceEffectsApplier.java b/core/java/android/service/notification/DeviceEffectsApplier.java
index 5194cdd..2472860 100644
--- a/core/java/android/service/notification/DeviceEffectsApplier.java
+++ b/core/java/android/service/notification/DeviceEffectsApplier.java
@@ -16,8 +16,6 @@
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
* make sense for the current platform.
@@ -43,5 +41,5 @@
* changing as a result of an explicit user action, then it makes sense to
* apply them immediately regardless.
*/
- void apply(ZenDeviceEffects effects, @ConfigChangeOrigin int source);
+ void apply(ZenDeviceEffects effects, @ZenModeConfig.ConfigOrigin int source);
}
diff --git a/core/java/android/service/notification/ZenModeConfig.java b/core/java/android/service/notification/ZenModeConfig.java
index 7ca248d..5e15e01 100644
--- a/core/java/android/service/notification/ZenModeConfig.java
+++ b/core/java/android/service/notification/ZenModeConfig.java
@@ -112,68 +112,83 @@
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).
*/
- 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. */
- public static final int UPDATE_ORIGIN_INIT_USER = 2;
+ /** The {@link ZenModeConfig} is updated (replaced) because of a user switch or unlock. */
+ 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>
- * <li>{@link NotificationManager#setAutomaticZenRuleState} with a
- * {@link Condition#source} equal to {@link Condition#SOURCE_USER_ACTION}.</li>
- * <li>Adding, updating, or removing a rule from Settings.</li>
- * <li>Directly activating or deactivating/snoozing a rule through some UI affordance (e.g.
- * Quick Settings).</li>
+ * <li>Adding, updating, or removing a rule from Settings.
+ * <li>Activating or deactivating a rule through the System (e.g. from Settings/Modes).
+ * <li>Activating or deactivating a rule through SystemUi (e.g. with Quick Settings).
* </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
- * a user's action inside that app (for example, activating an {@link AutomaticZenRule} based on
- * a previously set schedule).
+ * The {@link ZenModeConfig} is updated by an app, but (probably) not as a result of a user
+ * action (for example, activating an {@link AutomaticZenRule} based on a previously set
+ * 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
- * includes cases where the call is coming from the System/SystemUI but the change is not due to
- * a user action (e.g. automatically activating a schedule-based rule). If the change is a
- * result of a user action (e.g. activating a rule by tapping on its QS tile) then
- * {@link #UPDATE_ORIGIN_USER} is used instead.
+ * The {@link ZenModeConfig} is updated by the System (or SystemUI). This only includes cases
+ * where the call is coming from the System/SystemUI but the change is not due to a user action
+ * (e.g. automatically activating a schedule-based rule, or some service toggling Do Not
+ * Disturb). See {@link #ORIGIN_USER_IN_SYSTEMUI}.
*/
- 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
* 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,
- UPDATE_ORIGIN_INIT,
- UPDATE_ORIGIN_INIT_USER,
- UPDATE_ORIGIN_USER,
- UPDATE_ORIGIN_APP,
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI,
- UPDATE_ORIGIN_RESTORE_BACKUP
+ /**
+ * The {@link ZenModeConfig} is updated from an app, and the app reports it's the result
+ * of a user action (e.g. tapping a button in the Wellbeing App to start Bedtime Mode).
+ * Corresponds to {@link NotificationManager#setAutomaticZenRuleState} with a
+ * {@link Condition#source} equal to {@link Condition#SOURCE_USER_ACTION}.</li>
+ */
+ public static final int ORIGIN_USER_IN_APP = 7;
+
+ @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)
- public @interface ConfigChangeOrigin {}
+ public @interface ConfigOrigin {}
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_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_CALLS_SOURCE = SOURCE_STAR;
@@ -1174,7 +1189,7 @@
}
if (Flags.modesUi()) {
rt.disabledOrigin = safeInt(parser, RULE_ATT_DISABLED_ORIGIN,
- UPDATE_ORIGIN_UNKNOWN);
+ ORIGIN_UNKNOWN);
rt.legacySuppressedEffects = safeInt(parser,
RULE_ATT_LEGACY_SUPPRESSED_EFFECTS, 0);
}
@@ -2537,7 +2552,8 @@
@ZenDeviceEffects.ModifiableField public int zenDeviceEffectsUserModifiedFields;
@Nullable public Instant deletionInstant; // Only set on deleted rules.
@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
// ZenPolicy, so we store them here, only for the manual rule.
@FlaggedApi(Flags.FLAG_MODES_UI)
diff --git a/packages/SettingsLib/src/com/android/settingslib/notification/modes/TestModeBuilder.java b/packages/SettingsLib/src/com/android/settingslib/notification/modes/TestModeBuilder.java
index a06f084..22e6133 100644
--- a/packages/SettingsLib/src/com/android/settingslib/notification/modes/TestModeBuilder.java
+++ b/packages/SettingsLib/src/com/android/settingslib/notification/modes/TestModeBuilder.java
@@ -16,8 +16,8 @@
package com.android.settingslib.notification.modes;
-import static android.service.notification.ZenModeConfig.UPDATE_ORIGIN_UNKNOWN;
-import static android.service.notification.ZenModeConfig.UPDATE_ORIGIN_USER;
+import static android.service.notification.ZenModeConfig.ORIGIN_UNKNOWN;
+import static android.service.notification.ZenModeConfig.ORIGIN_USER_IN_SYSTEMUI;
import android.app.AutomaticZenRule;
import android.app.NotificationManager;
@@ -154,7 +154,7 @@
mRule.setEnabled(enabled);
mConfigZenRule.enabled = enabled;
if (!enabled) {
- mConfigZenRule.disabledOrigin = byUser ? UPDATE_ORIGIN_USER : UPDATE_ORIGIN_UNKNOWN;
+ mConfigZenRule.disabledOrigin = byUser ? ORIGIN_USER_IN_SYSTEMUI : ORIGIN_UNKNOWN;
}
return this;
}
diff --git a/packages/SettingsLib/src/com/android/settingslib/notification/modes/ZenMode.java b/packages/SettingsLib/src/com/android/settingslib/notification/modes/ZenMode.java
index 88af7ee..88497a3 100644
--- a/packages/SettingsLib/src/com/android/settingslib/notification/modes/ZenMode.java
+++ b/packages/SettingsLib/src/com/android/settingslib/notification/modes/ZenMode.java
@@ -66,7 +66,7 @@
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";
// Must match com.android.server.notification.ZenModeHelper#applyCustomPolicy.
@@ -119,7 +119,7 @@
return Status.ENABLED;
}
} else {
- if (zenRuleExtraData.disabledOrigin == ZenModeConfig.UPDATE_ORIGIN_USER) {
+ if (zenRuleExtraData.disabledOrigin == ZenModeConfig.ORIGIN_USER_IN_SYSTEMUI) {
return Status.DISABLED_BY_USER;
} else {
return Status.DISABLED_BY_OTHER; // by APP, SYSTEM, UNKNOWN.
diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/notification/modes/ZenModeTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/notification/modes/ZenModeTest.java
index 651e57c..d9fdcc38 100644
--- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/notification/modes/ZenModeTest.java
+++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/notification/modes/ZenModeTest.java
@@ -93,7 +93,7 @@
public void constructor_disabledRuleByUser_statusDisabledByUser() {
AutomaticZenRule azr = new AutomaticZenRule.Builder(ZEN_RULE).setEnabled(false).build();
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);
assertThat(mode.getStatus()).isEqualTo(ZenMode.Status.DISABLED_BY_USER);
@@ -103,7 +103,7 @@
public void constructor_disabledRuleByOther_statusDisabledByOther() {
AutomaticZenRule azr = new AutomaticZenRule.Builder(ZEN_RULE).setEnabled(false).build();
ZenModeConfig.ZenRule configZenRule = zenConfigRuleFor(azr, false);
- configZenRule.disabledOrigin = ZenModeConfig.UPDATE_ORIGIN_APP;
+ configZenRule.disabledOrigin = ZenModeConfig.ORIGIN_APP;
ZenMode mode = new ZenMode("id", azr, configZenRule);
assertThat(mode.getStatus()).isEqualTo(ZenMode.Status.DISABLED_BY_OTHER);
diff --git a/services/core/java/com/android/server/notification/ConditionProviders.java b/services/core/java/com/android/server/notification/ConditionProviders.java
index 3cc0457..a44e553 100644
--- a/services/core/java/com/android/server/notification/ConditionProviders.java
+++ b/services/core/java/com/android/server/notification/ConditionProviders.java
@@ -17,7 +17,7 @@
package com.android.server.notification;
import static android.service.notification.Condition.STATE_TRUE;
-import static android.service.notification.ZenModeConfig.UPDATE_ORIGIN_USER;
+import static android.service.notification.ZenModeConfig.ORIGIN_USER_IN_SYSTEMUI;
import android.app.INotificationManager;
import android.app.NotificationManager;
@@ -326,7 +326,7 @@
// if user turned on the mode, ignore the update unless the app also wants the
// mode on. this will update the origin of the mode and let the owner turn it
// off when the context ends
- if (r.condition != null && r.condition.source == UPDATE_ORIGIN_USER) {
+ if (r.condition != null && r.condition.source == ORIGIN_USER_IN_SYSTEMUI) {
if (r.condition.state == STATE_TRUE && c.state == STATE_TRUE) {
r.condition = c;
}
diff --git a/services/core/java/com/android/server/notification/DefaultDeviceEffectsApplier.java b/services/core/java/com/android/server/notification/DefaultDeviceEffectsApplier.java
index d060f8f2..c8cb54f 100644
--- a/services/core/java/com/android/server/notification/DefaultDeviceEffectsApplier.java
+++ b/services/core/java/com/android/server/notification/DefaultDeviceEffectsApplier.java
@@ -31,7 +31,7 @@
import android.service.notification.DeviceEffectsApplier;
import android.service.notification.ZenDeviceEffects;
import android.service.notification.ZenModeConfig;
-import android.service.notification.ZenModeConfig.ConfigChangeOrigin;
+import android.service.notification.ZenModeConfig.ConfigOrigin;
import android.util.Slog;
import com.android.internal.annotations.GuardedBy;
@@ -72,7 +72,7 @@
}
@Override
- public void apply(ZenDeviceEffects effects, @ConfigChangeOrigin int origin) {
+ public void apply(ZenDeviceEffects effects, @ConfigOrigin int origin) {
Binder.withCleanCallingIdentity(() -> {
if (mLastAppliedEffects.shouldSuppressAmbientDisplay()
!= effects.shouldSuppressAmbientDisplay()) {
@@ -120,15 +120,16 @@
mLastAppliedEffects = effects;
}
- private void updateOrScheduleNightMode(boolean useNightMode, @ConfigChangeOrigin int origin) {
+ private void updateOrScheduleNightMode(boolean useNightMode, @ConfigOrigin int origin) {
mPendingNightMode = useNightMode;
// Changing the theme can be disruptive for the user (Activities are likely recreated, may
// lose some state). Therefore we only apply the change immediately if the rule was
// activated manually, or we are initializing, or the screen is currently off/dreaming.
- if (origin == ZenModeConfig.UPDATE_ORIGIN_INIT
- || origin == ZenModeConfig.UPDATE_ORIGIN_INIT_USER
- || origin == ZenModeConfig.UPDATE_ORIGIN_USER
+ if (origin == ZenModeConfig.ORIGIN_INIT
+ || origin == ZenModeConfig.ORIGIN_INIT_USER
+ || origin == ZenModeConfig.ORIGIN_USER_IN_SYSTEMUI
+ || origin == ZenModeConfig.ORIGIN_USER_IN_APP
|| !mPowerManager.isInteractive()) {
unregisterScreenOffReceiver();
updateNightModeImmediately(useNightMode);
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index 4179edd..45b8da5 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -5771,16 +5771,20 @@
Binder.getCallingUid());
}
- @ZenModeConfig.ConfigChangeOrigin
+ @ZenModeConfig.ConfigOrigin
private int computeZenOrigin(boolean fromUser) {
// "fromUser" is introduced with MODES_API, so only consider it in that case.
- // (Non-MODES_API behavior should also not depend at all on UPDATE_ORIGIN_USER).
+ // (Non-MODES_API behavior should also not depend at all on ORIGIN_USER_IN_X).
if (android.app.Flags.modesApi() && fromUser) {
- return ZenModeConfig.UPDATE_ORIGIN_USER;
+ if (isCallerSystemOrSystemUi()) {
+ return ZenModeConfig.ORIGIN_USER_IN_SYSTEMUI;
+ } else {
+ return ZenModeConfig.ORIGIN_USER_IN_APP;
+ }
} else if (isCallerSystemOrSystemUi()) {
- return ZenModeConfig.UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI;
+ return ZenModeConfig.ORIGIN_SYSTEM;
} else {
- return ZenModeConfig.UPDATE_ORIGIN_APP;
+ return ZenModeConfig.ORIGIN_APP;
}
}
@@ -6137,7 +6141,7 @@
enforcePolicyAccess(pkg, "setNotificationPolicy");
enforceUserOriginOnlyFromSystem(fromUser, "setNotificationPolicy");
int callingUid = Binder.getCallingUid();
- @ZenModeConfig.ConfigChangeOrigin int origin = computeZenOrigin(fromUser);
+ @ZenModeConfig.ConfigOrigin int origin = computeZenOrigin(fromUser);
boolean shouldApplyAsImplicitRule = android.app.Flags.modesApi()
&& !canManageGlobalZenPolicy(pkg, callingUid);
diff --git a/services/core/java/com/android/server/notification/PreferencesHelper.java b/services/core/java/com/android/server/notification/PreferencesHelper.java
index c09504f..821722b 100644
--- a/services/core/java/com/android/server/notification/PreferencesHelper.java
+++ b/services/core/java/com/android/server/notification/PreferencesHelper.java
@@ -30,7 +30,6 @@
import static android.app.NotificationManager.IMPORTANCE_MAX;
import static android.app.NotificationManager.IMPORTANCE_NONE;
import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;
-
import static android.os.UserHandle.USER_SYSTEM;
import static android.service.notification.Flags.notificationClassification;
@@ -1979,8 +1978,8 @@
(areChannelsBypassingDnd
? NotificationManager.Policy.STATE_CHANNELS_BYPASSING_DND : 0),
policy.priorityConversationSenders),
- fromSystemOrSystemUi ? ZenModeConfig.UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI
- : ZenModeConfig.UPDATE_ORIGIN_APP,
+ fromSystemOrSystemUi ? ZenModeConfig.ORIGIN_SYSTEM
+ : ZenModeConfig.ORIGIN_APP,
callingUid);
}
diff --git a/services/core/java/com/android/server/notification/ZenModeConditions.java b/services/core/java/com/android/server/notification/ZenModeConditions.java
index 3650536..268d835 100644
--- a/services/core/java/com/android/server/notification/ZenModeConditions.java
+++ b/services/core/java/com/android/server/notification/ZenModeConditions.java
@@ -116,8 +116,8 @@
if (DEBUG) Log.d(TAG, "onServiceAdded " + component);
final int callingUid = Binder.getCallingUid();
mHelper.setConfig(mHelper.getConfig(), component,
- callingUid == Process.SYSTEM_UID ? ZenModeConfig.UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI
- : ZenModeConfig.UPDATE_ORIGIN_APP,
+ callingUid == Process.SYSTEM_UID ? ZenModeConfig.ORIGIN_SYSTEM
+ : ZenModeConfig.ORIGIN_APP,
"zmc.onServiceAdded:" + component, callingUid);
}
@@ -128,8 +128,8 @@
if (config == null) return;
final int callingUid = Binder.getCallingUid();
mHelper.setAutomaticZenRuleState(id, condition,
- callingUid == Process.SYSTEM_UID ? ZenModeConfig.UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI
- : ZenModeConfig.UPDATE_ORIGIN_APP,
+ callingUid == Process.SYSTEM_UID ? ZenModeConfig.ORIGIN_SYSTEM
+ : ZenModeConfig.ORIGIN_APP,
callingUid);
}
diff --git a/services/core/java/com/android/server/notification/ZenModeEventLogger.java b/services/core/java/com/android/server/notification/ZenModeEventLogger.java
index 4a82057..b03a54e 100644
--- a/services/core/java/com/android/server/notification/ZenModeEventLogger.java
+++ b/services/core/java/com/android/server/notification/ZenModeEventLogger.java
@@ -34,7 +34,7 @@
import android.service.notification.DNDPolicyProto;
import android.service.notification.ZenAdapters;
import android.service.notification.ZenModeConfig;
-import android.service.notification.ZenModeConfig.ConfigChangeOrigin;
+import android.service.notification.ZenModeConfig.ConfigOrigin;
import android.service.notification.ZenModeConfig.ZenRule;
import android.service.notification.ZenModeDiff;
import android.service.notification.ZenPolicy;
@@ -113,7 +113,7 @@
* @param origin The origin of the Zen change.
*/
public final void maybeLogZenChange(ZenModeInfo prevInfo, ZenModeInfo newInfo, int callingUid,
- @ConfigChangeOrigin int origin) {
+ @ConfigOrigin int origin) {
mChangeState.init(prevInfo, newInfo, callingUid, origin);
if (mChangeState.shouldLogChanges()) {
maybeReassignCallingUid();
@@ -250,11 +250,11 @@
ZenModeConfig mPrevConfig, mNewConfig;
NotificationManager.Policy mPrevPolicy, mNewPolicy;
int mCallingUid = Process.INVALID_UID;
- @ConfigChangeOrigin
- int mOrigin = ZenModeConfig.UPDATE_ORIGIN_UNKNOWN;
+ @ConfigOrigin
+ int mOrigin = ZenModeConfig.ORIGIN_UNKNOWN;
private void init(ZenModeInfo prevInfo, ZenModeInfo newInfo, int callingUid,
- @ConfigChangeOrigin int origin) {
+ @ConfigOrigin int origin) {
// previous & new may be the same -- that would indicate that zen mode hasn't changed.
mPrevZenMode = prevInfo.mZenMode;
mNewZenMode = newInfo.mZenMode;
@@ -484,7 +484,8 @@
*/
boolean getIsUserAction() {
if (Flags.modesApi()) {
- return mOrigin == ZenModeConfig.UPDATE_ORIGIN_USER;
+ return mOrigin == ZenModeConfig.ORIGIN_USER_IN_SYSTEMUI
+ || mOrigin == ZenModeConfig.ORIGIN_USER_IN_APP;
}
// Approach for pre-MODES_API:
@@ -549,10 +550,10 @@
}
boolean isFromSystemOrSystemUi() {
- return mOrigin == ZenModeConfig.UPDATE_ORIGIN_INIT
- || mOrigin == ZenModeConfig.UPDATE_ORIGIN_INIT_USER
- || mOrigin == ZenModeConfig.UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI
- || mOrigin == ZenModeConfig.UPDATE_ORIGIN_RESTORE_BACKUP;
+ return mOrigin == ZenModeConfig.ORIGIN_INIT
+ || mOrigin == ZenModeConfig.ORIGIN_INIT_USER
+ || mOrigin == ZenModeConfig.ORIGIN_SYSTEM
+ || mOrigin == ZenModeConfig.ORIGIN_RESTORE_BACKUP;
}
/**
diff --git a/services/core/java/com/android/server/notification/ZenModeHelper.java b/services/core/java/com/android/server/notification/ZenModeHelper.java
index 95d8bb9..b164a52 100644
--- a/services/core/java/com/android/server/notification/ZenModeHelper.java
+++ b/services/core/java/com/android/server/notification/ZenModeHelper.java
@@ -29,13 +29,14 @@
import static android.service.notification.Condition.STATE_FALSE;
import static android.service.notification.Condition.STATE_TRUE;
import static android.service.notification.NotificationServiceProto.ROOT_CONFIG;
-import static android.service.notification.ZenModeConfig.UPDATE_ORIGIN_APP;
-import static android.service.notification.ZenModeConfig.UPDATE_ORIGIN_INIT;
-import static android.service.notification.ZenModeConfig.UPDATE_ORIGIN_INIT_USER;
-import static android.service.notification.ZenModeConfig.UPDATE_ORIGIN_RESTORE_BACKUP;
-import static android.service.notification.ZenModeConfig.UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI;
-import static android.service.notification.ZenModeConfig.UPDATE_ORIGIN_UNKNOWN;
-import static android.service.notification.ZenModeConfig.UPDATE_ORIGIN_USER;
+import static android.service.notification.ZenModeConfig.ORIGIN_APP;
+import static android.service.notification.ZenModeConfig.ORIGIN_INIT;
+import static android.service.notification.ZenModeConfig.ORIGIN_INIT_USER;
+import static android.service.notification.ZenModeConfig.ORIGIN_RESTORE_BACKUP;
+import static android.service.notification.ZenModeConfig.ORIGIN_SYSTEM;
+import static android.service.notification.ZenModeConfig.ORIGIN_UNKNOWN;
+import static android.service.notification.ZenModeConfig.ORIGIN_USER_IN_APP;
+import static android.service.notification.ZenModeConfig.ORIGIN_USER_IN_SYSTEMUI;
import static com.android.internal.util.FrameworkStatsLog.DND_MODE_RULE;
import static com.android.internal.util.Preconditions.checkArgument;
@@ -95,7 +96,7 @@
import android.service.notification.ZenAdapters;
import android.service.notification.ZenDeviceEffects;
import android.service.notification.ZenModeConfig;
-import android.service.notification.ZenModeConfig.ConfigChangeOrigin;
+import android.service.notification.ZenModeConfig.ConfigOrigin;
import android.service.notification.ZenModeConfig.ZenRule;
import android.service.notification.ZenModeProto;
import android.service.notification.ZenPolicy;
@@ -294,7 +295,7 @@
// "update" config to itself, which will have no effect in the case where a config
// was read in via XML, but will initialize zen mode if nothing was read in and the
// config remains the default.
- updateConfigAndZenModeLocked(mConfig, UPDATE_ORIGIN_INIT, "init",
+ updateConfigAndZenModeLocked(mConfig, ORIGIN_INIT, "init",
true /*setRingerMode*/, Process.SYSTEM_UID /* callingUid */);
}
}
@@ -328,7 +329,7 @@
}
mDeviceEffectsApplier = deviceEffectsApplier;
}
- applyConsolidatedDeviceEffects(UPDATE_ORIGIN_INIT);
+ applyConsolidatedDeviceEffects(ORIGIN_INIT);
}
public void onUserSwitched(int user) {
@@ -368,7 +369,7 @@
config.user = user;
}
synchronized (mConfigLock) {
- setConfigLocked(config, null, UPDATE_ORIGIN_INIT_USER, reason,
+ setConfigLocked(config, null, ORIGIN_INIT_USER, reason,
Process.SYSTEM_UID);
}
cleanUpZenRules();
@@ -384,7 +385,7 @@
final int newZen = NotificationManager.zenModeFromInterruptionFilter(filter, -1);
if (newZen != -1) {
setManualZenMode(newZen, null,
- fromSystemOrSystemUi ? UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI : UPDATE_ORIGIN_APP,
+ fromSystemOrSystemUi ? ORIGIN_SYSTEM : ORIGIN_APP,
/* reason= */ "listener:" + (name != null ? name.flattenToShortString() : null),
/* caller= */ name != null ? name.getPackageName() : null,
callingUid);
@@ -447,8 +448,8 @@
}
public String addAutomaticZenRule(String pkg, AutomaticZenRule automaticZenRule,
- @ConfigChangeOrigin int origin, String reason, int callingUid) {
- requirePublicOrigin("addAutomaticZenRule", origin);
+ @ConfigOrigin int origin, String reason, int callingUid) {
+ checkManageRuleOrigin("addAutomaticZenRule", origin);
if (!ZenModeConfig.SYSTEM_AUTHORITY.equals(pkg)) {
PackageItemInfo component = getServiceInfo(automaticZenRule.getOwner());
if (component == null) {
@@ -497,7 +498,7 @@
@GuardedBy("mConfigLock")
private ZenRule maybeRestoreRemovedRule(ZenModeConfig config, ZenRule ruleToAdd,
- AutomaticZenRule azrToAdd, @ConfigChangeOrigin int origin) {
+ AutomaticZenRule azrToAdd, @ConfigOrigin int origin) {
if (!Flags.modesApi()) {
return ruleToAdd;
}
@@ -517,7 +518,7 @@
config.deletedRules.remove(deletedKey);
ruleToRestore.deletionInstant = null;
- if (origin != UPDATE_ORIGIN_APP) {
+ if (origin != ORIGIN_APP) {
return ruleToAdd; // Okay to create anew.
}
@@ -547,8 +548,8 @@
}
public boolean updateAutomaticZenRule(String ruleId, AutomaticZenRule automaticZenRule,
- @ConfigChangeOrigin int origin, String reason, int callingUid) {
- requirePublicOrigin("updateAutomaticZenRule", origin);
+ @ConfigOrigin int origin, String reason, int callingUid) {
+ checkManageRuleOrigin("updateAutomaticZenRule", origin);
if (ruleId == null) {
throw new IllegalArgumentException("ruleId cannot be null");
}
@@ -621,7 +622,7 @@
mContext.getString(R.string.zen_mode_implicit_deactivated),
STATE_FALSE);
setAutomaticZenRuleStateLocked(newConfig, Collections.singletonList(rule),
- deactivated, UPDATE_ORIGIN_APP, callingUid);
+ deactivated, ORIGIN_APP, callingUid);
}
} else {
// Either create a new rule with a default ZenPolicy, or update an existing rule's
@@ -647,7 +648,7 @@
mContext.getString(R.string.zen_mode_implicit_activated),
STATE_TRUE);
- setConfigLocked(newConfig, /* triggeringComponent= */ null, UPDATE_ORIGIN_APP,
+ setConfigLocked(newConfig, /* triggeringComponent= */ null, ORIGIN_APP,
"applyGlobalZenModeAsImplicitZenRule", callingUid);
}
}
@@ -701,7 +702,7 @@
/* updateBitmask= */ false,
isNew);
- setConfigLocked(newConfig, /* triggeringComponent= */ null, UPDATE_ORIGIN_APP,
+ setConfigLocked(newConfig, /* triggeringComponent= */ null, ORIGIN_APP,
"applyGlobalPolicyAsImplicitZenRule", callingUid);
}
}
@@ -788,9 +789,9 @@
return ruleId.startsWith(IMPLICIT_RULE_ID_PREFIX);
}
- boolean removeAutomaticZenRule(String id, @ConfigChangeOrigin int origin, String reason,
+ boolean removeAutomaticZenRule(String id, @ConfigOrigin int origin, String reason,
int callingUid) {
- requirePublicOrigin("removeAutomaticZenRule", origin);
+ checkManageRuleOrigin("removeAutomaticZenRule", origin);
ZenModeConfig newConfig;
synchronized (mConfigLock) {
if (mConfig == null) return false;
@@ -821,9 +822,9 @@
}
}
- boolean removeAutomaticZenRules(String packageName, @ConfigChangeOrigin int origin,
+ boolean removeAutomaticZenRules(String packageName, @ConfigOrigin int origin,
String reason, int callingUid) {
- requirePublicOrigin("removeAutomaticZenRules", origin);
+ checkManageRuleOrigin("removeAutomaticZenRules", origin);
ZenModeConfig newConfig;
synchronized (mConfigLock) {
if (mConfig == null) return false;
@@ -837,7 +838,7 @@
}
// If the system is clearing all rules this means DND access is revoked or the package
// was uninstalled, so also clear the preserved-deleted rules.
- if (origin == UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI) {
+ if (origin == ORIGIN_SYSTEM) {
for (int i = newConfig.deletedRules.size() - 1; i >= 0; i--) {
ZenRule rule = newConfig.deletedRules.get(newConfig.deletedRules.keyAt(i));
if (Objects.equals(rule.getPkg(), packageName)) {
@@ -850,7 +851,7 @@
}
private void maybePreserveRemovedRule(ZenModeConfig config, ZenRule ruleToRemove,
- @ConfigChangeOrigin int origin) {
+ @ConfigOrigin int origin) {
if (!Flags.modesApi()) {
return;
}
@@ -859,7 +860,7 @@
// We don't try to preserve system-owned rules because their conditionIds (used as
// deletedRuleKey) are not stable. This is almost moot anyway because an app cannot
// delete a system-owned rule.
- if (origin == UPDATE_ORIGIN_APP && !ruleToRemove.canBeUpdatedByApp()
+ if (origin == ORIGIN_APP && !ruleToRemove.canBeUpdatedByApp()
&& !PACKAGE_ANDROID.equals(ruleToRemove.pkg)) {
String deletedKey = ZenModeConfig.deletedRuleKey(ruleToRemove);
if (deletedKey != null) {
@@ -888,9 +889,9 @@
}
}
- void setAutomaticZenRuleState(String id, Condition condition, @ConfigChangeOrigin int origin,
+ void setAutomaticZenRuleState(String id, Condition condition, @ConfigOrigin int origin,
int callingUid) {
- requirePublicOrigin("setAutomaticZenRuleState", origin);
+ checkSetRuleStateOrigin("setAutomaticZenRuleState(String id)", origin);
ZenModeConfig newConfig;
synchronized (mConfigLock) {
if (mConfig == null) return;
@@ -911,8 +912,8 @@
}
void setAutomaticZenRuleState(Uri ruleDefinition, Condition condition,
- @ConfigChangeOrigin int origin, int callingUid) {
- requirePublicOrigin("setAutomaticZenRuleState", origin);
+ @ConfigOrigin int origin, int callingUid) {
+ checkSetRuleStateOrigin("setAutomaticZenRuleState(Uri ruleDefinition)", origin);
ZenModeConfig newConfig;
synchronized (mConfigLock) {
if (mConfig == null) return;
@@ -932,11 +933,13 @@
@GuardedBy("mConfigLock")
private void setAutomaticZenRuleStateLocked(ZenModeConfig config, List<ZenRule> rules,
- Condition condition, @ConfigChangeOrigin int origin, int callingUid) {
+ Condition condition, @ConfigOrigin int origin, int callingUid) {
if (rules == null || rules.isEmpty()) return;
- if (Flags.modesApi() && condition.source == SOURCE_USER_ACTION) {
- origin = UPDATE_ORIGIN_USER; // Although coming from app, it's actually a user action.
+ if (!Flags.modesUi()) {
+ if (Flags.modesApi() && condition.source == SOURCE_USER_ACTION) {
+ origin = ORIGIN_USER_IN_APP; // Although coming from app, it's actually from user.
+ }
}
for (ZenRule rule : rules) {
@@ -1062,7 +1065,7 @@
}
}
if (updated) {
- setConfigLocked(config, null, UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI,
+ setConfigLocked(config, null, ORIGIN_SYSTEM,
"updateZenRulesOnLocaleChange", Process.SYSTEM_UID);
}
}
@@ -1119,11 +1122,11 @@
* </ul>
*
* <p>The rule's {@link ZenRule#condition} is cleared (meaning that an active rule will be
- * deactivated) unless the update has origin == {@link ZenModeConfig#UPDATE_ORIGIN_USER}.
+ * deactivated) unless the update has origin == {@link ZenModeConfig#ORIGIN_USER_IN_SYSTEMUI}.
*/
@GuardedBy("mConfigLock")
private boolean populateZenRule(String pkg, AutomaticZenRule azr, ZenRule rule,
- @ConfigChangeOrigin int origin, boolean isNew) {
+ @ConfigOrigin int origin, boolean isNew) {
if (Flags.modesApi()) {
boolean modified = false;
// These values can always be edited by the app, so we apply changes immediately.
@@ -1137,7 +1140,7 @@
// Allow updating the CPS backing system rules (e.g. for custom manual -> schedule)
if (Flags.modesUi()
- && (origin == UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI || origin == UPDATE_ORIGIN_USER)
+ && (origin == ORIGIN_SYSTEM || origin == ORIGIN_USER_IN_SYSTEMUI)
&& Objects.equals(rule.pkg, SystemZenRules.PACKAGE_ANDROID)
&& !Objects.equals(rule.component, azr.getOwner())) {
rule.component = azr.getOwner();
@@ -1151,7 +1154,7 @@
rule.disabledOrigin = origin;
} else if (azr.isEnabled()) {
// Enabling or previously enabled. Clear disabler.
- rule.disabledOrigin = UPDATE_ORIGIN_UNKNOWN;
+ rule.disabledOrigin = ORIGIN_UNKNOWN;
}
}
@@ -1166,7 +1169,7 @@
Flags.modesApi()
&& (Flags.modesUi() || isWatch)
&& !isNew
- && origin == UPDATE_ORIGIN_USER
+ && origin == ORIGIN_USER_IN_SYSTEMUI
&& rule.enabled == azr.isEnabled()
&& rule.conditionId != null
&& rule.condition != null
@@ -1232,7 +1235,7 @@
}
// Updates the bitmasks if the origin of the change is the user.
- boolean updateBitmask = (origin == UPDATE_ORIGIN_USER);
+ boolean updateBitmask = (origin == ORIGIN_USER_IN_SYSTEMUI);
if (updateBitmask && !TextUtils.equals(previousName, azr.getName())) {
rule.userModifiedFields |= AutomaticZenRule.FIELD_NAME;
@@ -1263,7 +1266,7 @@
// Updates the bitmask and values for all device effect fields, based on the origin.
modified |= updateZenDeviceEffects(rule, azr.getDeviceEffects(),
- origin == UPDATE_ORIGIN_APP, updateBitmask);
+ origin == ORIGIN_APP, updateBitmask);
return modified;
} else {
@@ -1297,8 +1300,8 @@
* change. (Note that regardless of origin, fields can always be updated if they're not already
* user modified.)
*/
- private static boolean doesOriginAlwaysUpdateValues(@ConfigChangeOrigin int origin) {
- return origin == UPDATE_ORIGIN_USER || origin == UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI;
+ private static boolean doesOriginAlwaysUpdateValues(@ConfigOrigin int origin) {
+ return origin == ORIGIN_USER_IN_SYSTEMUI || origin == ORIGIN_SYSTEM;
}
/**
@@ -1539,7 +1542,7 @@
: AUTOMATIC_RULE_STATUS_DISABLED);
}
- void setManualZenMode(int zenMode, Uri conditionId, @ConfigChangeOrigin int origin,
+ void setManualZenMode(int zenMode, Uri conditionId, @ConfigOrigin int origin,
String reason, @Nullable String caller, int callingUid) {
setManualZenMode(zenMode, conditionId, origin, reason, caller, true /*setRingerMode*/,
callingUid);
@@ -1547,7 +1550,7 @@
Settings.Secure.SHOW_ZEN_SETTINGS_SUGGESTION, 0);
}
- private void setManualZenMode(int zenMode, Uri conditionId, @ConfigChangeOrigin int origin,
+ private void setManualZenMode(int zenMode, Uri conditionId, @ConfigOrigin int origin,
String reason, @Nullable String caller, boolean setRingerMode, int callingUid) {
ZenModeConfig newConfig;
synchronized (mConfigLock) {
@@ -1564,8 +1567,8 @@
newConfig.manualRule.zenMode = zenMode;
newConfig.manualRule.condition = new Condition(newConfig.manualRule.conditionId, "",
zenMode == Global.ZEN_MODE_OFF ? STATE_FALSE : STATE_TRUE,
- origin == UPDATE_ORIGIN_USER ? SOURCE_USER_ACTION : SOURCE_UNKNOWN);
- if (zenMode == Global.ZEN_MODE_OFF && origin != UPDATE_ORIGIN_USER) {
+ origin == ORIGIN_USER_IN_SYSTEMUI ? SOURCE_USER_ACTION : SOURCE_UNKNOWN);
+ if (zenMode == Global.ZEN_MODE_OFF && origin != ORIGIN_USER_IN_SYSTEMUI) {
// User deactivation of DND means just turning off the manual DND rule.
// For API calls (different origin) keep old behavior of snoozing all rules.
for (ZenRule automaticRule : newConfig.automaticRules.values()) {
@@ -1602,7 +1605,7 @@
}
public void setManualZenRuleDeviceEffects(ZenDeviceEffects deviceEffects,
- @ConfigChangeOrigin int origin, String reason, int callingUid) {
+ @ConfigOrigin int origin, String reason, int callingUid) {
if (!Flags.modesUi()) {
return;
}
@@ -1752,7 +1755,7 @@
if (DEBUG) Log.d(TAG, reason);
synchronized (mConfigLock) {
setConfigLocked(config, null,
- forRestore ? UPDATE_ORIGIN_RESTORE_BACKUP : UPDATE_ORIGIN_INIT, reason,
+ forRestore ? ORIGIN_RESTORE_BACKUP : ORIGIN_INIT, reason,
Process.SYSTEM_UID);
}
}
@@ -1787,7 +1790,7 @@
/**
* Sets the global notification policy used for priority only do not disturb
*/
- public void setNotificationPolicy(Policy policy, @ConfigChangeOrigin int origin,
+ public void setNotificationPolicy(Policy policy, @ConfigOrigin int origin,
int callingUid) {
synchronized (mConfigLock) {
if (policy == null || mConfig == null) return;
@@ -1843,7 +1846,7 @@
}
if (!newConfig.equals(mConfig)) {
- setConfigLocked(newConfig, null, UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI,
+ setConfigLocked(newConfig, null, ORIGIN_SYSTEM,
"cleanUpZenRules", Process.SYSTEM_UID);
}
}
@@ -1893,20 +1896,20 @@
@GuardedBy("mConfigLock")
private boolean setConfigLocked(ZenModeConfig config, ComponentName triggeringComponent,
- @ConfigChangeOrigin int origin, String reason, int callingUid) {
+ @ConfigOrigin int origin, String reason, int callingUid) {
return setConfigLocked(config, origin, reason, triggeringComponent, true /*setRingerMode*/,
callingUid);
}
void setConfig(ZenModeConfig config, ComponentName triggeringComponent,
- @ConfigChangeOrigin int origin, String reason, int callingUid) {
+ @ConfigOrigin int origin, String reason, int callingUid) {
synchronized (mConfigLock) {
setConfigLocked(config, triggeringComponent, origin, reason, callingUid);
}
}
@GuardedBy("mConfigLock")
- private boolean setConfigLocked(ZenModeConfig config, @ConfigChangeOrigin int origin,
+ private boolean setConfigLocked(ZenModeConfig config, @ConfigOrigin int origin,
String reason, ComponentName triggeringComponent, boolean setRingerMode,
int callingUid) {
final long identity = Binder.clearCallingIdentity();
@@ -1954,7 +1957,7 @@
* If logging is enabled, will also request logging of the outcome of this change if needed.
*/
@GuardedBy("mConfigLock")
- private void updateConfigAndZenModeLocked(ZenModeConfig config, @ConfigChangeOrigin int origin,
+ private void updateConfigAndZenModeLocked(ZenModeConfig config, @ConfigOrigin int origin,
String reason, boolean setRingerMode, int callingUid) {
final boolean logZenModeEvents = mFlagResolver.isEnabled(
SystemUiSystemPropertiesFlags.NotificationFlags.LOG_DND_STATE_EVENTS);
@@ -1963,7 +1966,7 @@
mZenMode, mConfig, mConsolidatedPolicy);
if (!config.equals(mConfig)) {
// Schedule broadcasts. Cannot be sent during boot, though.
- if (Flags.modesApi() && origin != UPDATE_ORIGIN_INIT) {
+ if (Flags.modesApi() && origin != ORIGIN_INIT) {
for (ZenRule rule : config.automaticRules.values()) {
ZenRule original = mConfig.automaticRules.get(rule.id);
if (original != null) {
@@ -2020,7 +2023,7 @@
@VisibleForTesting
@GuardedBy("mConfigLock")
- protected void evaluateZenModeLocked(@ConfigChangeOrigin int origin, String reason,
+ protected void evaluateZenModeLocked(@ConfigOrigin int origin, String reason,
boolean setRingerMode) {
if (DEBUG) Log.d(TAG, "evaluateZenMode");
if (mConfig == null) return;
@@ -2111,7 +2114,7 @@
}
@GuardedBy("mConfigLock")
- private void updateAndApplyConsolidatedPolicyAndDeviceEffects(@ConfigChangeOrigin int origin,
+ private void updateAndApplyConsolidatedPolicyAndDeviceEffects(@ConfigOrigin int origin,
String reason) {
synchronized (mConfigLock) {
if (mConfig == null) return;
@@ -2163,7 +2166,7 @@
}
}
- private void applyConsolidatedDeviceEffects(@ConfigChangeOrigin int source) {
+ private void applyConsolidatedDeviceEffects(@ConfigOrigin int source) {
if (!Flags.modesApi()) {
return;
}
@@ -2506,7 +2509,7 @@
}
if (newZen != -1) {
- setManualZenMode(newZen, null, UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI,
+ setManualZenMode(newZen, null, ORIGIN_SYSTEM,
"ringerModeInternal", /* caller= */ null, /* setRingerMode= */ false,
Process.SYSTEM_UID);
}
@@ -2551,7 +2554,7 @@
break;
}
if (newZen != -1) {
- setManualZenMode(newZen, null, UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI,
+ setManualZenMode(newZen, null, ORIGIN_SYSTEM,
"ringerModeExternal", caller, false /*setRingerMode*/, Process.SYSTEM_UID);
}
@@ -2708,15 +2711,33 @@
}
}
- /** Checks that the {@code origin} supplied to a ZenModeHelper "API" method makes sense. */
- private static void requirePublicOrigin(String method, @ConfigChangeOrigin int origin) {
+ /**
+ * Checks that the {@code origin} supplied to ZenModeHelper rule-management API methods
+ * ({@link #addAutomaticZenRule}, {@link #removeAutomaticZenRule}, etc, makes sense.
+ */
+ private static void checkManageRuleOrigin(String method, @ConfigOrigin int origin) {
if (!Flags.modesApi()) {
return;
}
- checkArgument(origin == UPDATE_ORIGIN_APP || origin == UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI
- || origin == UPDATE_ORIGIN_USER,
- "Expected one of UPDATE_ORIGIN_APP, UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, or "
- + "UPDATE_ORIGIN_USER for %s, but received '%s'.",
+ checkArgument(origin == ORIGIN_APP || origin == ORIGIN_SYSTEM
+ || origin == ORIGIN_USER_IN_SYSTEMUI,
+ "Expected one of ORIGIN_APP, ORIGIN_SYSTEM, or "
+ + "ORIGIN_USER_IN_SYSTEMUI for %s, but received '%s'.",
+ method, origin);
+ }
+
+ /**
+ * Checks that the {@code origin} supplied to {@link #setAutomaticZenRuleState} overloads makes
+ * sense.
+ */
+ private static void checkSetRuleStateOrigin(String method, @ConfigOrigin int origin) {
+ if (!Flags.modesApi()) {
+ return;
+ }
+ checkArgument(origin == ORIGIN_APP || origin == ORIGIN_USER_IN_APP
+ || origin == ORIGIN_SYSTEM || origin == ORIGIN_USER_IN_SYSTEMUI,
+ "Expected one of ORIGIN_APP, ORIGIN_USER_IN_APP, ORIGIN_SYSTEM, or "
+ + "ORIGIN_USER_IN_SYSTEMUI for %s, but received '%s'.",
method, origin);
}
@@ -2841,7 +2862,7 @@
}
}
- private void postApplyDeviceEffects(@ConfigChangeOrigin int origin) {
+ private void postApplyDeviceEffects(@ConfigOrigin int origin) {
removeMessages(MSG_APPLY_EFFECTS);
sendMessage(obtainMessage(MSG_APPLY_EFFECTS, origin, 0));
}
@@ -2862,7 +2883,7 @@
updateRingerAndAudio(/* shouldApplyToRinger= */ false);
break;
case MSG_APPLY_EFFECTS:
- @ConfigChangeOrigin int origin = msg.arg1;
+ @ConfigOrigin int origin = msg.arg1;
applyConsolidatedDeviceEffects(origin);
break;
}
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/DefaultDeviceEffectsApplierTest.java b/services/tests/uiservicestests/src/com/android/server/notification/DefaultDeviceEffectsApplierTest.java
index 4bea95f..7933f7a 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/DefaultDeviceEffectsApplierTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/DefaultDeviceEffectsApplierTest.java
@@ -18,8 +18,8 @@
import static android.app.UiModeManager.MODE_ATTENTION_THEME_OVERLAY_NIGHT;
import static android.app.UiModeManager.MODE_ATTENTION_THEME_OVERLAY_OFF;
-import static android.service.notification.ZenModeConfig.UPDATE_ORIGIN_APP;
-import static android.service.notification.ZenModeConfig.UPDATE_ORIGIN_USER;
+import static android.service.notification.ZenModeConfig.ORIGIN_APP;
+import static android.service.notification.ZenModeConfig.ORIGIN_USER_IN_SYSTEMUI;
import static com.google.common.truth.Truth.assertThat;
@@ -48,7 +48,6 @@
import android.os.PowerManager;
import android.platform.test.flag.junit.SetFlagsRule;
import android.service.notification.ZenDeviceEffects;
-import android.service.notification.ZenModeConfig;
import android.testing.TestableContext;
import androidx.test.InstrumentationRegistry;
@@ -78,27 +77,6 @@
@Mock UiModeManager mUiModeManager;
@Mock WallpaperManager mWallpaperManager;
- private enum ChangeOrigin {
- ORIGIN_UNKNOWN(ZenModeConfig.UPDATE_ORIGIN_UNKNOWN),
- ORIGIN_INIT(ZenModeConfig.UPDATE_ORIGIN_INIT),
- ORIGIN_INIT_USER(ZenModeConfig.UPDATE_ORIGIN_INIT_USER),
- ORIGIN_USER(ZenModeConfig.UPDATE_ORIGIN_USER),
- ORIGIN_APP(ZenModeConfig.UPDATE_ORIGIN_APP),
- ORIGIN_SYSTEM_OR_SYSTEMUI(ZenModeConfig.UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI),
- ORIGIN_RESTORE_BACKUP(ZenModeConfig.UPDATE_ORIGIN_RESTORE_BACKUP);
-
- private final int mValue;
-
- ChangeOrigin(@ZenModeConfig.ConfigChangeOrigin int value) {
- mValue = value;
- }
-
- @ZenModeConfig.ConfigChangeOrigin
- public int value() {
- return mValue;
- }
- }
-
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
@@ -123,7 +101,7 @@
.setShouldDisplayGrayscale(true)
.setShouldUseNightMode(true)
.build();
- mApplier.apply(effects, UPDATE_ORIGIN_USER);
+ mApplier.apply(effects, ORIGIN_USER_IN_SYSTEMUI);
verify(mPowerManager).suppressAmbientDisplay(anyString(), eq(true));
verify(mColorDisplayManager).setSaturationLevel(eq(0));
@@ -141,14 +119,14 @@
.setShouldDisplayGrayscale(true)
.setShouldUseNightMode(true)
.build();
- mApplier.apply(previousEffects, UPDATE_ORIGIN_USER);
+ mApplier.apply(previousEffects, ORIGIN_USER_IN_SYSTEMUI);
verify(mPowerManager).suppressAmbientDisplay(anyString(), eq(true));
verify(mColorDisplayManager).setSaturationLevel(eq(0));
verify(mWallpaperManager).setWallpaperDimAmount(eq(0.6f));
verify(mUiModeManager).setAttentionModeThemeOverlay(eq(MODE_ATTENTION_THEME_OVERLAY_NIGHT));
ZenDeviceEffects noEffects = new ZenDeviceEffects.Builder().build();
- mApplier.apply(noEffects, UPDATE_ORIGIN_USER);
+ mApplier.apply(noEffects, ORIGIN_USER_IN_SYSTEMUI);
verify(mPowerManager).suppressAmbientDisplay(anyString(), eq(false));
verify(mColorDisplayManager).setSaturationLevel(eq(100));
@@ -163,11 +141,11 @@
ZenDeviceEffects previousEffects = new ZenDeviceEffects.Builder()
.setShouldSuppressAmbientDisplay(true)
.build();
- mApplier.apply(previousEffects, UPDATE_ORIGIN_USER);
+ mApplier.apply(previousEffects, ORIGIN_USER_IN_SYSTEMUI);
verify(mPowerManager).suppressAmbientDisplay(anyString(), eq(true));
ZenDeviceEffects noEffects = new ZenDeviceEffects.Builder().build();
- mApplier.apply(noEffects, UPDATE_ORIGIN_USER);
+ mApplier.apply(noEffects, ORIGIN_USER_IN_SYSTEMUI);
verify(mPowerManager).suppressAmbientDisplay(anyString(), eq(false));
verifyZeroInteractions(mColorDisplayManager, mWallpaperManager, mUiModeManager);
@@ -186,7 +164,7 @@
.setShouldDisplayGrayscale(true)
.setShouldUseNightMode(true)
.build();
- mApplier.apply(effects, UPDATE_ORIGIN_USER);
+ mApplier.apply(effects, ORIGIN_USER_IN_SYSTEMUI);
verify(mPowerManager).suppressAmbientDisplay(anyString(), eq(true));
// (And no crash from missing services).
@@ -207,7 +185,7 @@
.setShouldDisplayGrayscale(true)
.setShouldUseNightMode(true)
.build();
- mApplier.apply(effects, UPDATE_ORIGIN_USER);
+ mApplier.apply(effects, ORIGIN_USER_IN_SYSTEMUI);
verifyNoMoreInteractions(mWallpaperManager);
}
@@ -220,7 +198,7 @@
.setShouldDimWallpaper(true)
.setShouldDisplayGrayscale(true)
.build();
- mApplier.apply(effects, UPDATE_ORIGIN_USER);
+ mApplier.apply(effects, ORIGIN_USER_IN_SYSTEMUI);
verify(mColorDisplayManager).setSaturationLevel(eq(0));
verify(mWallpaperManager).setWallpaperDimAmount(eq(0.6f));
@@ -234,12 +212,12 @@
mSetFlagsRule.enableFlags(android.app.Flags.FLAG_MODES_API);
mApplier.apply(new ZenDeviceEffects.Builder().setShouldDimWallpaper(true).build(),
- UPDATE_ORIGIN_USER);
+ ORIGIN_USER_IN_SYSTEMUI);
verify(mWallpaperManager).setWallpaperDimAmount(eq(0.6f));
// Apply a second effect and remove the first one.
mApplier.apply(new ZenDeviceEffects.Builder().setShouldDisplayGrayscale(true).build(),
- UPDATE_ORIGIN_USER);
+ ORIGIN_USER_IN_SYSTEMUI);
// Wallpaper dimming was undone, Grayscale was applied, nothing else was touched.
verify(mWallpaperManager).setWallpaperDimAmount(eq(0.0f));
@@ -259,7 +237,7 @@
when(mPowerManager.isInteractive()).thenReturn(true);
mApplier.apply(new ZenDeviceEffects.Builder().setShouldUseNightMode(true).build(),
- UPDATE_ORIGIN_APP);
+ ORIGIN_APP);
// Effect was not yet applied, but a broadcast receiver was registered.
verifyZeroInteractions(mUiModeManager);
@@ -278,7 +256,7 @@
@Test
public void apply_nightModeWithScreenOff_appliedImmediately(
- @TestParameter ChangeOrigin origin) {
+ @TestParameter ZenChangeOrigin origin) {
mSetFlagsRule.enableFlags(android.app.Flags.FLAG_MODES_API);
when(mPowerManager.isInteractive()).thenReturn(false);
@@ -292,9 +270,10 @@
}
@Test
- @TestParameters({"{origin: ORIGIN_USER}", "{origin: ORIGIN_INIT}",
- "{origin: ORIGIN_INIT_USER}"})
- public void apply_nightModeWithScreenOn_appliedImmediatelyBasedOnOrigin(ChangeOrigin origin) {
+ @TestParameters({"{origin: ORIGIN_USER_IN_SYSTEMUI}", "{origin: ORIGIN_USER_IN_APP}",
+ "{origin: ORIGIN_INIT}", "{origin: ORIGIN_INIT_USER}"})
+ public void apply_nightModeWithScreenOn_appliedImmediatelyBasedOnOrigin(
+ ZenChangeOrigin origin) {
mSetFlagsRule.enableFlags(android.app.Flags.FLAG_MODES_API);
when(mPowerManager.isInteractive()).thenReturn(true);
@@ -309,8 +288,9 @@
@Test
@TestParameters({"{origin: ORIGIN_APP}", "{origin: ORIGIN_RESTORE_BACKUP}",
- "{origin: ORIGIN_SYSTEM_OR_SYSTEMUI}", "{origin: ORIGIN_UNKNOWN}"})
- public void apply_nightModeWithScreenOn_willBeAppliedLaterBasedOnOrigin(ChangeOrigin origin) {
+ "{origin: ORIGIN_SYSTEM}", "{origin: ORIGIN_UNKNOWN}"})
+ public void apply_nightModeWithScreenOn_willBeAppliedLaterBasedOnOrigin(
+ ZenChangeOrigin origin) {
mSetFlagsRule.enableFlags(android.app.Flags.FLAG_MODES_API);
when(mPowerManager.isInteractive()).thenReturn(true);
@@ -342,7 +322,7 @@
.setShouldDisplayGrayscale(true)
.setShouldUseNightMode(true)
.build();
- mApplier.apply(effects, UPDATE_ORIGIN_USER);
+ mApplier.apply(effects, ORIGIN_USER_IN_SYSTEMUI);
// No crashes
}
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
index 1b999e4..4bb8017 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
@@ -10064,7 +10064,7 @@
// verify that zen mode helper gets passed in a package name of "android"
verify(mockZenModeHelper).addAutomaticZenRule(eq("android"), eq(rule),
- eq(ZenModeConfig.UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI), anyString(), anyInt());
+ eq(ZenModeConfig.ORIGIN_SYSTEM), anyString(), anyInt());
}
@Test
@@ -10086,7 +10086,7 @@
// verify that zen mode helper gets passed in a package name of "android"
verify(mockZenModeHelper).addAutomaticZenRule(eq("android"), eq(rule),
- eq(ZenModeConfig.UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI), anyString(), anyInt());
+ eq(ZenModeConfig.ORIGIN_SYSTEM), anyString(), anyInt());
}
@Test
@@ -10106,7 +10106,7 @@
// verify that zen mode helper gets passed in the package name from the arg, not the owner
verify(mockZenModeHelper).addAutomaticZenRule(
- eq("another.package"), eq(rule), eq(ZenModeConfig.UPDATE_ORIGIN_APP),
+ eq("another.package"), eq(rule), eq(ZenModeConfig.ORIGIN_APP),
anyString(), anyInt()); // doesn't count as a system/systemui call
}
@@ -10221,7 +10221,7 @@
mBinderService.addAutomaticZenRule(SOME_ZEN_RULE, "pkg", /* fromUser= */ true);
verify(zenModeHelper).addAutomaticZenRule(eq("pkg"), eq(SOME_ZEN_RULE),
- eq(ZenModeConfig.UPDATE_ORIGIN_USER), anyString(), anyInt());
+ eq(ZenModeConfig.ORIGIN_USER_IN_SYSTEMUI), anyString(), anyInt());
}
@Test
@@ -10233,7 +10233,7 @@
mBinderService.addAutomaticZenRule(SOME_ZEN_RULE, "pkg", /* fromUser= */ false);
verify(zenModeHelper).addAutomaticZenRule(eq("pkg"), eq(SOME_ZEN_RULE),
- eq(ZenModeConfig.UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI), anyString(), anyInt());
+ eq(ZenModeConfig.ORIGIN_SYSTEM), anyString(), anyInt());
}
@Test
@@ -10245,7 +10245,7 @@
mBinderService.addAutomaticZenRule(SOME_ZEN_RULE, "pkg", /* fromUser= */ false);
verify(zenModeHelper).addAutomaticZenRule(eq("pkg"), eq(SOME_ZEN_RULE),
- eq(ZenModeConfig.UPDATE_ORIGIN_APP), anyString(), anyInt());
+ eq(ZenModeConfig.ORIGIN_APP), anyString(), anyInt());
}
@Test
@@ -10267,7 +10267,7 @@
mBinderService.updateAutomaticZenRule("id", SOME_ZEN_RULE, /* fromUser= */ true);
verify(zenModeHelper).updateAutomaticZenRule(eq("id"), eq(SOME_ZEN_RULE),
- eq(ZenModeConfig.UPDATE_ORIGIN_USER), anyString(), anyInt());
+ eq(ZenModeConfig.ORIGIN_USER_IN_SYSTEMUI), anyString(), anyInt());
}
@Test
@@ -10289,7 +10289,7 @@
mBinderService.removeAutomaticZenRule("id", /* fromUser= */ true);
verify(zenModeHelper).removeAutomaticZenRule(eq("id"),
- eq(ZenModeConfig.UPDATE_ORIGIN_USER), anyString(), anyInt());
+ eq(ZenModeConfig.ORIGIN_USER_IN_SYSTEMUI), anyString(), anyInt());
}
@Test
@@ -10304,7 +10304,8 @@
@Test
@EnableFlags(android.app.Flags.FLAG_MODES_API)
- public void setAutomaticZenRuleState_conditionFromUser_mappedToOriginUser() throws Exception {
+ public void setAutomaticZenRuleState_fromAppWithConditionFromUser_originUserInApp()
+ throws Exception {
ZenModeHelper zenModeHelper = setUpMockZenTest();
mService.setCallerIsNormalPackage();
@@ -10313,12 +10314,12 @@
mBinderService.setAutomaticZenRuleState("id", withSourceUser);
verify(zenModeHelper).setAutomaticZenRuleState(eq("id"), eq(withSourceUser),
- eq(ZenModeConfig.UPDATE_ORIGIN_USER), anyInt());
+ eq(ZenModeConfig.ORIGIN_USER_IN_APP), anyInt());
}
@Test
@EnableFlags(android.app.Flags.FLAG_MODES_API)
- public void setAutomaticZenRuleState_fromAppWithConditionNotFromUser_mappedToOriginApp()
+ public void setAutomaticZenRuleState_fromAppWithConditionNotFromUser_originApp()
throws Exception {
ZenModeHelper zenModeHelper = setUpMockZenTest();
mService.setCallerIsNormalPackage();
@@ -10328,12 +10329,26 @@
mBinderService.setAutomaticZenRuleState("id", withSourceContext);
verify(zenModeHelper).setAutomaticZenRuleState(eq("id"), eq(withSourceContext),
- eq(ZenModeConfig.UPDATE_ORIGIN_APP), anyInt());
+ eq(ZenModeConfig.ORIGIN_APP), anyInt());
}
@Test
@EnableFlags(android.app.Flags.FLAG_MODES_API)
- public void setAutomaticZenRuleState_fromSystemWithConditionNotFromUser_mappedToOriginSystem()
+ public void setAutomaticZenRuleState_fromSystemWithConditionFromUser_originUserInSystemUi()
+ throws Exception {
+ ZenModeHelper zenModeHelper = setUpMockZenTest();
+ mService.isSystemUid = true;
+
+ Condition withSourceContext = new Condition(Uri.parse("uri"), "summary", STATE_TRUE,
+ SOURCE_USER_ACTION);
+ mBinderService.setAutomaticZenRuleState("id", withSourceContext);
+
+ verify(zenModeHelper).setAutomaticZenRuleState(eq("id"), eq(withSourceContext),
+ eq(ZenModeConfig.ORIGIN_USER_IN_SYSTEMUI), anyInt());
+ }
+ @Test
+ @EnableFlags(android.app.Flags.FLAG_MODES_API)
+ public void setAutomaticZenRuleState_fromSystemWithConditionNotFromUser_originSystem()
throws Exception {
ZenModeHelper zenModeHelper = setUpMockZenTest();
mService.isSystemUid = true;
@@ -10343,7 +10358,7 @@
mBinderService.setAutomaticZenRuleState("id", withSourceContext);
verify(zenModeHelper).setAutomaticZenRuleState(eq("id"), eq(withSourceContext),
- eq(ZenModeConfig.UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI), anyInt());
+ eq(ZenModeConfig.ORIGIN_SYSTEM), anyInt());
}
/** Prepares for a zen-related test that uses a mocked {@link ZenModeHelper}. */
@@ -15508,7 +15523,7 @@
mBinderService.setInterruptionFilter("package", INTERRUPTION_FILTER_PRIORITY, false);
verify(zenModeHelper).setManualZenMode(eq(ZEN_MODE_IMPORTANT_INTERRUPTIONS), eq(null),
- eq(ZenModeConfig.UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI), anyString(), eq("package"),
+ eq(ZenModeConfig.ORIGIN_SYSTEM), anyString(), eq("package"),
anyInt());
}
@@ -15554,7 +15569,7 @@
if (canSetGlobalPolicy) {
verify(zenModeHelper).setManualZenMode(eq(ZEN_MODE_IMPORTANT_INTERRUPTIONS), eq(null),
- eq(ZenModeConfig.UPDATE_ORIGIN_APP), anyString(), eq("package"), anyInt());
+ eq(ZenModeConfig.ORIGIN_APP), anyString(), eq("package"), anyInt());
} else {
verify(zenModeHelper).applyGlobalZenModeAsImplicitZenRule(anyString(), anyInt(),
eq(ZEN_MODE_IMPORTANT_INTERRUPTIONS));
@@ -15594,7 +15609,7 @@
INTERRUPTION_FILTER_PRIORITY);
verify(mService.mZenModeHelper).setManualZenMode(eq(ZEN_MODE_IMPORTANT_INTERRUPTIONS),
- eq(null), eq(ZenModeConfig.UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI), anyString(),
+ eq(null), eq(ZenModeConfig.ORIGIN_SYSTEM), anyString(),
eq("pkg"), eq(mUid));
}
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/ZenChangeOrigin.java b/services/tests/uiservicestests/src/com/android/server/notification/ZenChangeOrigin.java
new file mode 100644
index 0000000..5728788
--- /dev/null
+++ b/services/tests/uiservicestests/src/com/android/server/notification/ZenChangeOrigin.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.notification;
+
+import android.service.notification.ZenModeConfig;
+
+/** Enum version of {@link ZenModeConfig.ConfigOrigin}, for test parameterization. */
+public enum ZenChangeOrigin {
+ ORIGIN_UNKNOWN(ZenModeConfig.ORIGIN_UNKNOWN),
+ ORIGIN_INIT(ZenModeConfig.ORIGIN_INIT),
+ ORIGIN_INIT_USER(ZenModeConfig.ORIGIN_INIT_USER),
+ ORIGIN_APP(ZenModeConfig.ORIGIN_APP),
+ ORIGIN_USER_IN_APP(ZenModeConfig.ORIGIN_USER_IN_APP),
+ ORIGIN_SYSTEM(ZenModeConfig.ORIGIN_SYSTEM),
+ ORIGIN_USER_IN_SYSTEMUI(ZenModeConfig.ORIGIN_USER_IN_SYSTEMUI),
+ ORIGIN_RESTORE_BACKUP(ZenModeConfig.ORIGIN_RESTORE_BACKUP);
+
+ private final int mValue;
+
+ ZenChangeOrigin(@ZenModeConfig.ConfigOrigin int value) {
+ mValue = value;
+ }
+
+ /** Gets the {@link ZenModeConfig.ConfigOrigin} int value corresponding to the enum. */
+ @ZenModeConfig.ConfigOrigin
+ public int value() {
+ return mValue;
+ }
+}
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/ZenEnumTest.java b/services/tests/uiservicestests/src/com/android/server/notification/ZenEnumTest.java
index 8add2f9..cdceb1f 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/ZenEnumTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/ZenEnumTest.java
@@ -20,12 +20,14 @@
import android.app.AutomaticZenRule;
import android.provider.Settings;
+import android.service.notification.ZenModeConfig;
import android.service.notification.ZenPolicy;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
import com.android.os.dnd.ActiveRuleType;
+import com.android.os.dnd.ChangeOrigin;
import com.android.os.dnd.ChannelPolicy;
import com.android.os.dnd.ConversationType;
import com.android.os.dnd.PeopleType;
@@ -78,6 +80,11 @@
testEnum(ZenPolicy.class, "PEOPLE_TYPE", PeopleType.class, "PEOPLE");
}
+ @Test
+ public void testEnum_changeOrigin() {
+ testEnum(ZenModeConfig.class, "ORIGIN", ChangeOrigin.class, "ORIGIN");
+ }
+
/**
* Verifies that any constants (i.e. {@code public static final int} fields) named {@code
* <apiPrefix>_SOMETHING} in {@code apiClass} are present and have the same numerical value
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/ZenModeConfigTest.java b/services/tests/uiservicestests/src/com/android/server/notification/ZenModeConfigTest.java
index 3c3c2f3..b955a79 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/ZenModeConfigTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/ZenModeConfigTest.java
@@ -535,7 +535,7 @@
rule.triggerDescription = TRIGGER_DESC;
rule.deletionInstant = Instant.ofEpochMilli(1701790147000L);
if (Flags.modesUi()) {
- rule.disabledOrigin = ZenModeConfig.UPDATE_ORIGIN_USER;
+ rule.disabledOrigin = ZenModeConfig.ORIGIN_USER_IN_SYSTEMUI;
}
Parcel parcel = Parcel.obtain();
@@ -650,7 +650,7 @@
rule.triggerDescription = TRIGGER_DESC;
rule.deletionInstant = Instant.ofEpochMilli(1701790147000L);
if (Flags.modesUi()) {
- rule.disabledOrigin = ZenModeConfig.UPDATE_ORIGIN_APP;
+ rule.disabledOrigin = ZenModeConfig.ORIGIN_APP;
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/ZenModeHelperTest.java b/services/tests/uiservicestests/src/com/android/server/notification/ZenModeHelperTest.java
index d7bae45..63cf106 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/ZenModeHelperTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/ZenModeHelperTest.java
@@ -46,6 +46,7 @@
import static android.app.NotificationManager.Policy.STATE_PRIORITY_CHANNELS_BLOCKED;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_BADGE;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
+import static android.os.Process.SYSTEM_UID;
import static android.provider.Settings.Global.ZEN_MODE_ALARMS;
import static android.provider.Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS;
import static android.provider.Settings.Global.ZEN_MODE_NO_INTERRUPTIONS;
@@ -54,12 +55,12 @@
import static android.service.notification.Condition.SOURCE_USER_ACTION;
import static android.service.notification.Condition.STATE_FALSE;
import static android.service.notification.Condition.STATE_TRUE;
-import static android.service.notification.ZenModeConfig.UPDATE_ORIGIN_APP;
-import static android.service.notification.ZenModeConfig.UPDATE_ORIGIN_INIT;
-import static android.service.notification.ZenModeConfig.UPDATE_ORIGIN_INIT_USER;
-import static android.service.notification.ZenModeConfig.UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI;
-import static android.service.notification.ZenModeConfig.UPDATE_ORIGIN_UNKNOWN;
-import static android.service.notification.ZenModeConfig.UPDATE_ORIGIN_USER;
+import static android.service.notification.ZenModeConfig.ORIGIN_APP;
+import static android.service.notification.ZenModeConfig.ORIGIN_INIT;
+import static android.service.notification.ZenModeConfig.ORIGIN_INIT_USER;
+import static android.service.notification.ZenModeConfig.ORIGIN_UNKNOWN;
+import static android.service.notification.ZenModeConfig.ORIGIN_USER_IN_APP;
+import static android.service.notification.ZenModeConfig.ORIGIN_USER_IN_SYSTEMUI;
import static android.service.notification.ZenPolicy.PEOPLE_TYPE_CONTACTS;
import static android.service.notification.ZenPolicy.PEOPLE_TYPE_NONE;
import static android.service.notification.ZenPolicy.PEOPLE_TYPE_STARRED;
@@ -131,7 +132,6 @@
import android.media.VolumePolicy;
import android.net.Uri;
import android.os.Parcel;
-import android.os.Process;
import android.os.SimpleClock;
import android.os.UserHandle;
import android.platform.test.annotations.DisableFlags;
@@ -186,9 +186,6 @@
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;
@@ -208,6 +205,9 @@
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)
@@ -338,27 +338,6 @@
mZenModeEventLogger.reset();
}
- private enum ChangeOrigin {
- ORIGIN_UNKNOWN(ZenModeConfig.UPDATE_ORIGIN_UNKNOWN),
- ORIGIN_INIT(ZenModeConfig.UPDATE_ORIGIN_INIT),
- ORIGIN_INIT_USER(ZenModeConfig.UPDATE_ORIGIN_INIT_USER),
- ORIGIN_USER(ZenModeConfig.UPDATE_ORIGIN_USER),
- ORIGIN_APP(ZenModeConfig.UPDATE_ORIGIN_APP),
- ORIGIN_SYSTEM_OR_SYSTEMUI(ZenModeConfig.UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI),
- ORIGIN_RESTORE_BACKUP(ZenModeConfig.UPDATE_ORIGIN_RESTORE_BACKUP);
-
- private final int mValue;
-
- ChangeOrigin(@ZenModeConfig.ConfigChangeOrigin int value) {
- mValue = value;
- }
-
- @ZenModeConfig.ConfigChangeOrigin
- public int value() {
- return mValue;
- }
- }
-
private XmlResourceParser getDefaultConfigParser() throws IOException, XmlPullParserException {
String xml = "<zen version=\"10\">\n"
+ "<allow alarms=\"true\" media=\"true\" system=\"false\" calls=\"true\" "
@@ -395,8 +374,8 @@
mZenModeHelper.writeXml(serializer, false, version, UserHandle.USER_ALL);
serializer.endDocument();
serializer.flush();
- mZenModeHelper.setConfig(new ZenModeConfig(), null, UPDATE_ORIGIN_INIT, "writing xml",
- Process.SYSTEM_UID);
+ mZenModeHelper.setConfig(new ZenModeConfig(), null, ORIGIN_INIT, "writing xml",
+ SYSTEM_UID);
return baos;
}
@@ -411,8 +390,8 @@
serializer.flush();
ZenModeConfig newConfig = new ZenModeConfig();
newConfig.user = userId;
- mZenModeHelper.setConfig(newConfig, null, UPDATE_ORIGIN_INIT, "writing xml",
- Process.SYSTEM_UID);
+ mZenModeHelper.setConfig(newConfig, null, ORIGIN_INIT, "writing xml",
+ SYSTEM_UID);
return baos;
}
@@ -705,13 +684,13 @@
.setInterruptionFilter(INTERRUPTION_FILTER_NONE)
.build();
String ruleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(),
- azr, UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "reason", Process.SYSTEM_UID);
+ azr, ZenModeConfig.ORIGIN_SYSTEM, "reason", SYSTEM_UID);
// Enable rule
mZenModeHelper.setAutomaticZenRuleState(ruleId,
new Condition(azr.getConditionId(), "", STATE_TRUE),
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI,
- Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM,
+ SYSTEM_UID);
// Confirm that the consolidated policy doesn't allow anything
NotificationManager.Policy policy = mZenModeHelper.getConsolidatedNotificationPolicy();
@@ -739,13 +718,13 @@
.setInterruptionFilter(INTERRUPTION_FILTER_ALARMS)
.build();
String ruleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(),
- azr, UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "reason", Process.SYSTEM_UID);
+ azr, ZenModeConfig.ORIGIN_SYSTEM, "reason", SYSTEM_UID);
// Enable rule
mZenModeHelper.setAutomaticZenRuleState(ruleId,
new Condition(azr.getConditionId(), "", STATE_TRUE),
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI,
- Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM,
+ SYSTEM_UID);
// Confirm that the consolidated policy allows only alarms and media and nothing else
NotificationManager.Policy policy = mZenModeHelper.getConsolidatedNotificationPolicy();
@@ -819,7 +798,7 @@
when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_NORMAL);
// Set zen to priority-only with all notification sounds muted (so ringer will be muted)
Policy totalSilence = new Policy(0, 0, 0);
- mZenModeHelper.setNotificationPolicy(totalSilence, UPDATE_ORIGIN_APP, 1);
+ mZenModeHelper.setNotificationPolicy(totalSilence, ORIGIN_APP, 1);
mZenModeHelper.mZenMode = ZEN_MODE_IMPORTANT_INTERRUPTIONS;
// 2. verify ringer is unchanged
@@ -857,7 +836,7 @@
// in priority only mode:
// ringtone, notification and system streams are affected by ringer mode
mZenModeHelper.setManualZenMode(ZEN_MODE_IMPORTANT_INTERRUPTIONS, Uri.EMPTY,
- UPDATE_ORIGIN_APP, "test", "caller", 1);
+ ORIGIN_APP, "test", "caller", 1);
ZenModeHelper.RingerModeDelegate ringerModeDelegateRingerMuted =
mZenModeHelper.new RingerModeDelegate();
@@ -873,9 +852,9 @@
// even when ringer is muted (since all ringer sounds cannot bypass DND),
// system stream is still affected by ringer mode
- mZenModeHelper.setNotificationPolicy(new Policy(0, 0, 0), UPDATE_ORIGIN_APP, 1);
+ mZenModeHelper.setNotificationPolicy(new Policy(0, 0, 0), ORIGIN_APP, 1);
mZenModeHelper.setManualZenMode(ZEN_MODE_IMPORTANT_INTERRUPTIONS, Uri.EMPTY,
- UPDATE_ORIGIN_APP, "test", "caller", 1);
+ ORIGIN_APP, "test", "caller", 1);
ZenModeHelper.RingerModeDelegate ringerModeDelegateRingerNotMuted =
mZenModeHelper.new RingerModeDelegate();
@@ -983,7 +962,7 @@
when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_SILENT);
for (int i = 0; i < 3; i++) {
mZenModeHelper.setManualZenMode(ZEN_MODE_OFF, Uri.EMPTY,
- UPDATE_ORIGIN_APP, "test", "caller", 1);
+ ORIGIN_APP, "test", "caller", 1);
}
verify(mAudioManager, never()).setRingerModeInternal(AudioManager.RINGER_MODE_NORMAL,
mZenModeHelper.TAG);
@@ -1008,7 +987,7 @@
for (int i = 0; i < 3; i++) {
// if zen doesn't change, zen should not reapply itself to the ringer
mZenModeHelper.setManualZenMode(ZEN_MODE_OFF, Uri.EMPTY,
- UPDATE_ORIGIN_APP, "test", "caller", 1);
+ ORIGIN_APP, "test", "caller", 1);
}
verify(mAudioManager, never()).setRingerModeInternal(AudioManager.RINGER_MODE_NORMAL,
mZenModeHelper.TAG);
@@ -1033,7 +1012,7 @@
for (int i = 0; i < 3; i++) {
// if zen doesn't change, zen should not reapply itself to the ringer
mZenModeHelper.setManualZenMode(ZEN_MODE_OFF, Uri.EMPTY,
- UPDATE_ORIGIN_APP, "test", "caller", 1);
+ ORIGIN_APP, "test", "caller", 1);
}
verify(mAudioManager, never()).setRingerModeInternal(AudioManager.RINGER_MODE_NORMAL,
mZenModeHelper.TAG);
@@ -1048,7 +1027,8 @@
reset(mAudioManager);
// Turn manual zen mode on
- mZenModeHelper.setManualZenMode(ZEN_MODE_IMPORTANT_INTERRUPTIONS, null, UPDATE_ORIGIN_APP,
+ mZenModeHelper.setManualZenMode(ZEN_MODE_IMPORTANT_INTERRUPTIONS, null,
+ ORIGIN_APP,
null, "test", CUSTOM_PKG_UID);
// audio manager shouldn't do anything until the handler processes its messages
@@ -1076,14 +1056,14 @@
mZenModeHelper.setManualZenMode(
ZEN_MODE_IMPORTANT_INTERRUPTIONS,
null,
- UPDATE_ORIGIN_APP,
+ ORIGIN_APP,
null,
"test",
CUSTOM_PKG_UID);
mZenModeHelper.setManualZenMode(
ZEN_MODE_IMPORTANT_INTERRUPTIONS,
null,
- UPDATE_ORIGIN_APP,
+ ORIGIN_APP,
null,
"test",
CUSTOM_PKG_UID);
@@ -1108,15 +1088,15 @@
| PRIORITY_CATEGORY_MESSAGES | PRIORITY_CATEGORY_REPEAT_CALLERS
| PRIORITY_CATEGORY_CONVERSATIONS, PRIORITY_SENDERS_STARRED,
PRIORITY_SENDERS_STARRED, 0, CONVERSATION_SENDERS_ANYONE),
- UPDATE_ORIGIN_UNKNOWN,
+ ORIGIN_UNKNOWN,
1);
mZenModeHelper.setManualZenRuleDeviceEffects(new ZenDeviceEffects.Builder()
.setShouldDimWallpaper(true)
.setShouldDisplayGrayscale(true)
.setShouldUseNightMode(true)
- .build(), UPDATE_ORIGIN_UNKNOWN, "test", 1);
+ .build(), ORIGIN_UNKNOWN, "test", 1);
mZenModeHelper.setManualZenMode(ZEN_MODE_IMPORTANT_INTERRUPTIONS, Uri.EMPTY,
- UPDATE_ORIGIN_UNKNOWN, "test", "me", 1);
+ ORIGIN_UNKNOWN, "test", "me", 1);
ZenModeConfig actual = mZenModeHelper.mConfig.copy();
@@ -1130,13 +1110,13 @@
| PRIORITY_CATEGORY_CONVERSATIONS, PRIORITY_SENDERS_STARRED,
PRIORITY_SENDERS_STARRED, SUPPRESSED_EFFECT_BADGE,
CONVERSATION_SENDERS_ANYONE),
- UPDATE_ORIGIN_UNKNOWN, 1);
+ ORIGIN_UNKNOWN, 1);
mZenModeHelper.setManualZenRuleDeviceEffects(new ZenDeviceEffects.Builder()
.setShouldDimWallpaper(true)
.setShouldDisplayGrayscale(true)
- .build(), UPDATE_ORIGIN_UNKNOWN, "test", 1);
+ .build(), ORIGIN_UNKNOWN, "test", 1);
mZenModeHelper.setManualZenMode(ZEN_MODE_IMPORTANT_INTERRUPTIONS, Uri.EMPTY,
- UPDATE_ORIGIN_UNKNOWN, "test", "me", 1);
+ ORIGIN_UNKNOWN, "test", "me", 1);
ZenModeConfig expected = mZenModeHelper.mConfig.copy();
if (Flags.modesUi()) {
@@ -1157,7 +1137,7 @@
@Test
public void testProto() throws InvalidProtocolBufferException {
mZenModeHelper.setManualZenMode(ZEN_MODE_IMPORTANT_INTERRUPTIONS, null,
- Flags.modesApi() ? UPDATE_ORIGIN_USER : UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI,
+ Flags.modesApi() ? ORIGIN_USER_IN_SYSTEMUI : ZenModeConfig.ORIGIN_SYSTEM,
null, "test", CUSTOM_PKG_UID);
mZenModeHelper.mConfig.automaticRules = new ArrayMap<>(); // no automatic rules
@@ -1381,7 +1361,7 @@
List<StatsEvent> events = new LinkedList<>();
mZenModeHelper.pullRules(events);
- mZenModeHelper.removeAutomaticZenRule(CUSTOM_RULE_ID, UPDATE_ORIGIN_APP, "test",
+ mZenModeHelper.removeAutomaticZenRule(CUSTOM_RULE_ID, ORIGIN_APP, "test",
CUSTOM_PKG_UID);
assertTrue(-1
== mZenModeHelper.mRulesUidCache.getOrDefault(CUSTOM_PKG_NAME + "|" + 0, -1));
@@ -1410,7 +1390,8 @@
public void testProtoWithManualRule() throws Exception {
setupZenConfig();
mZenModeHelper.mConfig.automaticRules = getCustomAutomaticRules();
- mZenModeHelper.setManualZenMode(INTERRUPTION_FILTER_PRIORITY, Uri.EMPTY, UPDATE_ORIGIN_APP,
+ mZenModeHelper.setManualZenMode(INTERRUPTION_FILTER_PRIORITY, Uri.EMPTY,
+ ORIGIN_APP,
"test", "me", 1);
List<StatsEvent> events = new LinkedList<>();
@@ -1437,14 +1418,14 @@
Policy policy = new Policy(PRIORITY_CATEGORY_MEDIA | PRIORITY_CATEGORY_ALARMS, 0, 0);
config10.applyNotificationPolicy(policy);
config10.user = 10;
- mZenModeHelper.setConfig(config10, null, UPDATE_ORIGIN_INIT, "writeXml",
- Process.SYSTEM_UID);
+ mZenModeHelper.setConfig(config10, null, ORIGIN_INIT, "writeXml",
+ SYSTEM_UID);
ZenModeConfig config11 = mZenModeHelper.mConfig.copy();
config11.user = 11;
policy = new Policy(0, 0, 0);
config11.applyNotificationPolicy(policy);
- mZenModeHelper.setConfig(config11, null, UPDATE_ORIGIN_INIT, "writeXml",
- Process.SYSTEM_UID);
+ mZenModeHelper.setConfig(config11, null, ORIGIN_INIT, "writeXml",
+ SYSTEM_UID);
// Backup user 10 and reset values.
ByteArrayOutputStream baos = writeXmlAndPurgeForUser(null, 10);
@@ -2307,7 +2288,7 @@
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
// We need the package name to be something that's not "android" so there aren't any
// existing rules under that package.
- String id = mZenModeHelper.addAutomaticZenRule("pkgname", zenRule, UPDATE_ORIGIN_APP,
+ String id = mZenModeHelper.addAutomaticZenRule("pkgname", zenRule, ORIGIN_APP,
"test", CUSTOM_PKG_UID);
assertNotNull(id);
}
@@ -2318,7 +2299,7 @@
ZenModeConfig.toScheduleConditionId(new ScheduleInfo()),
new ZenPolicy.Builder().build(),
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
- String id = mZenModeHelper.addAutomaticZenRule("pkgname", zenRule, UPDATE_ORIGIN_APP,
+ String id = mZenModeHelper.addAutomaticZenRule("pkgname", zenRule, ORIGIN_APP,
"test", CUSTOM_PKG_UID);
fail("allowed too many rules to be created");
} catch (IllegalArgumentException e) {
@@ -2339,7 +2320,7 @@
ZenModeConfig.toScheduleConditionId(si),
new ZenPolicy.Builder().build(),
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
- String id = mZenModeHelper.addAutomaticZenRule("pkgname", zenRule, UPDATE_ORIGIN_APP,
+ String id = mZenModeHelper.addAutomaticZenRule("pkgname", zenRule, ORIGIN_APP,
"test", CUSTOM_PKG_UID);
assertNotNull(id);
}
@@ -2350,7 +2331,7 @@
ZenModeConfig.toScheduleConditionId(new ScheduleInfo()),
new ZenPolicy.Builder().build(),
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
- String id = mZenModeHelper.addAutomaticZenRule("pkgname", zenRule, UPDATE_ORIGIN_APP,
+ String id = mZenModeHelper.addAutomaticZenRule("pkgname", zenRule, ORIGIN_APP,
"test", CUSTOM_PKG_UID);
fail("allowed too many rules to be created");
} catch (IllegalArgumentException e) {
@@ -2371,7 +2352,7 @@
ZenModeConfig.toScheduleConditionId(si),
new ZenPolicy.Builder().build(),
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
- String id = mZenModeHelper.addAutomaticZenRule("pkgname", zenRule, UPDATE_ORIGIN_APP,
+ String id = mZenModeHelper.addAutomaticZenRule("pkgname", zenRule, ORIGIN_APP,
"test", CUSTOM_PKG_UID);
assertNotNull(id);
}
@@ -2382,7 +2363,7 @@
ZenModeConfig.toScheduleConditionId(new ScheduleInfo()),
new ZenPolicy.Builder().build(),
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
- String id = mZenModeHelper.addAutomaticZenRule("pkgname", zenRule, UPDATE_ORIGIN_APP,
+ String id = mZenModeHelper.addAutomaticZenRule("pkgname", zenRule, ORIGIN_APP,
"test", CUSTOM_PKG_UID);
fail("allowed too many rules to be created");
} catch (IllegalArgumentException e) {
@@ -2399,7 +2380,7 @@
new ZenPolicy.Builder().build(),
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
String id = mZenModeHelper.addAutomaticZenRule("android", zenRule,
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "test", Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, "test", SYSTEM_UID);
assertTrue(id != null);
ZenModeConfig.ZenRule ruleInConfig = mZenModeHelper.mConfig.automaticRules.get(id);
@@ -2420,7 +2401,7 @@
ZenModeConfig.toScheduleConditionId(new ScheduleInfo()),
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
String id = mZenModeHelper.addAutomaticZenRule("android", zenRule,
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "test", Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, "test", SYSTEM_UID);
assertTrue(id != null);
ZenModeConfig.ZenRule ruleInConfig = mZenModeHelper.mConfig.automaticRules.get(id);
@@ -2446,7 +2427,7 @@
ZenModeConfig.toScheduleConditionId(new ScheduleInfo()),
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
String id1 = mZenModeHelper.addAutomaticZenRule("android", zenRule1,
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "test", Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, "test", SYSTEM_UID);
// Zen rule with partially-filled policy: should get all of the filled fields set, and the
// rest filled with default state
@@ -2461,7 +2442,7 @@
.build(),
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
String id2 = mZenModeHelper.addAutomaticZenRule("android", zenRule2,
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "test", Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, "test", SYSTEM_UID);
// rule 1 should exist
assertThat(id1).isNotNull();
@@ -2506,11 +2487,11 @@
new ZenPolicy.Builder().build(),
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
- String id = mZenModeHelper.addAutomaticZenRule(null, zenRule, UPDATE_ORIGIN_APP, "test",
+ String id = mZenModeHelper.addAutomaticZenRule(null, zenRule, ORIGIN_APP, "test",
CUSTOM_PKG_UID);
mZenModeHelper.setAutomaticZenRuleState(zenRule.getConditionId(),
new Condition(zenRule.getConditionId(), "", STATE_TRUE),
- UPDATE_ORIGIN_APP,
+ ORIGIN_APP,
CUSTOM_PKG_UID);
ZenModeConfig.ZenRule ruleInConfig = mZenModeHelper.mConfig.automaticRules.get(id);
@@ -2526,7 +2507,7 @@
new ZenPolicy.Builder().build(),
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
- String id = mZenModeHelper.addAutomaticZenRule(null, zenRule, UPDATE_ORIGIN_APP, "test",
+ String id = mZenModeHelper.addAutomaticZenRule(null, zenRule, ORIGIN_APP, "test",
CUSTOM_PKG_UID);
AutomaticZenRule zenRule2 = new AutomaticZenRule("NEW",
@@ -2536,7 +2517,7 @@
new ZenPolicy.Builder().build(),
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
- mZenModeHelper.updateAutomaticZenRule(id, zenRule2, UPDATE_ORIGIN_APP, "", CUSTOM_PKG_UID);
+ mZenModeHelper.updateAutomaticZenRule(id, zenRule2, ORIGIN_APP, "", CUSTOM_PKG_UID);
ZenModeConfig.ZenRule ruleInConfig = mZenModeHelper.mConfig.automaticRules.get(id);
assertEquals("NEW", ruleInConfig.name);
@@ -2551,7 +2532,7 @@
new ZenPolicy.Builder().build(),
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
- String id = mZenModeHelper.addAutomaticZenRule(null, zenRule, UPDATE_ORIGIN_APP, "test",
+ String id = mZenModeHelper.addAutomaticZenRule(null, zenRule, ORIGIN_APP, "test",
CUSTOM_PKG_UID);
assertTrue(id != null);
@@ -2559,7 +2540,7 @@
assertTrue(ruleInConfig != null);
assertEquals(zenRule.getName(), ruleInConfig.name);
- mZenModeHelper.removeAutomaticZenRule(id, UPDATE_ORIGIN_APP, "test", CUSTOM_PKG_UID);
+ mZenModeHelper.removeAutomaticZenRule(id, ORIGIN_APP, "test", CUSTOM_PKG_UID);
assertNull(mZenModeHelper.mConfig.automaticRules.get(id));
}
@@ -2571,7 +2552,7 @@
ZenModeConfig.toScheduleConditionId(new ScheduleInfo()),
new ZenPolicy.Builder().build(),
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
- String id = mZenModeHelper.addAutomaticZenRule(null, zenRule, UPDATE_ORIGIN_APP, "test",
+ String id = mZenModeHelper.addAutomaticZenRule(null, zenRule, ORIGIN_APP, "test",
CUSTOM_PKG_UID);
assertTrue(id != null);
@@ -2579,7 +2560,7 @@
assertTrue(ruleInConfig != null);
assertEquals(zenRule.getName(), ruleInConfig.name);
- mZenModeHelper.removeAutomaticZenRules(mContext.getPackageName(), UPDATE_ORIGIN_APP, "test",
+ mZenModeHelper.removeAutomaticZenRules(mContext.getPackageName(), ORIGIN_APP, "test",
CUSTOM_PKG_UID);
assertNull(mZenModeHelper.mConfig.automaticRules.get(id));
}
@@ -2596,17 +2577,17 @@
sharedUri,
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
String id = mZenModeHelper.addAutomaticZenRule(mPkg, zenRule,
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "test", Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, "test", SYSTEM_UID);
AutomaticZenRule zenRule2 = new AutomaticZenRule("name2",
new ComponentName(mPkg, "ScheduleConditionProvider"),
sharedUri,
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
String id2 = mZenModeHelper.addAutomaticZenRule(mPkg, zenRule2,
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "test", Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, "test", SYSTEM_UID);
Condition condition = new Condition(sharedUri, "", STATE_TRUE);
mZenModeHelper.setAutomaticZenRuleState(sharedUri, condition,
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, SYSTEM_UID);
for (ZenModeConfig.ZenRule rule : mZenModeHelper.mConfig.automaticRules.values()) {
if (rule.id.equals(id)) {
@@ -2621,7 +2602,7 @@
condition = new Condition(sharedUri, "", STATE_FALSE);
mZenModeHelper.setAutomaticZenRuleState(sharedUri, condition,
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, SYSTEM_UID);
for (ZenModeConfig.ZenRule rule : mZenModeHelper.mConfig.automaticRules.values()) {
if (rule.id.equals(id)) {
@@ -2656,7 +2637,7 @@
.setOwner(OWNER)
.setDeviceEffects(zde)
.build(),
- UPDATE_ORIGIN_APP, "reasons", 0);
+ ORIGIN_APP, "reasons", 0);
AutomaticZenRule savedRule = mZenModeHelper.getAutomaticZenRule(ruleId);
assertThat(savedRule.getDeviceEffects()).isEqualTo(
@@ -2689,7 +2670,7 @@
.setOwner(OWNER)
.setDeviceEffects(zde)
.build(),
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "reasons", 0);
+ ZenModeConfig.ORIGIN_SYSTEM, "reasons", 0);
AutomaticZenRule savedRule = mZenModeHelper.getAutomaticZenRule(ruleId);
assertThat(savedRule.getDeviceEffects()).isEqualTo(zde);
@@ -2716,7 +2697,7 @@
.setOwner(OWNER)
.setDeviceEffects(zde)
.build(),
- UPDATE_ORIGIN_USER,
+ ORIGIN_USER_IN_SYSTEMUI,
"reasons", 0);
AutomaticZenRule savedRule = mZenModeHelper.getAutomaticZenRule(ruleId);
@@ -2736,7 +2717,7 @@
.setOwner(OWNER)
.setDeviceEffects(original)
.build(),
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "reasons", 0);
+ ZenModeConfig.ORIGIN_SYSTEM, "reasons", 0);
ZenDeviceEffects updateFromApp = new ZenDeviceEffects.Builder()
.setShouldUseNightMode(true) // Good
@@ -2748,7 +2729,7 @@
.setOwner(OWNER)
.setDeviceEffects(updateFromApp)
.build(),
- UPDATE_ORIGIN_APP, "reasons", 0);
+ ORIGIN_APP, "reasons", 0);
AutomaticZenRule savedRule = mZenModeHelper.getAutomaticZenRule(ruleId);
assertThat(savedRule.getDeviceEffects()).isEqualTo(
@@ -2770,7 +2751,7 @@
.setOwner(OWNER)
.setDeviceEffects(original)
.build(),
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "reasons", 0);
+ ZenModeConfig.ORIGIN_SYSTEM, "reasons", 0);
ZenDeviceEffects updateFromSystem = new ZenDeviceEffects.Builder()
.setShouldUseNightMode(true) // Good
@@ -2780,7 +2761,7 @@
new AutomaticZenRule.Builder("Rule", CONDITION_ID)
.setDeviceEffects(updateFromSystem)
.build(),
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "reasons", 0);
+ ZenModeConfig.ORIGIN_SYSTEM, "reasons", 0);
AutomaticZenRule savedRule = mZenModeHelper.getAutomaticZenRule(ruleId);
assertThat(savedRule.getDeviceEffects()).isEqualTo(updateFromSystem);
@@ -2797,7 +2778,7 @@
.setOwner(OWNER)
.setDeviceEffects(original)
.build(),
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "reasons", 0);
+ ZenModeConfig.ORIGIN_SYSTEM, "reasons", 0);
ZenDeviceEffects updateFromUser = new ZenDeviceEffects.Builder()
.setShouldUseNightMode(true)
@@ -2810,7 +2791,7 @@
new AutomaticZenRule.Builder("Rule", CONDITION_ID)
.setDeviceEffects(updateFromUser)
.build(),
- UPDATE_ORIGIN_USER, "reasons", 0);
+ ORIGIN_USER_IN_SYSTEMUI, "reasons", 0);
AutomaticZenRule savedRule = mZenModeHelper.getAutomaticZenRule(ruleId);
@@ -2829,13 +2810,13 @@
.allowCalls(ZenPolicy.PEOPLE_TYPE_NONE) // default is stars
.build())
.build(),
- UPDATE_ORIGIN_APP, "reasons", 0);
+ ORIGIN_APP, "reasons", 0);
mZenModeHelper.updateAutomaticZenRule(ruleId,
new AutomaticZenRule.Builder("Rule", CONDITION_ID)
// no zen policy
.build(),
- UPDATE_ORIGIN_APP, "reasons", 0);
+ ORIGIN_APP, "reasons", 0);
AutomaticZenRule savedRule = mZenModeHelper.getAutomaticZenRule(ruleId);
assertThat(savedRule.getZenPolicy().getPriorityCategoryCalls())
@@ -2857,7 +2838,7 @@
.allowReminders(true)
.build())
.build(),
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "reasons", 0);
+ ZenModeConfig.ORIGIN_SYSTEM, "reasons", 0);
mZenModeHelper.updateAutomaticZenRule(ruleId,
new AutomaticZenRule.Builder("Rule", CONDITION_ID)
@@ -2865,7 +2846,7 @@
.allowCalls(ZenPolicy.PEOPLE_TYPE_CONTACTS)
.build())
.build(),
- UPDATE_ORIGIN_APP, "reasons", 0);
+ ORIGIN_APP, "reasons", 0);
AutomaticZenRule savedRule = mZenModeHelper.getAutomaticZenRule(ruleId);
assertThat(savedRule.getZenPolicy().getPriorityCategoryCalls())
@@ -2893,7 +2874,8 @@
AutomaticZenRule bedtime = new AutomaticZenRule.Builder("Bedtime Mode (TM)", CONDITION_ID)
.setType(TYPE_BEDTIME)
.build();
- String bedtimeRuleId = mZenModeHelper.addAutomaticZenRule("pkg", bedtime, UPDATE_ORIGIN_APP,
+ String bedtimeRuleId = mZenModeHelper.addAutomaticZenRule("pkg", bedtime,
+ ORIGIN_APP,
"reason", CUSTOM_PKG_UID);
assertThat(mZenModeHelper.mConfig.automaticRules.keySet()).containsExactly(bedtimeRuleId);
@@ -2913,7 +2895,8 @@
AutomaticZenRule bedtime = new AutomaticZenRule.Builder("Bedtime Mode (TM)", CONDITION_ID)
.setType(TYPE_BEDTIME)
.build();
- String bedtimeRuleId = mZenModeHelper.addAutomaticZenRule("pkg", bedtime, UPDATE_ORIGIN_APP,
+ String bedtimeRuleId = mZenModeHelper.addAutomaticZenRule("pkg", bedtime,
+ ORIGIN_APP,
"reason", CUSTOM_PKG_UID);
assertThat(mZenModeHelper.mConfig.automaticRules.keySet()).containsExactly(
@@ -2934,7 +2917,8 @@
AutomaticZenRule bedtime = new AutomaticZenRule.Builder("Bedtime Mode (TM)", CONDITION_ID)
.setType(TYPE_BEDTIME)
.build();
- String bedtimeRuleId = mZenModeHelper.addAutomaticZenRule("pkg", bedtime, UPDATE_ORIGIN_APP,
+ String bedtimeRuleId = mZenModeHelper.addAutomaticZenRule("pkg", bedtime,
+ ORIGIN_APP,
"reason", CUSTOM_PKG_UID);
assertThat(mZenModeHelper.mConfig.automaticRules.keySet()).containsExactly(
@@ -2948,15 +2932,15 @@
// note that caller=null because that's how it comes in from NMS.setZenMode
mZenModeHelper.setManualZenMode(ZEN_MODE_IMPORTANT_INTERRUPTIONS, null,
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "", null, Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, "", null, SYSTEM_UID);
// confirm that setting zen mode via setManualZenMode changed the zen mode correctly
assertEquals(ZEN_MODE_IMPORTANT_INTERRUPTIONS, mZenModeHelper.mZenMode);
assertEquals(true, mZenModeHelper.mConfig.manualRule.allowManualInvocation);
// and also that it works to turn it back off again
- mZenModeHelper.setManualZenMode(Global.ZEN_MODE_OFF, null, UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI,
- "", null, Process.SYSTEM_UID);
+ mZenModeHelper.setManualZenMode(Global.ZEN_MODE_OFF, null, ZenModeConfig.ORIGIN_SYSTEM,
+ "", null, SYSTEM_UID);
assertEquals(Global.ZEN_MODE_OFF, mZenModeHelper.mZenMode);
}
@@ -2965,28 +2949,29 @@
@EnableFlags(FLAG_MODES_API)
@DisableFlags(FLAG_MODES_UI)
public void setManualZenMode_off_snoozesActiveRules() {
- for (ChangeOrigin origin : ChangeOrigin.values()) {
+ for (ZenChangeOrigin origin : ZenChangeOrigin.values()) {
// Start with an active rule and an inactive rule.
mZenModeHelper.mConfig.automaticRules.clear();
AutomaticZenRule activeRule = new AutomaticZenRule.Builder("Test", CONDITION_ID)
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
.build();
String activeRuleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(),
- activeRule, UPDATE_ORIGIN_APP, "add it", CUSTOM_PKG_UID);
- mZenModeHelper.setAutomaticZenRuleState(activeRuleId, CONDITION_TRUE, UPDATE_ORIGIN_APP,
+ activeRule, ORIGIN_APP, "add it", CUSTOM_PKG_UID);
+ mZenModeHelper.setAutomaticZenRuleState(activeRuleId, CONDITION_TRUE,
+ ORIGIN_APP,
CUSTOM_PKG_UID);
AutomaticZenRule inactiveRule = new AutomaticZenRule.Builder("Test", CONDITION_ID)
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
.build();
String inactiveRuleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(),
- inactiveRule, UPDATE_ORIGIN_APP, "add it", CUSTOM_PKG_UID);
+ inactiveRule, ORIGIN_APP, "add it", CUSTOM_PKG_UID);
assertWithMessage("Failure for origin " + origin.name())
.that(mZenModeHelper.getZenMode()).isEqualTo(ZEN_MODE_IMPORTANT_INTERRUPTIONS);
// User turns DND off.
mZenModeHelper.setManualZenMode(ZEN_MODE_OFF, null, origin.value(),
- "snoozing", "systemui", Process.SYSTEM_UID);
+ "snoozing", "systemui", SYSTEM_UID);
assertWithMessage("Failure for origin " + origin.name())
.that(mZenModeHelper.getZenMode()).isEqualTo(ZEN_MODE_OFF);
assertWithMessage("Failure for origin " + origin.name())
@@ -3000,30 +2985,31 @@
@Test
@EnableFlags({FLAG_MODES_API, FLAG_MODES_UI})
- public void setManualZenMode_off_doesNotSnoozeRulesIfFromUser() {
- for (ChangeOrigin origin : ChangeOrigin.values()) {
+ public void setManualZenMode_off_doesNotSnoozeRulesIfFromUserInSystemUi() {
+ for (ZenChangeOrigin origin : ZenChangeOrigin.values()) {
// Start with an active rule and an inactive rule
mZenModeHelper.mConfig.automaticRules.clear();
AutomaticZenRule activeRule = new AutomaticZenRule.Builder("Test", CONDITION_ID)
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
.build();
String activeRuleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(),
- activeRule, UPDATE_ORIGIN_APP, "add it", CUSTOM_PKG_UID);
- mZenModeHelper.setAutomaticZenRuleState(activeRuleId, CONDITION_TRUE, UPDATE_ORIGIN_APP,
+ activeRule, ORIGIN_APP, "add it", CUSTOM_PKG_UID);
+ mZenModeHelper.setAutomaticZenRuleState(activeRuleId, CONDITION_TRUE,
+ ORIGIN_APP,
CUSTOM_PKG_UID);
AutomaticZenRule inactiveRule = new AutomaticZenRule.Builder("Test", CONDITION_ID)
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
.build();
String inactiveRuleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(),
- inactiveRule, UPDATE_ORIGIN_APP, "add it", CUSTOM_PKG_UID);
+ inactiveRule, ORIGIN_APP, "add it", CUSTOM_PKG_UID);
assertThat(mZenModeHelper.getZenMode()).isEqualTo(ZEN_MODE_IMPORTANT_INTERRUPTIONS);
// User turns DND off.
mZenModeHelper.setManualZenMode(ZEN_MODE_OFF, null, origin.value(),
- "snoozing", "systemui", Process.SYSTEM_UID);
+ "snoozing", "systemui", SYSTEM_UID);
ZenModeConfig config = mZenModeHelper.mConfig;
- if (origin == ChangeOrigin.ORIGIN_USER) {
+ if (origin == ZenChangeOrigin.ORIGIN_USER_IN_SYSTEMUI) {
// Other rule was unaffected.
assertWithMessage("Failure for origin " + origin.name()).that(
mZenModeHelper.getZenMode()).isEqualTo(ZEN_MODE_IMPORTANT_INTERRUPTIONS);
@@ -3048,14 +3034,14 @@
// note that caller=null because that's how it comes in from NMS.setZenMode
mZenModeHelper.setManualZenMode(ZEN_MODE_IMPORTANT_INTERRUPTIONS, null,
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "", null, Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, "", null, SYSTEM_UID);
// confirm that setting zen mode via setManualZenMode changed the zen mode correctly
assertEquals(ZEN_MODE_IMPORTANT_INTERRUPTIONS, mZenModeHelper.mZenMode);
// and also that it works to turn it back off again
- mZenModeHelper.setManualZenMode(ZEN_MODE_OFF, null, UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "",
- null, Process.SYSTEM_UID);
+ mZenModeHelper.setManualZenMode(ZEN_MODE_OFF, null, ZenModeConfig.ORIGIN_SYSTEM, "",
+ null, SYSTEM_UID);
assertEquals(ZEN_MODE_OFF, mZenModeHelper.mZenMode);
}
@@ -3069,12 +3055,12 @@
// Turn zen mode on (to important_interruptions)
// Need to additionally call the looper in order to finish the post-apply-config process
mZenModeHelper.setManualZenMode(ZEN_MODE_IMPORTANT_INTERRUPTIONS, null,
- Flags.modesApi() ? UPDATE_ORIGIN_USER : UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "", null,
- Process.SYSTEM_UID);
+ Flags.modesApi() ? ORIGIN_USER_IN_SYSTEMUI : ZenModeConfig.ORIGIN_SYSTEM, "",
+ null, SYSTEM_UID);
// Now turn zen mode off, but via a different package UID -- this should get registered as
// "not an action by the user" because some other app is changing zen mode
- mZenModeHelper.setManualZenMode(ZEN_MODE_OFF, null, UPDATE_ORIGIN_APP, "", null,
+ mZenModeHelper.setManualZenMode(ZEN_MODE_OFF, null, ORIGIN_APP, "", null,
CUSTOM_PKG_UID);
// In total, this should be 2 loggable changes
@@ -3100,11 +3086,11 @@
assertThat(mZenModeEventLogger.getFromSystemOrSystemUi(0)).isEqualTo(
!(Flags.modesUi() || Flags.modesApi()));
assertTrue(mZenModeEventLogger.getIsUserAction(0));
- assertEquals(Process.SYSTEM_UID, mZenModeEventLogger.getPackageUid(0));
+ assertEquals(SYSTEM_UID, mZenModeEventLogger.getPackageUid(0));
checkDndProtoMatchesSetupZenConfig(mZenModeEventLogger.getPolicyProto(0));
// change origin should be populated only under modes_ui
assertThat(mZenModeEventLogger.getChangeOrigin(0)).isEqualTo(
- (Flags.modesApi() && Flags.modesUi()) ? UPDATE_ORIGIN_USER : 0);
+ (Flags.modesApi() && Flags.modesUi()) ? ORIGIN_USER_IN_SYSTEMUI : 0);
// and from turning zen mode off:
// - event ID: DND_TURNED_OFF
@@ -3128,7 +3114,7 @@
checkDndProtoMatchesSetupZenConfig(mZenModeEventLogger.getPolicyProto(1));
}
assertThat(mZenModeEventLogger.getChangeOrigin(1)).isEqualTo(
- Flags.modesUi() ? UPDATE_ORIGIN_APP : 0);
+ Flags.modesUi() ? ORIGIN_APP : 0);
}
@Test
@@ -3145,7 +3131,7 @@
null,
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
String id = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), zenRule,
- UPDATE_ORIGIN_APP, "test", CUSTOM_PKG_UID);
+ ORIGIN_APP, "test", CUSTOM_PKG_UID);
// Event 1: Mimic the rule coming on automatically by setting the Condition to STATE_TRUE
// Note that pre-modes_ui, this event serves as a test that automatic changes to an app's
@@ -3153,14 +3139,14 @@
// modes_ui is true, we opt to trust the provided change origin.
mZenModeHelper.setAutomaticZenRuleState(id,
new Condition(zenRule.getConditionId(), "", STATE_TRUE),
- Flags.modesUi() ? UPDATE_ORIGIN_APP : UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI,
+ Flags.modesUi() ? ORIGIN_APP : ZenModeConfig.ORIGIN_SYSTEM,
CUSTOM_PKG_UID);
// Event 2: "User" turns off the automatic rule (sets it to not enabled)
zenRule.setEnabled(false);
mZenModeHelper.updateAutomaticZenRule(id, zenRule,
- Flags.modesApi() ? UPDATE_ORIGIN_USER : UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "",
- Process.SYSTEM_UID);
+ Flags.modesApi() ? ORIGIN_USER_IN_SYSTEMUI : ZenModeConfig.ORIGIN_SYSTEM, "",
+ SYSTEM_UID);
AutomaticZenRule systemRule = new AutomaticZenRule("systemRule",
null,
@@ -3169,18 +3155,18 @@
null,
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
String systemId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), systemRule,
- Flags.modesApi() ? UPDATE_ORIGIN_USER : UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "test",
- Process.SYSTEM_UID);
+ Flags.modesApi() ? ORIGIN_USER_IN_SYSTEMUI : ZenModeConfig.ORIGIN_SYSTEM, "test",
+ SYSTEM_UID);
// Event 3: turn on the system rule
mZenModeHelper.setAutomaticZenRuleState(systemId,
new Condition(zenRule.getConditionId(), "", STATE_TRUE),
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, SYSTEM_UID);
// Event 4: "User" deletes the rule
mZenModeHelper.removeAutomaticZenRule(systemId,
- Flags.modesApi() ? UPDATE_ORIGIN_USER : UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "",
- Process.SYSTEM_UID);
+ Flags.modesApi() ? ORIGIN_USER_IN_SYSTEMUI : ZenModeConfig.ORIGIN_SYSTEM, "",
+ SYSTEM_UID);
// In total, this represents 4 events
assertEquals(4, mZenModeEventLogger.numLoggedChanges());
@@ -3203,7 +3189,7 @@
assertEquals(CUSTOM_PKG_UID, mZenModeEventLogger.getPackageUid(0));
checkDndProtoMatchesDefaultZenConfig(mZenModeEventLogger.getPolicyProto(0));
assertThat(mZenModeEventLogger.getChangeOrigin(0)).isEqualTo(
- Flags.modesUi() ? UPDATE_ORIGIN_APP : 0);
+ Flags.modesUi() ? ORIGIN_APP : 0);
// When the automatic rule is disabled, this should turn off zen mode and also count as a
// user action. We don't care what the consolidated policy is when DND turns off.
@@ -3217,14 +3203,14 @@
assertEquals(0, mZenModeEventLogger.getNumRulesActive(1));
assertTrue(mZenModeEventLogger.getIsUserAction(1));
assertThat(mZenModeEventLogger.getPackageUid(1)).isEqualTo(
- Flags.modesUi() ? CUSTOM_PKG_UID : Process.SYSTEM_UID);
+ Flags.modesUi() ? CUSTOM_PKG_UID : SYSTEM_UID);
if (Flags.modesApi()) {
assertThat(mZenModeEventLogger.getPolicyProto(1)).isNull();
} else {
checkDndProtoMatchesSetupZenConfig(mZenModeEventLogger.getPolicyProto(1));
}
assertThat(mZenModeEventLogger.getChangeOrigin(1)).isEqualTo(
- Flags.modesUi() ? UPDATE_ORIGIN_USER : 0);
+ Flags.modesUi() ? ORIGIN_USER_IN_SYSTEMUI : 0);
// When the system rule is enabled, this counts as an automatic action that comes from the
// system and turns on DND
@@ -3233,9 +3219,9 @@
assertEquals(DNDProtoEnums.AUTOMATIC_RULE, mZenModeEventLogger.getChangedRuleType(2));
assertEquals(1, mZenModeEventLogger.getNumRulesActive(2));
assertFalse(mZenModeEventLogger.getIsUserAction(2));
- assertEquals(Process.SYSTEM_UID, mZenModeEventLogger.getPackageUid(2));
+ assertEquals(SYSTEM_UID, mZenModeEventLogger.getPackageUid(2));
assertThat(mZenModeEventLogger.getChangeOrigin(2)).isEqualTo(
- Flags.modesUi() ? UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI : 0);
+ Flags.modesUi() ? ZenModeConfig.ORIGIN_SYSTEM : 0);
// When the system rule is deleted, we consider this a user action that turns DND off
// (again)
@@ -3244,9 +3230,9 @@
assertEquals(DNDProtoEnums.AUTOMATIC_RULE, mZenModeEventLogger.getChangedRuleType(3));
assertEquals(0, mZenModeEventLogger.getNumRulesActive(3));
assertTrue(mZenModeEventLogger.getIsUserAction(3));
- assertEquals(Process.SYSTEM_UID, mZenModeEventLogger.getPackageUid(3));
+ assertEquals(SYSTEM_UID, mZenModeEventLogger.getPackageUid(3));
assertThat(mZenModeEventLogger.getChangeOrigin(3)).isEqualTo(
- Flags.modesUi() ? UPDATE_ORIGIN_USER : 0);
+ Flags.modesUi() ? ORIGIN_USER_IN_SYSTEMUI : 0);
}
@Test
@@ -3264,28 +3250,28 @@
null,
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
String id = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), zenRule,
- UPDATE_ORIGIN_APP, "test", CUSTOM_PKG_UID);
+ ORIGIN_APP, "test", CUSTOM_PKG_UID);
// Event 1: Mimic the rule coming on manually when the user turns it on in the app
// ("Turn on bedtime now" because user goes to bed earlier).
mZenModeHelper.setAutomaticZenRuleState(id,
new Condition(zenRule.getConditionId(), "", STATE_TRUE, SOURCE_USER_ACTION),
- UPDATE_ORIGIN_USER, CUSTOM_PKG_UID);
+ ORIGIN_USER_IN_APP, CUSTOM_PKG_UID);
// Event 2: App deactivates the rule automatically (it's 8 AM, bedtime schedule ends)
mZenModeHelper.setAutomaticZenRuleState(id,
new Condition(zenRule.getConditionId(), "", STATE_FALSE, SOURCE_SCHEDULE),
- UPDATE_ORIGIN_APP, CUSTOM_PKG_UID);
+ ORIGIN_APP, CUSTOM_PKG_UID);
// Event 3: App activates the rule automatically (it's now 11 PM, bedtime schedule starts)
mZenModeHelper.setAutomaticZenRuleState(id,
new Condition(zenRule.getConditionId(), "", STATE_TRUE, SOURCE_SCHEDULE),
- UPDATE_ORIGIN_APP, CUSTOM_PKG_UID);
+ ORIGIN_APP, CUSTOM_PKG_UID);
// Event 4: User deactivates the rule manually (they get up before 8 AM on the next day)
mZenModeHelper.setAutomaticZenRuleState(id,
new Condition(zenRule.getConditionId(), "", STATE_FALSE, SOURCE_USER_ACTION),
- UPDATE_ORIGIN_USER, CUSTOM_PKG_UID);
+ ORIGIN_USER_IN_APP, CUSTOM_PKG_UID);
// In total, this represents 4 events
assertEquals(4, mZenModeEventLogger.numLoggedChanges());
@@ -3301,7 +3287,7 @@
assertTrue(mZenModeEventLogger.getIsUserAction(0));
assertEquals(CUSTOM_PKG_UID, mZenModeEventLogger.getPackageUid(0));
assertThat(mZenModeEventLogger.getChangeOrigin(0)).isEqualTo(
- Flags.modesUi() ? UPDATE_ORIGIN_USER : 0);
+ Flags.modesUi() ? ORIGIN_USER_IN_APP : 0);
// Automatic rule turned off automatically by app:
// - event ID: DND_TURNED_OFF
@@ -3314,7 +3300,7 @@
assertFalse(mZenModeEventLogger.getIsUserAction(1));
assertEquals(CUSTOM_PKG_UID, mZenModeEventLogger.getPackageUid(1));
assertThat(mZenModeEventLogger.getChangeOrigin(1)).isEqualTo(
- Flags.modesUi() ? UPDATE_ORIGIN_APP : 0);
+ Flags.modesUi() ? ORIGIN_APP : 0);
// Automatic rule turned on automatically by app:
// - event ID: DND_TURNED_ON
@@ -3328,7 +3314,7 @@
assertFalse(mZenModeEventLogger.getIsUserAction(2));
assertEquals(CUSTOM_PKG_UID, mZenModeEventLogger.getPackageUid(2));
assertThat(mZenModeEventLogger.getChangeOrigin(2)).isEqualTo(
- Flags.modesUi() ? UPDATE_ORIGIN_APP : 0);
+ Flags.modesUi() ? ORIGIN_APP : 0);
// Automatic rule turned off automatically by the user:
// - event ID: DND_TURNED_ON
@@ -3341,7 +3327,7 @@
assertTrue(mZenModeEventLogger.getIsUserAction(3));
assertEquals(CUSTOM_PKG_UID, mZenModeEventLogger.getPackageUid(3));
assertThat(mZenModeEventLogger.getChangeOrigin(3)).isEqualTo(
- Flags.modesUi() ? UPDATE_ORIGIN_USER : 0);
+ Flags.modesUi() ? ORIGIN_USER_IN_APP : 0);
}
@Test
@@ -3352,21 +3338,21 @@
// First just turn zen mode on
mZenModeHelper.setManualZenMode(ZEN_MODE_IMPORTANT_INTERRUPTIONS, null,
- UPDATE_ORIGIN_USER, "", null, Process.SYSTEM_UID);
+ ORIGIN_USER_IN_SYSTEMUI, "", null, SYSTEM_UID);
// Now change the policy slightly; want to confirm that this'll be reflected in the logs
ZenModeConfig newConfig = mZenModeHelper.mConfig.copy();
mZenModeHelper.setNotificationPolicy(new Policy(PRIORITY_CATEGORY_ALARMS, 0, 0),
- UPDATE_ORIGIN_USER, Process.SYSTEM_UID);
+ ORIGIN_USER_IN_SYSTEMUI, SYSTEM_UID);
// Turn zen mode off; we want to make sure policy changes do not get logged when zen mode
// is off.
- mZenModeHelper.setManualZenMode(ZEN_MODE_OFF, null, UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "",
- null, Process.SYSTEM_UID);
+ mZenModeHelper.setManualZenMode(ZEN_MODE_OFF, null, ZenModeConfig.ORIGIN_SYSTEM, "",
+ null, SYSTEM_UID);
// Change the policy again
mZenModeHelper.setNotificationPolicy(new Policy(PRIORITY_CATEGORY_REPEAT_CALLERS, 0, 0),
- UPDATE_ORIGIN_USER, Process.SYSTEM_UID);
+ ORIGIN_USER_IN_SYSTEMUI, SYSTEM_UID);
// Total events: we only expect ones for turning on, changing policy, and turning off
assertEquals(3, mZenModeEventLogger.numLoggedChanges());
@@ -3386,7 +3372,7 @@
mZenModeEventLogger.getEventId(1));
assertEquals(DNDProtoEnums.UNKNOWN_RULE, mZenModeEventLogger.getChangedRuleType(1));
assertTrue(mZenModeEventLogger.getIsUserAction(1));
- assertEquals(Process.SYSTEM_UID, mZenModeEventLogger.getPackageUid(1));
+ assertEquals(SYSTEM_UID, mZenModeEventLogger.getPackageUid(1));
DNDPolicyProto dndProto = mZenModeEventLogger.getPolicyProto(1);
assertEquals(STATE_ALLOW, dndProto.getAlarms().getNumber());
assertEquals(STATE_DISALLOW, dndProto.getRepeatCallers().getNumber());
@@ -3410,7 +3396,7 @@
null,
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
String id = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), zenRule,
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "test", Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, "test", SYSTEM_UID);
// Rule 2, same as rule 1
AutomaticZenRule zenRule2 = new AutomaticZenRule("name2",
@@ -3420,7 +3406,7 @@
null,
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
String id2 = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), zenRule2,
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "test", Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, "test", SYSTEM_UID);
// Rule 3, has stricter settings than the default settings
ZenModeConfig ruleConfig = mZenModeHelper.mConfig.copy();
@@ -3432,27 +3418,27 @@
ruleConfig.getZenPolicy(),
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
String id3 = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), zenRule3,
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "test", Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, "test", SYSTEM_UID);
// First: turn on rule 1
mZenModeHelper.setAutomaticZenRuleState(id,
new Condition(zenRule.getConditionId(), "", STATE_TRUE),
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, SYSTEM_UID);
// Second: turn on rule 2
mZenModeHelper.setAutomaticZenRuleState(id2,
new Condition(zenRule2.getConditionId(), "", STATE_TRUE),
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, SYSTEM_UID);
// Third: turn on rule 3
mZenModeHelper.setAutomaticZenRuleState(id3,
new Condition(zenRule3.getConditionId(), "", STATE_TRUE),
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, SYSTEM_UID);
// Fourth: Turn *off* rule 2
mZenModeHelper.setAutomaticZenRuleState(id2,
new Condition(zenRule2.getConditionId(), "", STATE_FALSE),
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, SYSTEM_UID);
// This should result in a total of four events
assertEquals(4, mZenModeEventLogger.numLoggedChanges());
@@ -3465,7 +3451,7 @@
assertEquals(ZEN_MODE_IMPORTANT_INTERRUPTIONS, mZenModeEventLogger.getNewZenMode(0));
assertEquals(1, mZenModeEventLogger.getNumRulesActive(0));
assertFalse(mZenModeEventLogger.getIsUserAction(0));
- assertEquals(Process.SYSTEM_UID, mZenModeEventLogger.getPackageUid(0));
+ assertEquals(SYSTEM_UID, mZenModeEventLogger.getPackageUid(0));
checkDndProtoMatchesDefaultZenConfig(mZenModeEventLogger.getPolicyProto(0));
// Event 2: rule 2 turns on. This should not change anything about the policy, so the only
@@ -3474,7 +3460,7 @@
mZenModeEventLogger.getEventId(1));
assertEquals(2, mZenModeEventLogger.getNumRulesActive(1));
assertFalse(mZenModeEventLogger.getIsUserAction(1));
- assertEquals(Process.SYSTEM_UID, mZenModeEventLogger.getPackageUid(1));
+ assertEquals(SYSTEM_UID, mZenModeEventLogger.getPackageUid(1));
checkDndProtoMatchesDefaultZenConfig(mZenModeEventLogger.getPolicyProto(1));
// Event 3: rule 3 turns on. This should trigger a policy change, and be classified as such,
@@ -3484,7 +3470,7 @@
mZenModeEventLogger.getEventId(2));
assertEquals(3, mZenModeEventLogger.getNumRulesActive(2));
assertFalse(mZenModeEventLogger.getIsUserAction(2));
- assertEquals(Process.SYSTEM_UID, mZenModeEventLogger.getPackageUid(2));
+ assertEquals(SYSTEM_UID, mZenModeEventLogger.getPackageUid(2));
DNDPolicyProto dndProto = mZenModeEventLogger.getPolicyProto(2);
assertEquals(STATE_DISALLOW, dndProto.getReminders().getNumber());
assertEquals(STATE_DISALLOW, dndProto.getCalls().getNumber());
@@ -3508,7 +3494,7 @@
// Artificially turn zen mode "on". Re-evaluating zen mode should cause it to turn back off
// given that we don't have any zen rules active.
mZenModeHelper.mZenMode = ZEN_MODE_IMPORTANT_INTERRUPTIONS;
- mZenModeHelper.evaluateZenModeLocked(UPDATE_ORIGIN_UNKNOWN, "test", true);
+ mZenModeHelper.evaluateZenModeLocked(ORIGIN_UNKNOWN, "test", true);
// Check that the change actually took: zen mode should be off now
assertEquals(ZEN_MODE_OFF, mZenModeHelper.mZenMode);
@@ -3537,7 +3523,7 @@
manualRulePolicy,
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
String id = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), zenRule,
- UPDATE_ORIGIN_APP, "test", Process.SYSTEM_UID);
+ ORIGIN_APP, "test", SYSTEM_UID);
// Rule 2, same as rule 1 but owned by the system
AutomaticZenRule zenRule2 = new AutomaticZenRule("name2",
@@ -3547,7 +3533,7 @@
manualRulePolicy,
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
String id2 = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), zenRule2,
- UPDATE_ORIGIN_USER, "test", Process.SYSTEM_UID);
+ ORIGIN_USER_IN_SYSTEMUI, "test", SYSTEM_UID);
// Turn on rule 1; call looks like it's from the system. Because setting a condition is
// typically an automatic (non-user-initiated) action, expect the calling UID to be
@@ -3555,23 +3541,24 @@
// When modes_ui is true: we expect the change origin to be the source of truth.
mZenModeHelper.setAutomaticZenRuleState(id,
new Condition(zenRule.getConditionId(), "", STATE_TRUE),
- Flags.modesUi() ? UPDATE_ORIGIN_APP : UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI,
- Process.SYSTEM_UID);
+ Flags.modesUi() ? ORIGIN_APP : ZenModeConfig.ORIGIN_SYSTEM,
+ SYSTEM_UID);
// Second: turn on rule 2. This is a system-owned rule and the UID should not be modified
// (nor even looked up; the mock PackageManager won't handle "android" as input).
mZenModeHelper.setAutomaticZenRuleState(id2,
new Condition(zenRule2.getConditionId(), "", STATE_TRUE),
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, SYSTEM_UID);
// Disable rule 1. Because this looks like a user action, the UID should not be modified
// from the system-provided one unless modes_ui is true.
zenRule.setEnabled(false);
mZenModeHelper.updateAutomaticZenRule(id, zenRule,
- UPDATE_ORIGIN_USER, "", Process.SYSTEM_UID);
+ ORIGIN_USER_IN_SYSTEMUI, "", SYSTEM_UID);
// Add a manual rule. Any manual rule changes should not get calling uids reassigned.
- mZenModeHelper.setManualZenMode(ZEN_MODE_IMPORTANT_INTERRUPTIONS, null, UPDATE_ORIGIN_APP,
+ mZenModeHelper.setManualZenMode(ZEN_MODE_IMPORTANT_INTERRUPTIONS, null,
+ ORIGIN_APP,
"", null, CUSTOM_PKG_UID);
// Change rule 2's condition, but from some other UID. Since it doesn't look like it's from
@@ -3579,7 +3566,7 @@
// Note that this probably shouldn't be able to occur in real scenarios.
mZenModeHelper.setAutomaticZenRuleState(id2,
new Condition(zenRule2.getConditionId(), "", STATE_FALSE),
- UPDATE_ORIGIN_APP, 12345);
+ ORIGIN_APP, 12345);
// That was 5 events total
assertEquals(5, mZenModeEventLogger.numLoggedChanges());
@@ -3598,7 +3585,7 @@
mZenModeEventLogger.getEventId(1));
assertEquals(DNDProtoEnums.AUTOMATIC_RULE, mZenModeEventLogger.getChangedRuleType(1));
assertFalse(mZenModeEventLogger.getIsUserAction(1));
- assertEquals(Process.SYSTEM_UID, mZenModeEventLogger.getPackageUid(1));
+ assertEquals(SYSTEM_UID, mZenModeEventLogger.getPackageUid(1));
// Third event: disable rule 1. This looks like a user action so UID should be left alone.
// When modes_ui is true, we assign log this user action with the app that owns the rule.
@@ -3607,7 +3594,7 @@
assertEquals(DNDProtoEnums.AUTOMATIC_RULE, mZenModeEventLogger.getChangedRuleType(2));
assertTrue(mZenModeEventLogger.getIsUserAction(2));
assertThat(mZenModeEventLogger.getPackageUid(2)).isEqualTo(
- Flags.modesUi() ? CUSTOM_PKG_UID : Process.SYSTEM_UID);
+ Flags.modesUi() ? CUSTOM_PKG_UID : SYSTEM_UID);
// Fourth event: turns on manual mode. Doesn't change effective policy so this is just a
// change in active rules. Confirm that the package UID is left unchanged.
@@ -3636,29 +3623,30 @@
// Turn on zen mode with a manual rule with an enabler set. This should *not* count
// as a user action, and *should* get its UID reassigned.
mZenModeHelper.setManualZenMode(ZEN_MODE_IMPORTANT_INTERRUPTIONS, null,
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "", CUSTOM_PKG_NAME, Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, "", CUSTOM_PKG_NAME, SYSTEM_UID);
assertEquals(1, mZenModeEventLogger.numLoggedChanges());
// Now change apps bypassing to true
ZenModeConfig newConfig = mZenModeHelper.mConfig.copy();
newConfig.areChannelsBypassingDnd = true;
mZenModeHelper.setNotificationPolicy(newConfig.toNotificationPolicy(),
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, SYSTEM_UID);
assertEquals(2, mZenModeEventLogger.numLoggedChanges());
// and then back to false, all without changing anything else
newConfig.areChannelsBypassingDnd = false;
mZenModeHelper.setNotificationPolicy(newConfig.toNotificationPolicy(),
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, SYSTEM_UID);
assertEquals(3, mZenModeEventLogger.numLoggedChanges());
// Turn off manual mode, call from a package: don't reset UID even though enabler is set
- mZenModeHelper.setManualZenMode(ZEN_MODE_OFF, null, UPDATE_ORIGIN_APP, "",
+ mZenModeHelper.setManualZenMode(ZEN_MODE_OFF, null, ORIGIN_APP, "",
CUSTOM_PKG_NAME, 12345);
assertEquals(4, mZenModeEventLogger.numLoggedChanges());
// And likewise when turning it back on again
- mZenModeHelper.setManualZenMode(ZEN_MODE_IMPORTANT_INTERRUPTIONS, null, UPDATE_ORIGIN_APP,
+ mZenModeHelper.setManualZenMode(ZEN_MODE_IMPORTANT_INTERRUPTIONS, null,
+ ORIGIN_APP,
"", CUSTOM_PKG_NAME, 12345);
// These are 5 events in total.
@@ -3705,7 +3693,7 @@
// First just turn zen mode on
mZenModeHelper.setManualZenMode(ZEN_MODE_IMPORTANT_INTERRUPTIONS, null,
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "", null, Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, "", null, SYSTEM_UID);
// Now change only the channels part of the policy; want to confirm that this'll be
// reflected in the logs
@@ -3716,7 +3704,7 @@
STATE_PRIORITY_CHANNELS_BLOCKED,
oldPolicy.priorityConversationSenders);
mZenModeHelper.setNotificationPolicy(newPolicy,
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, SYSTEM_UID);
// Total events: one for turning on, one for changing policy
assertThat(mZenModeEventLogger.numLoggedChanges()).isEqualTo(2);
@@ -3757,17 +3745,17 @@
null,
NotificationManager.INTERRUPTION_FILTER_ALL, true);
String id = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), zenRule,
- UPDATE_ORIGIN_APP, "test", CUSTOM_PKG_UID);
+ ORIGIN_APP, "test", CUSTOM_PKG_UID);
// Event 1: App activates the rule automatically.
mZenModeHelper.setAutomaticZenRuleState(id,
new Condition(zenRule.getConditionId(), "", STATE_TRUE, SOURCE_SCHEDULE),
- UPDATE_ORIGIN_APP, CUSTOM_PKG_UID);
+ ORIGIN_APP, CUSTOM_PKG_UID);
// Event 2: App deactivates the rule automatically.
mZenModeHelper.setAutomaticZenRuleState(id,
new Condition(zenRule.getConditionId(), "", STATE_FALSE, SOURCE_SCHEDULE),
- UPDATE_ORIGIN_APP, CUSTOM_PKG_UID);
+ ORIGIN_APP, CUSTOM_PKG_UID);
// In total, this represents 2 events.
assertEquals(2, mZenModeEventLogger.numLoggedChanges());
@@ -3798,7 +3786,8 @@
.setInterruptionFilter(INTERRUPTION_FILTER_ALL)
.setType(TYPE_BEDTIME)
.build();
- String bedtimeRuleId = mZenModeHelper.addAutomaticZenRule(mPkg, bedtime, UPDATE_ORIGIN_APP,
+ String bedtimeRuleId = mZenModeHelper.addAutomaticZenRule(mPkg, bedtime,
+ ORIGIN_APP,
"reason", CUSTOM_PKG_UID);
// Create immersive rule
@@ -3806,27 +3795,28 @@
.setType(TYPE_IMMERSIVE)
.setZenPolicy(mZenModeHelper.mConfig.getZenPolicy()) // same as the manual rule
.build();
- String immersiveId = mZenModeHelper.addAutomaticZenRule(mPkg, immersive, UPDATE_ORIGIN_APP,
+ String immersiveId = mZenModeHelper.addAutomaticZenRule(mPkg, immersive,
+ ORIGIN_APP,
"reason", CUSTOM_PKG_UID);
// Event 1: Activate bedtime rule. This doesn't turn on notification filtering
mZenModeHelper.setAutomaticZenRuleState(bedtimeRuleId,
new Condition(bedtime.getConditionId(), "", STATE_TRUE, SOURCE_SCHEDULE),
- UPDATE_ORIGIN_APP, CUSTOM_PKG_UID);
+ ORIGIN_APP, CUSTOM_PKG_UID);
// Event 2: turn on manual zen mode. Manual rule will have ACTIVE_RULE_TYPE_MANUAL
mZenModeHelper.setManualZenMode(ZEN_MODE_IMPORTANT_INTERRUPTIONS, null,
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "", null, Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, "", null, SYSTEM_UID);
// Event 3: Turn immersive on
mZenModeHelper.setAutomaticZenRuleState(immersiveId,
new Condition(immersive.getConditionId(), "", STATE_TRUE, SOURCE_SCHEDULE),
- UPDATE_ORIGIN_APP, CUSTOM_PKG_UID);
+ ORIGIN_APP, CUSTOM_PKG_UID);
// Event 4: Turn off bedtime mode, leaving just manual + immersive
mZenModeHelper.setAutomaticZenRuleState(bedtimeRuleId,
new Condition(bedtime.getConditionId(), "", STATE_FALSE, SOURCE_SCHEDULE),
- UPDATE_ORIGIN_APP, CUSTOM_PKG_UID);
+ ORIGIN_APP, CUSTOM_PKG_UID);
// Total of 4 events
assertEquals(4, mZenModeEventLogger.numLoggedChanges());
@@ -3887,12 +3877,12 @@
null,
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
String id = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), zenRule,
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "test", Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, "test", SYSTEM_UID);
// enable the rule
mZenModeHelper.setAutomaticZenRuleState(id,
new Condition(zenRule.getConditionId(), "", STATE_TRUE),
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, SYSTEM_UID);
assertEquals(mZenModeHelper.getNotificationPolicy(),
mZenModeHelper.getConsolidatedNotificationPolicy());
@@ -3923,12 +3913,12 @@
null, // null policy
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
String id = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), zenRule,
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "test", Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, "test", SYSTEM_UID);
// enable the rule
mZenModeHelper.setAutomaticZenRuleState(id,
new Condition(zenRule.getConditionId(), "", STATE_TRUE),
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, SYSTEM_UID);
// inspect the consolidated policy, which should match the device default settings.
assertThat(ZenAdapters.notificationPolicyToZenPolicy(mZenModeHelper.mConsolidatedPolicy))
@@ -3961,12 +3951,12 @@
customPolicy,
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
String id = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), zenRule,
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "test", Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, "test", SYSTEM_UID);
// enable the rule; this will update the consolidated policy
mZenModeHelper.setAutomaticZenRuleState(id,
new Condition(zenRule.getConditionId(), "", STATE_TRUE),
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, SYSTEM_UID);
// since this is the only active rule, the consolidated policy should match the custom
// policy for every field specified, and take default values (from device default or
@@ -4006,12 +3996,12 @@
customPolicy,
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
String id = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), zenRule,
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "test", Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, "test", SYSTEM_UID);
// enable the rule; this will update the consolidated policy
mZenModeHelper.setAutomaticZenRuleState(id,
new Condition(zenRule.getConditionId(), "", STATE_TRUE),
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, SYSTEM_UID);
// since this is the only active rule, the consolidated policy should match the custom
// policy for every field specified, and take default values (from either device default
@@ -4046,12 +4036,12 @@
null,
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
String id = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), zenRule,
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "test", Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, "test", SYSTEM_UID);
// enable rule 1
mZenModeHelper.setAutomaticZenRuleState(id,
new Condition(zenRule.getConditionId(), "", STATE_TRUE),
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, SYSTEM_UID);
// custom policy for rule 2
ZenPolicy customPolicy = new ZenPolicy.Builder()
@@ -4070,12 +4060,12 @@
customPolicy,
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
String id2 = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), zenRule2,
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "test", Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, "test", SYSTEM_UID);
// enable rule 2; this will update the consolidated policy
mZenModeHelper.setAutomaticZenRuleState(id2,
new Condition(zenRule2.getConditionId(), "", STATE_TRUE),
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, SYSTEM_UID);
// now both rules should be on, and the consolidated policy should reflect the most
// restrictive option of each of the two
@@ -4107,12 +4097,12 @@
null,
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
String id = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), zenRule,
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "test", Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, "test", SYSTEM_UID);
// enable rule 1
mZenModeHelper.setAutomaticZenRuleState(id,
new Condition(zenRule.getConditionId(), "", STATE_TRUE),
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, SYSTEM_UID);
// custom policy for rule 2
ZenPolicy customPolicy = new ZenPolicy.Builder()
@@ -4131,12 +4121,12 @@
customPolicy,
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
String id2 = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), zenRule2,
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "test", Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, "test", SYSTEM_UID);
// enable rule 2; this will update the consolidated policy
mZenModeHelper.setAutomaticZenRuleState(id2,
new Condition(zenRule2.getConditionId(), "", STATE_TRUE),
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, SYSTEM_UID);
// now both rules should be on, and the consolidated policy should reflect the most
// restrictive option of each of the two
@@ -4173,12 +4163,12 @@
customPolicy,
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
String id = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), zenRule,
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "test", Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, "test", SYSTEM_UID);
// enable the rule; this will update the consolidated policy
mZenModeHelper.setAutomaticZenRuleState(id,
new Condition(zenRule.getConditionId(), "", STATE_TRUE),
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, SYSTEM_UID);
// confirm that channels make it through
assertTrue(mZenModeHelper.mConsolidatedPolicy.allowPriorityChannels());
@@ -4195,12 +4185,12 @@
strictPolicy,
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
String id2 = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), zenRule2,
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "test", Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, "test", SYSTEM_UID);
// enable rule 2; this will update the consolidated policy
mZenModeHelper.setAutomaticZenRuleState(id2,
new Condition(zenRule2.getConditionId(), "", STATE_TRUE),
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, SYSTEM_UID);
// rule 2 should override rule 1
assertFalse(mZenModeHelper.mConsolidatedPolicy.allowPriorityChannels());
@@ -4226,10 +4216,10 @@
.build(),
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
String rule1Id = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(),
- zenRuleWithPriority, UPDATE_ORIGIN_APP, "test", CUSTOM_PKG_UID);
+ zenRuleWithPriority, ORIGIN_APP, "test", CUSTOM_PKG_UID);
mZenModeHelper.setAutomaticZenRuleState(rule1Id,
new Condition(zenRuleWithPriority.getConditionId(), "", STATE_TRUE),
- UPDATE_ORIGIN_APP, CUSTOM_PKG_UID);
+ ORIGIN_APP, CUSTOM_PKG_UID);
// Rule 2: ALL, but somehow with a super strict ZenPolicy.
AutomaticZenRule zenRuleWithAll = new AutomaticZenRule("All",
@@ -4239,10 +4229,10 @@
new ZenPolicy.Builder().disallowAllSounds().build(),
NotificationManager.INTERRUPTION_FILTER_ALL, true);
String rule2Id = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(),
- zenRuleWithAll, UPDATE_ORIGIN_APP, "test", CUSTOM_PKG_UID);
+ zenRuleWithAll, ORIGIN_APP, "test", CUSTOM_PKG_UID);
mZenModeHelper.setAutomaticZenRuleState(rule2Id,
new Condition(zenRuleWithPriority.getConditionId(), "", STATE_TRUE),
- UPDATE_ORIGIN_APP, CUSTOM_PKG_UID);
+ ORIGIN_APP, CUSTOM_PKG_UID);
// Consolidated Policy should be default + rule1.
assertThat(mZenModeHelper.mConsolidatedPolicy.allowAlarms()).isEqualTo(
@@ -4321,7 +4311,7 @@
.build();
String ruleId = mZenModeHelper.addAutomaticZenRule(OWNER.getPackageName(), azr,
- UPDATE_ORIGIN_APP, "add", CUSTOM_PKG_UID);
+ ORIGIN_APP, "add", CUSTOM_PKG_UID);
ZenModeConfig.ZenRule storedRule = mZenModeHelper.mConfig.automaticRules.get(ruleId);
@@ -4351,15 +4341,15 @@
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
.build();
String ruleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(),
- azrBase, UPDATE_ORIGIN_APP, "reason", Process.SYSTEM_UID);
+ azrBase, ORIGIN_APP, "reason", SYSTEM_UID);
AutomaticZenRule rule = mZenModeHelper.getAutomaticZenRule(ruleId);
// Checks the name can be changed by the app because the user has not modified it.
AutomaticZenRule azrUpdate = new AutomaticZenRule.Builder(rule)
.setName("NewName")
.build();
- mZenModeHelper.updateAutomaticZenRule(ruleId, azrUpdate, UPDATE_ORIGIN_APP, "reason",
- Process.SYSTEM_UID);
+ mZenModeHelper.updateAutomaticZenRule(ruleId, azrUpdate, ORIGIN_APP, "reason",
+ SYSTEM_UID);
rule = mZenModeHelper.getAutomaticZenRule(ruleId);
assertThat(rule.getName()).isEqualTo("NewName");
@@ -4368,16 +4358,16 @@
azrUpdate = new AutomaticZenRule.Builder(rule)
.setInterruptionFilter(INTERRUPTION_FILTER_ALARMS)
.build();
- mZenModeHelper.updateAutomaticZenRule(ruleId, azrUpdate, UPDATE_ORIGIN_USER, "reason",
- Process.SYSTEM_UID);
+ mZenModeHelper.updateAutomaticZenRule(ruleId, azrUpdate, ORIGIN_USER_IN_SYSTEMUI, "reason",
+ SYSTEM_UID);
// ...but the app can still modify the name, because the name itself hasn't been modified
// by the user.
azrUpdate = new AutomaticZenRule.Builder(rule)
.setName("NewAppName")
.build();
- mZenModeHelper.updateAutomaticZenRule(ruleId, azrUpdate, UPDATE_ORIGIN_APP, "reason",
- Process.SYSTEM_UID);
+ mZenModeHelper.updateAutomaticZenRule(ruleId, azrUpdate, ORIGIN_APP, "reason",
+ SYSTEM_UID);
rule = mZenModeHelper.getAutomaticZenRule(ruleId);
assertThat(rule.getName()).isEqualTo("NewAppName");
@@ -4385,8 +4375,8 @@
azrUpdate = new AutomaticZenRule.Builder(rule)
.setName("UserProvidedName")
.build();
- mZenModeHelper.updateAutomaticZenRule(ruleId, azrUpdate, UPDATE_ORIGIN_USER, "reason",
- Process.SYSTEM_UID);
+ mZenModeHelper.updateAutomaticZenRule(ruleId, azrUpdate, ORIGIN_USER_IN_SYSTEMUI, "reason",
+ SYSTEM_UID);
rule = mZenModeHelper.getAutomaticZenRule(ruleId);
assertThat(rule.getName()).isEqualTo("UserProvidedName");
@@ -4394,8 +4384,8 @@
azrUpdate = new AutomaticZenRule.Builder(rule)
.setName("NewAppName")
.build();
- mZenModeHelper.updateAutomaticZenRule(ruleId, azrUpdate, UPDATE_ORIGIN_APP, "reason",
- Process.SYSTEM_UID);
+ mZenModeHelper.updateAutomaticZenRule(ruleId, azrUpdate, ORIGIN_APP, "reason",
+ SYSTEM_UID);
rule = mZenModeHelper.getAutomaticZenRule(ruleId);
assertThat(rule.getName()).isEqualTo("UserProvidedName");
}
@@ -4411,7 +4401,7 @@
.build();
// Adds the rule using the app, to avoid having any user modified bits set.
String ruleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(),
- azrBase, UPDATE_ORIGIN_APP, "reason", Process.SYSTEM_UID);
+ azrBase, ORIGIN_APP, "reason", SYSTEM_UID);
AutomaticZenRule rule = mZenModeHelper.getAutomaticZenRule(ruleId);
// Modifies the filter, icon, zen policy, and device effects
@@ -4430,8 +4420,8 @@
.build();
// Update the rule with the AZR from origin user.
- mZenModeHelper.updateAutomaticZenRule(ruleId, azrUpdate, UPDATE_ORIGIN_USER, "reason",
- Process.SYSTEM_UID);
+ mZenModeHelper.updateAutomaticZenRule(ruleId, azrUpdate, ORIGIN_USER_IN_SYSTEMUI, "reason",
+ SYSTEM_UID);
rule = mZenModeHelper.getAutomaticZenRule(ruleId);
// UPDATE_ORIGIN_USER should change the bitmask and change the values.
@@ -4468,7 +4458,7 @@
.build();
// Adds the rule using the app, to avoid having any user modified bits set.
String ruleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(),
- azrBase, UPDATE_ORIGIN_APP, "reason", Process.SYSTEM_UID);
+ azrBase, ORIGIN_APP, "reason", SYSTEM_UID);
AutomaticZenRule rule = mZenModeHelper.getAutomaticZenRule(ruleId);
// Modifies the icon, zen policy and device effects
@@ -4487,8 +4477,8 @@
.build();
// Update the rule with the AZR from origin systemUI.
- mZenModeHelper.updateAutomaticZenRule(ruleId, azrUpdate, UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI,
- "reason", Process.SYSTEM_UID);
+ mZenModeHelper.updateAutomaticZenRule(ruleId, azrUpdate, ZenModeConfig.ORIGIN_SYSTEM,
+ "reason", SYSTEM_UID);
rule = mZenModeHelper.getAutomaticZenRule(ruleId);
// UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI should change the value but NOT update the bitmask.
@@ -4518,7 +4508,7 @@
.build();
// Adds the rule using the app, to avoid having any user modified bits set.
String ruleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(),
- azrBase, UPDATE_ORIGIN_APP, "reason", Process.SYSTEM_UID);
+ azrBase, ORIGIN_APP, "reason", SYSTEM_UID);
AutomaticZenRule rule = mZenModeHelper.getAutomaticZenRule(ruleId);
ZenPolicy policy = new ZenPolicy.Builder()
@@ -4535,8 +4525,8 @@
// Since the rule is not already user modified, UPDATE_ORIGIN_APP can modify the rule.
// The bitmask is not modified.
- mZenModeHelper.updateAutomaticZenRule(ruleId, azrUpdate, UPDATE_ORIGIN_APP, "reason",
- Process.SYSTEM_UID);
+ mZenModeHelper.updateAutomaticZenRule(ruleId, azrUpdate, ORIGIN_APP, "reason",
+ SYSTEM_UID);
ZenRule storedRule = mZenModeHelper.mConfig.automaticRules.get(ruleId);
assertThat(storedRule.userModifiedFields).isEqualTo(0);
@@ -4551,7 +4541,7 @@
// Creates another rule, this time from user. This will have user modified bits set.
String ruleIdUser = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(),
- azrBase, UPDATE_ORIGIN_USER, "reason", Process.SYSTEM_UID);
+ azrBase, ORIGIN_USER_IN_SYSTEMUI, "reason", SYSTEM_UID);
storedRule = mZenModeHelper.mConfig.automaticRules.get(ruleIdUser);
int ruleModifiedFields = storedRule.userModifiedFields;
int rulePolicyModifiedFields = storedRule.zenPolicyUserModifiedFields;
@@ -4559,8 +4549,8 @@
// Zen rule update coming from the app again. This cannot fully update the rule, because
// the rule is already considered user modified.
- mZenModeHelper.updateAutomaticZenRule(ruleIdUser, azrUpdate, UPDATE_ORIGIN_APP,
- "reason", Process.SYSTEM_UID);
+ mZenModeHelper.updateAutomaticZenRule(ruleIdUser, azrUpdate, ORIGIN_APP,
+ "reason", SYSTEM_UID);
AutomaticZenRule ruleUser = mZenModeHelper.getAutomaticZenRule(ruleIdUser);
// The app can only change the value if the rule is not already user modified,
@@ -4591,7 +4581,7 @@
.build())
.build();
String ruleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(),
- azrBase, UPDATE_ORIGIN_APP, "reason", Process.SYSTEM_UID);
+ azrBase, ORIGIN_APP, "reason", SYSTEM_UID);
AutomaticZenRule rule = mZenModeHelper.getAutomaticZenRule(ruleId);
// The values are modified but the bitmask is not.
@@ -4613,7 +4603,7 @@
.build();
// Adds the rule using the app, to avoid having any user modified bits set.
String ruleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(),
- azrBase, UPDATE_ORIGIN_APP, "reason", Process.SYSTEM_UID);
+ azrBase, ORIGIN_APP, "reason", SYSTEM_UID);
AutomaticZenRule azr = new AutomaticZenRule.Builder(azrBase)
// Sets Device Effects to null
@@ -4622,8 +4612,8 @@
// Zen rule update coming from app, but since the rule isn't already
// user modified, it can be updated.
- mZenModeHelper.updateAutomaticZenRule(ruleId, azr, UPDATE_ORIGIN_APP, "reason",
- Process.SYSTEM_UID);
+ mZenModeHelper.updateAutomaticZenRule(ruleId, azr, ORIGIN_APP, "reason",
+ SYSTEM_UID);
AutomaticZenRule rule = mZenModeHelper.getAutomaticZenRule(ruleId);
// When AZR's ZenDeviceEffects is null, the updated rule's device effects are kept.
@@ -4639,7 +4629,7 @@
.build();
// Adds the rule using the app, to avoid having any user modified bits set.
String ruleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(),
- azrBase, UPDATE_ORIGIN_APP, "reason", Process.SYSTEM_UID);
+ azrBase, ORIGIN_APP, "reason", SYSTEM_UID);
AutomaticZenRule rule = mZenModeHelper.getAutomaticZenRule(ruleId);
AutomaticZenRule azr = new AutomaticZenRule.Builder(azrBase)
@@ -4649,8 +4639,8 @@
// Zen rule update coming from app, but since the rule isn't already
// user modified, it can be updated.
- mZenModeHelper.updateAutomaticZenRule(ruleId, azr, UPDATE_ORIGIN_APP, "reason",
- Process.SYSTEM_UID);
+ mZenModeHelper.updateAutomaticZenRule(ruleId, azr, ORIGIN_APP, "reason",
+ SYSTEM_UID);
rule = mZenModeHelper.getAutomaticZenRule(ruleId);
// When AZR's ZenPolicy is null, we expect the updated rule's policy to be unchanged
@@ -4671,7 +4661,7 @@
.build();
// Adds the rule using the app, to avoid having any user modified bits set.
String ruleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(),
- azrBase, UPDATE_ORIGIN_APP, "reason", Process.SYSTEM_UID);
+ azrBase, ORIGIN_APP, "reason", SYSTEM_UID);
AutomaticZenRule rule = mZenModeHelper.getAutomaticZenRule(ruleId);
// Create a fully populated ZenPolicy.
@@ -4700,8 +4690,8 @@
// Applies the update to the rule.
// Default config defined in getDefaultConfigParser() is used as the original rule.
- mZenModeHelper.updateAutomaticZenRule(ruleId, azr, UPDATE_ORIGIN_USER, "reason",
- Process.SYSTEM_UID);
+ mZenModeHelper.updateAutomaticZenRule(ruleId, azr, ORIGIN_USER_IN_SYSTEMUI, "reason",
+ SYSTEM_UID);
rule = mZenModeHelper.getAutomaticZenRule(ruleId);
// New ZenPolicy differs from the default config
@@ -4732,7 +4722,7 @@
.build();
// Adds the rule using the app, to avoid having any user modified bits set.
String ruleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(),
- azrBase, UPDATE_ORIGIN_APP, "reason", Process.SYSTEM_UID);
+ azrBase, ORIGIN_APP, "reason", SYSTEM_UID);
AutomaticZenRule rule = mZenModeHelper.getAutomaticZenRule(ruleId);
ZenDeviceEffects deviceEffects = new ZenDeviceEffects.Builder()
@@ -4743,8 +4733,8 @@
.build();
// Applies the update to the rule.
- mZenModeHelper.updateAutomaticZenRule(ruleId, azr, UPDATE_ORIGIN_USER, "reason",
- Process.SYSTEM_UID);
+ mZenModeHelper.updateAutomaticZenRule(ruleId, azr, ORIGIN_USER_IN_SYSTEMUI, "reason",
+ SYSTEM_UID);
rule = mZenModeHelper.getAutomaticZenRule(ruleId);
// New ZenDeviceEffects is used; all fields considered set, since previously were null.
@@ -4769,7 +4759,7 @@
null,
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
final String createdId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(),
- zenRule, UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "test", Process.SYSTEM_UID);
+ zenRule, ZenModeConfig.ORIGIN_SYSTEM, "test", SYSTEM_UID);
CountDownLatch latch = new CountDownLatch(1);
final int[] actualStatus = new int[1];
@@ -4785,8 +4775,8 @@
mZenModeHelper.addCallback(callback);
zenRule.setEnabled(false);
- mZenModeHelper.updateAutomaticZenRule(createdId, zenRule, UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI,
- "", Process.SYSTEM_UID);
+ mZenModeHelper.updateAutomaticZenRule(createdId, zenRule, ZenModeConfig.ORIGIN_SYSTEM,
+ "", SYSTEM_UID);
assertTrue(latch.await(500, TimeUnit.MILLISECONDS));
assertEquals(AUTOMATIC_RULE_STATUS_DISABLED, actualStatus[0]);
@@ -4804,7 +4794,7 @@
null,
NotificationManager.INTERRUPTION_FILTER_PRIORITY, false);
final String createdId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(),
- zenRule, UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "test", Process.SYSTEM_UID);
+ zenRule, ZenModeConfig.ORIGIN_SYSTEM, "test", SYSTEM_UID);
CountDownLatch latch = new CountDownLatch(1);
final int[] actualStatus = new int[1];
@@ -4820,8 +4810,8 @@
mZenModeHelper.addCallback(callback);
zenRule.setEnabled(true);
- mZenModeHelper.updateAutomaticZenRule(createdId, zenRule, UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI,
- "", Process.SYSTEM_UID);
+ mZenModeHelper.updateAutomaticZenRule(createdId, zenRule, ZenModeConfig.ORIGIN_SYSTEM,
+ "", SYSTEM_UID);
assertTrue(latch.await(500, TimeUnit.MILLISECONDS));
assertEquals(AUTOMATIC_RULE_STATUS_ENABLED, actualStatus[0]);
@@ -4840,7 +4830,7 @@
null,
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
final String createdId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(),
- zenRule, UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "test", Process.SYSTEM_UID);
+ zenRule, ZenModeConfig.ORIGIN_SYSTEM, "test", SYSTEM_UID);
CountDownLatch latch = new CountDownLatch(1);
final int[] actualStatus = new int[1];
@@ -4857,7 +4847,7 @@
mZenModeHelper.setAutomaticZenRuleState(createdId,
new Condition(zenRule.getConditionId(), "", STATE_TRUE),
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, SYSTEM_UID);
assertTrue(latch.await(500, TimeUnit.MILLISECONDS));
if (CompatChanges.isChangeEnabled(ZenModeHelper.SEND_ACTIVATION_AZR_STATUSES)) {
@@ -4880,7 +4870,7 @@
null,
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
final String createdId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(),
- zenRule, UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "test", Process.SYSTEM_UID);
+ zenRule, ZenModeConfig.ORIGIN_SYSTEM, "test", SYSTEM_UID);
CountDownLatch latch = new CountDownLatch(1);
final int[] actualStatus = new int[2];
@@ -4899,10 +4889,10 @@
mZenModeHelper.setAutomaticZenRuleState(createdId,
new Condition(zenRule.getConditionId(), "", STATE_TRUE),
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, SYSTEM_UID);
- mZenModeHelper.setManualZenMode(Global.ZEN_MODE_OFF, null, UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI,
- null, "", Process.SYSTEM_UID);
+ mZenModeHelper.setManualZenMode(Global.ZEN_MODE_OFF, null, ZenModeConfig.ORIGIN_SYSTEM,
+ null, "", SYSTEM_UID);
assertTrue(latch.await(500, TimeUnit.MILLISECONDS));
if (CompatChanges.isChangeEnabled(ZenModeHelper.SEND_ACTIVATION_AZR_STATUSES)) {
@@ -4925,7 +4915,7 @@
null,
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
final String createdId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(),
- zenRule, UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "test", Process.SYSTEM_UID);
+ zenRule, ZenModeConfig.ORIGIN_SYSTEM, "test", SYSTEM_UID);
CountDownLatch latch = new CountDownLatch(1);
final int[] actualStatus = new int[2];
@@ -4944,11 +4934,11 @@
mZenModeHelper.setAutomaticZenRuleState(createdId,
new Condition(zenRule.getConditionId(), "", STATE_TRUE),
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, SYSTEM_UID);
mZenModeHelper.setAutomaticZenRuleState(createdId,
new Condition(zenRule.getConditionId(), "", STATE_FALSE),
- UPDATE_ORIGIN_APP, Process.SYSTEM_UID);
+ ORIGIN_APP, SYSTEM_UID);
assertTrue(latch.await(500, TimeUnit.MILLISECONDS));
if (CompatChanges.isChangeEnabled(ZenModeHelper.SEND_ACTIVATION_AZR_STATUSES)) {
@@ -4970,21 +4960,21 @@
null,
NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
final String createdId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(),
- zenRule, UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "test", Process.SYSTEM_UID);
+ zenRule, ZenModeConfig.ORIGIN_SYSTEM, "test", SYSTEM_UID);
// Event 1: Mimic the rule coming on automatically by setting the Condition to STATE_TRUE
mZenModeHelper.setAutomaticZenRuleState(createdId,
new Condition(zenRule.getConditionId(), "", STATE_TRUE),
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, SYSTEM_UID);
// Event 2: Snooze rule by turning off DND
- mZenModeHelper.setManualZenMode(Global.ZEN_MODE_OFF, null, UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI,
- "", null, Process.SYSTEM_UID);
+ mZenModeHelper.setManualZenMode(Global.ZEN_MODE_OFF, null, ZenModeConfig.ORIGIN_SYSTEM,
+ "", null, SYSTEM_UID);
// Event 3: "User" turns off the automatic rule (sets it to not enabled)
zenRule.setEnabled(false);
- mZenModeHelper.updateAutomaticZenRule(createdId, zenRule, UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI,
- "", Process.SYSTEM_UID);
+ mZenModeHelper.updateAutomaticZenRule(createdId, zenRule, ZenModeConfig.ORIGIN_SYSTEM,
+ "", SYSTEM_UID);
assertEquals(false, mZenModeHelper.mConfig.automaticRules.get(createdId).snoozing);
}
@@ -4997,16 +4987,16 @@
.setConfigurationActivity(new ComponentName(mPkg, "cls"))
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
.build();
- String ruleId = mZenModeHelper.addAutomaticZenRule(mPkg, rule, UPDATE_ORIGIN_APP, "reason",
+ String ruleId = mZenModeHelper.addAutomaticZenRule(mPkg, rule, ORIGIN_APP, "reason",
CUSTOM_PKG_UID);
- mZenModeHelper.setAutomaticZenRuleState(ruleId, CONDITION_TRUE, UPDATE_ORIGIN_APP,
+ mZenModeHelper.setAutomaticZenRuleState(ruleId, CONDITION_TRUE, 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_APP, "reason",
+ mZenModeHelper.updateAutomaticZenRule(ruleId, updateWithDiff, ORIGIN_APP, "reason",
CUSTOM_PKG_UID);
assertThat(mZenModeHelper.getZenMode()).isEqualTo(ZEN_MODE_OFF);
@@ -5021,14 +5011,14 @@
.setConfigurationActivity(new ComponentName(mPkg, "cls"))
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
.build();
- String ruleId = mZenModeHelper.addAutomaticZenRule(mPkg, rule, UPDATE_ORIGIN_APP, "reason",
+ String ruleId = mZenModeHelper.addAutomaticZenRule(mPkg, rule, ORIGIN_APP, "reason",
CUSTOM_PKG_UID);
- mZenModeHelper.setAutomaticZenRuleState(ruleId, CONDITION_TRUE, UPDATE_ORIGIN_APP,
+ mZenModeHelper.setAutomaticZenRuleState(ruleId, CONDITION_TRUE, ORIGIN_APP,
CUSTOM_PKG_UID);
assertThat(mZenModeHelper.getZenMode()).isEqualTo(ZEN_MODE_IMPORTANT_INTERRUPTIONS);
AutomaticZenRule updateUnchanged = new AutomaticZenRule.Builder(rule).build();
- mZenModeHelper.updateAutomaticZenRule(ruleId, updateUnchanged, UPDATE_ORIGIN_APP, "reason",
+ mZenModeHelper.updateAutomaticZenRule(ruleId, updateUnchanged, ORIGIN_APP, "reason",
CUSTOM_PKG_UID);
assertThat(mZenModeHelper.getZenMode()).isEqualTo(ZEN_MODE_IMPORTANT_INTERRUPTIONS);
@@ -5044,17 +5034,17 @@
.setConfigurationActivity(new ComponentName(mPkg, "cls"))
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
.build();
- String ruleId = mZenModeHelper.addAutomaticZenRule(mPkg, rule, UPDATE_ORIGIN_APP, "reason",
+ String ruleId = mZenModeHelper.addAutomaticZenRule(mPkg, rule, ORIGIN_APP, "reason",
CUSTOM_PKG_UID);
- mZenModeHelper.setAutomaticZenRuleState(ruleId, CONDITION_TRUE, UPDATE_ORIGIN_APP,
+ mZenModeHelper.setAutomaticZenRuleState(ruleId, CONDITION_TRUE, 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);
+ mZenModeHelper.updateAutomaticZenRule(ruleId, updateWithDiff, ORIGIN_USER_IN_SYSTEMUI,
+ "reason", SYSTEM_UID);
assertThat(mZenModeHelper.getZenMode()).isEqualTo(ZEN_MODE_IMPORTANT_INTERRUPTIONS);
assertThat(mZenModeHelper.mConfig.automaticRules.get(ruleId).condition).isEqualTo(
@@ -5074,15 +5064,15 @@
.build();
String ruleId =
mZenModeHelper.addAutomaticZenRule(
- mPkg, rule, UPDATE_ORIGIN_APP, "reason", CUSTOM_PKG_UID);
+ mPkg, rule, ORIGIN_APP, "reason", CUSTOM_PKG_UID);
mZenModeHelper.setAutomaticZenRuleState(
- ruleId, CONDITION_TRUE, UPDATE_ORIGIN_APP, CUSTOM_PKG_UID);
+ ruleId, CONDITION_TRUE, 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);
+ mZenModeHelper.updateAutomaticZenRule(ruleId, updateWithDiff, ORIGIN_USER_IN_SYSTEMUI,
+ "reason", SYSTEM_UID);
assertThat(mZenModeHelper.getZenMode()).isEqualTo(ZEN_MODE_IMPORTANT_INTERRUPTIONS);
assertThat(mZenModeHelper.mConfig.automaticRules.get(ruleId).condition).isEqualTo(
@@ -5097,18 +5087,18 @@
.setConfigurationActivity(new ComponentName(mPkg, "cls"))
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
.build();
- String ruleId = mZenModeHelper.addAutomaticZenRule(mPkg, rule, UPDATE_ORIGIN_APP, "reason",
+ String ruleId = mZenModeHelper.addAutomaticZenRule(mPkg, rule, ORIGIN_APP, "reason",
CUSTOM_PKG_UID);
- mZenModeHelper.setAutomaticZenRuleState(ruleId, CONDITION_TRUE, UPDATE_ORIGIN_APP,
+ mZenModeHelper.setAutomaticZenRuleState(ruleId, CONDITION_TRUE, ORIGIN_APP,
CUSTOM_PKG_UID);
assertThat(mZenModeHelper.getZenMode()).isEqualTo(ZEN_MODE_IMPORTANT_INTERRUPTIONS);
mZenModeHelper.updateAutomaticZenRule(ruleId,
- new AutomaticZenRule.Builder(rule).setEnabled(false).build(), UPDATE_ORIGIN_USER,
- "disable", CUSTOM_PKG_UID);
+ new AutomaticZenRule.Builder(rule).setEnabled(false).build(),
+ ORIGIN_USER_IN_SYSTEMUI, "disable", SYSTEM_UID);
mZenModeHelper.updateAutomaticZenRule(ruleId,
- new AutomaticZenRule.Builder(rule).setEnabled(true).build(), UPDATE_ORIGIN_USER,
- "enable", CUSTOM_PKG_UID);
+ new AutomaticZenRule.Builder(rule).setEnabled(true).build(),
+ ORIGIN_USER_IN_SYSTEMUI, "enable", SYSTEM_UID);
assertThat(mZenModeHelper.getZenMode()).isEqualTo(ZEN_MODE_OFF);
assertThat(mZenModeHelper.mConfig.automaticRules.get(ruleId).condition).isNull();
@@ -5123,13 +5113,13 @@
.setOwner(new ComponentName("android", "some.old.cps"))
.build();
String ruleId = mZenModeHelper.addAutomaticZenRule("android", original,
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "reason", Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, "reason", SYSTEM_UID);
AutomaticZenRule update = new AutomaticZenRule.Builder("Rule", Uri.EMPTY)
.setOwner(new ComponentName("android", "brand.new.cps"))
.build();
- mZenModeHelper.updateAutomaticZenRule(ruleId, update, UPDATE_ORIGIN_USER, "reason",
- Process.SYSTEM_UID);
+ mZenModeHelper.updateAutomaticZenRule(ruleId, update, ORIGIN_USER_IN_SYSTEMUI, "reason",
+ SYSTEM_UID);
AutomaticZenRule result = mZenModeHelper.getAutomaticZenRule(ruleId);
assertThat(result).isNotNull();
@@ -5143,13 +5133,13 @@
.setOwner(new ComponentName(mContext.getPackageName(), "old.third.party.cps"))
.build();
String ruleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), original,
- UPDATE_ORIGIN_APP, "reason", CUSTOM_PKG_UID);
+ ORIGIN_APP, "reason", CUSTOM_PKG_UID);
AutomaticZenRule update = new AutomaticZenRule.Builder("Rule", Uri.EMPTY)
.setOwner(new ComponentName(mContext.getPackageName(), "new.third.party.cps"))
.build();
- mZenModeHelper.updateAutomaticZenRule(ruleId, update, UPDATE_ORIGIN_USER, "reason",
- Process.SYSTEM_UID);
+ mZenModeHelper.updateAutomaticZenRule(ruleId, update, ORIGIN_USER_IN_SYSTEMUI, "reason",
+ SYSTEM_UID);
AutomaticZenRule result = mZenModeHelper.getAutomaticZenRule(ruleId);
assertThat(result).isNotNull();
@@ -5166,24 +5156,24 @@
.setShouldSuppressAmbientDisplay(true)
.setShouldDimWallpaper(true)
.build());
- mZenModeHelper.setAutomaticZenRuleState(ruleId, CONDITION_TRUE, UPDATE_ORIGIN_APP,
+ mZenModeHelper.setAutomaticZenRuleState(ruleId, CONDITION_TRUE, ORIGIN_APP,
CUSTOM_PKG_UID);
mTestableLooper.processAllMessages();
- verify(mDeviceEffectsApplier).apply(any(), eq(UPDATE_ORIGIN_APP));
+ verify(mDeviceEffectsApplier).apply(any(), eq(ORIGIN_APP));
// Now delete the (currently active!) rule. For example, assume this is done from settings.
- mZenModeHelper.removeAutomaticZenRule(ruleId, UPDATE_ORIGIN_USER, "remove",
- Process.SYSTEM_UID);
+ mZenModeHelper.removeAutomaticZenRule(ruleId, ORIGIN_USER_IN_SYSTEMUI, "remove",
+ SYSTEM_UID);
mTestableLooper.processAllMessages();
- verify(mDeviceEffectsApplier).apply(eq(NO_EFFECTS), eq(UPDATE_ORIGIN_USER));
+ verify(mDeviceEffectsApplier).apply(eq(NO_EFFECTS), eq(ORIGIN_USER_IN_SYSTEMUI));
}
@Test
@EnableFlags(FLAG_MODES_API)
public void testDeviceEffects_applied() {
mZenModeHelper.setDeviceEffectsApplier(mDeviceEffectsApplier);
- verify(mDeviceEffectsApplier).apply(eq(NO_EFFECTS), eq(UPDATE_ORIGIN_INIT));
+ verify(mDeviceEffectsApplier).apply(eq(NO_EFFECTS), eq(ORIGIN_INIT));
ZenDeviceEffects effects = new ZenDeviceEffects.Builder()
.setShouldSuppressAmbientDisplay(true)
@@ -5192,11 +5182,11 @@
String ruleId = addRuleWithEffects(effects);
verifyNoMoreInteractions(mDeviceEffectsApplier);
- mZenModeHelper.setAutomaticZenRuleState(ruleId, CONDITION_TRUE, UPDATE_ORIGIN_APP,
+ mZenModeHelper.setAutomaticZenRuleState(ruleId, CONDITION_TRUE, ORIGIN_APP,
CUSTOM_PKG_UID);
mTestableLooper.processAllMessages();
- verify(mDeviceEffectsApplier).apply(eq(effects), eq(UPDATE_ORIGIN_APP));
+ verify(mDeviceEffectsApplier).apply(eq(effects), eq(ORIGIN_APP));
}
@Test
@@ -5206,30 +5196,30 @@
ZenDeviceEffects zde = new ZenDeviceEffects.Builder().setShouldUseNightMode(true).build();
String ruleId = addRuleWithEffects(zde);
- mZenModeHelper.setAutomaticZenRuleState(ruleId, CONDITION_TRUE, UPDATE_ORIGIN_APP,
+ mZenModeHelper.setAutomaticZenRuleState(ruleId, CONDITION_TRUE, ORIGIN_APP,
CUSTOM_PKG_UID);
mTestableLooper.processAllMessages();
- verify(mDeviceEffectsApplier).apply(eq(zde), eq(UPDATE_ORIGIN_APP));
+ verify(mDeviceEffectsApplier).apply(eq(zde), eq(ORIGIN_APP));
- mZenModeHelper.setAutomaticZenRuleState(ruleId, CONDITION_FALSE, UPDATE_ORIGIN_APP,
+ mZenModeHelper.setAutomaticZenRuleState(ruleId, CONDITION_FALSE, ORIGIN_APP,
CUSTOM_PKG_UID);
mTestableLooper.processAllMessages();
- verify(mDeviceEffectsApplier).apply(eq(NO_EFFECTS), eq(UPDATE_ORIGIN_APP));
+ verify(mDeviceEffectsApplier).apply(eq(NO_EFFECTS), eq(ORIGIN_APP));
}
@Test
@EnableFlags(FLAG_MODES_API)
public void testDeviceEffects_changeToConsolidatedEffects_applied() {
mZenModeHelper.setDeviceEffectsApplier(mDeviceEffectsApplier);
- verify(mDeviceEffectsApplier).apply(eq(NO_EFFECTS), eq(UPDATE_ORIGIN_INIT));
+ verify(mDeviceEffectsApplier).apply(eq(NO_EFFECTS), eq(ORIGIN_INIT));
String ruleId = addRuleWithEffects(
new ZenDeviceEffects.Builder()
.setShouldDisplayGrayscale(true)
.addExtraEffect("ONE")
.build());
- mZenModeHelper.setAutomaticZenRuleState(ruleId, CONDITION_TRUE, UPDATE_ORIGIN_APP,
+ mZenModeHelper.setAutomaticZenRuleState(ruleId, CONDITION_TRUE, ORIGIN_APP,
CUSTOM_PKG_UID);
mTestableLooper.processAllMessages();
verify(mDeviceEffectsApplier).apply(
@@ -5237,7 +5227,7 @@
.setShouldDisplayGrayscale(true)
.addExtraEffect("ONE")
.build()),
- eq(UPDATE_ORIGIN_APP));
+ eq(ORIGIN_APP));
// Now create and activate a second rule that adds more effects.
String secondRuleId = addRuleWithEffects(
@@ -5245,7 +5235,7 @@
.setShouldDimWallpaper(true)
.addExtraEffect("TWO")
.build());
- mZenModeHelper.setAutomaticZenRuleState(secondRuleId, CONDITION_TRUE, UPDATE_ORIGIN_APP,
+ mZenModeHelper.setAutomaticZenRuleState(secondRuleId, CONDITION_TRUE, ORIGIN_APP,
CUSTOM_PKG_UID);
mTestableLooper.processAllMessages();
@@ -5255,28 +5245,28 @@
.setShouldDimWallpaper(true)
.setExtraEffects(ImmutableSet.of("ONE", "TWO"))
.build()),
- eq(UPDATE_ORIGIN_APP));
+ eq(ORIGIN_APP));
}
@Test
@EnableFlags(FLAG_MODES_API)
public void testDeviceEffects_noChangeToConsolidatedEffects_notApplied() {
mZenModeHelper.setDeviceEffectsApplier(mDeviceEffectsApplier);
- verify(mDeviceEffectsApplier).apply(eq(NO_EFFECTS), eq(UPDATE_ORIGIN_INIT));
+ verify(mDeviceEffectsApplier).apply(eq(NO_EFFECTS), eq(ORIGIN_INIT));
ZenDeviceEffects zde = new ZenDeviceEffects.Builder()
.setShouldUseNightMode(true)
.addExtraEffect("extra_effect")
.build();
String ruleId = addRuleWithEffects(zde);
- mZenModeHelper.setAutomaticZenRuleState(ruleId, CONDITION_TRUE, UPDATE_ORIGIN_APP,
+ mZenModeHelper.setAutomaticZenRuleState(ruleId, CONDITION_TRUE, ORIGIN_APP,
CUSTOM_PKG_UID);
mTestableLooper.processAllMessages();
- verify(mDeviceEffectsApplier).apply(eq(zde), eq(UPDATE_ORIGIN_APP));
+ verify(mDeviceEffectsApplier).apply(eq(zde), eq(ORIGIN_APP));
// Now create and activate a second rule that doesn't add any more effects.
String secondRuleId = addRuleWithEffects(zde);
- mZenModeHelper.setAutomaticZenRuleState(secondRuleId, CONDITION_TRUE, UPDATE_ORIGIN_APP,
+ mZenModeHelper.setAutomaticZenRuleState(secondRuleId, CONDITION_TRUE, ORIGIN_APP,
CUSTOM_PKG_UID);
mTestableLooper.processAllMessages();
@@ -5290,20 +5280,20 @@
String ruleId = addRuleWithEffects(zde);
verify(mDeviceEffectsApplier, never()).apply(any(), anyInt());
- mZenModeHelper.setAutomaticZenRuleState(ruleId, CONDITION_TRUE, UPDATE_ORIGIN_APP,
+ mZenModeHelper.setAutomaticZenRuleState(ruleId, CONDITION_TRUE, ORIGIN_APP,
CUSTOM_PKG_UID);
mTestableLooper.processAllMessages();
verify(mDeviceEffectsApplier, never()).apply(any(), anyInt());
mZenModeHelper.setDeviceEffectsApplier(mDeviceEffectsApplier);
- verify(mDeviceEffectsApplier).apply(eq(zde), eq(UPDATE_ORIGIN_INIT));
+ verify(mDeviceEffectsApplier).apply(eq(zde), eq(ORIGIN_INIT));
}
@Test
@EnableFlags(FLAG_MODES_API)
public void testDeviceEffects_onUserSwitch_appliedImmediately() {
mZenModeHelper.setDeviceEffectsApplier(mDeviceEffectsApplier);
- verify(mDeviceEffectsApplier).apply(eq(NO_EFFECTS), eq(UPDATE_ORIGIN_INIT));
+ verify(mDeviceEffectsApplier).apply(eq(NO_EFFECTS), eq(ORIGIN_INIT));
// Initialize default configurations (default rules) for both users.
mZenModeHelper.onUserSwitched(1);
@@ -5324,7 +5314,7 @@
mTestableLooper.processAllMessages();
verify(mDeviceEffectsApplier).apply(eq(user1Rule.zenDeviceEffects),
- eq(UPDATE_ORIGIN_INIT_USER));
+ eq(ORIGIN_INIT_USER));
}
private String addRuleWithEffects(ZenDeviceEffects effects) {
@@ -5332,7 +5322,7 @@
.setDeviceEffects(effects)
.build();
return mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), rule,
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "reasons", Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, "reasons", SYSTEM_UID);
}
@Test
@@ -5346,7 +5336,7 @@
.setZenPolicy(new ZenPolicy.Builder().allowRepeatCallers(false).build())
.build();
String ruleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), rule,
- UPDATE_ORIGIN_APP, "add it", CUSTOM_PKG_UID);
+ ORIGIN_APP, "add it", CUSTOM_PKG_UID);
assertThat(mZenModeHelper.getAutomaticZenRule(ruleId).getCreationTime()).isEqualTo(1000);
// User customizes it.
@@ -5354,12 +5344,12 @@
.setInterruptionFilter(INTERRUPTION_FILTER_ALARMS)
.setZenPolicy(new ZenPolicy.Builder().allowRepeatCallers(true).build())
.build();
- mZenModeHelper.updateAutomaticZenRule(ruleId, userUpdate, UPDATE_ORIGIN_USER, "userUpdate",
- Process.SYSTEM_UID);
+ mZenModeHelper.updateAutomaticZenRule(ruleId, userUpdate, ORIGIN_USER_IN_SYSTEMUI,
+ "userUpdate", SYSTEM_UID);
// App deletes it.
mTestClock.advanceByMillis(1000);
- mZenModeHelper.removeAutomaticZenRule(ruleId, UPDATE_ORIGIN_APP, "delete it",
+ mZenModeHelper.removeAutomaticZenRule(ruleId, ORIGIN_APP, "delete it",
CUSTOM_PKG_UID);
assertThat(mZenModeHelper.mConfig.automaticRules).hasSize(0);
assertThat(mZenModeHelper.mConfig.deletedRules).hasSize(1);
@@ -5367,7 +5357,7 @@
// App adds it again.
mTestClock.advanceByMillis(1000);
String newRuleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), rule,
- UPDATE_ORIGIN_APP, "add it again", CUSTOM_PKG_UID);
+ ORIGIN_APP, "add it again", CUSTOM_PKG_UID);
// Verify that the rule was restored:
// - id and creation time is the same as the original one.
@@ -5401,12 +5391,12 @@
.setZenPolicy(new ZenPolicy.Builder().allowRepeatCallers(false).build())
.build();
String ruleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), rule,
- UPDATE_ORIGIN_APP, "add it", CUSTOM_PKG_UID);
+ ORIGIN_APP, "add it", CUSTOM_PKG_UID);
assertThat(mZenModeHelper.getAutomaticZenRule(ruleId).getCreationTime()).isEqualTo(1000);
// App deletes it.
mTestClock.advanceByMillis(1000);
- mZenModeHelper.removeAutomaticZenRule(ruleId, UPDATE_ORIGIN_APP, "delete it",
+ mZenModeHelper.removeAutomaticZenRule(ruleId, ORIGIN_APP, "delete it",
CUSTOM_PKG_UID);
assertThat(mZenModeHelper.mConfig.automaticRules).hasSize(0);
assertThat(mZenModeHelper.mConfig.deletedRules).hasSize(0);
@@ -5414,7 +5404,7 @@
// App adds it again.
mTestClock.advanceByMillis(1000);
String newRuleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), rule,
- UPDATE_ORIGIN_APP, "add it again", CUSTOM_PKG_UID);
+ ORIGIN_APP, "add it again", CUSTOM_PKG_UID);
// Verify that the rule was recreated. This means id and creation time are new.
AutomaticZenRule finalRule = mZenModeHelper.getAutomaticZenRule(newRuleId);
@@ -5433,7 +5423,7 @@
.setZenPolicy(new ZenPolicy.Builder().allowRepeatCallers(false).build())
.build();
String ruleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), rule,
- UPDATE_ORIGIN_APP, "add it", CUSTOM_PKG_UID);
+ ORIGIN_APP, "add it", CUSTOM_PKG_UID);
assertThat(mZenModeHelper.getAutomaticZenRule(ruleId).getCreationTime()).isEqualTo(1000);
// User customizes it.
@@ -5442,12 +5432,12 @@
.setInterruptionFilter(INTERRUPTION_FILTER_ALARMS)
.setZenPolicy(new ZenPolicy.Builder().allowRepeatCallers(true).build())
.build();
- mZenModeHelper.updateAutomaticZenRule(ruleId, userUpdate, UPDATE_ORIGIN_USER, "userUpdate",
- Process.SYSTEM_UID);
+ mZenModeHelper.updateAutomaticZenRule(ruleId, userUpdate, ORIGIN_USER_IN_SYSTEMUI,
+ "userUpdate", SYSTEM_UID);
// App deletes it.
mTestClock.advanceByMillis(1000);
- mZenModeHelper.removeAutomaticZenRule(ruleId, UPDATE_ORIGIN_APP, "delete it",
+ mZenModeHelper.removeAutomaticZenRule(ruleId, ORIGIN_APP, "delete it",
CUSTOM_PKG_UID);
assertThat(mZenModeHelper.mConfig.automaticRules).hasSize(0);
assertThat(mZenModeHelper.mConfig.deletedRules).hasSize(1);
@@ -5455,7 +5445,7 @@
// User creates it again (unusual case, but ok).
mTestClock.advanceByMillis(1000);
String newRuleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), rule,
- UPDATE_ORIGIN_USER, "add it anew", CUSTOM_PKG_UID);
+ ORIGIN_USER_IN_SYSTEMUI, "add it anew", SYSTEM_UID);
// Verify that the rule was recreated. This means id and creation time are new, and the rule
// matches the latest data supplied to addAZR.
@@ -5481,7 +5471,7 @@
.setZenPolicy(new ZenPolicy.Builder().allowRepeatCallers(false).build())
.build();
String ruleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), rule,
- UPDATE_ORIGIN_APP, "add it", CUSTOM_PKG_UID);
+ ORIGIN_APP, "add it", CUSTOM_PKG_UID);
assertThat(mZenModeHelper.getAutomaticZenRule(ruleId).getCreationTime()).isEqualTo(1000);
// User customizes it.
@@ -5490,20 +5480,20 @@
.setInterruptionFilter(INTERRUPTION_FILTER_ALARMS)
.setZenPolicy(new ZenPolicy.Builder().allowRepeatCallers(true).build())
.build();
- mZenModeHelper.updateAutomaticZenRule(ruleId, userUpdate, UPDATE_ORIGIN_USER, "userUpdate",
- Process.SYSTEM_UID);
+ mZenModeHelper.updateAutomaticZenRule(ruleId, userUpdate, ORIGIN_USER_IN_SYSTEMUI,
+ "userUpdate", SYSTEM_UID);
// User deletes it.
mTestClock.advanceByMillis(1000);
- mZenModeHelper.removeAutomaticZenRule(ruleId, UPDATE_ORIGIN_USER, "delete it",
- CUSTOM_PKG_UID);
+ mZenModeHelper.removeAutomaticZenRule(ruleId, ORIGIN_USER_IN_SYSTEMUI, "delete it",
+ SYSTEM_UID);
assertThat(mZenModeHelper.mConfig.automaticRules).hasSize(0);
assertThat(mZenModeHelper.mConfig.deletedRules).hasSize(0);
// App creates it again.
mTestClock.advanceByMillis(1000);
String newRuleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), rule,
- UPDATE_ORIGIN_APP, "add it again", CUSTOM_PKG_UID);
+ ORIGIN_APP, "add it again", CUSTOM_PKG_UID);
// Verify that the rule was recreated. This means id and creation time are new.
AutomaticZenRule finalRule = mZenModeHelper.getAutomaticZenRule(newRuleId);
@@ -5520,29 +5510,34 @@
// Start with a bunch of customized rules where conditionUris are not unique.
String id1 = mZenModeHelper.addAutomaticZenRule("pkg1",
- new AutomaticZenRule.Builder("Test1", Uri.parse("uri1")).build(), UPDATE_ORIGIN_APP,
+ new AutomaticZenRule.Builder("Test1", Uri.parse("uri1")).build(),
+ ORIGIN_APP,
"add it", CUSTOM_PKG_UID);
String id2 = mZenModeHelper.addAutomaticZenRule("pkg1",
- new AutomaticZenRule.Builder("Test2", Uri.parse("uri2")).build(), UPDATE_ORIGIN_APP,
+ new AutomaticZenRule.Builder("Test2", Uri.parse("uri2")).build(),
+ ORIGIN_APP,
"add it", CUSTOM_PKG_UID);
String id3 = mZenModeHelper.addAutomaticZenRule("pkg1",
- new AutomaticZenRule.Builder("Test3", Uri.parse("uri2")).build(), UPDATE_ORIGIN_APP,
+ new AutomaticZenRule.Builder("Test3", Uri.parse("uri2")).build(),
+ ORIGIN_APP,
"add it", CUSTOM_PKG_UID);
String id4 = mZenModeHelper.addAutomaticZenRule("pkg2",
- new AutomaticZenRule.Builder("Test4", Uri.parse("uri1")).build(), UPDATE_ORIGIN_APP,
+ new AutomaticZenRule.Builder("Test4", Uri.parse("uri1")).build(),
+ ORIGIN_APP,
"add it", CUSTOM_PKG_UID);
String id5 = mZenModeHelper.addAutomaticZenRule("pkg2",
- new AutomaticZenRule.Builder("Test5", Uri.parse("uri1")).build(), UPDATE_ORIGIN_APP,
+ new AutomaticZenRule.Builder("Test5", Uri.parse("uri1")).build(),
+ ORIGIN_APP,
"add it", CUSTOM_PKG_UID);
for (ZenRule zenRule : mZenModeHelper.mConfig.automaticRules.values()) {
zenRule.userModifiedFields = AutomaticZenRule.FIELD_INTERRUPTION_FILTER;
}
- mZenModeHelper.removeAutomaticZenRule(id1, UPDATE_ORIGIN_APP, "begone", CUSTOM_PKG_UID);
- mZenModeHelper.removeAutomaticZenRule(id2, UPDATE_ORIGIN_APP, "begone", CUSTOM_PKG_UID);
- mZenModeHelper.removeAutomaticZenRule(id3, UPDATE_ORIGIN_APP, "begone", CUSTOM_PKG_UID);
- mZenModeHelper.removeAutomaticZenRule(id4, UPDATE_ORIGIN_APP, "begone", CUSTOM_PKG_UID);
- mZenModeHelper.removeAutomaticZenRule(id5, UPDATE_ORIGIN_APP, "begone", CUSTOM_PKG_UID);
+ mZenModeHelper.removeAutomaticZenRule(id1, ORIGIN_APP, "begone", CUSTOM_PKG_UID);
+ mZenModeHelper.removeAutomaticZenRule(id2, ORIGIN_APP, "begone", CUSTOM_PKG_UID);
+ mZenModeHelper.removeAutomaticZenRule(id3, ORIGIN_APP, "begone", CUSTOM_PKG_UID);
+ mZenModeHelper.removeAutomaticZenRule(id4, ORIGIN_APP, "begone", CUSTOM_PKG_UID);
+ mZenModeHelper.removeAutomaticZenRule(id5, ORIGIN_APP, "begone", CUSTOM_PKG_UID);
assertThat(mZenModeHelper.mConfig.deletedRules.keySet())
.containsExactly("pkg1|uri1", "pkg1|uri2", "pkg2|uri1");
@@ -5557,17 +5552,19 @@
mZenModeHelper.mConfig.automaticRules.clear();
mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(),
- new AutomaticZenRule.Builder("Test1", Uri.parse("uri1")).build(), UPDATE_ORIGIN_APP,
+ new AutomaticZenRule.Builder("Test1", Uri.parse("uri1")).build(),
+ ORIGIN_APP,
"add it", CUSTOM_PKG_UID);
mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(),
- new AutomaticZenRule.Builder("Test2", Uri.parse("uri2")).build(), UPDATE_ORIGIN_APP,
+ new AutomaticZenRule.Builder("Test2", Uri.parse("uri2")).build(),
+ ORIGIN_APP,
"add it", CUSTOM_PKG_UID);
for (ZenRule zenRule : mZenModeHelper.mConfig.automaticRules.values()) {
zenRule.userModifiedFields = AutomaticZenRule.FIELD_INTERRUPTION_FILTER;
}
- mZenModeHelper.removeAutomaticZenRules(mContext.getPackageName(), UPDATE_ORIGIN_APP,
+ mZenModeHelper.removeAutomaticZenRules(mContext.getPackageName(), ORIGIN_APP,
"begone", CUSTOM_PKG_UID);
assertThat(mZenModeHelper.mConfig.deletedRules).hasSize(2);
@@ -5586,7 +5583,7 @@
mZenModeHelper.mConfig.deletedRules.put(ZenModeConfig.deletedRuleKey(pkg2Rule), pkg2Rule);
mZenModeHelper.removeAutomaticZenRules("pkg1",
- UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "goodbye pkg1", Process.SYSTEM_UID);
+ ZenModeConfig.ORIGIN_SYSTEM, "goodbye pkg1", SYSTEM_UID);
// Preserved rules from pkg1 are gone; those from pkg2 are still there.
assertThat(mZenModeHelper.mConfig.deletedRules.values().stream().map(r -> r.pkg)
@@ -5603,23 +5600,23 @@
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
.build();
String ruleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), rule,
- UPDATE_ORIGIN_APP, "add it", CUSTOM_PKG_UID);
+ ORIGIN_APP, "add it", CUSTOM_PKG_UID);
// User customizes it.
AutomaticZenRule userUpdate = new AutomaticZenRule.Builder(rule)
.setInterruptionFilter(INTERRUPTION_FILTER_ALARMS)
.build();
- mZenModeHelper.updateAutomaticZenRule(ruleId, userUpdate, UPDATE_ORIGIN_USER, "userUpdate",
- Process.SYSTEM_UID);
+ mZenModeHelper.updateAutomaticZenRule(ruleId, userUpdate, ORIGIN_USER_IN_SYSTEMUI,
+ "userUpdate", SYSTEM_UID);
assertThat(mZenModeHelper.getZenMode()).isEqualTo(ZEN_MODE_OFF);
// App activates it.
- mZenModeHelper.setAutomaticZenRuleState(ruleId, CONDITION_TRUE, UPDATE_ORIGIN_APP,
+ mZenModeHelper.setAutomaticZenRuleState(ruleId, CONDITION_TRUE, ORIGIN_APP,
CUSTOM_PKG_UID);
assertThat(mZenModeHelper.getZenMode()).isEqualTo(ZEN_MODE_ALARMS);
// App deletes it.
- mZenModeHelper.removeAutomaticZenRule(ruleId, UPDATE_ORIGIN_APP, "delete it",
+ mZenModeHelper.removeAutomaticZenRule(ruleId, ORIGIN_APP, "delete it",
CUSTOM_PKG_UID);
assertThat(mZenModeHelper.mConfig.automaticRules).hasSize(0);
assertThat(mZenModeHelper.mConfig.deletedRules).hasSize(1);
@@ -5627,7 +5624,7 @@
// App adds it again.
String newRuleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), rule,
- UPDATE_ORIGIN_APP, "add it again", CUSTOM_PKG_UID);
+ ORIGIN_APP, "add it again", CUSTOM_PKG_UID);
// The rule is restored...
assertThat(newRuleId).isEqualTo(ruleId);
@@ -5652,35 +5649,35 @@
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
.build();
String ruleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), rule,
- UPDATE_ORIGIN_APP, "add it", CUSTOM_PKG_UID);
+ ORIGIN_APP, "add it", CUSTOM_PKG_UID);
// User customizes it.
AutomaticZenRule userUpdate = new AutomaticZenRule.Builder(rule)
.setInterruptionFilter(INTERRUPTION_FILTER_ALARMS)
.build();
- mZenModeHelper.updateAutomaticZenRule(ruleId, userUpdate, UPDATE_ORIGIN_USER, "userUpdate",
- Process.SYSTEM_UID);
+ mZenModeHelper.updateAutomaticZenRule(ruleId, userUpdate, ORIGIN_USER_IN_SYSTEMUI,
+ "userUpdate", SYSTEM_UID);
assertThat(mZenModeHelper.getZenMode()).isEqualTo(ZEN_MODE_OFF);
// App activates it.
- mZenModeHelper.setAutomaticZenRuleState(ruleId, CONDITION_TRUE, UPDATE_ORIGIN_APP,
+ mZenModeHelper.setAutomaticZenRuleState(ruleId, CONDITION_TRUE, ORIGIN_APP,
CUSTOM_PKG_UID);
assertThat(mZenModeHelper.getZenMode()).isEqualTo(ZEN_MODE_ALARMS);
// User snoozes it.
- mZenModeHelper.setManualZenMode(ZEN_MODE_OFF, null, UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI,
- "snoozing", "systemui", Process.SYSTEM_UID);
+ mZenModeHelper.setManualZenMode(ZEN_MODE_OFF, null, ZenModeConfig.ORIGIN_SYSTEM,
+ "snoozing", "systemui", SYSTEM_UID);
assertThat(mZenModeHelper.getZenMode()).isEqualTo(ZEN_MODE_OFF);
// App deletes it.
- mZenModeHelper.removeAutomaticZenRule(ruleId, UPDATE_ORIGIN_APP, "delete it",
+ mZenModeHelper.removeAutomaticZenRule(ruleId, ORIGIN_APP, "delete it",
CUSTOM_PKG_UID);
assertThat(mZenModeHelper.mConfig.automaticRules).hasSize(0);
assertThat(mZenModeHelper.mConfig.deletedRules).hasSize(1);
// App adds it again.
String newRuleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), rule,
- UPDATE_ORIGIN_APP, "add it again", CUSTOM_PKG_UID);
+ ORIGIN_APP, "add it again", CUSTOM_PKG_UID);
// The rule is restored...
assertThat(newRuleId).isEqualTo(ruleId);
@@ -5762,20 +5759,20 @@
.setConfigurationActivity(
new ComponentName(mContext.getPackageName(), "Blah"))
.build(),
- UPDATE_ORIGIN_APP, "reasons", CUSTOM_PKG_UID);
+ ORIGIN_APP, "reasons", CUSTOM_PKG_UID);
// Null condition -> STATE_FALSE
assertThat(mZenModeHelper.getAutomaticZenRuleState(id)).isEqualTo(Condition.STATE_FALSE);
- mZenModeHelper.setAutomaticZenRuleState(id, CONDITION_TRUE, UPDATE_ORIGIN_APP,
+ mZenModeHelper.setAutomaticZenRuleState(id, CONDITION_TRUE, ORIGIN_APP,
CUSTOM_PKG_UID);
assertThat(mZenModeHelper.getAutomaticZenRuleState(id)).isEqualTo(Condition.STATE_TRUE);
- mZenModeHelper.setAutomaticZenRuleState(id, CONDITION_FALSE, UPDATE_ORIGIN_APP,
+ mZenModeHelper.setAutomaticZenRuleState(id, CONDITION_FALSE, ORIGIN_APP,
CUSTOM_PKG_UID);
assertThat(mZenModeHelper.getAutomaticZenRuleState(id)).isEqualTo(Condition.STATE_FALSE);
- mZenModeHelper.removeAutomaticZenRule(id, UPDATE_ORIGIN_APP, "", CUSTOM_PKG_UID);
+ mZenModeHelper.removeAutomaticZenRule(id, ORIGIN_APP, "", CUSTOM_PKG_UID);
assertThat(mZenModeHelper.getAutomaticZenRuleState(id)).isEqualTo(Condition.STATE_UNKNOWN);
}
@@ -5788,7 +5785,7 @@
systemRule.condition = new Condition(systemRule.conditionId, "on", Condition.STATE_TRUE);
ZenModeConfig config = mZenModeHelper.mConfig.copy();
config.automaticRules.put("systemRule", systemRule);
- mZenModeHelper.setConfig(config, null, UPDATE_ORIGIN_INIT, "", Process.SYSTEM_UID);
+ mZenModeHelper.setConfig(config, null, ORIGIN_INIT, "", SYSTEM_UID);
assertThat(mZenModeHelper.getZenMode()).isEqualTo(ZEN_MODE_ALARMS);
assertThat(mZenModeHelper.getAutomaticZenRuleState("systemRule")).isEqualTo(
@@ -5805,13 +5802,13 @@
otherRule.condition = new Condition(otherRule.conditionId, "on", Condition.STATE_TRUE);
ZenModeConfig config = mZenModeHelper.mConfig.copy();
config.automaticRules.put("otherRule", otherRule);
- mZenModeHelper.setConfig(config, null, UPDATE_ORIGIN_INIT, "", Process.SYSTEM_UID);
+ mZenModeHelper.setConfig(config, null, ORIGIN_INIT, "", SYSTEM_UID);
assertThat(mZenModeHelper.getZenMode()).isEqualTo(ZEN_MODE_ALARMS);
// Should be ignored.
mZenModeHelper.setAutomaticZenRuleState("otherRule",
new Condition(otherRule.conditionId, "off", Condition.STATE_FALSE),
- UPDATE_ORIGIN_APP, CUSTOM_PKG_UID);
+ ORIGIN_APP, CUSTOM_PKG_UID);
assertThat(mZenModeHelper.getZenMode()).isEqualTo(ZEN_MODE_ALARMS);
}
@@ -5826,13 +5823,13 @@
otherRule.condition = new Condition(otherRule.conditionId, "on", Condition.STATE_TRUE);
ZenModeConfig config = mZenModeHelper.mConfig.copy();
config.automaticRules.put("otherRule", otherRule);
- mZenModeHelper.setConfig(config, null, UPDATE_ORIGIN_INIT, "", Process.SYSTEM_UID);
+ mZenModeHelper.setConfig(config, null, ORIGIN_INIT, "", SYSTEM_UID);
assertThat(mZenModeHelper.getZenMode()).isEqualTo(ZEN_MODE_ALARMS);
// Should be ignored.
mZenModeHelper.setAutomaticZenRuleState(otherRule.conditionId,
new Condition(otherRule.conditionId, "off", Condition.STATE_FALSE),
- UPDATE_ORIGIN_APP, CUSTOM_PKG_UID);
+ ORIGIN_APP, CUSTOM_PKG_UID);
assertThat(mZenModeHelper.getZenMode()).isEqualTo(ZEN_MODE_ALARMS);
}
@@ -5851,7 +5848,7 @@
});
Policy totalSilencePolicy = new Policy(0, 0, 0);
- mZenModeHelper.setNotificationPolicy(totalSilencePolicy, UPDATE_ORIGIN_APP, CUSTOM_PKG_UID);
+ mZenModeHelper.setNotificationPolicy(totalSilencePolicy, ORIGIN_APP, CUSTOM_PKG_UID);
Policy callbackPolicy = futurePolicy.get(1, TimeUnit.SECONDS);
assertThat(callbackPolicy.allowReminders()).isFalse();
@@ -5874,9 +5871,9 @@
.setOwner(OWNER)
.setInterruptionFilter(INTERRUPTION_FILTER_NONE)
.build(),
- UPDATE_ORIGIN_APP, "reasons", 0);
+ ORIGIN_APP, "reasons", 0);
mZenModeHelper.setAutomaticZenRuleState(totalSilenceRuleId,
- new Condition(CONDITION_ID, "", STATE_TRUE), UPDATE_ORIGIN_APP, CUSTOM_PKG_UID);
+ new Condition(CONDITION_ID, "", STATE_TRUE), ORIGIN_APP, CUSTOM_PKG_UID);
Policy callbackPolicy = futureConsolidatedPolicy.get(1, TimeUnit.SECONDS);
assertThat(callbackPolicy.allowMedia()).isFalse();
@@ -5905,7 +5902,7 @@
mZenModeHelper.applyGlobalZenModeAsImplicitZenRule(CUSTOM_PKG_NAME, CUSTOM_PKG_UID,
ZEN_MODE_IMPORTANT_INTERRUPTIONS);
- mZenModeHelper.setManualZenMode(ZEN_MODE_OFF, null, UPDATE_ORIGIN_APP, "test", "test", 0);
+ mZenModeHelper.setManualZenMode(ZEN_MODE_OFF, null, ORIGIN_APP, "test", "test", 0);
assertThat(mZenModeHelper.mConfig.automaticRules).hasSize(1);
mZenModeHelper.applyGlobalZenModeAsImplicitZenRule(CUSTOM_PKG_NAME, CUSTOM_PKG_UID,
@@ -5937,8 +5934,8 @@
AutomaticZenRule userUpdateRule = new AutomaticZenRule.Builder(rule)
.setInterruptionFilter(INTERRUPTION_FILTER_ALARMS)
.build();
- mZenModeHelper.updateAutomaticZenRule(ruleId, userUpdateRule, UPDATE_ORIGIN_USER, "reason",
- Process.SYSTEM_UID);
+ mZenModeHelper.updateAutomaticZenRule(ruleId, userUpdateRule, ORIGIN_USER_IN_SYSTEMUI,
+ "reason", SYSTEM_UID);
// From app, call "setInterruptionFilter" again.
mZenModeHelper.applyGlobalZenModeAsImplicitZenRule(pkg, CUSTOM_PKG_UID,
@@ -5969,8 +5966,8 @@
AutomaticZenRule userUpdateRule = new AutomaticZenRule.Builder(rule)
.setName("Renamed")
.build();
- mZenModeHelper.updateAutomaticZenRule(ruleId, userUpdateRule, UPDATE_ORIGIN_USER, "reason",
- Process.SYSTEM_UID);
+ mZenModeHelper.updateAutomaticZenRule(ruleId, userUpdateRule, ORIGIN_USER_IN_SYSTEMUI,
+ "reason", SYSTEM_UID);
// From app, call "setInterruptionFilter" again.
mZenModeHelper.applyGlobalZenModeAsImplicitZenRule(pkg, CUSTOM_PKG_UID,
@@ -6020,7 +6017,7 @@
assertThat(mZenModeHelper.mConfig.automaticRules).hasSize(1);
assertThat(mZenModeHelper.mConfig.automaticRules.valueAt(0).snoozing).isFalse();
- mZenModeHelper.setManualZenMode(ZEN_MODE_OFF, null, UPDATE_ORIGIN_APP, "test", "test", 0);
+ mZenModeHelper.setManualZenMode(ZEN_MODE_OFF, null, ORIGIN_APP, "test", "test", 0);
assertThat(mZenModeHelper.mConfig.automaticRules.valueAt(0).snoozing).isTrue();
mZenModeHelper.applyGlobalZenModeAsImplicitZenRule(CUSTOM_PKG_NAME, CUSTOM_PKG_UID,
@@ -6121,8 +6118,8 @@
AutomaticZenRule userUpdateRule = new AutomaticZenRule.Builder(rule)
.setZenPolicy(userUpdateZenPolicy)
.build();
- mZenModeHelper.updateAutomaticZenRule(ruleId, userUpdateRule, UPDATE_ORIGIN_USER, "reason",
- Process.SYSTEM_UID);
+ mZenModeHelper.updateAutomaticZenRule(ruleId, userUpdateRule, ORIGIN_USER_IN_SYSTEMUI,
+ "reason", SYSTEM_UID);
// From app, call "setNotificationPolicy" again.
Policy appUpdatePolicy = new Policy(PRIORITY_CATEGORY_SYSTEM, 0, 0);
@@ -6159,8 +6156,8 @@
AutomaticZenRule userUpdateRule = new AutomaticZenRule.Builder(rule)
.setName("Rule renamed, not touching policy")
.build();
- mZenModeHelper.updateAutomaticZenRule(ruleId, userUpdateRule, UPDATE_ORIGIN_USER, "reason",
- Process.SYSTEM_UID);
+ mZenModeHelper.updateAutomaticZenRule(ruleId, userUpdateRule, ORIGIN_USER_IN_SYSTEMUI,
+ "reason", SYSTEM_UID);
// From app, call "setNotificationPolicy" again.
Policy appUpdatePolicy = new Policy(PRIORITY_CATEGORY_SYSTEM, 0, 0);
@@ -6215,7 +6212,7 @@
// If the policy then changes afterwards, it should inherit updates because user cannot
// edit the policy in the UI.
mZenModeHelper.setNotificationPolicy(new Policy(PRIORITY_CATEGORY_ALARMS, 0, 0),
- UPDATE_ORIGIN_APP, 1);
+ ORIGIN_APP, 1);
Policy readPolicy = mZenModeHelper.getNotificationPolicyFromImplicitZenRule(
CUSTOM_PKG_NAME);
@@ -6228,7 +6225,7 @@
@EnableFlags(FLAG_MODES_API)
public void getNotificationPolicyFromImplicitZenRule_noImplicitRule_returnsGlobalPolicy() {
Policy policy = new Policy(PRIORITY_CATEGORY_CALLS, PRIORITY_SENDERS_STARRED, 0);
- mZenModeHelper.setNotificationPolicy(policy, UPDATE_ORIGIN_USER, 1);
+ mZenModeHelper.setNotificationPolicy(policy, ORIGIN_APP, CUSTOM_PKG_UID);
Policy readPolicy = mZenModeHelper.getNotificationPolicyFromImplicitZenRule(
CUSTOM_PKG_NAME);
@@ -6264,7 +6261,7 @@
ZEN_MODE_IMPORTANT_INTERRUPTIONS, previousManualZenPolicy);
Policy newManualPolicy = new Policy(PRIORITY_CATEGORY_EVENTS, 0, 0);
- mZenModeHelper.setNotificationPolicy(newManualPolicy, UPDATE_ORIGIN_USER, 0);
+ mZenModeHelper.setNotificationPolicy(newManualPolicy, ORIGIN_APP, CUSTOM_PKG_UID);
ZenPolicy newManualZenPolicy = ZenAdapters.notificationPolicyToZenPolicy(newManualPolicy);
// Only app rules with default or same-as-manual policies were updated.
@@ -6294,7 +6291,7 @@
String ruleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(),
new AutomaticZenRule.Builder("Rule", CONDITION_ID).setIconResId(resourceId).build(),
- UPDATE_ORIGIN_APP, "reason", CUSTOM_PKG_UID);
+ ORIGIN_APP, "reason", CUSTOM_PKG_UID);
AutomaticZenRule storedRule = mZenModeHelper.getAutomaticZenRule(ruleId);
assertThat(storedRule.getIconResId()).isEqualTo(0);
@@ -6306,7 +6303,8 @@
ZenDeviceEffects effects = new ZenDeviceEffects.Builder()
.setShouldDimWallpaper(true)
.build();
- mZenModeHelper.setManualZenRuleDeviceEffects(effects, UPDATE_ORIGIN_USER, "settings", 1000);
+ mZenModeHelper.setManualZenRuleDeviceEffects(effects, ORIGIN_USER_IN_SYSTEMUI, "settings",
+ SYSTEM_UID);
assertThat(mZenModeHelper.getConfig().manualRule).isNotNull();
assertThat(mZenModeHelper.getConfig().isManualActive()).isFalse();
@@ -6316,13 +6314,14 @@
@Test
@EnableFlags({FLAG_MODES_API, FLAG_MODES_UI})
public void setManualZenRuleDeviceEffects_preexistingMode() {
- mZenModeHelper.setManualZenMode(ZEN_MODE_OFF, Uri.EMPTY, UPDATE_ORIGIN_USER,
- "create manual rule", "settings", 1000);
+ mZenModeHelper.setManualZenMode(ZEN_MODE_OFF, Uri.EMPTY, ORIGIN_USER_IN_SYSTEMUI,
+ "create manual rule", "settings", SYSTEM_UID);
ZenDeviceEffects effects = new ZenDeviceEffects.Builder()
.setShouldDimWallpaper(true)
.build();
- mZenModeHelper.setManualZenRuleDeviceEffects(effects, UPDATE_ORIGIN_USER, "settings", 1000);
+ mZenModeHelper.setManualZenRuleDeviceEffects(effects, ORIGIN_USER_IN_SYSTEMUI, "settings",
+ SYSTEM_UID);
assertThat(mZenModeHelper.getConfig().manualRule).isNotNull();
assertThat(mZenModeHelper.getConfig().isManualActive()).isFalse();
@@ -6337,11 +6336,12 @@
.setEnabled(false)
.build();
- String ruleId = mZenModeHelper.addAutomaticZenRule(mPkg, startsDisabled, UPDATE_ORIGIN_APP,
+ String ruleId = mZenModeHelper.addAutomaticZenRule(mPkg, startsDisabled,
+ ORIGIN_APP,
"new", CUSTOM_PKG_UID);
assertThat(mZenModeHelper.mConfig.automaticRules.get(ruleId).disabledOrigin).isEqualTo(
- UPDATE_ORIGIN_APP);
+ ORIGIN_APP);
}
@Test
@@ -6351,19 +6351,20 @@
.setOwner(new ComponentName(mPkg, "SomeProvider"))
.setEnabled(true)
.build();
- String ruleId = mZenModeHelper.addAutomaticZenRule(mPkg, startsEnabled, UPDATE_ORIGIN_APP,
+ String ruleId = mZenModeHelper.addAutomaticZenRule(mPkg, startsEnabled,
+ ORIGIN_APP,
"new", CUSTOM_PKG_UID);
assertThat(mZenModeHelper.mConfig.automaticRules.get(ruleId).disabledOrigin).isEqualTo(
- UPDATE_ORIGIN_UNKNOWN);
+ ORIGIN_UNKNOWN);
AutomaticZenRule nowDisabled = new AutomaticZenRule.Builder(startsEnabled)
.setEnabled(false)
.build();
- mZenModeHelper.updateAutomaticZenRule(ruleId, nowDisabled, UPDATE_ORIGIN_USER, "off",
- Process.SYSTEM_UID);
+ mZenModeHelper.updateAutomaticZenRule(ruleId, nowDisabled, ORIGIN_USER_IN_SYSTEMUI, "off",
+ SYSTEM_UID);
assertThat(mZenModeHelper.mConfig.automaticRules.get(ruleId).disabledOrigin).isEqualTo(
- UPDATE_ORIGIN_USER);
+ ORIGIN_USER_IN_SYSTEMUI);
}
@Test
@@ -6373,26 +6374,27 @@
.setOwner(new ComponentName(mPkg, "SomeProvider"))
.setEnabled(true)
.build();
- String ruleId = mZenModeHelper.addAutomaticZenRule(mPkg, startsEnabled, UPDATE_ORIGIN_APP,
+ String ruleId = mZenModeHelper.addAutomaticZenRule(mPkg, startsEnabled,
+ ORIGIN_APP,
"new", CUSTOM_PKG_UID);
AutomaticZenRule nowDisabled = new AutomaticZenRule.Builder(startsEnabled)
.setEnabled(false)
.build();
- mZenModeHelper.updateAutomaticZenRule(ruleId, nowDisabled, UPDATE_ORIGIN_USER, "off",
- Process.SYSTEM_UID);
+ mZenModeHelper.updateAutomaticZenRule(ruleId, nowDisabled, ORIGIN_USER_IN_SYSTEMUI, "off",
+ SYSTEM_UID);
assertThat(mZenModeHelper.mConfig.automaticRules.get(ruleId).disabledOrigin).isEqualTo(
- UPDATE_ORIGIN_USER);
+ ORIGIN_USER_IN_SYSTEMUI);
// Now update it again, for an unrelated reason with a different origin.
AutomaticZenRule nowRenamed = new AutomaticZenRule.Builder(nowDisabled)
.setName("Fancy pants rule")
.build();
- mZenModeHelper.updateAutomaticZenRule(ruleId, nowRenamed, UPDATE_ORIGIN_APP, "update",
+ mZenModeHelper.updateAutomaticZenRule(ruleId, nowRenamed, ORIGIN_APP, "update",
CUSTOM_PKG_UID);
// Identity of the disabler is preserved.
assertThat(mZenModeHelper.mConfig.automaticRules.get(ruleId).disabledOrigin).isEqualTo(
- UPDATE_ORIGIN_USER);
+ ORIGIN_USER_IN_SYSTEMUI);
}
@Test
@@ -6402,26 +6404,27 @@
.setOwner(new ComponentName(mPkg, "SomeProvider"))
.setEnabled(true)
.build();
- String ruleId = mZenModeHelper.addAutomaticZenRule(mPkg, startsEnabled, UPDATE_ORIGIN_APP,
+ String ruleId = mZenModeHelper.addAutomaticZenRule(mPkg, startsEnabled,
+ ORIGIN_APP,
"new", CUSTOM_PKG_UID);
AutomaticZenRule nowDisabled = new AutomaticZenRule.Builder(startsEnabled)
.setEnabled(false)
.build();
- mZenModeHelper.updateAutomaticZenRule(ruleId, nowDisabled, UPDATE_ORIGIN_USER, "off",
- Process.SYSTEM_UID);
+ mZenModeHelper.updateAutomaticZenRule(ruleId, nowDisabled, ORIGIN_USER_IN_SYSTEMUI, "off",
+ SYSTEM_UID);
assertThat(mZenModeHelper.mConfig.automaticRules.get(ruleId).disabledOrigin).isEqualTo(
- UPDATE_ORIGIN_USER);
+ ORIGIN_USER_IN_SYSTEMUI);
// Now enable it again
AutomaticZenRule nowEnabled = new AutomaticZenRule.Builder(nowDisabled)
.setEnabled(true)
.build();
- mZenModeHelper.updateAutomaticZenRule(ruleId, nowEnabled, UPDATE_ORIGIN_APP, "on",
+ mZenModeHelper.updateAutomaticZenRule(ruleId, nowEnabled, ORIGIN_APP, "on",
CUSTOM_PKG_UID);
// Identity of the disabler was cleared.
assertThat(mZenModeHelper.mConfig.automaticRules.get(ruleId).disabledOrigin).isEqualTo(
- UPDATE_ORIGIN_UNKNOWN);
+ ORIGIN_UNKNOWN);
}
private static void addZenRule(ZenModeConfig config, String id, String ownerPkg, int zenMode,
@@ -6494,7 +6497,7 @@
SUPPRESSED_EFFECT_BADGE,
0,
CONVERSATION_SENDERS_IMPORTANT);
- mZenModeHelper.setNotificationPolicy(customPolicy, UPDATE_ORIGIN_UNKNOWN, 1);
+ mZenModeHelper.setNotificationPolicy(customPolicy, ORIGIN_UNKNOWN, 1);
if (!Flags.modesUi()) {
mZenModeHelper.mConfig.manualRule = null;
}