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

Commit 99064f7d authored by Yuri Lin's avatar Yuri Lin
Browse files

Handle allowChannels in ZenAdapters

Fixes: 316382678
Test: ZenAdaptersTest
Change-Id: I3b92848e015bd95acf94c8599623e02cccc1b421
parent 170445c4
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.server.notification;

import android.app.Flags;
import android.app.NotificationManager.Policy;
import android.service.notification.ZenModeConfig;
import android.service.notification.ZenPolicy;
@@ -57,6 +58,12 @@ class ZenAdapters {
                    .showStatusBarIcons(policy.showStatusBarIcons());
        }

        if (Flags.modesApi()) {
            zenPolicyBuilder.allowChannels(
                    policy.allowPriorityChannels()
                            ? ZenPolicy.CHANNEL_TYPE_PRIORITY : ZenPolicy.CHANNEL_TYPE_NONE);
        }

        return zenPolicyBuilder.build();
    }

+39 −0
Original line number Diff line number Diff line
@@ -20,7 +20,11 @@ import static com.android.server.notification.ZenAdapters.notificationPolicyToZe

import static com.google.common.truth.Truth.assertThat;

import android.app.Flags;
import android.app.NotificationManager.Policy;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.service.notification.ZenPolicy;

import androidx.test.filters.SmallTest;
@@ -28,6 +32,7 @@ import androidx.test.runner.AndroidJUnit4;

import com.android.server.UiServiceTestCase;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

@@ -35,6 +40,9 @@ import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public class ZenAdaptersTest extends UiServiceTestCase {

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

    @Test
    public void notificationPolicyToZenPolicy_allCallers() {
        Policy policy = new Policy(Policy.PRIORITY_CATEGORY_CALLS, Policy.PRIORITY_SENDERS_ANY, 0);
@@ -127,4 +135,35 @@ public class ZenAdaptersTest extends UiServiceTestCase {
        assertThat(zenPolicy.getVisualEffectPeek()).isEqualTo(ZenPolicy.STATE_UNSET);
        assertThat(zenPolicy.getVisualEffectStatusBar()).isEqualTo(ZenPolicy.STATE_UNSET);
    }

    @Test
    @EnableFlags(Flags.FLAG_MODES_API)
    public void notificationPolicyToZenPolicy_modesApi_priorityChannels() {
        Policy policy = new Policy(0, 0, 0, 0,
                Policy.policyState(false, true), 0);

        ZenPolicy zenPolicy = notificationPolicyToZenPolicy(policy);
        assertThat(zenPolicy.getAllowedChannels()).isEqualTo(ZenPolicy.CHANNEL_TYPE_PRIORITY);

        Policy notAllowed = new Policy(0, 0, 0, 0,
                Policy.policyState(false, false), 0);
        ZenPolicy zenPolicyNotAllowed = notificationPolicyToZenPolicy(notAllowed);
        assertThat(zenPolicyNotAllowed.getAllowedChannels()).isEqualTo(ZenPolicy.CHANNEL_TYPE_NONE);
    }

    @Test
    @DisableFlags(Flags.FLAG_MODES_API)
    public void notificationPolicyToZenPolicy_noModesApi_priorityChannelsUnset() {
        Policy policy = new Policy(0, 0, 0, 0,
                Policy.policyState(false, true), 0);

        ZenPolicy zenPolicy = notificationPolicyToZenPolicy(policy);
        assertThat(zenPolicy.getAllowedChannels()).isEqualTo(ZenPolicy.CHANNEL_TYPE_UNSET);

        Policy notAllowed = new Policy(0, 0, 0, 0,
                Policy.policyState(false, false), 0);
        ZenPolicy zenPolicyNotAllowed = notificationPolicyToZenPolicy(notAllowed);
        assertThat(zenPolicyNotAllowed.getAllowedChannels())
                .isEqualTo(ZenPolicy.CHANNEL_TYPE_UNSET);
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -3780,6 +3780,7 @@ public class ZenModeHelperTest extends UiServiceTestCase {
                .allowCalls(PEOPLE_TYPE_CONTACTS)
                .allowConversations(CONVERSATION_SENDERS_IMPORTANT)
                .hideAllVisualEffects()
                .allowChannels(ZenPolicy.CHANNEL_TYPE_PRIORITY)
                .build();
        assertThat(mZenModeHelper.mConfig.automaticRules.values())
                .comparingElementsUsing(IGNORE_TIMESTAMPS)
@@ -3811,6 +3812,7 @@ public class ZenModeHelperTest extends UiServiceTestCase {
                .allowCalls(PEOPLE_TYPE_STARRED)
                .allowConversations(CONVERSATION_SENDERS_IMPORTANT)
                .hideAllVisualEffects()
                .allowChannels(ZenPolicy.CHANNEL_TYPE_PRIORITY)
                .build();
        assertThat(mZenModeHelper.mConfig.automaticRules.values())
                .comparingElementsUsing(IGNORE_TIMESTAMPS)