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

Commit 3f6b68a6 authored by Garfield Tan's avatar Garfield Tan
Browse files

Iteration on findDocumentPath() API.

Rename findPath() to findDocumentPath() per comment in ag/1588156.

Bug: 30948740
Change-Id: I84ef4d9c0ed1f854e0e33f3552a1805b944c2791
parent a3230467
Loading
Loading
Loading
Loading
+8 −8
Original line number Original line Diff line number Diff line
@@ -636,7 +636,7 @@ public final class DocumentsContract {
    /** {@hide} */
    /** {@hide} */
    public static final String METHOD_EJECT_ROOT = "android:ejectRoot";
    public static final String METHOD_EJECT_ROOT = "android:ejectRoot";
    /** {@hide} */
    /** {@hide} */
    public static final String METHOD_FIND_PATH = "android:findPath";
    public static final String METHOD_FIND_DOCUMENT_PATH = "android:findDocumentPath";


    /** {@hide} */
    /** {@hide} */
    public static final String EXTRA_PARENT_URI = "parentUri";
    public static final String EXTRA_PARENT_URI = "parentUri";
@@ -1304,22 +1304,22 @@ public final class DocumentsContract {
     * from the top of the tree or the root document to the requested document,
     * from the top of the tree or the root document to the requested document,
     * both inclusive.
     * both inclusive.
     *
     *
     * Document id should be unique across roots.
     * Document ID should be unique across roots.
     *
     *
     * @param treeUri treeUri of the document which path is requested.
     * @param treeUri treeUri of the document which path is requested.
     * @return a list of documents ID starting from the top of the tree to the
     * @return a list of documents ID starting from the top of the tree to the
     *      requested document, or {@code null} if failed.
     *      requested document, or {@code null} if failed.
     * @see DocumentsProvider#findPath(String, String)
     * @see DocumentsProvider#findDocumentPath(String, String)
     *
     *
     * {@hide}
     * {@hide}
     */
     */
    public static List<String> findPath(ContentResolver resolver, Uri treeUri) {
    public static List<String> findDocumentPath(ContentResolver resolver, Uri treeUri) {
        checkArgument(isTreeUri(treeUri), treeUri + " is not a tree uri.");
        checkArgument(isTreeUri(treeUri), treeUri + " is not a tree uri.");


        final ContentProviderClient client = resolver.acquireUnstableContentProviderClient(
        final ContentProviderClient client = resolver.acquireUnstableContentProviderClient(
                treeUri.getAuthority());
                treeUri.getAuthority());
        try {
        try {
            return findPath(client, treeUri).getPath();
            return findDocumentPath(client, treeUri).getPath();
        } catch (Exception e) {
        } catch (Exception e) {
            Log.w(TAG, "Failed to find path", e);
            Log.w(TAG, "Failed to find path", e);
            return null;
            return null;
@@ -1339,15 +1339,15 @@ public final class DocumentsContract {
     * @param uri uri of the document which path is requested. It can be either a
     * @param uri uri of the document which path is requested. It can be either a
     *          plain document uri or a tree uri.
     *          plain document uri or a tree uri.
     * @return the path of the document.
     * @return the path of the document.
     * @see DocumentsProvider#findPath(String, String)
     * @see DocumentsProvider#findDocumentPath(String, String)
     *
     *
     * {@hide}
     * {@hide}
     */
     */
    public static Path findPath(ContentProviderClient client, Uri uri) throws RemoteException {
    public static Path findDocumentPath(ContentProviderClient client, Uri uri) throws RemoteException {
        final Bundle in = new Bundle();
        final Bundle in = new Bundle();
        in.putParcelable(DocumentsContract.EXTRA_URI, uri);
        in.putParcelable(DocumentsContract.EXTRA_URI, uri);


        final Bundle out = client.call(METHOD_FIND_PATH, null, in);
        final Bundle out = client.call(METHOD_FIND_DOCUMENT_PATH, null, in);


        return out.getParcelable(DocumentsContract.EXTRA_RESULT);
        return out.getParcelable(DocumentsContract.EXTRA_RESULT);
    }
    }
+7 −7
Original line number Original line Diff line number Diff line
@@ -20,7 +20,7 @@ import static android.provider.DocumentsContract.METHOD_COPY_DOCUMENT;
import static android.provider.DocumentsContract.METHOD_CREATE_DOCUMENT;
import static android.provider.DocumentsContract.METHOD_CREATE_DOCUMENT;
import static android.provider.DocumentsContract.METHOD_DELETE_DOCUMENT;
import static android.provider.DocumentsContract.METHOD_DELETE_DOCUMENT;
import static android.provider.DocumentsContract.METHOD_EJECT_ROOT;
import static android.provider.DocumentsContract.METHOD_EJECT_ROOT;
import static android.provider.DocumentsContract.METHOD_FIND_PATH;
import static android.provider.DocumentsContract.METHOD_FIND_DOCUMENT_PATH;
import static android.provider.DocumentsContract.METHOD_IS_CHILD_DOCUMENT;
import static android.provider.DocumentsContract.METHOD_IS_CHILD_DOCUMENT;
import static android.provider.DocumentsContract.METHOD_MOVE_DOCUMENT;
import static android.provider.DocumentsContract.METHOD_MOVE_DOCUMENT;
import static android.provider.DocumentsContract.METHOD_REMOVE_DOCUMENT;
import static android.provider.DocumentsContract.METHOD_REMOVE_DOCUMENT;
@@ -350,17 +350,17 @@ public abstract class DocumentsProvider extends ContentProvider {
     * document.
     * document.
     *
     *
     * @param childDocumentId the document which path is requested.
     * @param childDocumentId the document which path is requested.
     * @param parentDocumentId the document with which path starts if not null, or
     * @param parentDocumentId the document from which the path starts if not null,
     *     null to indicate path to root is requested.
     *     or null to indicate a path from the root is requested.
     * @return the path of the requested document. If parentDocumentId is null
     * @return the path of the requested document. If parentDocumentId is null
     *     returned root ID must not be null. If parentDocumentId is not null
     *     returned root ID must not be null. If parentDocumentId is not null
     *     returned root ID must be null.
     *     returned root ID must be null.
     *
     *
     * @hide
     * @hide
     */
     */
    public Path findPath(String childDocumentId, @Nullable String parentDocumentId)
    public Path findDocumentPath(String childDocumentId, @Nullable String parentDocumentId)
            throws FileNotFoundException {
            throws FileNotFoundException {
        throw new UnsupportedOperationException("findPath not supported.");
        throw new UnsupportedOperationException("findDocumentPath not supported.");
    }
    }


    /**
    /**
@@ -914,7 +914,7 @@ public abstract class DocumentsProvider extends ContentProvider {


            // It's responsibility of the provider to revoke any grants, as the document may be
            // It's responsibility of the provider to revoke any grants, as the document may be
            // still attached to another parents.
            // still attached to another parents.
        } else if (METHOD_FIND_PATH.equals(method)) {
        } else if (METHOD_FIND_DOCUMENT_PATH.equals(method)) {
            final boolean isTreeUri = isTreeUri(documentUri);
            final boolean isTreeUri = isTreeUri(documentUri);


            if (isTreeUri) {
            if (isTreeUri) {
@@ -927,7 +927,7 @@ public abstract class DocumentsProvider extends ContentProvider {
                    ? DocumentsContract.getTreeDocumentId(documentUri)
                    ? DocumentsContract.getTreeDocumentId(documentUri)
                    : null;
                    : null;


            Path path = findPath(documentId, parentDocumentId);
            Path path = findDocumentPath(documentId, parentDocumentId);


            // Ensure provider doesn't leak information to unprivileged callers.
            // Ensure provider doesn't leak information to unprivileged callers.
            if (isTreeUri) {
            if (isTreeUri) {
+4 −4
Original line number Original line Diff line number Diff line
@@ -60,7 +60,7 @@ public class DocumentsProviderTest extends ProviderTestCase2<TestDocumentsProvid
                DocumentsContract.buildDocumentUri(TestDocumentsProvider.AUTHORITY, DOCUMENT_ID);
                DocumentsContract.buildDocumentUri(TestDocumentsProvider.AUTHORITY, DOCUMENT_ID);
        try (ContentProviderClient client =
        try (ContentProviderClient client =
                     mResolver.acquireUnstableContentProviderClient(docUri)) {
                     mResolver.acquireUnstableContentProviderClient(docUri)) {
            final Path actual = DocumentsContract.findPath(client, docUri);
            final Path actual = DocumentsContract.findDocumentPath(client, docUri);
            assertEquals(expected, actual);
            assertEquals(expected, actual);
        }
        }
    }
    }
@@ -73,7 +73,7 @@ public class DocumentsProviderTest extends ProviderTestCase2<TestDocumentsProvid


        final Uri docUri = buildTreeDocumentUri(
        final Uri docUri = buildTreeDocumentUri(
                TestDocumentsProvider.AUTHORITY, PARENT_DOCUMENT_ID, DOCUMENT_ID);
                TestDocumentsProvider.AUTHORITY, PARENT_DOCUMENT_ID, DOCUMENT_ID);
        final List<String> actual = DocumentsContract.findPath(mResolver, docUri);
        final List<String> actual = DocumentsContract.findDocumentPath(mResolver, docUri);


        assertEquals(expected.getPath(), actual);
        assertEquals(expected.getPath(), actual);
    }
    }
@@ -83,7 +83,7 @@ public class DocumentsProviderTest extends ProviderTestCase2<TestDocumentsProvid


        final Uri docUri = buildTreeDocumentUri(
        final Uri docUri = buildTreeDocumentUri(
                TestDocumentsProvider.AUTHORITY, PARENT_DOCUMENT_ID, DOCUMENT_ID);
                TestDocumentsProvider.AUTHORITY, PARENT_DOCUMENT_ID, DOCUMENT_ID);
        assertNull(DocumentsContract.findPath(mResolver, docUri));
        assertNull(DocumentsContract.findDocumentPath(mResolver, docUri));
    }
    }


    public void testFindPath_treeUri_erasesNonNullRootId() throws Exception {
    public void testFindPath_treeUri_erasesNonNullRootId() throws Exception {
@@ -95,7 +95,7 @@ public class DocumentsProviderTest extends ProviderTestCase2<TestDocumentsProvid
                TestDocumentsProvider.AUTHORITY, PARENT_DOCUMENT_ID, DOCUMENT_ID);
                TestDocumentsProvider.AUTHORITY, PARENT_DOCUMENT_ID, DOCUMENT_ID);
        try (ContentProviderClient client =
        try (ContentProviderClient client =
                     mResolver.acquireUnstableContentProviderClient(docUri)) {
                     mResolver.acquireUnstableContentProviderClient(docUri)) {
            Path path = DocumentsContract.findPath(client, docUri);
            Path path = DocumentsContract.findDocumentPath(client, docUri);
            assertNull(path.getRootId());
            assertNull(path.getRootId());
        }
        }
    }
    }
+1 −1
Original line number Original line Diff line number Diff line
@@ -85,7 +85,7 @@ public class TestDocumentsProvider extends DocumentsProvider {
    }
    }


    @Override
    @Override
    public Path findPath(String documentId, @Nullable String parentDocumentId) {
    public Path findDocumentPath(String documentId, @Nullable String parentDocumentId) {
        lastDocumentId = documentId;
        lastDocumentId = documentId;
        lastParentDocumentId = parentDocumentId;
        lastParentDocumentId = parentDocumentId;


+1 −1
Original line number Original line Diff line number Diff line
@@ -445,7 +445,7 @@ public class ExternalStorageProvider extends DocumentsProvider {
    }
    }


    @Override
    @Override
    public Path findPath(String childDocId, @Nullable String parentDocId)
    public Path findDocumentPath(String childDocId, @Nullable String parentDocId)
            throws FileNotFoundException {
            throws FileNotFoundException {
        LinkedList<String> path = new LinkedList<>();
        LinkedList<String> path = new LinkedList<>();