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

Commit 58b0688f authored by Kelvin Kwan's avatar Kelvin Kwan Committed by Android (Google) Code Review
Browse files

Merge "Loads UserId into DocumentInfo"

parents 02eeaf52 2788bf12
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -90,6 +90,8 @@
    <string name="debug_stream_types" translatable="false">Stream types</string>
    <!-- String label for developer/debug file details, specifying the size of the file in bytes. -->
    <string name="debug_raw_size" translatable="false">Raw size (bytes)</string>
    <!-- String label for developer/debug file details, specifying a user id -->
    <string name="debug_user_id" translatable="false">User id</string>
    <!-- String label for developer/debug file details, specifying a file's uri/content address. -->
    <string name="debug_content_uri" translatable="false">Uri</string>
    <!-- String label for developer/debug file details, specifying document id. -->
+6 −4
Original line number Diff line number Diff line
@@ -358,6 +358,7 @@ public abstract class AbstractActionHandler<T extends FragmentActivity & CommonA
        if (mSearchMgr.isSearching()) {
            loadDocument(
                    doc.derivedUri,
                    doc.userId,
                    (@Nullable DocumentStack stack) -> openFolderInSearchResult(stack, doc));
        } else {
            openChildContainer(doc);
@@ -581,7 +582,7 @@ public abstract class AbstractActionHandler<T extends FragmentActivity & CommonA
            if (top.isArchive()) {
                // Swap the zip file in original provider and the one provided by ArchiveProvider.
                stack.pop();
                stack.push(mDocs.getArchiveDocument(top.derivedUri));
                stack.push(mDocs.getArchiveDocument(top.derivedUri, top.userId));
            }

            mState.stack.reset();
@@ -609,7 +610,7 @@ public abstract class AbstractActionHandler<T extends FragmentActivity & CommonA
            currentDoc = doc;
        } else if (doc.isArchive()) {
            // Archive.
            currentDoc = mDocs.getArchiveDocument(doc.derivedUri);
            currentDoc = mDocs.getArchiveDocument(doc.derivedUri, doc.userId);
        }

        assert(currentDoc != null);
