Loading core/java/android/provider/DocumentsContract.java +1 −1 Original line number Diff line number Diff line Loading @@ -1412,7 +1412,7 @@ public final class DocumentsContract { * @param path the list of document ids from the parent document at * position 0 to the child document. */ public Path(String rootId, List<String> path) { public Path(@Nullable String rootId, List<String> path) { checkCollectionNotEmpty(path, "path"); checkCollectionElementsNotNull(path, "path"); Loading core/java/android/provider/DocumentsProvider.java +12 −6 Original line number Diff line number Diff line Loading @@ -927,14 +927,20 @@ public abstract class DocumentsProvider extends ContentProvider { ? DocumentsContract.getTreeDocumentId(documentUri) : null; final Path path = findPath(documentId, parentDocumentId); Path path = findPath(documentId, parentDocumentId); // Ensure provider doesn't leak information to unprivileged callers. if (isTreeUri && (path.getRootId() != null || !Objects.equals(path.getPath().get(0), parentDocumentId))) { throw new IllegalStateException( "Provider returns an invalid result for findPath."); 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)); } if (path.getRootId() != null) { Log.wtf(TAG, "Provider returns root id :" + path.getRootId() + " unexpectedly. Erase root id."); path = new Path(null, path.getPath()); } } out.putParcelable(DocumentsContract.EXTRA_RESULT, path); Loading core/tests/coretests/src/android/provider/DocumentsProviderTest.java +6 −13 Original line number Diff line number Diff line Loading @@ -86,25 +86,18 @@ public class DocumentsProviderTest extends ProviderTestCase2<TestDocumentsProvid assertNull(DocumentsContract.findPath(mResolver, docUri)); } public void testFindPath_treeUri_throwsOnNonNullRootId() throws Exception { public void testFindPath_treeUri_erasesNonNullRootId() throws Exception { mProvider.nextIsChildDocument = true; mProvider.nextPath = new Path(ROOT_ID, Arrays.asList(PARENT_DOCUMENT_ID, DOCUMENT_ID)); final Uri docUri = buildTreeDocumentUri( TestDocumentsProvider.AUTHORITY, PARENT_DOCUMENT_ID, DOCUMENT_ID); assertNull(DocumentsContract.findPath(mResolver, docUri)); try (ContentProviderClient client = mResolver.acquireUnstableContentProviderClient(docUri)) { Path path = DocumentsContract.findPath(client, docUri); assertNull(path.getRootId()); } public void testFindPath_treeUri_throwsOnDifferentParentDocId() throws Exception { mProvider.nextIsChildDocument = true; mProvider.nextPath = new Path( null, Arrays.asList(ANCESTOR_DOCUMENT_ID, PARENT_DOCUMENT_ID, DOCUMENT_ID)); final Uri docUri = buildTreeDocumentUri( TestDocumentsProvider.AUTHORITY, PARENT_DOCUMENT_ID, DOCUMENT_ID); assertNull(DocumentsContract.findPath(mResolver, docUri)); } private static Uri buildTreeDocumentUri(String authority, String parentDocId, String docId) { Loading Loading
core/java/android/provider/DocumentsContract.java +1 −1 Original line number Diff line number Diff line Loading @@ -1412,7 +1412,7 @@ public final class DocumentsContract { * @param path the list of document ids from the parent document at * position 0 to the child document. */ public Path(String rootId, List<String> path) { public Path(@Nullable String rootId, List<String> path) { checkCollectionNotEmpty(path, "path"); checkCollectionElementsNotNull(path, "path"); Loading
core/java/android/provider/DocumentsProvider.java +12 −6 Original line number Diff line number Diff line Loading @@ -927,14 +927,20 @@ public abstract class DocumentsProvider extends ContentProvider { ? DocumentsContract.getTreeDocumentId(documentUri) : null; final Path path = findPath(documentId, parentDocumentId); Path path = findPath(documentId, parentDocumentId); // Ensure provider doesn't leak information to unprivileged callers. if (isTreeUri && (path.getRootId() != null || !Objects.equals(path.getPath().get(0), parentDocumentId))) { throw new IllegalStateException( "Provider returns an invalid result for findPath."); 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)); } if (path.getRootId() != null) { Log.wtf(TAG, "Provider returns root id :" + path.getRootId() + " unexpectedly. Erase root id."); path = new Path(null, path.getPath()); } } out.putParcelable(DocumentsContract.EXTRA_RESULT, path); Loading
core/tests/coretests/src/android/provider/DocumentsProviderTest.java +6 −13 Original line number Diff line number Diff line Loading @@ -86,25 +86,18 @@ public class DocumentsProviderTest extends ProviderTestCase2<TestDocumentsProvid assertNull(DocumentsContract.findPath(mResolver, docUri)); } public void testFindPath_treeUri_throwsOnNonNullRootId() throws Exception { public void testFindPath_treeUri_erasesNonNullRootId() throws Exception { mProvider.nextIsChildDocument = true; mProvider.nextPath = new Path(ROOT_ID, Arrays.asList(PARENT_DOCUMENT_ID, DOCUMENT_ID)); final Uri docUri = buildTreeDocumentUri( TestDocumentsProvider.AUTHORITY, PARENT_DOCUMENT_ID, DOCUMENT_ID); assertNull(DocumentsContract.findPath(mResolver, docUri)); try (ContentProviderClient client = mResolver.acquireUnstableContentProviderClient(docUri)) { Path path = DocumentsContract.findPath(client, docUri); assertNull(path.getRootId()); } public void testFindPath_treeUri_throwsOnDifferentParentDocId() throws Exception { mProvider.nextIsChildDocument = true; mProvider.nextPath = new Path( null, Arrays.asList(ANCESTOR_DOCUMENT_ID, PARENT_DOCUMENT_ID, DOCUMENT_ID)); final Uri docUri = buildTreeDocumentUri( TestDocumentsProvider.AUTHORITY, PARENT_DOCUMENT_ID, DOCUMENT_ID); assertNull(DocumentsContract.findPath(mResolver, docUri)); } private static Uri buildTreeDocumentUri(String authority, String parentDocId, String docId) { Loading