Loading core/java/android/service/notification/ZenModeConfig.java +101 −275 File changed.Preview size limit exceeded, changes collapsed. Show changes core/java/android/service/notification/ZenModeDiff.java +0 −5 Original line number Original line Diff line number Diff line Loading @@ -235,7 +235,6 @@ public class ZenModeDiff { // Field name constants // Field name constants public static final String FIELD_USER = "user"; public static final String FIELD_USER = "user"; public static final String FIELD_HAS_PRIORITY_CHANNELS = "hasPriorityChannels"; public static final String FIELD_HAS_PRIORITY_CHANNELS = "hasPriorityChannels"; public static final String FIELD_ALLOW_PRIORITY_CHANNELS = "allowPriorityChannels"; /** /** * Create a diff that contains diffs between the "from" and "to" ZenModeConfigs. * Create a diff that contains diffs between the "from" and "to" ZenModeConfigs. Loading Loading @@ -263,10 +262,6 @@ public class ZenModeDiff { addField(FIELD_HAS_PRIORITY_CHANNELS, addField(FIELD_HAS_PRIORITY_CHANNELS, new FieldDiff<>(from.hasPriorityChannels, to.hasPriorityChannels)); new FieldDiff<>(from.hasPriorityChannels, to.hasPriorityChannels)); } } if (from.allowPriorityChannels != to.allowPriorityChannels) { addField(FIELD_ALLOW_PRIORITY_CHANNELS, new FieldDiff<>(from.allowPriorityChannels, to.allowPriorityChannels)); } // Compare automatic and manual rules // Compare automatic and manual rules final ArraySet<String> allRules = new ArraySet<>(); final ArraySet<String> allRules = new ArraySet<>(); Loading services/tests/uiservicestests/src/com/android/server/notification/ZenModeConfigTest.java +40 −8 Original line number Original line Diff line number Diff line Loading @@ -35,8 +35,11 @@ import static android.service.notification.ZenModeConfig.XML_VERSION_MODES_UI; import static android.service.notification.ZenModeConfig.ZEN_TAG; import static android.service.notification.ZenModeConfig.ZEN_TAG; import static android.service.notification.ZenModeConfig.ZenRule.OVERRIDE_DEACTIVATE; import static android.service.notification.ZenModeConfig.ZenRule.OVERRIDE_DEACTIVATE; import static android.service.notification.ZenModeConfig.ZenRule.OVERRIDE_NONE; import static android.service.notification.ZenModeConfig.ZenRule.OVERRIDE_NONE; import static android.service.notification.ZenPolicy.CONVERSATION_SENDERS_ANYONE; import static android.service.notification.ZenPolicy.CONVERSATION_SENDERS_IMPORTANT; import static android.service.notification.ZenPolicy.CONVERSATION_SENDERS_IMPORTANT; import static android.service.notification.ZenPolicy.PEOPLE_TYPE_ANYONE; import static android.service.notification.ZenPolicy.PEOPLE_TYPE_ANYONE; import static android.service.notification.ZenPolicy.PEOPLE_TYPE_CONTACTS; import static android.service.notification.ZenPolicy.PEOPLE_TYPE_STARRED; import static android.service.notification.ZenPolicy.STATE_ALLOW; import static android.service.notification.ZenPolicy.STATE_ALLOW; import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat; Loading Loading @@ -271,7 +274,7 @@ public class ZenModeConfigTest extends UiServiceTestCase { .showBadges(false) .showBadges(false) .showInAmbientDisplay(false) .showInAmbientDisplay(false) .allowCalls(ZenPolicy.PEOPLE_TYPE_CONTACTS) .allowCalls(ZenPolicy.PEOPLE_TYPE_CONTACTS) .allowMessages(ZenPolicy.PEOPLE_TYPE_STARRED) .allowMessages(PEOPLE_TYPE_STARRED) .allowConversations(ZenPolicy.CONVERSATION_SENDERS_NONE) .allowConversations(ZenPolicy.CONVERSATION_SENDERS_NONE) .allowPriorityChannels(false) .allowPriorityChannels(false) .build(); .build(); Loading @@ -298,21 +301,18 @@ public class ZenModeConfigTest extends UiServiceTestCase { public void testPriorityOnlyMutingAll() { public void testPriorityOnlyMutingAll() { ZenModeConfig config = getMutedAllConfig(); ZenModeConfig config = getMutedAllConfig(); assertTrue(ZenModeConfig.areAllPriorityOnlyRingerSoundsMuted(config)); assertTrue(ZenModeConfig.areAllPriorityOnlyRingerSoundsMuted(config)); assertTrue(ZenModeConfig.areAllZenBehaviorSoundsMuted(config)); config.manualRule.zenPolicy = new ZenPolicy.Builder(config.manualRule.zenPolicy) config.manualRule.zenPolicy = new ZenPolicy.Builder(config.manualRule.zenPolicy) .allowReminders(true) .allowReminders(true) .build(); .build(); assertFalse(ZenModeConfig.areAllPriorityOnlyRingerSoundsMuted(config)); assertFalse(ZenModeConfig.areAllPriorityOnlyRingerSoundsMuted(config)); assertFalse(ZenModeConfig.areAllZenBehaviorSoundsMuted(config)); config.manualRule.zenPolicy = new ZenPolicy.Builder(config.manualRule.zenPolicy) config.manualRule.zenPolicy = new ZenPolicy.Builder(config.manualRule.zenPolicy) .allowReminders(false) .allowReminders(false) .build(); .build(); assertTrue(ZenModeConfig.areAllPriorityOnlyRingerSoundsMuted(config)); assertTrue(ZenModeConfig.areAllPriorityOnlyRingerSoundsMuted(config)); assertTrue(ZenModeConfig.areAllZenBehaviorSoundsMuted(config)); config.hasPriorityChannels = true; config.hasPriorityChannels = true; config.manualRule.zenPolicy = new ZenPolicy.Builder(config.manualRule.zenPolicy) config.manualRule.zenPolicy = new ZenPolicy.Builder(config.manualRule.zenPolicy) Loading @@ -320,7 +320,6 @@ public class ZenModeConfigTest extends UiServiceTestCase { .build(); .build(); assertFalse(ZenModeConfig.areAllPriorityOnlyRingerSoundsMuted(config)); assertFalse(ZenModeConfig.areAllPriorityOnlyRingerSoundsMuted(config)); assertFalse(ZenModeConfig.areAllZenBehaviorSoundsMuted(config)); config.hasPriorityChannels = false; config.hasPriorityChannels = false; config.manualRule.zenPolicy = new ZenPolicy.Builder(config.manualRule.zenPolicy) config.manualRule.zenPolicy = new ZenPolicy.Builder(config.manualRule.zenPolicy) Loading @@ -331,14 +330,12 @@ public class ZenModeConfigTest extends UiServiceTestCase { .build(); .build(); assertTrue(ZenModeConfig.areAllPriorityOnlyRingerSoundsMuted(config)); assertTrue(ZenModeConfig.areAllPriorityOnlyRingerSoundsMuted(config)); assertFalse(ZenModeConfig.areAllZenBehaviorSoundsMuted(config)); config.manualRule.zenPolicy = new ZenPolicy.Builder(config.manualRule.zenPolicy) config.manualRule.zenPolicy = new ZenPolicy.Builder(config.manualRule.zenPolicy) .allowAlarms(false) .allowAlarms(false) .build(); .build(); assertTrue(ZenModeConfig.areAllPriorityOnlyRingerSoundsMuted(config)); assertTrue(ZenModeConfig.areAllPriorityOnlyRingerSoundsMuted(config)); assertTrue(ZenModeConfig.areAllZenBehaviorSoundsMuted(config)); } } @Test @Test Loading Loading @@ -400,8 +397,43 @@ public class ZenModeConfigTest extends UiServiceTestCase { } } @Test @Test @EnableFlags(FLAG_BACKUP_RESTORE_LOGGING) public void testBackupRestore_fromPreModesUi() throws IOException, XmlPullParserException { public void testBackupRestore_fromPreModesUi() throws IOException, XmlPullParserException { // Very non-default XML, to check that DND policy is transferred from the old values. String xml = """ <zen version="12"> <allow calls="true" repeatCallers="false" messages="true" reminders="false" events="true" callsFrom="0" messagesFrom="1" alarms="true" media="false" system="true" convos="true" convosFrom="1" priorityChannelsAllowed="false" /> <disallow visualEffects="24" /> <manual enabled="true" zen="1" creationTime="0" modified="false" /> <state areChannelsBypassingDnd="true" /> </zen>"""; ZenModeConfig config = readConfigXml(new ByteArrayInputStream(xml.getBytes()), mock(BackupRestoreEventLogger.class)); assertThat(config.manualRule.zenPolicy).isEqualTo( new ZenPolicy.Builder() .allowCalls(PEOPLE_TYPE_ANYONE) .allowMessages(PEOPLE_TYPE_CONTACTS) .allowConversations(CONVERSATION_SENDERS_ANYONE) .allowRepeatCallers(false) .allowReminders(false) .allowEvents(true) .allowAlarms(true) .allowMedia(false) .allowSystem(true) .allowPriorityChannels(false) .showAllVisualEffects() .showLights(false) .showPeeking(false) .build()); } @Test @EnableFlags(FLAG_BACKUP_RESTORE_LOGGING) public void testBackupRestore_fromPreModesUi_logs() throws IOException, XmlPullParserException { String xml = "<zen version=\"12\">\n" String xml = "<zen version=\"12\">\n" + "<allow calls=\"true\" repeatCallers=\"true\" messages=\"true\"" + "<allow calls=\"true\" repeatCallers=\"true\" messages=\"true\"" + " reminders=\"false\" events=\"false\" callsFrom=\"2\" messagesFrom=\"2\"" + " reminders=\"false\" events=\"false\" callsFrom=\"2\" messagesFrom=\"2\"" Loading services/tests/uiservicestests/src/com/android/server/notification/ZenModeDiffTest.java +1 −6 Original line number Original line Diff line number Diff line Loading @@ -76,12 +76,7 @@ public class ZenModeDiffTest extends UiServiceTestCase { // version is not included in the diff; manual & automatic rules have special handling; // version is not included in the diff; manual & automatic rules have special handling; // deleted rules are not included in the diff. // deleted rules are not included in the diff. public static final Set<String> ZEN_MODE_CONFIG_EXEMPT_FIELDS = public static final Set<String> ZEN_MODE_CONFIG_EXEMPT_FIELDS = Set.of("version", "manualRule", "automaticRules", "deletedRules", Set.of("version", "manualRule", "automaticRules", "deletedRules"); // TODO: b/368247671 - Delete these exemptions once fields are gone. "allowAlarms", "allowMedia", "allowSystem", "allowCalls", "allowReminders", "allowEvents", "allowRepeatCallers", "allowMessages", "allowConversations", "allowCallsFrom", "allowMessagesFrom", "allowConversationsFrom", "suppressedVisualEffects"); @Rule @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); Loading Loading
core/java/android/service/notification/ZenModeConfig.java +101 −275 File changed.Preview size limit exceeded, changes collapsed. Show changes
core/java/android/service/notification/ZenModeDiff.java +0 −5 Original line number Original line Diff line number Diff line Loading @@ -235,7 +235,6 @@ public class ZenModeDiff { // Field name constants // Field name constants public static final String FIELD_USER = "user"; public static final String FIELD_USER = "user"; public static final String FIELD_HAS_PRIORITY_CHANNELS = "hasPriorityChannels"; public static final String FIELD_HAS_PRIORITY_CHANNELS = "hasPriorityChannels"; public static final String FIELD_ALLOW_PRIORITY_CHANNELS = "allowPriorityChannels"; /** /** * Create a diff that contains diffs between the "from" and "to" ZenModeConfigs. * Create a diff that contains diffs between the "from" and "to" ZenModeConfigs. Loading Loading @@ -263,10 +262,6 @@ public class ZenModeDiff { addField(FIELD_HAS_PRIORITY_CHANNELS, addField(FIELD_HAS_PRIORITY_CHANNELS, new FieldDiff<>(from.hasPriorityChannels, to.hasPriorityChannels)); new FieldDiff<>(from.hasPriorityChannels, to.hasPriorityChannels)); } } if (from.allowPriorityChannels != to.allowPriorityChannels) { addField(FIELD_ALLOW_PRIORITY_CHANNELS, new FieldDiff<>(from.allowPriorityChannels, to.allowPriorityChannels)); } // Compare automatic and manual rules // Compare automatic and manual rules final ArraySet<String> allRules = new ArraySet<>(); final ArraySet<String> allRules = new ArraySet<>(); Loading
services/tests/uiservicestests/src/com/android/server/notification/ZenModeConfigTest.java +40 −8 Original line number Original line Diff line number Diff line Loading @@ -35,8 +35,11 @@ import static android.service.notification.ZenModeConfig.XML_VERSION_MODES_UI; import static android.service.notification.ZenModeConfig.ZEN_TAG; import static android.service.notification.ZenModeConfig.ZEN_TAG; import static android.service.notification.ZenModeConfig.ZenRule.OVERRIDE_DEACTIVATE; import static android.service.notification.ZenModeConfig.ZenRule.OVERRIDE_DEACTIVATE; import static android.service.notification.ZenModeConfig.ZenRule.OVERRIDE_NONE; import static android.service.notification.ZenModeConfig.ZenRule.OVERRIDE_NONE; import static android.service.notification.ZenPolicy.CONVERSATION_SENDERS_ANYONE; import static android.service.notification.ZenPolicy.CONVERSATION_SENDERS_IMPORTANT; import static android.service.notification.ZenPolicy.CONVERSATION_SENDERS_IMPORTANT; import static android.service.notification.ZenPolicy.PEOPLE_TYPE_ANYONE; import static android.service.notification.ZenPolicy.PEOPLE_TYPE_ANYONE; import static android.service.notification.ZenPolicy.PEOPLE_TYPE_CONTACTS; import static android.service.notification.ZenPolicy.PEOPLE_TYPE_STARRED; import static android.service.notification.ZenPolicy.STATE_ALLOW; import static android.service.notification.ZenPolicy.STATE_ALLOW; import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat; Loading Loading @@ -271,7 +274,7 @@ public class ZenModeConfigTest extends UiServiceTestCase { .showBadges(false) .showBadges(false) .showInAmbientDisplay(false) .showInAmbientDisplay(false) .allowCalls(ZenPolicy.PEOPLE_TYPE_CONTACTS) .allowCalls(ZenPolicy.PEOPLE_TYPE_CONTACTS) .allowMessages(ZenPolicy.PEOPLE_TYPE_STARRED) .allowMessages(PEOPLE_TYPE_STARRED) .allowConversations(ZenPolicy.CONVERSATION_SENDERS_NONE) .allowConversations(ZenPolicy.CONVERSATION_SENDERS_NONE) .allowPriorityChannels(false) .allowPriorityChannels(false) .build(); .build(); Loading @@ -298,21 +301,18 @@ public class ZenModeConfigTest extends UiServiceTestCase { public void testPriorityOnlyMutingAll() { public void testPriorityOnlyMutingAll() { ZenModeConfig config = getMutedAllConfig(); ZenModeConfig config = getMutedAllConfig(); assertTrue(ZenModeConfig.areAllPriorityOnlyRingerSoundsMuted(config)); assertTrue(ZenModeConfig.areAllPriorityOnlyRingerSoundsMuted(config)); assertTrue(ZenModeConfig.areAllZenBehaviorSoundsMuted(config)); config.manualRule.zenPolicy = new ZenPolicy.Builder(config.manualRule.zenPolicy) config.manualRule.zenPolicy = new ZenPolicy.Builder(config.manualRule.zenPolicy) .allowReminders(true) .allowReminders(true) .build(); .build(); assertFalse(ZenModeConfig.areAllPriorityOnlyRingerSoundsMuted(config)); assertFalse(ZenModeConfig.areAllPriorityOnlyRingerSoundsMuted(config)); assertFalse(ZenModeConfig.areAllZenBehaviorSoundsMuted(config)); config.manualRule.zenPolicy = new ZenPolicy.Builder(config.manualRule.zenPolicy) config.manualRule.zenPolicy = new ZenPolicy.Builder(config.manualRule.zenPolicy) .allowReminders(false) .allowReminders(false) .build(); .build(); assertTrue(ZenModeConfig.areAllPriorityOnlyRingerSoundsMuted(config)); assertTrue(ZenModeConfig.areAllPriorityOnlyRingerSoundsMuted(config)); assertTrue(ZenModeConfig.areAllZenBehaviorSoundsMuted(config)); config.hasPriorityChannels = true; config.hasPriorityChannels = true; config.manualRule.zenPolicy = new ZenPolicy.Builder(config.manualRule.zenPolicy) config.manualRule.zenPolicy = new ZenPolicy.Builder(config.manualRule.zenPolicy) Loading @@ -320,7 +320,6 @@ public class ZenModeConfigTest extends UiServiceTestCase { .build(); .build(); assertFalse(ZenModeConfig.areAllPriorityOnlyRingerSoundsMuted(config)); assertFalse(ZenModeConfig.areAllPriorityOnlyRingerSoundsMuted(config)); assertFalse(ZenModeConfig.areAllZenBehaviorSoundsMuted(config)); config.hasPriorityChannels = false; config.hasPriorityChannels = false; config.manualRule.zenPolicy = new ZenPolicy.Builder(config.manualRule.zenPolicy) config.manualRule.zenPolicy = new ZenPolicy.Builder(config.manualRule.zenPolicy) Loading @@ -331,14 +330,12 @@ public class ZenModeConfigTest extends UiServiceTestCase { .build(); .build(); assertTrue(ZenModeConfig.areAllPriorityOnlyRingerSoundsMuted(config)); assertTrue(ZenModeConfig.areAllPriorityOnlyRingerSoundsMuted(config)); assertFalse(ZenModeConfig.areAllZenBehaviorSoundsMuted(config)); config.manualRule.zenPolicy = new ZenPolicy.Builder(config.manualRule.zenPolicy) config.manualRule.zenPolicy = new ZenPolicy.Builder(config.manualRule.zenPolicy) .allowAlarms(false) .allowAlarms(false) .build(); .build(); assertTrue(ZenModeConfig.areAllPriorityOnlyRingerSoundsMuted(config)); assertTrue(ZenModeConfig.areAllPriorityOnlyRingerSoundsMuted(config)); assertTrue(ZenModeConfig.areAllZenBehaviorSoundsMuted(config)); } } @Test @Test Loading Loading @@ -400,8 +397,43 @@ public class ZenModeConfigTest extends UiServiceTestCase { } } @Test @Test @EnableFlags(FLAG_BACKUP_RESTORE_LOGGING) public void testBackupRestore_fromPreModesUi() throws IOException, XmlPullParserException { public void testBackupRestore_fromPreModesUi() throws IOException, XmlPullParserException { // Very non-default XML, to check that DND policy is transferred from the old values. String xml = """ <zen version="12"> <allow calls="true" repeatCallers="false" messages="true" reminders="false" events="true" callsFrom="0" messagesFrom="1" alarms="true" media="false" system="true" convos="true" convosFrom="1" priorityChannelsAllowed="false" /> <disallow visualEffects="24" /> <manual enabled="true" zen="1" creationTime="0" modified="false" /> <state areChannelsBypassingDnd="true" /> </zen>"""; ZenModeConfig config = readConfigXml(new ByteArrayInputStream(xml.getBytes()), mock(BackupRestoreEventLogger.class)); assertThat(config.manualRule.zenPolicy).isEqualTo( new ZenPolicy.Builder() .allowCalls(PEOPLE_TYPE_ANYONE) .allowMessages(PEOPLE_TYPE_CONTACTS) .allowConversations(CONVERSATION_SENDERS_ANYONE) .allowRepeatCallers(false) .allowReminders(false) .allowEvents(true) .allowAlarms(true) .allowMedia(false) .allowSystem(true) .allowPriorityChannels(false) .showAllVisualEffects() .showLights(false) .showPeeking(false) .build()); } @Test @EnableFlags(FLAG_BACKUP_RESTORE_LOGGING) public void testBackupRestore_fromPreModesUi_logs() throws IOException, XmlPullParserException { String xml = "<zen version=\"12\">\n" String xml = "<zen version=\"12\">\n" + "<allow calls=\"true\" repeatCallers=\"true\" messages=\"true\"" + "<allow calls=\"true\" repeatCallers=\"true\" messages=\"true\"" + " reminders=\"false\" events=\"false\" callsFrom=\"2\" messagesFrom=\"2\"" + " reminders=\"false\" events=\"false\" callsFrom=\"2\" messagesFrom=\"2\"" Loading
services/tests/uiservicestests/src/com/android/server/notification/ZenModeDiffTest.java +1 −6 Original line number Original line Diff line number Diff line Loading @@ -76,12 +76,7 @@ public class ZenModeDiffTest extends UiServiceTestCase { // version is not included in the diff; manual & automatic rules have special handling; // version is not included in the diff; manual & automatic rules have special handling; // deleted rules are not included in the diff. // deleted rules are not included in the diff. public static final Set<String> ZEN_MODE_CONFIG_EXEMPT_FIELDS = public static final Set<String> ZEN_MODE_CONFIG_EXEMPT_FIELDS = Set.of("version", "manualRule", "automaticRules", "deletedRules", Set.of("version", "manualRule", "automaticRules", "deletedRules"); // TODO: b/368247671 - Delete these exemptions once fields are gone. "allowAlarms", "allowMedia", "allowSystem", "allowCalls", "allowReminders", "allowEvents", "allowRepeatCallers", "allowMessages", "allowConversations", "allowCallsFrom", "allowMessagesFrom", "allowConversationsFrom", "suppressedVisualEffects"); @Rule @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); Loading