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

Commit ee1572af authored by Christophe Koessler's avatar Christophe Koessler Committed by Android (Google) Code Review
Browse files

Merge changes from topic "audiomanagertest_cts_dnd"

* changes:
  [Notification] Fix NotificationManagerServiceTest
  [Notification] Fix Notification channel Dnd bypass for multiusers
parents 1ab180da 3a543bb4
Loading
Loading
Loading
Loading
+25 −20
Original line number Original line Diff line number Diff line
@@ -33,6 +33,7 @@ import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.annotation.UserIdInt;
import android.app.ActivityManager;
import android.app.AppOpsManager;
import android.app.AppOpsManager;
import android.app.Notification;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationChannel;
@@ -73,7 +74,6 @@ import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONObject;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;


import java.io.IOException;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.PrintWriter;
@@ -184,6 +184,8 @@ public class PreferencesHelper implements RankingConfig {


    private Map<String, List<String>> mOemLockedApps = new HashMap();
    private Map<String, List<String>> mOemLockedApps = new HashMap();


    private int mCurrentUserId = UserHandle.USER_NULL;

    public PreferencesHelper(Context context, PackageManager pm, RankingHandler rankingHandler,
    public PreferencesHelper(Context context, PackageManager pm, RankingHandler rankingHandler,
            ZenModeHelper zenHelper, NotificationChannelLogger notificationChannelLogger,
            ZenModeHelper zenHelper, NotificationChannelLogger notificationChannelLogger,
            AppOpsManager appOpsManager,
            AppOpsManager appOpsManager,
@@ -199,7 +201,8 @@ public class PreferencesHelper implements RankingConfig {
        updateBadgingEnabled();
        updateBadgingEnabled();
        updateBubblesEnabled();
        updateBubblesEnabled();
        updateMediaNotificationFilteringEnabled();
        updateMediaNotificationFilteringEnabled();
        syncChannelsBypassingDnd(mContext.getUserId());
        mCurrentUserId = ActivityManager.getCurrentUser();
        syncChannelsBypassingDnd();
    }
    }


    public void readXml(TypedXmlPullParser parser, boolean forRestore, int userId)
    public void readXml(TypedXmlPullParser parser, boolean forRestore, int userId)
@@ -806,7 +809,7 @@ public class PreferencesHelper implements RankingConfig {
                    // but the system can
                    // but the system can
                    if (group.isBlocked() != oldGroup.isBlocked()) {
                    if (group.isBlocked() != oldGroup.isBlocked()) {
                        group.lockFields(NotificationChannelGroup.USER_LOCKED_BLOCKED_STATE);
                        group.lockFields(NotificationChannelGroup.USER_LOCKED_BLOCKED_STATE);
                        updateChannelsBypassingDnd(mContext.getUserId());
                        updateChannelsBypassingDnd();
                    }
                    }
                }
                }
            }
            }
