Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fa2f28de authored by Matías Hernández's avatar Matías Hernández
Browse files

Remove obsolete ZenModeConfig fields and methods

This is the last step of MODES_UI inlining. The fields previously used for the "global" policy were only used to read from old XML versions and move them to manualRule.zenPolicy.

Bug: 368247671
Flag: EXEMPT Small change with good test coverage
Test: atest ZenModeConfigTest ZenModeDiffTest ZenModeHelperTest
Change-Id: If6f122f861b06968be00bcbcb71d7a10e3dee453
parent b9cffe82
Loading
Loading
Loading
Loading
+101 −275

File changed.

Preview size limit exceeded, changes collapsed.

+0 −5
Original line number Diff line number Diff line
@@ -235,7 +235,6 @@ public class ZenModeDiff {
        // Field name constants
        public static final String FIELD_USER = "user";
        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.
@@ -263,10 +262,6 @@ public class ZenModeDiff {
                addField(FIELD_HAS_PRIORITY_CHANNELS,
                        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
            final ArraySet<String> allRules = new ArraySet<>();
+40 −8
Original line number Diff line number Diff line
@@ -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.ZenRule.OVERRIDE_DEACTIVATE;
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.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 com.google.common.truth.Truth.assertThat;
@@ -271,7 +274,7 @@ public class ZenModeConfigTest extends UiServiceTestCase {
                .showBadges(false)
                .showInAmbientDisplay(false)
                .allowCalls(ZenPolicy.PEOPLE_TYPE_CONTACTS)
                .allowMessages(ZenPolicy.PEOPLE_TYPE_STARRED)
                .allowMessages(PEOPLE_TYPE_STARRED)
                .allowConversations(ZenPolicy.CONVERSATION_SENDERS_NONE)
                .allowPriorityChannels(false)
                .build();
@@ -298,21 +301,18 @@ public class ZenModeConfigTest extends UiServiceTestCase {
    public void testPriorityOnlyMutingAll() {
        ZenModeConfig config = getMutedAllConfig();
        assertTrue(ZenModeConfig.areAllPriorityOnlyRingerSoundsMuted(config));
        assertTrue(ZenModeConfig.areAllZenBehaviorSoundsMuted(config));

        config.manualRule.zenPolicy = new ZenPolicy.Builder(config.manualRule.zenPolicy)
                .allowReminders(true)
                .build();

        assertFalse(ZenModeConfig.areAllPriorityOnlyRingerSoundsMuted(config));
        assertFalse(ZenModeConfig.areAllZenBehaviorSoundsMuted(config));

        config.manualRule.zenPolicy = new ZenPolicy.Builder(config.manualRule.zenPolicy)
                .allowReminders(false)
                .build();

        assertTrue(ZenModeConfig.areAllPriorityOnlyRingerSoundsMuted(config));
        assertTrue(ZenModeConfig.areAllZenBehaviorSoundsMuted(config));

        config.hasPriorityChannels = true;
        config.manualRule.zenPolicy = new ZenPolicy.Builder(config.manualRule.zenPolicy)
@@ -320,7 +320,6 @@ public class ZenModeConfigTest extends UiServiceTestCase {
                .build();

        assertFalse(ZenModeConfig.areAllPriorityOnlyRingerSoundsMuted(config));
        assertFalse(ZenModeConfig.areAllZenBehaviorSoundsMuted(config));

        config.hasPriorityChannels = false;
        config.manualRule.zenPolicy = new ZenPolicy.Builder(config.manualRule.zenPolicy)
@@ -331,14 +330,12 @@ public class ZenModeConfigTest extends UiServiceTestCase {
                .build();

        assertTrue(ZenModeConfig.areAllPriorityOnlyRingerSoundsMuted(config));
        assertFalse(ZenModeConfig.areAllZenBehaviorSoundsMuted(config));

        config.manualRule.zenPolicy = new ZenPolicy.Builder(config.manualRule.zenPolicy)
                .allowAlarms(false)
                .build();

        assertTrue(ZenModeConfig.areAllPriorityOnlyRingerSoundsMuted(config));
        assertTrue(ZenModeConfig.areAllZenBehaviorSoundsMuted(config));
    }

    @Test
@@ -400,8 +397,43 @@ public class ZenModeConfigTest extends UiServiceTestCase {
    }

    @Test
    @EnableFlags(FLAG_BACKUP_RESTORE_LOGGING)
    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"
                + "<allow calls=\"true\" repeatCallers=\"true\" messages=\"true\""
                + " reminders=\"false\" events=\"false\" callsFrom=\"2\" messagesFrom=\"2\""
+1 −6
Original line number Diff line number Diff line
@@ -76,12 +76,7 @@ public class ZenModeDiffTest extends UiServiceTestCase {
    // version is not included in the diff; manual & automatic rules have special handling;
    // deleted rules are not included in the diff.
    public static final Set<String> ZEN_MODE_CONFIG_EXEMPT_FIELDS =
            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");
            Set.of("version", "manualRule", "automaticRules", "deletedRules");

    @Rule
    public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();