From ab52ea019453fe31d91a5f9afc227c4caa77e884 Mon Sep 17 00:00:00 2001 From: Garfield Tan Date: Thu, 6 Oct 2016 17:26:05 +0000 Subject: [PATCH] Revert "DO NOT MERGE ANYWHERE: Add findPath API to SAF." This reverts commit 2f6d0d6db3af4451ae209a07c7dd7ee089cc5653. Change-Id: I0b8581c6d5edb2a47ddfb75afaaa52c43964087b --- .../android/provider/DocumentsContract.java | 86 ------------------- .../android/provider/DocumentsProvider.java | 29 ------- .../ExternalStorageProvider.java | 35 +------- 3 files changed, 3 insertions(+), 147 deletions(-) diff --git a/core/java/android/provider/DocumentsContract.java b/core/java/android/provider/DocumentsContract.java index 98371f444c78b..6ddaf3bff77f4 100644 --- a/core/java/android/provider/DocumentsContract.java +++ b/core/java/android/provider/DocumentsContract.java @@ -36,10 +36,8 @@ import android.net.Uri; import android.os.Bundle; import android.os.CancellationSignal; import android.os.OperationCanceledException; -import android.os.Parcel; import android.os.ParcelFileDescriptor; import android.os.ParcelFileDescriptor.OnCloseListener; -import android.os.Parcelable; import android.os.RemoteException; import android.os.storage.StorageVolume; import android.system.ErrnoException; @@ -646,8 +644,6 @@ public final class DocumentsContract { public static final String METHOD_REMOVE_DOCUMENT = "android:removeDocument"; /** {@hide} */ public static final String METHOD_EJECT_ROOT = "android:ejectRoot"; - /** {@hide} */ - public static final String METHOD_FIND_PATH = "android:findPath"; /** {@hide} */ public static final String EXTRA_PARENT_URI = "parentUri"; @@ -1310,41 +1306,6 @@ public final class DocumentsContract { return out.getBoolean(DocumentsContract.EXTRA_RESULT); } - /** - * Finds the canonical path to the root. Document id should be unique across - * roots. - * - * @param documentUri uri of the document which path is requested. - * @return the path to the root of the document, or {@code null} if failed. - * @see DocumentsProvider#findPath(String) - * - * {@hide} - */ - public static Path findPath(ContentResolver resolver, Uri documentUri) - throws RemoteException { - final ContentProviderClient client = resolver.acquireUnstableContentProviderClient( - documentUri.getAuthority()); - try { - return findPath(client, documentUri); - } catch (Exception e) { - Log.w(TAG, "Failed to find path", e); - return null; - } finally { - ContentProviderClient.releaseQuietly(client); - } - } - - /** {@hide} */ - public static Path findPath(ContentProviderClient client, Uri documentUri) - throws RemoteException { - final Bundle in = new Bundle(); - in.putParcelable(DocumentsContract.EXTRA_URI, documentUri); - - final Bundle out = client.call(METHOD_FIND_PATH, null, in); - - return out.getParcelable(DocumentsContract.EXTRA_RESULT); - } - /** * Open the given image for thumbnail purposes, using any embedded EXIF * thumbnail if available, and providing orientation hints from the parent @@ -1384,51 +1345,4 @@ public final class DocumentsContract { return new AssetFileDescriptor(pfd, 0, AssetFileDescriptor.UNKNOWN_LENGTH, extras); } - - /** - * Holds a path from a root to a particular document under it. - * - * @hide - */ - public static final class Path implements Parcelable { - - public final String mRootId; - public final List mPath; - - /** - * Creates a Path. - * @param rootId the id of the root - * @param path the list of document ids from the root document - * at position 0 to the target document - */ - public Path(String rootId, List path) { - mRootId = rootId; - mPath = path; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeString(mRootId); - dest.writeStringList(mPath); - } - - @Override - public int describeContents() { - return 0; - } - - public static final Creator CREATOR = new Creator() { - @Override - public Path createFromParcel(Parcel in) { - final String rootId = in.readString(); - final List path = in.createStringArrayList(); - return new Path(rootId, path); - } - - @Override - public Path[] newArray(int size) { - return new Path[size]; - } - }; - } } diff --git a/core/java/android/provider/DocumentsProvider.java b/core/java/android/provider/DocumentsProvider.java index 6234f6ae71312..6117ce4cc24ad 100644 --- a/core/java/android/provider/DocumentsProvider.java +++ b/core/java/android/provider/DocumentsProvider.java @@ -20,7 +20,6 @@ import static android.provider.DocumentsContract.METHOD_COPY_DOCUMENT; import static android.provider.DocumentsContract.METHOD_CREATE_DOCUMENT; import static android.provider.DocumentsContract.METHOD_DELETE_DOCUMENT; import static android.provider.DocumentsContract.METHOD_EJECT_ROOT; -import static android.provider.DocumentsContract.METHOD_FIND_PATH; import static android.provider.DocumentsContract.METHOD_IS_CHILD_DOCUMENT; import static android.provider.DocumentsContract.METHOD_MOVE_DOCUMENT; import static android.provider.DocumentsContract.METHOD_REMOVE_DOCUMENT; @@ -34,7 +33,6 @@ import static android.provider.DocumentsContract.getSearchDocumentsQuery; import static android.provider.DocumentsContract.getTreeDocumentId; import static android.provider.DocumentsContract.isTreeUri; -import android.Manifest; import android.annotation.CallSuper; import android.content.ClipDescription; import android.content.ContentProvider; @@ -55,7 +53,6 @@ import android.os.ParcelFileDescriptor; import android.os.ParcelFileDescriptor.OnCloseListener; import android.provider.DocumentsContract.Document; import android.provider.DocumentsContract.Root; -import android.provider.DocumentsContract.Path; import android.util.Log; import libcore.io.IoUtils; @@ -325,26 +322,6 @@ public abstract class DocumentsProvider extends ContentProvider { throw new UnsupportedOperationException("Remove not supported"); } - /** - * Finds the canonical path to the root for the requested document. If there are - * more than one path to this document, return the most typical one. - * - *

This API assumes that document id has enough info to infer the root. - * Different roots should use different document id to refer to the same - * document. - * - * @param documentId the document which path is requested. - * @return the path of the requested document to the root, or null if - * such operation is not supported. - * - * @hide - */ - public Path findPath(String documentId) - throws FileNotFoundException { - Log.w(TAG, "findPath is called on an unsupported provider."); - return null; - } - /** * Return all roots currently provided. To display to users, you must define * at least one root. You should avoid making network requests to keep this @@ -896,12 +873,6 @@ public abstract class DocumentsProvider extends ContentProvider { // It's responsibility of the provider to revoke any grants, as the document may be // still attached to another parents. - } else if (METHOD_FIND_PATH.equals(method)) { - getContext().enforceCallingPermission(Manifest.permission.MANAGE_DOCUMENTS, null); - - final Path path = findPath(documentId); - - out.putParcelable(DocumentsContract.EXTRA_RESULT, path); } else { throw new UnsupportedOperationException("Method not supported " + method); } diff --git a/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java b/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java index 3b575a8a03a64..33d6b9a33ef8e 100644 --- a/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java +++ b/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java @@ -41,7 +41,6 @@ import android.os.storage.VolumeInfo; import android.provider.DocumentsContract; import android.provider.DocumentsContract.Document; import android.provider.DocumentsContract.Root; -import android.provider.DocumentsContract.Path; import android.provider.DocumentsProvider; import android.provider.MediaStore; import android.provider.Settings; @@ -49,7 +48,6 @@ import android.text.TextUtils; import android.util.ArrayMap; import android.util.DebugUtils; import android.util.Log; -import android.util.Pair; import android.webkit.MimeTypeMap; import com.android.internal.annotations.GuardedBy; @@ -185,8 +183,7 @@ public class ExternalStorageProvider extends DocumentsProvider { root.rootId = rootId; root.volumeId = volume.id; root.flags = Root.FLAG_LOCAL_ONLY - | Root.FLAG_SUPPORTS_SEARCH - | Root.FLAG_SUPPORTS_IS_CHILD; + | Root.FLAG_SUPPORTS_SEARCH | Root.FLAG_SUPPORTS_IS_CHILD; final DiskInfo disk = volume.getDisk(); if (DEBUG) Log.d(TAG, "Disk for root " + rootId + " is " + disk); @@ -273,6 +270,7 @@ public class ExternalStorageProvider extends DocumentsProvider { return projection != null ? projection : DEFAULT_DOCUMENT_PROJECTION; } + private String getDocIdForFile(File file) throws FileNotFoundException { return getDocIdForFileMaybeCreate(file, false); } @@ -325,11 +323,6 @@ public class ExternalStorageProvider extends DocumentsProvider { } private File getFileForDocId(String docId, boolean visible) throws FileNotFoundException { - return resolveDocId(docId, visible).second; - } - - private Pair resolveDocId(String docId, boolean visible) - throws FileNotFoundException { final int splitIndex = docId.indexOf(':', 1); final String tag = docId.substring(0, splitIndex); final String path = docId.substring(splitIndex + 1); @@ -353,7 +346,7 @@ public class ExternalStorageProvider extends DocumentsProvider { if (!target.exists()) { throw new FileNotFoundException("Missing file for " + docId + " at " + target); } - return Pair.create(root, target); + return target; } private void includeFile(MatrixCursor result, String docId, File file) @@ -429,28 +422,6 @@ public class ExternalStorageProvider extends DocumentsProvider { } } - @Override - public Path findPath(String documentId) - throws FileNotFoundException { - LinkedList path = new LinkedList<>(); - - final Pair resolvedDocId = resolveDocId(documentId, false); - RootInfo root = resolvedDocId.first; - File file = resolvedDocId.second; - - if (!file.exists()) { - throw new FileNotFoundException(); - } - - while (file != null && file.getAbsolutePath().startsWith(root.path.getAbsolutePath())) { - path.addFirst(getDocIdForFile(file)); - - file = file.getParentFile(); - } - - return new Path(root.rootId, path); - } - @Override public String createDocument(String docId, String mimeType, String displayName) throws FileNotFoundException {