Tag Zen operations from Settings as coming from the user
Bug: 308670715 Test: atest ApprovalPreferenceControllerTest Change-Id: Id118f867e84f3d742db6b12eab0f34df1357d178
This commit is contained in:
@@ -56,7 +56,6 @@ public class ZenModeBackend {
|
||||
@VisibleForTesting
|
||||
protected static final String ZEN_MODE_FROM_NONE = "zen_mode_from_none";
|
||||
protected static final int SOURCE_NONE = -1;
|
||||
private static List<String> mDefaultRuleIds;
|
||||
|
||||
private static ZenModeBackend sInstance;
|
||||
|
||||
@@ -65,7 +64,7 @@ public class ZenModeBackend {
|
||||
protected NotificationManager.Policy mPolicy;
|
||||
private final NotificationManager mNotificationManager;
|
||||
|
||||
private String TAG = "ZenModeSettingsBackend";
|
||||
private static final String TAG = "ZenModeSettingsBackend";
|
||||
private final Context mContext;
|
||||
|
||||
public static ZenModeBackend getInstance(Context context) {
|
||||
@@ -95,19 +94,32 @@ public class ZenModeBackend {
|
||||
}
|
||||
|
||||
protected boolean updateZenRule(String id, AutomaticZenRule rule) {
|
||||
return NotificationManager.from(mContext).updateAutomaticZenRule(id, rule);
|
||||
if (android.app.Flags.modesApi()) {
|
||||
return mNotificationManager.updateAutomaticZenRule(id, rule, /* fromUser= */ true);
|
||||
} else {
|
||||
return NotificationManager.from(mContext).updateAutomaticZenRule(id, rule);
|
||||
}
|
||||
}
|
||||
|
||||
protected void setZenMode(int zenMode) {
|
||||
NotificationManager.from(mContext).setZenMode(zenMode, null, TAG);
|
||||
if (android.app.Flags.modesApi()) {
|
||||
mNotificationManager.setZenMode(zenMode, null, TAG, /* fromUser= */ true);
|
||||
} else {
|
||||
NotificationManager.from(mContext).setZenMode(zenMode, null, TAG);
|
||||
}
|
||||
mZenMode = getZenMode();
|
||||
}
|
||||
|
||||
protected void setZenModeForDuration(int minutes) {
|
||||
Uri conditionId = ZenModeConfig.toTimeCondition(mContext, minutes,
|
||||
ActivityManager.getCurrentUser(), true).id;
|
||||
mNotificationManager.setZenMode(Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS,
|
||||
conditionId, TAG);
|
||||
if (android.app.Flags.modesApi()) {
|
||||
mNotificationManager.setZenMode(Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS,
|
||||
conditionId, TAG, /* fromUser= */ true);
|
||||
} else {
|
||||
mNotificationManager.setZenMode(Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS,
|
||||
conditionId, TAG);
|
||||
}
|
||||
mZenMode = getZenMode();
|
||||
}
|
||||
|
||||
@@ -180,7 +192,11 @@ public class ZenModeBackend {
|
||||
int priorityConversationSenders) {
|
||||
mPolicy = new NotificationManager.Policy(priorityCategories, priorityCallSenders,
|
||||
priorityMessageSenders, suppressedVisualEffects, priorityConversationSenders);
|
||||
mNotificationManager.setNotificationPolicy(mPolicy);
|
||||
if (android.app.Flags.modesApi()) {
|
||||
mNotificationManager.setNotificationPolicy(mPolicy, /* fromUser= */ true);
|
||||
} else {
|
||||
mNotificationManager.setNotificationPolicy(mPolicy);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -357,7 +373,11 @@ public class ZenModeBackend {
|
||||
}
|
||||
|
||||
public boolean removeZenRule(String ruleId) {
|
||||
return NotificationManager.from(mContext).removeAutomaticZenRule(ruleId);
|
||||
if (android.app.Flags.modesApi()) {
|
||||
return mNotificationManager.removeAutomaticZenRule(ruleId, /* fromUser= */ true);
|
||||
} else {
|
||||
return NotificationManager.from(mContext).removeAutomaticZenRule(ruleId);
|
||||
}
|
||||
}
|
||||
|
||||
public NotificationManager.Policy getConsolidatedPolicy() {
|
||||
@@ -366,7 +386,11 @@ public class ZenModeBackend {
|
||||
|
||||
protected String addZenRule(AutomaticZenRule rule) {
|
||||
try {
|
||||
return NotificationManager.from(mContext).addAutomaticZenRule(rule);
|
||||
if (android.app.Flags.modesApi()) {
|
||||
return mNotificationManager.addAutomaticZenRule(rule, /* fromUser= */ true);
|
||||
} else {
|
||||
return NotificationManager.from(mContext).addAutomaticZenRule(rule);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
@@ -429,10 +453,7 @@ public class ZenModeBackend {
|
||||
}
|
||||
|
||||
private static List<String> getDefaultRuleIds() {
|
||||
if (mDefaultRuleIds == null) {
|
||||
mDefaultRuleIds = ZenModeConfig.DEFAULT_RULE_IDS;
|
||||
}
|
||||
return mDefaultRuleIds;
|
||||
return ZenModeConfig.DEFAULT_RULE_IDS;
|
||||
}
|
||||
|
||||
NotificationManager.Policy toNotificationPolicy(ZenPolicy policy) {
|
||||
|
||||
Reference in New Issue
Block a user