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) {
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.android.settings.notification.zen;
|
||||
import static android.app.slice.Slice.EXTRA_TOGGLE_STATE;
|
||||
|
||||
import android.annotation.ColorInt;
|
||||
import android.app.Flags;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.settings.SettingsEnums;
|
||||
@@ -116,7 +117,12 @@ public class ZenModeSliceBuilder {
|
||||
} else {
|
||||
zenMode = Settings.Global.ZEN_MODE_OFF;
|
||||
}
|
||||
NotificationManager.from(context).setZenMode(zenMode, null /* conditionId */, TAG);
|
||||
if (Flags.modesApi()) {
|
||||
NotificationManager.from(context).setZenMode(zenMode, /* conditionId= */ null, TAG,
|
||||
/* fromUser= */ true);
|
||||
} else {
|
||||
NotificationManager.from(context).setZenMode(zenMode, null /* conditionId */, TAG);
|
||||
}
|
||||
// Do not notifyChange on Uri. The service takes longer to update the current value than it
|
||||
// does for the Slice to check the current value again. Let {@link SliceBroadcastRelay}
|
||||
// handle it.
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.android.settings.notification.zen;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Flags;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.NotificationManager.Policy;
|
||||
import android.app.settings.SettingsEnums;
|
||||
@@ -129,7 +130,11 @@ public class ZenOnboardingActivity extends Activity {
|
||||
Policy.PRIORITY_SENDERS_STARRED,
|
||||
policy.priorityMessageSenders,
|
||||
NotificationManager.Policy.getAllSuppressedVisualEffects());
|
||||
mNm.setNotificationPolicy(newPolicy);
|
||||
if (Flags.modesApi()) {
|
||||
mNm.setNotificationPolicy(newPolicy, /* fromUser= */ true);
|
||||
} else {
|
||||
mNm.setNotificationPolicy(newPolicy);
|
||||
}
|
||||
mMetrics.action(SettingsEnums.ACTION_ZEN_ONBOARDING_OK);
|
||||
} else {
|
||||
mMetrics.action(SettingsEnums.ACTION_ZEN_ONBOARDING_KEEP_CURRENT_SETTINGS);
|
||||
|
||||
Reference in New Issue
Block a user