summaryrefslogtreecommitdiff
path: root/packages/ExternalStorageProvider/src
diff options
context:
space:
mode:
authorGarfield Tan <xutan@google.com>2016-09-23 13:27:59 -0700
committerGarfield Tan <xutan@google.com>2016-10-05 23:28:34 +0000
commit2f6d0d6db3af4451ae209a07c7dd7ee089cc5653 (patch)
tree95acbf42258d295c14427a55ccbf46517669f2eb /packages/ExternalStorageProvider/src
parent12e319b7357d203ac02f0c6f0b1f7ee23ad0b2df (diff)
DO NOT MERGE ANYWHERE: Add findPath API to SAF.
Implement it in ExternalStorageProvider. Bug: 30948740 Change-Id: I03241cdfa561ef2fc0a0b829c9a59ad845e8f844 (cherry picked from commit 51efc73f3f341393cf93f71604be791205021b69)
Diffstat (limited to 'packages/ExternalStorageProvider/src')
-rw-r--r--packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java35
1 files changed, 32 insertions, 3 deletions
diff --git a/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java b/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java
index 33d6b9a33ef8..3b575a8a03a6 100644
--- a/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java
+++ b/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java
@@ -41,6 +41,7 @@ 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;
@@ -48,6 +49,7 @@ 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;
@@ -183,7 +185,8 @@ 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);
@@ -270,7 +273,6 @@ public class ExternalStorageProvider extends DocumentsProvider {
return projection != null ? projection : DEFAULT_DOCUMENT_PROJECTION;
}
-
private String getDocIdForFile(File file) throws FileNotFoundException {
return getDocIdForFileMaybeCreate(file, false);
}
@@ -323,6 +325,11 @@ public class ExternalStorageProvider extends DocumentsProvider {
}
private File getFileForDocId(String docId, boolean visible) throws FileNotFoundException {
+ return resolveDocId(docId, visible).second;
+ }
+
+ private Pair<RootInfo, File> 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);
@@ -346,7 +353,7 @@ public class ExternalStorageProvider extends DocumentsProvider {
if (!target.exists()) {
throw new FileNotFoundException("Missing file for " + docId + " at " + target);
}
- return target;
+ return Pair.create(root, target);
}
private void includeFile(MatrixCursor result, String docId, File file)
@@ -423,6 +430,28 @@ public class ExternalStorageProvider extends DocumentsProvider {
}
@Override
+ public Path findPath(String documentId)
+ throws FileNotFoundException {
+ LinkedList<String> path = new LinkedList<>();
+
+ final Pair<RootInfo, File> 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 {
displayName = FileUtils.buildValidFatFilename(displayName);