summaryrefslogtreecommitdiff
path: root/core/java/android/provider/DocumentsProvider.java
diff options
context:
space:
mode:
authorGarfield Tan <xutan@google.com>2017-03-01 16:05:23 -0800
committerGarfield Tan <xutan@google.com>2017-03-02 12:48:13 -0800
commitb690b4de06385a821aed3442e10058986c03badc (patch)
tree0e23c6df416d3a327c9e8b676f6a9d764c63127d /core/java/android/provider/DocumentsProvider.java
parent85d0eee1a840ae78f31f2f02a41714803ab41e7b (diff)
Address comments from API council.
Test: Code builds and tests pass. Also some manual tests around ESP. Bug: 35813037 Bug: 35812990 Change-Id: Ia9d3a3964e9a83d0c1c08e5db4c2e231504aa99a
Diffstat (limited to 'core/java/android/provider/DocumentsProvider.java')
-rw-r--r--core/java/android/provider/DocumentsProvider.java13
1 files changed, 10 insertions, 3 deletions
diff --git a/core/java/android/provider/DocumentsProvider.java b/core/java/android/provider/DocumentsProvider.java
index f5e558a01c56..89a80f054ded 100644
--- a/core/java/android/provider/DocumentsProvider.java
+++ b/core/java/android/provider/DocumentsProvider.java
@@ -65,6 +65,7 @@ import android.util.Log;
import libcore.io.IoUtils;
import java.io.FileNotFoundException;
+import java.util.LinkedList;
import java.util.Objects;
/**
@@ -352,14 +353,14 @@ public abstract class DocumentsProvider extends ContentProvider {
* Different roots should use different document ID to refer to the same
* document.
*
- * @param childDocumentId the document which path is requested.
* @param parentDocumentId the document from which the path starts if not null,
* or null to indicate a path from the root is requested.
+ * @param childDocumentId the document which path is requested.
* @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 be null.
*/
- public Path findDocumentPath(String childDocumentId, @Nullable String parentDocumentId)
+ public Path findDocumentPath(@Nullable String parentDocumentId, String childDocumentId)
throws FileNotFoundException {
throw new UnsupportedOperationException("findDocumentPath not supported.");
}
@@ -1048,13 +1049,19 @@ public abstract class DocumentsProvider extends ContentProvider {
? DocumentsContract.getTreeDocumentId(documentUri)
: null;
- Path path = findDocumentPath(documentId, parentDocumentId);
+ Path path = findDocumentPath(parentDocumentId, documentId);
// Ensure provider doesn't leak information to unprivileged callers.
if (isTreeUri) {
if (!Objects.equals(path.getPath().get(0), parentDocumentId)) {
Log.wtf(TAG, "Provider doesn't return path from the tree root. Expected: "
+ parentDocumentId + " found: " + path.getPath().get(0));
+
+ LinkedList<String> docs = new LinkedList<>(path.getPath());
+ while (docs.size() > 1 && !Objects.equals(docs.getFirst(), parentDocumentId)) {
+ docs.removeFirst();
+ }
+ path = new Path(null, docs);
}
if (path.getRootId() != null) {