@@ -699,11 +700,12 @@ public abstract class AbstractActionHandler<T extends FragmentActivity & CommonA
        throw new UnsupportedOperationException("Share not supported!");
    }

    protected final void loadDocument(Uri uri, LoadDocStackCallback callback) {
    protected final void loadDocument(Uri uri, UserId userId, LoadDocStackCallback callback) {
        new LoadDocStackTask(
                mActivity,
                mProviders,
                mDocs,
                userId,
                callback
                ).executeOnExecutor(mExecutors.lookup(uri.getAuthority()), uri);
    }
@@ -739,7 +741,7 @@ public abstract class AbstractActionHandler<T extends FragmentActivity & CommonA
    protected final boolean launchToDocument(Uri uri) {
        // We don't support launching to a document in an archive.
        if (!Providers.isArchiveUri(uri)) {
            loadDocument(uri, this::onStackLoaded);
            loadDocument(uri, UserId.DEFAULT_USER, this::onStackLoaded);
            return true;
        }

+1 −1
Original line number Diff line number Diff line
@@ -150,7 +150,7 @@ public class CreateDirectoryFragment extends DialogFragment {
                        resolver, mCwd.derivedUri.getAuthority());
                final Uri childUri = DocumentsContract.createDocument(
                        wrap(client), mCwd.derivedUri, Document.MIME_TYPE_DIR, mDisplayName);
                DocumentInfo doc = DocumentInfo.fromUri(resolver, childUri);
                DocumentInfo doc = DocumentInfo.fromUri(resolver, childUri, mCwd.userId);
                return doc.isDirectory() ? doc : null;
            } catch (Exception e) {
                Log.w(TAG, "Failed to create directory", e);
+2 −1
Original line number Diff line number Diff line
@@ -142,7 +142,8 @@ public class DirectoryLoader extends AsyncTaskLoader<DirectoryResult> {

            cursor.registerContentObserver(mObserver);

            cursor = new RootCursorWrapper(mUri.getAuthority(), mRoot.rootId, cursor, -1);
            cursor = new RootCursorWrapper(mDoc.userId, mUri.getAuthority(), mRoot.rootId, cursor,
                    -1);

            if (mSearchMode && !mFeatures.isFoldersInSearchResultsEnabled()) {
                // There is no findDocumentPath API. Enable filtering on folders in search mode.
+27 −20
Original line number Diff line number Diff line
@@ -16,8 +16,6 @@

package com.android.documentsui;

import androidx.annotation.Nullable;

import static android.content.ContentResolver.wrap;

import android.content.ContentProviderClient;
@@ -31,9 +29,12 @@ import android.provider.DocumentsContract;
import android.provider.DocumentsContract.Path;
import android.util.Log;

import androidx.annotation.Nullable;

import com.android.documentsui.archives.ArchivesProvider;
import com.android.documentsui.base.DocumentInfo;
import com.android.documentsui.base.RootInfo;
import com.android.documentsui.base.UserId;

import java.io.FileNotFoundException;
import java.util.ArrayList;
@@ -46,13 +47,16 @@ import java.util.List;
public interface DocumentsAccess {

    @Nullable DocumentInfo getRootDocument(RootInfo root);
    @Nullable DocumentInfo getDocument(Uri uri);
    @Nullable DocumentInfo getArchiveDocument(Uri uri);
    @Nullable DocumentInfo getDocument(Uri uri, UserId userId);
    @Nullable DocumentInfo getArchiveDocument(Uri uri, UserId userId);

    boolean isDocumentUri(Uri uri);
    @Nullable Path findDocumentPath(Uri uri) throws RemoteException, FileNotFoundException;

    List<DocumentInfo> getDocuments(String authority, List<String> docIds) throws RemoteException;
    @Nullable
    Path findDocumentPath(Uri uri, UserId userId) throws RemoteException, FileNotFoundException;

    List<DocumentInfo> getDocuments(UserId userId, String authority, List<String> docIds)
            throws RemoteException;

    @Nullable Uri createDocument(DocumentInfo parentDoc, String mimeType, String displayName);

@@ -71,15 +75,16 @@ public interface DocumentsAccess {
        }

        @Override
        public @Nullable DocumentInfo getRootDocument(RootInfo root) {
            return getDocument(
                    DocumentsContract.buildDocumentUri(root.authority, root.documentId));
        @Nullable
        public DocumentInfo getRootDocument(RootInfo root) {
            return getDocument(DocumentsContract.buildDocumentUri(root.authority, root.documentId),
                    root.userId);
        }

        @Override
        public @Nullable DocumentInfo getDocument(Uri uri) {
        public @Nullable DocumentInfo getDocument(Uri uri, UserId userId) {
            try {
                return DocumentInfo.fromUri(mContext.getContentResolver(), uri);
                return DocumentInfo.fromUri(userId.getContentResolver(mContext), uri, userId);
            } catch (FileNotFoundException e) {
                Log.w(TAG, "Couldn't create DocumentInfo for uri: " + uri);
            }
@@ -88,11 +93,11 @@ public interface DocumentsAccess {
        }

        @Override
        public List<DocumentInfo> getDocuments(String authority, List<String> docIds)
        public List<DocumentInfo> getDocuments(UserId userId, String authority, List<String> docIds)
                throws RemoteException {

            try(final ContentProviderClient client = DocumentsApplication
                    .acquireUnstableProviderOrThrow(mContext.getContentResolver(), authority)) {
            try (ContentProviderClient client = DocumentsApplication.acquireUnstableProviderOrThrow(
                    userId.getContentResolver(mContext), authority)) {

                List<DocumentInfo> result = new ArrayList<>(docIds.size());
                for (String docId : docIds) {
@@ -103,7 +108,7 @@ public interface DocumentsAccess {
                            throw new RemoteException("Failed to move cursor.");
                        }

                        result.add(DocumentInfo.fromCursor(cursor, authority));
                        result.add(DocumentInfo.fromCursor(cursor, userId, authority));
                    }
                }

@@ -112,9 +117,10 @@ public interface DocumentsAccess {
        }

        @Override
        public DocumentInfo getArchiveDocument(Uri uri) {
            return getDocument(ArchivesProvider.buildUriForArchive(uri,
                    ParcelFileDescriptor.MODE_READ_ONLY));
        public DocumentInfo getArchiveDocument(Uri uri, UserId userId) {
            return getDocument(
                    ArchivesProvider.buildUriForArchive(uri, ParcelFileDescriptor.MODE_READ_ONLY),
                    userId);
        }

        @Override
@@ -123,8 +129,9 @@ public interface DocumentsAccess {
        }

        @Override
        public Path findDocumentPath(Uri docUri) throws RemoteException, FileNotFoundException {
            final ContentResolver resolver = mContext.getContentResolver();
        public Path findDocumentPath(Uri docUri, UserId userId)
                throws RemoteException, FileNotFoundException {
            final ContentResolver resolver = userId.getContentResolver(mContext);
            try (final ContentProviderClient client = DocumentsApplication
                    .acquireUnstableProviderOrThrow(resolver, docUri.getAuthority())) {
                return DocumentsContract.findDocumentPath(wrap(client), docUri);
Loading