summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorIvan Chiang <chiangi@google.com>2018-10-15 15:33:16 +0800
committerIvan Chiang <chiangi@google.com>2018-11-14 15:08:13 +0800
commit0ca115a3f0367f81015d7815dcb046f4becc96b9 (patch)
tree787f57dd9da03304e2f79775292514cafd5c7467 /src
parent5f1ea5263ff0cf21e4f531253c49c23efed1ba76 (diff)
downloadandroid_packages_providers_DownloadProvider-0ca115a3f0367f81015d7815dcb046f4becc96b9.tar.gz
android_packages_providers_DownloadProvider-0ca115a3f0367f81015d7815dcb046f4becc96b9.tar.bz2
android_packages_providers_DownloadProvider-0ca115a3f0367f81015d7815dcb046f4becc96b9.zip
Extend DocumentsContract search to accept mime types
Implement new querySearchDocuments method Bug: 111786939 Test: Manual Test Change-Id: I154e7e3e9c059f9b18cfef64b7f6c907284d27ea
Diffstat (limited to 'src')
-rw-r--r--src/com/android/providers/downloads/DownloadStorageProvider.java30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/com/android/providers/downloads/DownloadStorageProvider.java b/src/com/android/providers/downloads/DownloadStorageProvider.java
index afcba961..89c1a55a 100644
--- a/src/com/android/providers/downloads/DownloadStorageProvider.java
+++ b/src/com/android/providers/downloads/DownloadStorageProvider.java
@@ -27,6 +27,7 @@ import android.database.MatrixCursor.RowBuilder;
import android.graphics.Point;
import android.net.Uri;
import android.os.Binder;
+import android.os.Bundle;
import android.os.CancellationSignal;
import android.os.Environment;
import android.os.FileObserver;
@@ -234,7 +235,7 @@ public class DownloadStorageProvider extends FileSystemProvider {
if (cursor.moveToFirst()) {
// We don't know if this queryDocument() call is from Downloads (manage)
// or Files. Safely assume it's Files.
- includeDownloadFromCursor(result, cursor, filePaths);
+ includeDownloadFromCursor(result, cursor, filePaths, null);
}
}
result.start();
@@ -283,7 +284,7 @@ public class DownloadStorageProvider extends FileSystemProvider {
copyNotificationUri(result, cursor);
Set<String> filePaths = new HashSet<>();
while (cursor.moveToNext()) {
- includeDownloadFromCursor(result, cursor, filePaths);
+ includeDownloadFromCursor(result, cursor, filePaths, null);
}
includeFilesFromSharedStorage(result, filePaths, null);
@@ -331,7 +332,7 @@ public class DownloadStorageProvider extends FileSystemProvider {
}
@Override
- public Cursor querySearchDocuments(String rootId, String query, String[] projection)
+ public Cursor querySearchDocuments(String rootId, String[] projection, Bundle queryArgs)
throws FileNotFoundException {
final DownloadsCursor result =
@@ -342,14 +343,15 @@ public class DownloadStorageProvider extends FileSystemProvider {
Cursor cursor = null;
try {
cursor = mDm.query(new DownloadManager.Query().setOnlyIncludeVisibleInDownloadsUi(true)
- .setFilterByString(query));
+ .setFilterByString(DocumentsContract.getSearchDocumentsQuery(queryArgs)));
copyNotificationUri(result, cursor);
Set<String> filePaths = new HashSet<>();
while (cursor.moveToNext()) {
- includeDownloadFromCursor(result, cursor, filePaths);
+ includeDownloadFromCursor(result, cursor, filePaths, queryArgs);
}
- Cursor rawFilesCursor = super.querySearchDocuments(getDownloadsDirectory(), query,
- projection, filePaths);
+ Cursor rawFilesCursor = super.querySearchDocuments(getDownloadsDirectory(),
+ projection, filePaths, queryArgs);
+
while (rawFilesCursor.moveToNext()) {
String docId = rawFilesCursor.getString(
rawFilesCursor.getColumnIndexOrThrow(Document.COLUMN_DOCUMENT_ID));
@@ -361,6 +363,13 @@ public class DownloadStorageProvider extends FileSystemProvider {
Binder.restoreCallingIdentity(token);
}
+ final String[] handledQueryArgs = DocumentsContract.getHandledQueryArguments(queryArgs);
+ if (handledQueryArgs.length > 0) {
+ final Bundle extras = new Bundle();
+ extras.putStringArray(ContentResolver.EXTRA_HONORED_ARGS, handledQueryArgs);
+ result.setExtras(extras);
+ }
+
result.start();
return result;
}
@@ -456,7 +465,7 @@ public class DownloadStorageProvider extends FileSystemProvider {
* if the file exists in the file system.
*/
private void includeDownloadFromCursor(MatrixCursor result, Cursor cursor,
- Set<String> filePaths) {
+ Set<String> filePaths, Bundle queryArgs) {
final long id = cursor.getLong(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_ID));
final String docId = String.valueOf(id);
@@ -526,6 +535,11 @@ public class DownloadStorageProvider extends FileSystemProvider {
final long lastModified = cursor.getLong(
cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_LAST_MODIFIED_TIMESTAMP));
+ if (!DocumentsContract.matchSearchQueryArguments(queryArgs, displayName, mimeType,
+ lastModified, size)) {
+ return;
+ }
+
final RowBuilder row = result.newRow();
row.add(Document.COLUMN_DOCUMENT_ID, docId);
row.add(Document.COLUMN_DISPLAY_NAME, displayName);