DO NOT MERGE: Consolidate queryChildDocumentsXxx() implementations

Make sure to override the single right variant of the
FileSystemProvider#queryChildDocuments() method: the one that takes the
"includeHidden" boolean argument.

Bug: 200034476
Bug: 220066255
Bug: 283962634
Test: make, install and run manually
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:e11e4ca6eef7e77042f2b27fce4fdb8a0b3d0371)
Merged-In: I4c00693e28f3d50d716350a65e9e6bfd7482b085
Change-Id: I4c00693e28f3d50d716350a65e9e6bfd7482b085
diff --git a/src/com/android/providers/downloads/DownloadStorageProvider.java b/src/com/android/providers/downloads/DownloadStorageProvider.java
index b6f70e3..cb0335b 100644
--- a/src/com/android/providers/downloads/DownloadStorageProvider.java
+++ b/src/com/android/providers/downloads/DownloadStorageProvider.java
@@ -308,39 +308,26 @@
     }
 
     @Override
-    public Cursor queryChildDocuments(String parentDocId, String[] projection, String sortOrder)
-            throws FileNotFoundException {
-        return queryChildDocuments(parentDocId, projection, sortOrder, false);
-    }
-
-    @Override
-    public Cursor queryChildDocumentsForManage(
-            String parentDocId, String[] projection, String sortOrder)
-            throws FileNotFoundException {
-        return queryChildDocuments(parentDocId, projection, sortOrder, true);
-    }
-
-    private Cursor queryChildDocuments(String parentDocId, String[] projection,
-            String sortOrder, boolean manage) throws FileNotFoundException {
-
+    protected Cursor queryChildDocuments(String documentId, String[] projection, String sortOrder,
+            boolean includeHidden) throws FileNotFoundException {
         // Delegate to real provider
         final long token = Binder.clearCallingIdentity();
         Cursor cursor = null;
         try {
-            if (RawDocumentsHelper.isRawDocId(parentDocId)) {
-                return super.queryChildDocuments(parentDocId, projection, sortOrder);
+            if (RawDocumentsHelper.isRawDocId(documentId)) {
+                return super.queryChildDocuments(documentId, projection, sortOrder, includeHidden);
             }
 
             final DownloadsCursor result = new DownloadsCursor(projection,
                     getContext().getContentResolver());
             final ArrayList<Uri> notificationUris = new ArrayList<>();
-            if (isMediaStoreDownloadDir(parentDocId)) {
+            if (isMediaStoreDownloadDir(documentId)) {
                 includeDownloadsFromMediaStore(result, null /* queryArgs */,
                         null /* filePaths */, notificationUris,
-                        getMediaStoreIdString(parentDocId), NO_LIMIT, manage);
+                        getMediaStoreIdString(documentId), NO_LIMIT, includeHidden);
             } else {
-                assert (DOC_ID_ROOT.equals(parentDocId));
-                if (manage) {
+                assert (DOC_ID_ROOT.equals(documentId));
+                if (includeHidden) {
                     cursor = mDm.query(
                             new DownloadManager.Query().setOnlyIncludeVisibleInDownloadsUi(true));
                 } else {
@@ -355,7 +342,7 @@
                 notificationUris.add(cursor.getNotificationUri());
                 includeDownloadsFromMediaStore(result, null /* queryArgs */,
                         filePaths, notificationUris,
-                        null /* parentId */, NO_LIMIT, manage);
+                        null /* parentId */, NO_LIMIT, includeHidden);
                 includeFilesFromSharedStorage(result, filePaths, null);
             }
             result.setNotificationUris(getContext().getContentResolver(), notificationUris);
@@ -477,12 +464,11 @@
         return result;
     }
 
-    private void includeSearchFilesFromSharedStorage(DownloadsCursor result,
-            String[] projection, Set<String> filePaths,
-            Bundle queryArgs) throws FileNotFoundException {
+    private void includeSearchFilesFromSharedStorage(DownloadsCursor result, String[] projection,
+            Set<String> filePaths, Bundle queryArgs) throws FileNotFoundException {
         final File downloadDir = getPublicDownloadsDirectory();
         try (Cursor rawFilesCursor = super.querySearchDocuments(downloadDir,
-                projection, filePaths, queryArgs)) {
+                projection, /* exclusion */ filePaths, queryArgs)) {
 
             final boolean shouldExcludeMedia = queryArgs.getBoolean(
                     DocumentsContract.QUERY_ARG_EXCLUDE_MEDIA, false /* defaultValue */);