Update DND/Priority Mode defaults for new users.

The new default settings are that, by default:
- starred contacts are allowed through
- priority conversations are allowed through
- rather than suppressing all visual effects, only suppress full screen intents, lights, peek, ambient display, and everything when screen is off for older target sdks

Test: manually verified settings for a fresh user via factory reset
Bug: 190180868

Change-Id: I3efb4d8192a6699743bc8be1616074c5c65c26a7
This commit is contained in:
Yuri Lin
2021-07-13 14:37:54 -04:00
parent 30eb87d8e0
commit 72e45ffe4d
3 changed files with 34 additions and 19 deletions

View File

@@ -19,9 +19,11 @@ package android.service.notification;
import static android.app.NotificationManager.Policy.CONVERSATION_SENDERS_ANYONE;
import static android.app.NotificationManager.Policy.CONVERSATION_SENDERS_IMPORTANT;
import static android.app.NotificationManager.Policy.CONVERSATION_SENDERS_NONE;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_AMBIENT;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_FULL_SCREEN_INTENT;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_LIGHTS;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_PEEK;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_SCREEN_OFF;
import android.annotation.Nullable;
import android.app.ActivityManager;
@@ -79,7 +81,7 @@ public class ZenModeConfig implements Parcelable {
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 DEFAULT_SOURCE = SOURCE_CONTACT;
private static final int DEFAULT_SOURCE = SOURCE_STAR;
private static final int DEFAULT_CALLS_SOURCE = SOURCE_STAR;
public static final String MANUAL_RULE_ID = "MANUAL_RULE";
@@ -103,14 +105,17 @@ public class ZenModeConfig implements Parcelable {
private static final boolean DEFAULT_ALLOW_MEDIA = true;
private static final boolean DEFAULT_ALLOW_SYSTEM = false;
private static final boolean DEFAULT_ALLOW_CALLS = true;
private static final boolean DEFAULT_ALLOW_MESSAGES = false;
private static final boolean DEFAULT_ALLOW_MESSAGES = true;
private static final boolean DEFAULT_ALLOW_REMINDERS = false;
private static final boolean DEFAULT_ALLOW_EVENTS = false;
private static final boolean DEFAULT_ALLOW_REPEAT_CALLERS = true;
private static final boolean DEFAULT_ALLOW_CONV = false;
private static final int DEFAULT_ALLOW_CONV_FROM = ZenPolicy.CONVERSATION_SENDERS_NONE;
private static final boolean DEFAULT_ALLOW_CONV = true;
private static final int DEFAULT_ALLOW_CONV_FROM = ZenPolicy.CONVERSATION_SENDERS_IMPORTANT;
private static final boolean DEFAULT_CHANNELS_BYPASSING_DND = false;
private static final int DEFAULT_SUPPRESSED_VISUAL_EFFECTS = 0;
// Default setting here is 010011101 = 157
private static final int DEFAULT_SUPPRESSED_VISUAL_EFFECTS =
SUPPRESSED_EFFECT_SCREEN_OFF | SUPPRESSED_EFFECT_FULL_SCREEN_INTENT
| SUPPRESSED_EFFECT_LIGHTS | SUPPRESSED_EFFECT_PEEK | SUPPRESSED_EFFECT_AMBIENT;
public static final int XML_VERSION = 8;
public static final String ZEN_TAG = "zen";
@@ -568,16 +573,22 @@ public class ZenModeConfig implements Parcelable {
// migrate old suppressed visual effects fields, if they still exist in the xml
Boolean allowWhenScreenOff = unsafeBoolean(parser, ALLOW_ATT_SCREEN_OFF);
if (allowWhenScreenOff != null) {
Boolean allowWhenScreenOn = unsafeBoolean(parser, ALLOW_ATT_SCREEN_ON);
if (allowWhenScreenOff != null || allowWhenScreenOn != null) {
// If either setting exists, then reset the suppressed visual effects field
// to 0 (all allowed) so that only the relevant bits are disallowed by
// the migrated settings.
readSuppressedEffects = true;
rt.suppressedVisualEffects = 0;
}
if (allowWhenScreenOff != null) {
if (!allowWhenScreenOff) {
rt.suppressedVisualEffects |= SUPPRESSED_EFFECT_LIGHTS
| SUPPRESSED_EFFECT_FULL_SCREEN_INTENT;
| SUPPRESSED_EFFECT_FULL_SCREEN_INTENT
| SUPPRESSED_EFFECT_AMBIENT;
}
}
Boolean allowWhenScreenOn = unsafeBoolean(parser, ALLOW_ATT_SCREEN_ON);
if (allowWhenScreenOn != null) {
readSuppressedEffects = true;
if (!allowWhenScreenOn) {
rt.suppressedVisualEffects |= SUPPRESSED_EFFECT_PEEK;
}
@@ -1001,7 +1012,7 @@ public class ZenModeConfig implements Parcelable {
builder.showBadges(
(suppressedVisualEffects & Policy.SUPPRESSED_EFFECT_BADGE) == 0);
builder.showInAmbientDisplay(
(suppressedVisualEffects & Policy.SUPPRESSED_EFFECT_AMBIENT) == 0);
(suppressedVisualEffects & SUPPRESSED_EFFECT_AMBIENT) == 0);
builder.showInNotificationList(
(suppressedVisualEffects & Policy.SUPPRESSED_EFFECT_NOTIFICATION_LIST) == 0);
}
@@ -1085,7 +1096,7 @@ public class ZenModeConfig implements Parcelable {
boolean suppressAmbient = !zenPolicy.isVisualEffectAllowed(
ZenPolicy.VISUAL_EFFECT_AMBIENT,
isVisualEffectAllowed(Policy.SUPPRESSED_EFFECT_AMBIENT,
isVisualEffectAllowed(SUPPRESSED_EFFECT_AMBIENT,
defaultPolicy));
if (suppressFullScreenIntent && suppressLights && suppressAmbient) {
@@ -1120,7 +1131,7 @@ public class ZenModeConfig implements Parcelable {
}
if (suppressAmbient) {
suppressedVisualEffects |= Policy.SUPPRESSED_EFFECT_AMBIENT;
suppressedVisualEffects |= SUPPRESSED_EFFECT_AMBIENT;
}
if (!zenPolicy.isVisualEffectAllowed(ZenPolicy.VISUAL_EFFECT_NOTIFICATION_LIST,

View File

@@ -18,18 +18,18 @@
-->
<!-- Default configuration for zen mode. See android.service.notification.ZenModeConfig. -->
<zen version="9">
<allow alarms="true" media="true" system="false" calls="true" callsFrom="2" messages="false"
reminders="false" events="false" repeatCallers="true" convos="false"
convosFrom="3"/>
<zen version="10">
<allow alarms="true" media="true" system="false" calls="true" callsFrom="2" messages="true"
messagesFrom="2" reminders="false" events="false" repeatCallers="true" convos="true"
convosFrom="2"/>
<automatic ruleId="EVENTS_DEFAULT_RULE" enabled="false" snoozing="false" name="Event" zen="1"
component="android/com.android.server.notification.EventConditionProvider"
conditionId="condition://android/event?userId=-10000&amp;calendar=&amp;reply=1"/>
<automatic ruleId="EVERY_NIGHT_DEFAULT_RULE" enabled="false" snoozing="false" name="Sleeping"
zen="1" component="android/com.android.server.notification.ScheduleConditionProvider"
conditionId="condition://android/schedule?days=1.2.3.4.5.6.7&amp;start=22.0&amp;end=7.0&amp;exitAtAlarm=true"/>
<!-- all visual effects that exist as of P -->
<disallow visualEffects="511" />
<!-- everything when screen off (for old target sdks); fullscreen; lights; peek; ambient -->
<disallow visualEffects="157" />
<!-- whether there are notification channels that can bypass dnd -->
<state areChannelsBypassingDnd="false" />
</zen>

View File

@@ -28,6 +28,7 @@ import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_REPEAT_CA
import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_SYSTEM;
import static android.app.NotificationManager.Policy.PRIORITY_SENDERS_ANY;
import static android.app.NotificationManager.Policy.PRIORITY_SENDERS_STARRED;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_AMBIENT;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_BADGE;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_FULL_SCREEN_INTENT;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_LIGHTS;
@@ -1248,6 +1249,7 @@ public class ZenModeHelperTest extends UiServiceTestCase {
assertEquals(SUPPRESSED_EFFECT_FULL_SCREEN_INTENT
| SUPPRESSED_EFFECT_LIGHTS
| SUPPRESSED_EFFECT_AMBIENT
| SUPPRESSED_EFFECT_PEEK,
mZenModeHelperSpy.mConfig.suppressedVisualEffects);
@@ -1281,7 +1283,9 @@ public class ZenModeHelperTest extends UiServiceTestCase {
parser.nextTag();
mZenModeHelperSpy.readXml(parser, false, UserHandle.USER_ALL);
assertEquals(SUPPRESSED_EFFECT_FULL_SCREEN_INTENT | SUPPRESSED_EFFECT_LIGHTS,
assertEquals(SUPPRESSED_EFFECT_FULL_SCREEN_INTENT
| SUPPRESSED_EFFECT_LIGHTS
| SUPPRESSED_EFFECT_AMBIENT,
mZenModeHelperSpy.mConfig.suppressedVisualEffects);
}