@@ -888,13 +891,13 @@ public class PreferencesHelper implements RankingConfig {
                // fields on the channel yet
                // fields on the channel yet
                if (existing.getUserLockedFields() == 0 && hasDndAccess) {
                if (existing.getUserLockedFields() == 0 && hasDndAccess) {
                    boolean bypassDnd = channel.canBypassDnd();
                    boolean bypassDnd = channel.canBypassDnd();
                    if (bypassDnd != existing.canBypassDnd()) {
                    if (bypassDnd != existing.canBypassDnd() || wasUndeleted) {
                        existing.setBypassDnd(bypassDnd);
                        existing.setBypassDnd(bypassDnd);
                        needsPolicyFileChange = true;
                        needsPolicyFileChange = true;


                        if (bypassDnd != mAreChannelsBypassingDnd
                        if (bypassDnd != mAreChannelsBypassingDnd
                                || previousExistingImportance != existing.getImportance()) {
                                || previousExistingImportance != existing.getImportance()) {
                            updateChannelsBypassingDnd(mContext.getUserId());
                            updateChannelsBypassingDnd();
                        }
                        }
                    }
                    }
                }
                }
@@ -958,7 +961,7 @@ public class PreferencesHelper implements RankingConfig {


            r.channels.put(channel.getId(), channel);
            r.channels.put(channel.getId(), channel);
            if (channel.canBypassDnd() != mAreChannelsBypassingDnd) {
            if (channel.canBypassDnd() != mAreChannelsBypassingDnd) {
                updateChannelsBypassingDnd(mContext.getUserId());
                updateChannelsBypassingDnd();
            }
            }
            MetricsLogger.action(getChannelLog(channel, pkg).setType(
            MetricsLogger.action(getChannelLog(channel, pkg).setType(
                    com.android.internal.logging.nano.MetricsProto.MetricsEvent.TYPE_OPEN));
                    com.android.internal.logging.nano.MetricsProto.MetricsEvent.TYPE_OPEN));
@@ -1047,7 +1050,7 @@ public class PreferencesHelper implements RankingConfig {


            if (updatedChannel.canBypassDnd() != mAreChannelsBypassingDnd
            if (updatedChannel.canBypassDnd() != mAreChannelsBypassingDnd
                    || channel.getImportance() != updatedChannel.getImportance()) {
                    || channel.getImportance() != updatedChannel.getImportance()) {
                updateChannelsBypassingDnd(mContext.getUserId());
                updateChannelsBypassingDnd();
            }
            }
        }
        }
        updateConfig();
        updateConfig();
@@ -1145,7 +1148,7 @@ public class PreferencesHelper implements RankingConfig {
            mNotificationChannelLogger.logNotificationChannelDeleted(channel, uid, pkg);
            mNotificationChannelLogger.logNotificationChannelDeleted(channel, uid, pkg);


            if (mAreChannelsBypassingDnd && channel.canBypassDnd()) {
            if (mAreChannelsBypassingDnd && channel.canBypassDnd()) {
                updateChannelsBypassingDnd(mContext.getUserId());
                updateChannelsBypassingDnd();
            }
            }
        }
        }
    }
    }
@@ -1512,7 +1515,7 @@ public class PreferencesHelper implements RankingConfig {
                }
                }
            }
            }
            if (!deletedChannelIds.isEmpty() && mAreChannelsBypassingDnd) {
            if (!deletedChannelIds.isEmpty() && mAreChannelsBypassingDnd) {
                updateChannelsBypassingDnd(mContext.getUserId());
                updateChannelsBypassingDnd();
            }
            }
            return deletedChannelIds;
            return deletedChannelIds;
        }
        }
