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

Commit f92607b8 authored by Yuri Lin's avatar Yuri Lin Committed by Android (Google) Code Review
Browse files

Merge "When disallowing all sounds, also turn off priority channels." into main

parents 2fd19818 8014484e
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -673,6 +673,10 @@ public final class ZenPolicy implements Parcelable {
            mZenPolicy.mPriorityMessages = PEOPLE_TYPE_NONE;
            mZenPolicy.mPriorityCalls = PEOPLE_TYPE_NONE;
            mZenPolicy.mConversationSenders = CONVERSATION_SENDERS_NONE;

            if (Flags.modesApi()) {
                mZenPolicy.mAllowChannels = CHANNEL_POLICY_NONE;
            }
            return this;
        }

+68 −0
Original line number Diff line number Diff line
@@ -648,6 +648,74 @@ public class ZenModeHelperTest extends UiServiceTestCase {
        }
    }

    @Test
    @EnableFlags(Flags.FLAG_MODES_API)
    public void testTotalSilence_consolidatedPolicyDisallowsAll() {
        // Start with zen mode off just to make sure global/manual mode isn't doing anything.
        mZenModeHelper.mZenMode = ZEN_MODE_OFF;

        // Create a zen rule that calls for total silence via zen mode, but does not specify any
        // particular policy. This confirms that the application of the policy is based only on the
        // actual zen mode setting.
        AutomaticZenRule azr = new AutomaticZenRule.Builder("OriginalName", CONDITION_ID)
                .setInterruptionFilter(INTERRUPTION_FILTER_NONE)
                .build();
        String ruleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(),
                azr, UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "reason", Process.SYSTEM_UID);

        // Enable rule
        mZenModeHelper.setAutomaticZenRuleState(ruleId,
                new Condition(azr.getConditionId(), "", STATE_TRUE),
                UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI,
                Process.SYSTEM_UID);

        // Confirm that the consolidated policy doesn't allow anything
        NotificationManager.Policy policy = mZenModeHelper.getConsolidatedNotificationPolicy();
        assertThat(policy.allowAlarms()).isFalse();
        assertThat(policy.allowMedia()).isFalse();
        assertThat(policy.allowCalls()).isFalse();
        assertThat(policy.allowMessages()).isFalse();
        assertThat(policy.allowConversations()).isFalse();
        assertThat(policy.allowEvents()).isFalse();
        assertThat(policy.allowReminders()).isFalse();
        assertThat(policy.allowRepeatCallers()).isFalse();
        assertThat(policy.allowPriorityChannels()).isFalse();
    }

    @Test
    @EnableFlags(Flags.FLAG_MODES_API)
    public void testAlarmsOnly_consolidatedPolicyOnlyAllowsAlarmsAndMedia() {
        // Start with zen mode off just to make sure global/manual mode isn't doing anything.
        mZenModeHelper.mZenMode = ZEN_MODE_OFF;

        // Create a zen rule that calls for alarms only via zen mode, but does not specify any
        // particular policy. This confirms that the application of the policy is based only on the
        // actual zen mode setting.
        AutomaticZenRule azr = new AutomaticZenRule.Builder("OriginalName", CONDITION_ID)
                .setInterruptionFilter(INTERRUPTION_FILTER_ALARMS)
                .build();
        String ruleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(),
                azr, UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI, "reason", Process.SYSTEM_UID);

        // Enable rule
        mZenModeHelper.setAutomaticZenRuleState(ruleId,
                new Condition(azr.getConditionId(), "", STATE_TRUE),
                UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI,
                Process.SYSTEM_UID);

        // Confirm that the consolidated policy allows only alarms and media and nothing else
        NotificationManager.Policy policy = mZenModeHelper.getConsolidatedNotificationPolicy();
        assertThat(policy.allowAlarms()).isTrue();
        assertThat(policy.allowMedia()).isTrue();
        assertThat(policy.allowCalls()).isFalse();
        assertThat(policy.allowMessages()).isFalse();
        assertThat(policy.allowConversations()).isFalse();
        assertThat(policy.allowEvents()).isFalse();
        assertThat(policy.allowReminders()).isFalse();
        assertThat(policy.allowRepeatCallers()).isFalse();
        assertThat(policy.allowPriorityChannels()).isFalse();
    }

    @Test
    public void testZenUpgradeNotification() {
        /**