Design refresh for modes that don't filter notifications

And fix a crash noticed in ZenModeAppsLinkPreferenceController

Test: atest com/android/settings/notification/modes
Fixes: 308820027
Flag: android.app.modes_ui
Change-Id: I0cfe4e10ca7ff97dac3b3b8756cc36f4d6f91ea2
This commit is contained in:
Julia Reynolds
2024-06-17 09:15:57 -04:00
parent 78a0662272
commit 3b62c23310
18 changed files with 281 additions and 276 deletions

View File

@@ -59,26 +59,8 @@ class ZenMode {
private static final String TAG = "ZenMode";
/**
* Additional value for the {@code @ZenPolicy.ChannelType} enumeration that indicates that all
* channels can bypass DND when this policy is active.
*
* <p>This value shouldn't be used on "real" ZenPolicy objects sent to or returned from
* {@link android.app.NotificationManager}; it's a way of representing rules with interruption
* filter = {@link NotificationManager#INTERRUPTION_FILTER_ALL} in the UI.
*/
public static final int CHANNEL_POLICY_ALL = -1;
static final String MANUAL_DND_MODE_ID = "manual_dnd";
@SuppressLint("WrongConstant")
private static final ZenPolicy POLICY_INTERRUPTION_FILTER_ALL =
new ZenPolicy.Builder()
.allowChannels(CHANNEL_POLICY_ALL)
.allowAllSounds()
.showAllVisualEffects()
.build();
// Must match com.android.server.notification.ZenModeHelper#applyCustomPolicy.
private static final ZenPolicy POLICY_INTERRUPTION_FILTER_ALARMS =
new ZenPolicy.Builder()
@@ -141,10 +123,8 @@ class ZenMode {
public ZenPolicy getPolicy() {
switch (mRule.getInterruptionFilter()) {
case INTERRUPTION_FILTER_PRIORITY:
return requireNonNull(mRule.getZenPolicy());
case NotificationManager.INTERRUPTION_FILTER_ALL:
return POLICY_INTERRUPTION_FILTER_ALL;
return requireNonNull(mRule.getZenPolicy());
case NotificationManager.INTERRUPTION_FILTER_ALARMS:
return POLICY_INTERRUPTION_FILTER_ALARMS;
@@ -172,31 +152,8 @@ class ZenMode {
return;
}
// A policy with CHANNEL_POLICY_ALL is only a UI representation of the
// INTERRUPTION_FILTER_ALL filter. Thus, switching to or away to this value only updates
// the filter, discarding the rest of the supplied policy.
if (policy.getAllowedChannels() == CHANNEL_POLICY_ALL
&& currentPolicy.getAllowedChannels() != CHANNEL_POLICY_ALL) {
if (mIsManualDnd) {
throw new IllegalArgumentException("Manual DND cannot have CHANNEL_POLICY_ALL");
}
mRule.setInterruptionFilter(INTERRUPTION_FILTER_ALL);
// Preserve the existing policy, e.g. if the user goes PRIORITY -> ALL -> PRIORITY that
// shouldn't discard all other policy customizations. The existing policy will be a
// synthetic one if the rule originally had filter NONE or ALARMS_ONLY and that's fine.
if (mRule.getZenPolicy() == null) {
mRule.setZenPolicy(currentPolicy);
}
return;
} else if (policy.getAllowedChannels() != CHANNEL_POLICY_ALL
&& currentPolicy.getAllowedChannels() == CHANNEL_POLICY_ALL) {
mRule.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY);
// Go back to whatever policy the rule had before, unless the rule never had one, in
// which case we use the supplied policy (which we know has a valid allowedChannels).
if (mRule.getZenPolicy() == null) {
mRule.setZenPolicy(policy);
}
return;
if (mRule.getInterruptionFilter() == INTERRUPTION_FILTER_ALL) {
Log.wtf(TAG, "Able to change policy without filtering being enabled");
}
// If policy is customized from any of the "special" ones, make the rule PRIORITY.