@@ -1658,29 +1661,29 @@ public class PreferencesHelper implements RankingConfig {
    }
    }


    /**
    /**
     * Syncs {@link #mAreChannelsBypassingDnd} with the user's notification policy before
     * Syncs {@link #mAreChannelsBypassingDnd} with the current user's notification policy before
     * updating
     * updating
     * @param userId
     */
     */
    private void syncChannelsBypassingDnd(int userId) {
    private void syncChannelsBypassingDnd() {
        mAreChannelsBypassingDnd = (mZenModeHelper.getNotificationPolicy().state
        mAreChannelsBypassingDnd = (mZenModeHelper.getNotificationPolicy().state
                & NotificationManager.Policy.STATE_CHANNELS_BYPASSING_DND) == 1;
                & NotificationManager.Policy.STATE_CHANNELS_BYPASSING_DND) == 1;
        updateChannelsBypassingDnd(userId);
        updateChannelsBypassingDnd();
    }
    }


    /**
    /**
     * Updates the user's NotificationPolicy based on whether the given userId
     * Updates the user's NotificationPolicy based on whether the current userId
     * has channels bypassing DND
     * has channels bypassing DND
     * @param userId
     * @param userId
     */
     */
    private void updateChannelsBypassingDnd(int userId) {
    private void updateChannelsBypassingDnd() {
        synchronized (mPackagePreferences) {
        synchronized (mPackagePreferences) {
            final int numPackagePreferences = mPackagePreferences.size();
            final int numPackagePreferences = mPackagePreferences.size();
            for (int i = 0; i < numPackagePreferences; i++) {
            for (int i = 0; i < numPackagePreferences; i++) {
                final PackagePreferences r = mPackagePreferences.valueAt(i);
                final PackagePreferences r = mPackagePreferences.valueAt(i);
                // Package isn't associated with this userId or notifications from this package are
                // Package isn't associated with the current userId or notifications from this
                // blocked
                // package are blocked
                if (userId != UserHandle.getUserId(r.uid) || r.importance == IMPORTANCE_NONE) {
                if (mCurrentUserId != UserHandle.getUserId(r.uid)
                        || r.importance == IMPORTANCE_NONE) {
                    continue;
                    continue;
                }
                }


@@ -2226,14 +2229,16 @@ public class PreferencesHelper implements RankingConfig {
     * Called when user switches
     * Called when user switches
     */
     */
    public void onUserSwitched(int userId) {
    public void onUserSwitched(int userId) {
        syncChannelsBypassingDnd(userId);
        mCurrentUserId = userId;
        syncChannelsBypassingDnd();
    }
    }


    /**
    /**
     * Called when user is unlocked
     * Called when user is unlocked
     */
     */
    public void onUserUnlocked(int userId) {
    public void onUserUnlocked(int userId) {
        syncChannelsBypassingDnd(userId);
        mCurrentUserId = userId;
        syncChannelsBypassingDnd();
    }
    }


    public void onUserRemoved(int userId) {
    public void onUserRemoved(int userId) {
+42 −41
Original line number Original line Diff line number Diff line
@@ -900,10 +900,10 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {


    @Test
    @Test
    public void testDefaultAssistant_overrideDefault() {
    public void testDefaultAssistant_overrideDefault() {
        final int userId = 0;
        final int userId = mContext.getUserId();
        final String testComponent = "package/class";
        final String testComponent = "package/class";
        final List<UserInfo> userInfos = new ArrayList<>();
        final List<UserInfo> userInfos = new ArrayList<>();
        userInfos.add(new UserInfo(0, "", 0));
        userInfos.add(new UserInfo(userId, "", 0));
        final ArraySet<ComponentName> validAssistants = new ArraySet<>();
        final ArraySet<ComponentName> validAssistants = new ArraySet<>();
        validAssistants.add(ComponentName.unflattenFromString(testComponent));
        validAssistants.add(ComponentName.unflattenFromString(testComponent));
        when(mActivityManager.isLowRamDevice()).thenReturn(false);
        when(mActivityManager.isLowRamDevice()).thenReturn(false);
@@ -2346,7 +2346,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                .thenReturn(mTestNotificationChannel);
                .thenReturn(mTestNotificationChannel);


        reset(mListeners);
        reset(mListeners);
        mBinderService.updateNotificationChannelForPackage(PKG, 0, mTestNotificationChannel);
        mBinderService.updateNotificationChannelForPackage(PKG, mUid, mTestNotificationChannel);
        verify(mListeners, times(1)).notifyNotificationChannelChanged(eq(PKG),
        verify(mListeners, times(1)).notifyNotificationChannelChanged(eq(PKG),
                eq(Process.myUserHandle()), eq(mTestNotificationChannel),
                eq(Process.myUserHandle()), eq(mTestNotificationChannel),
                eq(NotificationListenerService.NOTIFICATION_CHANNEL_OR_GROUP_UPDATED));
                eq(NotificationListenerService.NOTIFICATION_CHANNEL_OR_GROUP_UPDATED));
@@ -2882,7 +2882,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {


    @Test
    @Test
    public void testSetListenerAccessForUser() throws Exception {
    public void testSetListenerAccessForUser() throws Exception {
        UserHandle user = UserHandle.of(10);
        UserHandle user = UserHandle.of(mContext.getUserId() + 10);
        ComponentName c = ComponentName.unflattenFromString("package/Component");
        ComponentName c = ComponentName.unflattenFromString("package/Component");
        mBinderService.setNotificationListenerAccessGrantedForUser(
        mBinderService.setNotificationListenerAccessGrantedForUser(
                c, user.getIdentifier(), true, true);
                c, user.getIdentifier(), true, true);
@@ -2899,20 +2899,20 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {


    @Test
    @Test
    public void testSetAssistantAccessForUser() throws Exception {
    public void testSetAssistantAccessForUser() throws Exception {
        UserHandle user = UserHandle.of(10);
        List<UserInfo> uis = new ArrayList<>();
        UserInfo ui = new UserInfo();
        UserInfo ui = new UserInfo();
        ui.id = 10;
        ui.id = mContext.getUserId() + 10;
        UserHandle user = UserHandle.of(ui.id);
        List<UserInfo> uis = new ArrayList<>();
        uis.add(ui);
        uis.add(ui);
        ComponentName c = ComponentName.unflattenFromString("package/Component");
        ComponentName c = ComponentName.unflattenFromString("package/Component");
        when(mUm.getEnabledProfiles(10)).thenReturn(uis);
        when(mUm.getEnabledProfiles(ui.id)).thenReturn(uis);


        mBinderService.setNotificationAssistantAccessGrantedForUser(c, user.getIdentifier(), true);
        mBinderService.setNotificationAssistantAccessGrantedForUser(c, user.getIdentifier(), true);


        verify(mContext, times(1)).sendBroadcastAsUser(any(), eq(user), any());
        verify(mContext, times(1)).sendBroadcastAsUser(any(), eq(user), any());
        verify(mAssistants, times(1)).setPackageOrComponentEnabled(
        verify(mAssistants, times(1)).setPackageOrComponentEnabled(
                c.flattenToString(), user.getIdentifier(), true, true, true);
                c.flattenToString(), user.getIdentifier(), true, true, true);
        verify(mAssistants).setUserSet(10, true);
        verify(mAssistants).setUserSet(ui.id, true);
        verify(mConditionProviders, times(1)).setPackageOrComponentEnabled(
        verify(mConditionProviders, times(1)).setPackageOrComponentEnabled(
                c.flattenToString(), user.getIdentifier(), false, true);
                c.flattenToString(), user.getIdentifier(), false, true);
        verify(mListeners, never()).setPackageOrComponentEnabled(
        verify(mListeners, never()).setPackageOrComponentEnabled(
@@ -2921,7 +2921,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {


    @Test
    @Test
    public void testGetAssistantAllowedForUser() throws Exception {
    public void testGetAssistantAllowedForUser() throws Exception {
        UserHandle user = UserHandle.of(10);
        UserHandle user = UserHandle.of(mContext.getUserId() + 10);
        try {
        try {
            mBinderService.getAllowedNotificationAssistantForUser(user.getIdentifier());
            mBinderService.getAllowedNotificationAssistantForUser(user.getIdentifier());
        } catch (IllegalStateException e) {
        } catch (IllegalStateException e) {
@@ -2941,12 +2941,12 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                throw e;
                throw e;
            }
            }
        }
        }
        verify(mAssistants, times(1)).getAllowedComponents(0);
        verify(mAssistants, times(1)).getAllowedComponents(mContext.getUserId());
    }
    }


    @Test
    @Test
    public void testSetDndAccessForUser() throws Exception {
    public void testSetDndAccessForUser() throws Exception {
        UserHandle user = UserHandle.of(10);
        UserHandle user = UserHandle.of(mContext.getUserId() + 10);
        ComponentName c = ComponentName.unflattenFromString("package/Component");
        ComponentName c = ComponentName.unflattenFromString("package/Component");
        mBinderService.setNotificationPolicyAccessGrantedForUser(
        mBinderService.setNotificationPolicyAccessGrantedForUser(
                c.getPackageName(), user.getIdentifier(), true);
                c.getPackageName(), user.getIdentifier(), true);
@@ -2966,9 +2966,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        mBinderService.setNotificationListenerAccessGranted(c, true, true);
        mBinderService.setNotificationListenerAccessGranted(c, true, true);


        verify(mListeners, times(1)).setPackageOrComponentEnabled(
        verify(mListeners, times(1)).setPackageOrComponentEnabled(
                c.flattenToString(), 0, true, true, true);
                c.flattenToString(), mContext.getUserId(), true, true, true);
        verify(mConditionProviders, times(1)).setPackageOrComponentEnabled(
        verify(mConditionProviders, times(1)).setPackageOrComponentEnabled(
                c.flattenToString(), 0, false, true, true);
                c.flattenToString(), mContext.getUserId(), false, true, true);
        verify(mAssistants, never()).setPackageOrComponentEnabled(
        verify(mAssistants, never()).setPackageOrComponentEnabled(
                any(), anyInt(), anyBoolean(), anyBoolean(), anyBoolean());
                any(), anyInt(), anyBoolean(), anyBoolean(), anyBoolean());
    }
    }
@@ -2977,7 +2977,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
    public void testSetAssistantAccess() throws Exception {
    public void testSetAssistantAccess() throws Exception {
        List<UserInfo> uis = new ArrayList<>();
        List<UserInfo> uis = new ArrayList<>();
        UserInfo ui = new UserInfo();
        UserInfo ui = new UserInfo();
        ui.id = 0;
        ui.id = mContext.getUserId();
        uis.add(ui);
        uis.add(ui);
        when(mUm.getEnabledProfiles(ui.id)).thenReturn(uis);
        when(mUm.getEnabledProfiles(ui.id)).thenReturn(uis);
        ComponentName c = ComponentName.unflattenFromString("package/Component");
        ComponentName c = ComponentName.unflattenFromString("package/Component");
@@ -2985,9 +2985,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        mBinderService.setNotificationAssistantAccessGranted(c, true);
        mBinderService.setNotificationAssistantAccessGranted(c, true);


        verify(mAssistants, times(1)).setPackageOrComponentEnabled(
        verify(mAssistants, times(1)).setPackageOrComponentEnabled(
                c.flattenToString(), 0, true, true, true);
                c.flattenToString(), ui.id, true, true, true);
        verify(mConditionProviders, times(1)).setPackageOrComponentEnabled(
        verify(mConditionProviders, times(1)).setPackageOrComponentEnabled(
                c.flattenToString(), 0, false, true);
                c.flattenToString(), ui.id, false, true);
        verify(mListeners, never()).setPackageOrComponentEnabled(
        verify(mListeners, never()).setPackageOrComponentEnabled(
                any(), anyInt(), anyBoolean(), anyBoolean());
                any(), anyInt(), anyBoolean(), anyBoolean());
    }
    }
@@ -2996,10 +2996,10 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
    public void testSetAssistantAccess_multiProfile() throws Exception {
    public void testSetAssistantAccess_multiProfile() throws Exception {
        List<UserInfo> uis = new ArrayList<>();
        List<UserInfo> uis = new ArrayList<>();
        UserInfo ui = new UserInfo();
        UserInfo ui = new UserInfo();
        ui.id = 0;
        ui.id = mContext.getUserId();
        uis.add(ui);
        uis.add(ui);
        UserInfo ui10 = new UserInfo();
        UserInfo ui10 = new UserInfo();
        ui10.id = 10;
        ui10.id = mContext.getUserId() + 10;
        uis.add(ui10);
        uis.add(ui10);
        when(mUm.getEnabledProfiles(ui.id)).thenReturn(uis);
        when(mUm.getEnabledProfiles(ui.id)).thenReturn(uis);
        ComponentName c = ComponentName.unflattenFromString("package/Component");
        ComponentName c = ComponentName.unflattenFromString("package/Component");
@@ -3007,13 +3007,14 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        mBinderService.setNotificationAssistantAccessGranted(c, true);
        mBinderService.setNotificationAssistantAccessGranted(c, true);


        verify(mAssistants, times(1)).setPackageOrComponentEnabled(
        verify(mAssistants, times(1)).setPackageOrComponentEnabled(
                c.flattenToString(), 0, true, true, true);
                c.flattenToString(), ui.id, true, true, true);
        verify(mAssistants, times(1)).setPackageOrComponentEnabled(
        verify(mAssistants, times(1)).setPackageOrComponentEnabled(
                c.flattenToString(), 10, true, true, true);
                c.flattenToString(), ui10.id, true, true, true);

        verify(mConditionProviders, times(1)).setPackageOrComponentEnabled(
        verify(mConditionProviders, times(1)).setPackageOrComponentEnabled(
                c.flattenToString(), 0, false, true);
                c.flattenToString(), ui.id, false, true);
        verify(mConditionProviders, times(1)).setPackageOrComponentEnabled(
        verify(mConditionProviders, times(1)).setPackageOrComponentEnabled(
                c.flattenToString(), 10, false, true);
                c.flattenToString(), ui10.id, false, true);
        verify(mListeners, never()).setPackageOrComponentEnabled(
        verify(mListeners, never()).setPackageOrComponentEnabled(
                any(), anyInt(), anyBoolean(), anyBoolean());
                any(), anyInt(), anyBoolean(), anyBoolean());
    }
    }
@@ -3026,16 +3027,16 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        when(mAssistants.getAllowedComponents(anyInt())).thenReturn(componentList);
        when(mAssistants.getAllowedComponents(anyInt())).thenReturn(componentList);
        List<UserInfo> uis = new ArrayList<>();
        List<UserInfo> uis = new ArrayList<>();
        UserInfo ui = new UserInfo();
        UserInfo ui = new UserInfo();
        ui.id = 0;
        ui.id = mContext.getUserId();
        uis.add(ui);
        uis.add(ui);
        when(mUm.getEnabledProfiles(ui.id)).thenReturn(uis);
        when(mUm.getEnabledProfiles(ui.id)).thenReturn(uis);


        mBinderService.setNotificationAssistantAccessGranted(null, true);
        mBinderService.setNotificationAssistantAccessGranted(null, true);


        verify(mAssistants, times(1)).setPackageOrComponentEnabled(
        verify(mAssistants, times(1)).setPackageOrComponentEnabled(
                c.flattenToString(), 0, true, false, true);
                c.flattenToString(), ui.id, true, false, true);
        verify(mConditionProviders, times(1)).setPackageOrComponentEnabled(
        verify(mConditionProviders, times(1)).setPackageOrComponentEnabled(
                c.flattenToString(), 0, false,  false);
                c.flattenToString(), ui.id, false,  false);
        verify(mListeners, never()).setPackageOrComponentEnabled(
        verify(mListeners, never()).setPackageOrComponentEnabled(
                any(), anyInt(), anyBoolean(), anyBoolean());
                any(), anyInt(), anyBoolean(), anyBoolean());
    }
    }
@@ -3044,21 +3045,21 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
    public void testSetAssistantAccessForUser_nullWithAllowedAssistant() throws Exception {
    public void testSetAssistantAccessForUser_nullWithAllowedAssistant() throws Exception {
        List<UserInfo> uis = new ArrayList<>();
        List<UserInfo> uis = new ArrayList<>();
        UserInfo ui = new UserInfo();
        UserInfo ui = new UserInfo();
        ui.id = 10;
        ui.id = mContext.getUserId() + 10;
        uis.add(ui);
        uis.add(ui);
        UserHandle user = ui.getUserHandle();
        UserHandle user = ui.getUserHandle();
        ArrayList<ComponentName> componentList = new ArrayList<>();
        ArrayList<ComponentName> componentList = new ArrayList<>();
        ComponentName c = ComponentName.unflattenFromString("package/Component");
        ComponentName c = ComponentName.unflattenFromString("package/Component");
        componentList.add(c);
        componentList.add(c);
        when(mAssistants.getAllowedComponents(anyInt())).thenReturn(componentList);
        when(mAssistants.getAllowedComponents(anyInt())).thenReturn(componentList);
        when(mUm.getEnabledProfiles(10)).thenReturn(uis);
        when(mUm.getEnabledProfiles(ui.id)).thenReturn(uis);


        mBinderService.setNotificationAssistantAccessGrantedForUser(
        mBinderService.setNotificationAssistantAccessGrantedForUser(
                null, user.getIdentifier(), true);
                null, user.getIdentifier(), true);


        verify(mAssistants, times(1)).setPackageOrComponentEnabled(
        verify(mAssistants, times(1)).setPackageOrComponentEnabled(
                c.flattenToString(), user.getIdentifier(), true, false, true);
                c.flattenToString(), user.getIdentifier(), true, false, true);
        verify(mAssistants).setUserSet(10, true);
        verify(mAssistants).setUserSet(ui.id, true);
        verify(mConditionProviders, times(1)).setPackageOrComponentEnabled(
        verify(mConditionProviders, times(1)).setPackageOrComponentEnabled(
                c.flattenToString(), user.getIdentifier(), false,  false);
                c.flattenToString(), user.getIdentifier(), false,  false);
        verify(mListeners, never()).setPackageOrComponentEnabled(
        verify(mListeners, never()).setPackageOrComponentEnabled(
@@ -3070,10 +3071,10 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
            throws Exception {
            throws Exception {
        List<UserInfo> uis = new ArrayList<>();
        List<UserInfo> uis = new ArrayList<>();
        UserInfo ui = new UserInfo();
        UserInfo ui = new UserInfo();
        ui.id = 0;
        ui.id = mContext.getUserId();
        uis.add(ui);
        uis.add(ui);
        UserInfo ui10 = new UserInfo();
        UserInfo ui10 = new UserInfo();
        ui10.id = 10;
        ui10.id = mContext.getUserId() + 10;
        uis.add(ui10);
        uis.add(ui10);
        UserHandle user = ui.getUserHandle();
        UserHandle user = ui.getUserHandle();
        ArrayList<ComponentName> componentList = new ArrayList<>();
        ArrayList<ComponentName> componentList = new ArrayList<>();
@@ -3089,8 +3090,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                c.flattenToString(), user.getIdentifier(), true, false, true);
                c.flattenToString(), user.getIdentifier(), true, false, true);
        verify(mAssistants, times(1)).setPackageOrComponentEnabled(
        verify(mAssistants, times(1)).setPackageOrComponentEnabled(
                c.flattenToString(), ui10.id, true, false, true);
                c.flattenToString(), ui10.id, true, false, true);
        verify(mAssistants).setUserSet(0, true);
        verify(mAssistants).setUserSet(ui.id, true);
        verify(mAssistants).setUserSet(10, true);
        verify(mAssistants).setUserSet(ui10.id, true);
        verify(mConditionProviders, times(1)).setPackageOrComponentEnabled(
        verify(mConditionProviders, times(1)).setPackageOrComponentEnabled(
                c.flattenToString(), user.getIdentifier(), false,  false);
                c.flattenToString(), user.getIdentifier(), false,  false);
        verify(mConditionProviders, times(1)).setPackageOrComponentEnabled(
        verify(mConditionProviders, times(1)).setPackageOrComponentEnabled(
@@ -3106,7 +3107,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        mBinderService.setNotificationPolicyAccessGranted(c.getPackageName(), true);
        mBinderService.setNotificationPolicyAccessGranted(c.getPackageName(), true);


        verify(mConditionProviders, times(1)).setPackageOrComponentEnabled(
        verify(mConditionProviders, times(1)).setPackageOrComponentEnabled(
                c.getPackageName(), 0, true, true);
                c.getPackageName(), mContext.getUserId(), true, true);
        verify(mAssistants, never()).setPackageOrComponentEnabled(
        verify(mAssistants, never()).setPackageOrComponentEnabled(
                any(), anyInt(), anyBoolean(), anyBoolean(), anyBoolean());
                any(), anyInt(), anyBoolean(), anyBoolean(), anyBoolean());
        verify(mListeners, never()).setPackageOrComponentEnabled(
        verify(mListeners, never()).setPackageOrComponentEnabled(
@@ -3133,7 +3134,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        ComponentName c = ComponentName.unflattenFromString("package/Component");
        ComponentName c = ComponentName.unflattenFromString("package/Component");
        List<UserInfo> uis = new ArrayList<>();
        List<UserInfo> uis = new ArrayList<>();
        UserInfo ui = new UserInfo();
        UserInfo ui = new UserInfo();
        ui.id = 0;
        ui.id = mContext.getUserId();
        uis.add(ui);
        uis.add(ui);
        when(mUm.getEnabledProfiles(ui.id)).thenReturn(uis);
        when(mUm.getEnabledProfiles(ui.id)).thenReturn(uis);


@@ -3168,9 +3169,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        mBinderService.setNotificationListenerAccessGranted(c, true, true);
        mBinderService.setNotificationListenerAccessGranted(c, true, true);


        verify(mListeners, times(1)).setPackageOrComponentEnabled(
        verify(mListeners, times(1)).setPackageOrComponentEnabled(
                c.flattenToString(), 0, true, true, true);
                c.flattenToString(), mContext.getUserId(), true, true, true);
        verify(mConditionProviders, times(1)).setPackageOrComponentEnabled(
        verify(mConditionProviders, times(1)).setPackageOrComponentEnabled(
                c.flattenToString(), 0, false, true, true);
                c.flattenToString(), mContext.getUserId(), false, true, true);
        verify(mAssistants, never()).setPackageOrComponentEnabled(
        verify(mAssistants, never()).setPackageOrComponentEnabled(
                any(), anyInt(), anyBoolean(), anyBoolean(), anyBoolean());
                any(), anyInt(), anyBoolean(), anyBoolean(), anyBoolean());
    }
    }
@@ -3182,7 +3183,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        ComponentName c = ComponentName.unflattenFromString("package/Component");
        ComponentName c = ComponentName.unflattenFromString("package/Component");
        List<UserInfo> uis = new ArrayList<>();
        List<UserInfo> uis = new ArrayList<>();
        UserInfo ui = new UserInfo();
        UserInfo ui = new UserInfo();
        ui.id = 0;
        ui.id = mContext.getUserId();
        uis.add(ui);
        uis.add(ui);
        when(mUm.getEnabledProfiles(ui.id)).thenReturn(uis);
        when(mUm.getEnabledProfiles(ui.id)).thenReturn(uis);


@@ -3191,9 +3192,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        verify(mListeners, never()).setPackageOrComponentEnabled(
        verify(mListeners, never()).setPackageOrComponentEnabled(
                anyString(), anyInt(), anyBoolean(), anyBoolean());
                anyString(), anyInt(), anyBoolean(), anyBoolean());
        verify(mConditionProviders, times(1)).setPackageOrComponentEnabled(
        verify(mConditionProviders, times(1)).setPackageOrComponentEnabled(
                c.flattenToString(), 0, false, true);
                c.flattenToString(), ui.id, false, true);
        verify(mAssistants, times(1)).setPackageOrComponentEnabled(
        verify(mAssistants, times(1)).setPackageOrComponentEnabled(
                c.flattenToString(), 0, true, true, true);
                c.flattenToString(), ui.id, true, true, true);
    }
    }


    @Test
    @Test
@@ -3207,7 +3208,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        verify(mListeners, never()).setPackageOrComponentEnabled(
        verify(mListeners, never()).setPackageOrComponentEnabled(
                anyString(), anyInt(), anyBoolean(), anyBoolean());
                anyString(), anyInt(), anyBoolean(), anyBoolean());
        verify(mConditionProviders, times(1)).setPackageOrComponentEnabled(
        verify(mConditionProviders, times(1)).setPackageOrComponentEnabled(
                c.getPackageName(), 0, true, true);
                c.getPackageName(), mContext.getUserId(), true, true);
        verify(mAssistants, never()).setPackageOrComponentEnabled(
        verify(mAssistants, never()).setPackageOrComponentEnabled(
                any(), anyInt(), anyBoolean(), anyBoolean(), anyBoolean());
                any(), anyInt(), anyBoolean(), anyBoolean(), anyBoolean());
    }
    }