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

Commit f79f44e3 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 13511273 from a21d71df to 25Q3-release

Change-Id: I6dce92182b4ecf0011af31ebb4e60cfdf5df4f33
parents 6967abba a21d71df
Loading
Loading
Loading
Loading
+21 −8
Original line number Diff line number Diff line
@@ -40,9 +40,14 @@ import com.android.documentsui.sorting.SortModel
 *  - A content lock for which a locking content observer is built
 *  - A list of user IDs on behalf of which the search is conducted
 *  - The root info of the listed directory
 *  - The document info of the listed directory
 *  - The document info of the listed directory, may be null.
 *  - a lookup from file extension to file type
 *  - The model capable of sorting results
 *
 *  Typically, here we expect mListedDir to be not null, as this is the directory we are listing.
 *  However, when profile is switched while using the app as a file picker, it is possible that
 *  the listing directory is null. If this is the case, we assume that we should be listing the
 *  location specified by the mRoot.
 */
class FolderLoader(
    context: Context,
@@ -50,7 +55,7 @@ class FolderLoader(
    mimeTypeLookup: Lookup<String, String>,
    contentLock: ContentLock,
    private val mRoot: RootInfo,
    private val mListedDir: DocumentInfo,
    private val mListedDir: DocumentInfo?,
    private val mOptions: QueryOptions,
    private val mSortModel: SortModel,
) : BaseFileLoader(context, userIdList, mimeTypeLookup) {
@@ -61,14 +66,22 @@ class FolderLoader(
    // Creates a directory result object corresponding to the current parameters of the loader.
    override fun loadInBackground(): DirectoryResult? {
        val rejectBeforeTimestamp = mOptions.getRejectBeforeTimestamp()
        val folderChildrenUri = DocumentsContract.buildChildDocumentsUri(
        val folderChildrenUri =
            if (mListedDir == null) {
                DocumentsContract.buildChildDocumentsUri(
                    mRoot.authority,
                    mRoot.documentId
                )
            } else {
                DocumentsContract.buildChildDocumentsUri(
                    mListedDir.authority,
                    mListedDir.documentId
                )
            }
        val result = DirectoryResult()
        // If we are listing an archive, in the current approach, we cache the client as part of
        // DirectoryResult. This way, when the loader is closed, we can close the archive client.
        if (mListedDir.isInArchive) {
        if (mListedDir != null && mListedDir.isInArchive) {
            result.setClient(openArchive(folderChildrenUri))
        }
        var cursor =
@@ -88,7 +101,7 @@ class FolderLoader(
        // TODO(b:380945065): Add filtering by category, such as images, audio, video.
        val sortedCursor = mSortModel.sortCursor(filteredCursor, mimeTypeLookup)

        result.doc = mListedDir
        result.doc = mListedDir ?: DocumentInfo()
        result.cursor = sortedCursor
        return result
    }
+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(
+42 −11
Original line number Diff line number Diff line
@@ -25,7 +25,8 @@ import com.android.documentsui.rules.CheckAndForceMaterial3Flag
import com.android.documentsui.testing.TestFileTypeLookup
import com.android.documentsui.testing.TestProvidersAccess
import java.time.Duration
import junit.framework.Assert.assertEquals
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@@ -57,23 +58,31 @@ class FolderLoaderTest(private val testParams: LoaderTestParams) : BaseLoaderTes
    @get:Rule
    val checkFlags = CheckAndForceMaterial3Flag()

    @Test
    @RequiresFlagsEnabled(FLAG_USE_SEARCH_V2_READ_ONLY)
    fun testLoadInBackground() {
        val mockProvider = mEnv.mockProviders[TestProvidersAccess.DOWNLOADS.authority]
        val docs = createDocuments(TOTAL_FILE_COUNT)
        mockProvider!!.setNextChildDocumentsReturns(*docs)
        val userIds = listOf(TestProvidersAccess.DOWNLOADS.userId)
        val queryOptions =
    val contentLock = ContentLock()
    lateinit var queryOptions: QueryOptions

    @Before
    override fun setUp() {
        super.setUp()
        queryOptions =
            QueryOptions(
                TOTAL_FILE_COUNT,
                testParams.lastModifiedDelta,
                null,
                true,
                arrayOf<String>("*/*"),
                arrayOf("*/*"),
                testParams.otherArgs,
            )
        val contentLock = ContentLock()
        // Set up sample files using Downloads provider.
        val mockProvider = mEnv.mockProviders[TestProvidersAccess.DOWNLOADS.authority]
        val docs = createDocuments(TOTAL_FILE_COUNT)
        mockProvider!!.setNextChildDocumentsReturns(*docs)
    }

    @Test
    @RequiresFlagsEnabled(FLAG_USE_SEARCH_V2_READ_ONLY)
    fun testLoadInBackground() {
        val userIds = listOf(TestProvidersAccess.DOWNLOADS.userId)
        // TODO(majewski): Is there a better way to create Downloads root folder DocumentInfo?
        val rootFolderInfo = DocumentInfo()
        rootFolderInfo.authority = TestProvidersAccess.DOWNLOADS.authority
@@ -93,4 +102,26 @@ class FolderLoaderTest(private val testParams: LoaderTestParams) : BaseLoaderTes
        val directoryResult = loader.loadInBackground()
        assertEquals(testParams.expectedCount, getFileCount(directoryResult))
    }

    @Test
    @RequiresFlagsEnabled(FLAG_USE_SEARCH_V2_READ_ONLY)
    fun testListRootIfNullFolder() {
        val mockProvider = mEnv.mockProviders[TestProvidersAccess.DOWNLOADS.authority]
        val docs = createDocuments(TOTAL_FILE_COUNT)
        mockProvider!!.setNextChildDocumentsReturns(*docs)

        val loader =
            FolderLoader(
                mActivity,
                listOf(TestProvidersAccess.DOWNLOADS.userId),
                TestFileTypeLookup(),
                contentLock,
                TestProvidersAccess.DOWNLOADS,
                null,
                queryOptions,
                mEnv.state.sortModel
            )
        val directoryResult = loader.loadInBackground()
        assertEquals(testParams.expectedCount, getFileCount(directoryResult))
    }
}
+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);