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

Commit a21d71df authored by Ben Reich's avatar Ben Reich Committed by Android (Google) Code Review
Browse files

Merge "Don't use isSystemUser for UserItemsCombiner" into main

parents cfff4f1d 6495efaa
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle;
import android.os.UserManager;
import android.os.ext.SdkExtensions;
import android.provider.DocumentsContract;
import android.provider.MediaStore;
@@ -572,16 +573,22 @@ public class RootsFragment extends Fragment {
    private List<Item> getPresentableListPrivateSpaceEnabled(Context context, State state,
            List<List<Item>> rootListAllUsers, List<UserId> userIds,
            UserManagerState userManagerState) {
        return new UserItemsCombiner(context.getResources(),
                context.getSystemService(DevicePolicyManager.class), state)
        return new UserItemsCombiner(
                        context.getResources(),
                        context.getSystemService(UserManager.class),
                        context.getSystemService(DevicePolicyManager.class),
                        state)
                .setRootListForAllUsers(rootListAllUsers)
                .createPresentableListForAllUsers(userIds, userManagerState.getUserIdToLabelMap());
    }

    private List<Item> getPresentableListPrivateSpaceDisabled(Context context, State state,
            List<Item> rootList, List<Item> rootListOtherUser) {
        return new UserItemsCombiner(context.getResources(),
                context.getSystemService(DevicePolicyManager.class), state)
        return new UserItemsCombiner(
                        context.getResources(),
                        context.getSystemService(UserManager.class),
                        context.getSystemService(DevicePolicyManager.class),
                        state)
                .setRootListForCurrentUser(rootList)
                .setRootListForOtherUser(rootListOtherUser)
                .createPresentableList();
+10 −5
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import static com.android.documentsui.util.Material3Config.getRes;
import android.app.admin.DevicePolicyManager;
import android.content.res.Resources;
import android.os.Build;
import android.os.UserManager;

import androidx.annotation.RequiresApi;
import androidx.annotation.VisibleForTesting;
@@ -47,14 +48,17 @@ class UserItemsCombiner {

    private UserId mCurrentUser;
    private final Resources mResources;
    private final UserManager mUserManager;
    private final DevicePolicyManager mDpm;
    private final State mState;
    private List<Item> mRootList;
    private List<Item> mRootListOtherUser;
    private List<List<Item>> mRootListAllUsers;

    UserItemsCombiner(Resources resources, DevicePolicyManager dpm, State state) {
    UserItemsCombiner(
            Resources resources, UserManager userManager, DevicePolicyManager dpm, State state) {
        mCurrentUser = UserId.CURRENT_USER;
        mUserManager = userManager;
        mResources = checkNotNull(resources);
        mDpm = dpm;
        mState = checkNotNull(state);
@@ -95,12 +99,13 @@ class UserItemsCombiner {
                // Identify personal and work root list.
                final List<Item> personalRootList;
                final List<Item> workRootList;
                if (mCurrentUser.isSystem()) {
                    personalRootList = mRootList;
                    workRootList = mRootListOtherUser;
                } else {

                if (mCurrentUser.isManagedProfile(mUserManager)) {
                    personalRootList = mRootListOtherUser;
                    workRootList = mRootList;
                } else {
                    personalRootList = mRootList;
                    workRootList = mRootListOtherUser;
                }
                result.add(
                        new HeaderItem(
+91 −63
Original line number Diff line number Diff line
@@ -18,8 +18,12 @@ package com.android.documentsui.sidebar;

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

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import android.app.admin.DevicePolicyManager;
import android.content.res.Resources;
import android.os.UserManager;
import android.view.View;

import androidx.test.filters.MediumTest;
@@ -80,6 +84,7 @@ public class UserItemsCombinerTest {
    private final State mState = new State();
    private final Resources mResources =
            InstrumentationRegistry.getInstrumentation().getTargetContext().getResources();
    private final UserManager mMockUserManager = mock(UserManager.class);
    private final DevicePolicyManager mDpm =
            InstrumentationRegistry.getInstrumentation().getTargetContext().getSystemService(
                    DevicePolicyManager.class);
@@ -106,11 +111,14 @@ public class UserItemsCombinerTest {
            mState.canForwardToProfileIdMap.put(PRIVATE_USER, true);
            mTestConfigStore.enablePrivateSpaceInPhotoPicker();
        }

        when(mMockUserManager.isManagedProfile(WORK_USER.getIdentifier())).thenReturn(true);
    }

    @Test
    public void testCreatePresentableList_empty() {
        mCombiner = new UserItemsCombiner(mResources, mDpm, mState)
        mCombiner =
                new UserItemsCombiner(mResources, mMockUserManager, mDpm, mState)
                        .setRootListForCurrentUser(Collections.emptyList())
                        .setRootListForOtherUser(Collections.emptyList());
        assertThat(mCombiner.createPresentableList()).isEmpty();
@@ -124,7 +132,8 @@ public class UserItemsCombinerTest {
        if (SdkLevel.isAtLeastV()) {
            rootListAllUsers.add(Collections.emptyList());
        }
        mCombiner = new UserItemsCombiner(mResources, mDpm, mState)
        mCombiner =
                new UserItemsCombiner(mResources, mMockUserManager, mDpm, mState)
                        .setRootListForAllUsers(rootListAllUsers);
        assertThat(
                mCombiner.createPresentableListForAllUsers(mUserIds, mUserIdToLabelMap)).isEmpty();
@@ -132,7 +141,8 @@ public class UserItemsCombinerTest {

    @Test
    public void testCreatePresentableList_currentIsPersonal_personalItemsOnly() {
        mCombiner = new UserItemsCombiner(mResources, mDpm, mState)
        mCombiner =
                new UserItemsCombiner(mResources, mMockUserManager, mDpm, mState)
                        .setRootListForCurrentUser(PERSONAL_ITEMS)
                        .setRootListForOtherUser(Collections.emptyList());
        assertThat(mCombiner.createPresentableList())
@@ -143,7 +153,8 @@ public class UserItemsCombinerTest {

    @Test
    public void testCreatePresentableList_currentIsWork_personalItemsOnly() {
        mCombiner = new UserItemsCombiner(mResources, mDpm, mState)
        mCombiner =
                new UserItemsCombiner(mResources, mMockUserManager, mDpm, mState)
                        .overrideCurrentUserForTest(WORK_USER)
                        .setRootListForCurrentUser(Collections.emptyList())
                        .setRootListForOtherUser(PERSONAL_ITEMS);
@@ -161,7 +172,8 @@ public class UserItemsCombinerTest {
        if (SdkLevel.isAtLeastV()) {
            rootListAllUsers.add(Collections.emptyList());
        }
        mCombiner = new UserItemsCombiner(mResources, mDpm, mState)
        mCombiner =
                new UserItemsCombiner(mResources, mMockUserManager, mDpm, mState)
                        .setRootListForAllUsers(rootListAllUsers);
        assertThat(mCombiner.createPresentableListForAllUsers(mUserIds, mUserIdToLabelMap))
                .comparingElementsUsing(ITEM_CORRESPONDENCE)
@@ -177,7 +189,8 @@ public class UserItemsCombinerTest {
        if (SdkLevel.isAtLeastV()) {
            rootListAllUsers.add(Collections.emptyList());
        }
        mCombiner = new UserItemsCombiner(mResources, mDpm, mState)
        mCombiner =
                new UserItemsCombiner(mResources, mMockUserManager, mDpm, mState)
                        .overrideCurrentUserForTest(WORK_USER)
                        .setRootListForAllUsers(rootListAllUsers);
        assertThat(mCombiner.createPresentableListForAllUsers(mUserIds, mUserIdToLabelMap))
@@ -193,7 +206,8 @@ public class UserItemsCombinerTest {
        rootListAllUsers.add(Lists.newArrayList(PERSONAL_ITEMS));
        rootListAllUsers.add(Collections.emptyList());
        rootListAllUsers.add(Collections.emptyList());
        mCombiner = new UserItemsCombiner(mResources, mDpm, mState)
        mCombiner =
                new UserItemsCombiner(mResources, mMockUserManager, mDpm, mState)
                        .overrideCurrentUserForTest(PRIVATE_USER)
                        .setRootListForAllUsers(rootListAllUsers);
        assertThat(mCombiner.createPresentableListForAllUsers(mUserIds, mUserIdToLabelMap))
@@ -204,7 +218,8 @@ public class UserItemsCombinerTest {

    @Test
    public void testCreatePresentableList_currentIsPersonal_workItemsOnly() {
        mCombiner = new UserItemsCombiner(mResources, mDpm, mState)
        mCombiner =
                new UserItemsCombiner(mResources, mMockUserManager, mDpm, mState)
                        .setRootListForCurrentUser(Collections.emptyList())
                        .setRootListForOtherUser(WORK_ITEMS);
        assertThat(mCombiner.createPresentableList())
@@ -215,7 +230,8 @@ public class UserItemsCombinerTest {

    @Test
    public void testCreatePresentableList_currentIsWork_workItemsOnly() {
        mCombiner = new UserItemsCombiner(mResources, mDpm, mState)
        mCombiner =
                new UserItemsCombiner(mResources, mMockUserManager, mDpm, mState)
                        .overrideCurrentUserForTest(WORK_USER)
                        .setRootListForCurrentUser(WORK_ITEMS)
                        .setRootListForOtherUser(Collections.emptyList());
@@ -233,7 +249,8 @@ public class UserItemsCombinerTest {
        if (SdkLevel.isAtLeastV()) {
            rootListAllUsers.add(Collections.emptyList());
        }
        mCombiner = new UserItemsCombiner(mResources, mDpm, mState)
        mCombiner =
                new UserItemsCombiner(mResources, mMockUserManager, mDpm, mState)
                        .overrideCurrentUserForTest(PERSONAL_USER)
                        .setRootListForAllUsers(rootListAllUsers);
        assertThat(mCombiner.createPresentableListForAllUsers(mUserIds, mUserIdToLabelMap))
@@ -250,7 +267,8 @@ public class UserItemsCombinerTest {
        if (SdkLevel.isAtLeastV()) {
            rootListAllUsers.add(Collections.emptyList());
        }
        mCombiner = new UserItemsCombiner(mResources, mDpm, mState)
        mCombiner =
                new UserItemsCombiner(mResources, mMockUserManager, mDpm, mState)
                        .overrideCurrentUserForTest(WORK_USER)
                        .setRootListForAllUsers(rootListAllUsers);
        assertThat(mCombiner.createPresentableListForAllUsers(mUserIds, mUserIdToLabelMap))
@@ -266,7 +284,8 @@ public class UserItemsCombinerTest {
        rootListAllUsers.add(Collections.emptyList());
        rootListAllUsers.add(Lists.newArrayList(WORK_ITEMS));
        rootListAllUsers.add(Collections.emptyList());
        mCombiner = new UserItemsCombiner(mResources, mDpm, mState)
        mCombiner =
                new UserItemsCombiner(mResources, mMockUserManager, mDpm, mState)
                        .overrideCurrentUserForTest(PRIVATE_USER)
                        .setRootListForAllUsers(rootListAllUsers);
        assertThat(mCombiner.createPresentableListForAllUsers(mUserIds, mUserIdToLabelMap))
@@ -277,7 +296,8 @@ public class UserItemsCombinerTest {

    @Test
    public void testCreatePresentableList_currentIsPersonal_personalAndWorkItems() {
        mCombiner = new UserItemsCombiner(mResources, mDpm, mState)
        mCombiner =
                new UserItemsCombiner(mResources, mMockUserManager, mDpm, mState)
                        .setRootListForCurrentUser(PERSONAL_ITEMS)
                        .setRootListForOtherUser(WORK_ITEMS);

@@ -295,7 +315,8 @@ public class UserItemsCombinerTest {

    @Test
    public void testCreatePresentableList_currentIsWork_personalAndWorkItems() {
        mCombiner = new UserItemsCombiner(mResources, mDpm, mState)
        mCombiner =
                new UserItemsCombiner(mResources, mMockUserManager, mDpm, mState)
                        .overrideCurrentUserForTest(WORK_USER)
                        .setRootListForCurrentUser(WORK_ITEMS)
                        .setRootListForOtherUser(PERSONAL_ITEMS);
@@ -320,7 +341,8 @@ public class UserItemsCombinerTest {
        if (SdkLevel.isAtLeastV()) {
            rootListAllUsers.add(PRIVATE_ITEMS);
        }
        mCombiner = new UserItemsCombiner(mResources, mDpm, mState)
        mCombiner =
                new UserItemsCombiner(mResources, mMockUserManager, mDpm, mState)
                        .setRootListForAllUsers(rootListAllUsers);

        List<Item> expected = Lists.newArrayList();
@@ -347,7 +369,8 @@ public class UserItemsCombinerTest {
        if (SdkLevel.isAtLeastV()) {
            rootListAllUsers.add(PRIVATE_ITEMS);
        }
        mCombiner = new UserItemsCombiner(mResources, mDpm, mState)
        mCombiner =
                new UserItemsCombiner(mResources, mMockUserManager, mDpm, mState)
                        .overrideCurrentUserForTest(WORK_USER)
                        .setRootListForAllUsers(rootListAllUsers);

@@ -375,7 +398,8 @@ public class UserItemsCombinerTest {
        if (SdkLevel.isAtLeastV()) {
            rootListAllUsers.add(PRIVATE_ITEMS);
        }
        mCombiner = new UserItemsCombiner(mResources, mDpm, mState)
        mCombiner =
                new UserItemsCombiner(mResources, mMockUserManager, mDpm, mState)
                        .overrideCurrentUserForTest(PRIVATE_USER)
                        .setRootListForAllUsers(rootListAllUsers);

@@ -398,7 +422,8 @@ public class UserItemsCombinerTest {
    @Test
    public void testCreatePresentableList_currentIsPersonal_personalAndWorkItems_cannotShare() {
        mState.canShareAcrossProfile = false;
        mCombiner = new UserItemsCombiner(mResources, mDpm, mState)
        mCombiner =
                new UserItemsCombiner(mResources, mMockUserManager, mDpm, mState)
                        .setRootListForCurrentUser(PERSONAL_ITEMS)
                        .setRootListForOtherUser(WORK_ITEMS);

@@ -411,7 +436,8 @@ public class UserItemsCombinerTest {
    @Test
    public void testCreatePresentableList_currentIsWork_personalItemsOnly_cannotShare() {
        mState.canShareAcrossProfile = false;
        mCombiner = new UserItemsCombiner(mResources, mDpm, mState)
        mCombiner =
                new UserItemsCombiner(mResources, mMockUserManager, mDpm, mState)
                        .overrideCurrentUserForTest(WORK_USER)
                        .setRootListForCurrentUser(Collections.emptyList())
                        .setRootListForOtherUser(PERSONAL_ITEMS);
@@ -429,7 +455,8 @@ public class UserItemsCombinerTest {
        if (SdkLevel.isAtLeastV()) {
            rootListAllUsers.add(PRIVATE_ITEMS);
        }
        mCombiner = new UserItemsCombiner(mResources, mDpm, mState)
        mCombiner =
                new UserItemsCombiner(mResources, mMockUserManager, mDpm, mState)
                        .setRootListForAllUsers(rootListAllUsers);

        List<Item> expected = Lists.newArrayList();
@@ -460,7 +487,8 @@ public class UserItemsCombinerTest {
        if (SdkLevel.isAtLeastV()) {
            rootListAllUsers.add(PRIVATE_ITEMS);
        }
        mCombiner = new UserItemsCombiner(mResources, mDpm, mState)
        mCombiner =
                new UserItemsCombiner(mResources, mMockUserManager, mDpm, mState)
                        .overrideCurrentUserForTest(WORK_USER)
                        .setRootListForAllUsers(rootListAllUsers);