summaryrefslogtreecommitdiffstats
path: root/src/com/android
diff options
context:
space:
mode:
authorBen Lin <linben@google.com>2016-04-29 16:56:48 -0700
committerBen Lin <linben@google.com>2016-05-10 21:48:01 +0000
commitb759707b80987d0cb4ad2a3a78c11702a45a36c2 (patch)
tree273d219e7c57f25d032b6c34d2679c8e74175842 /src/com/android
parent511c31fcfdb29a44f55a0e22c8f3759ce3e64a79 (diff)
downloadandroid_packages_providers_DownloadProvider-b759707b80987d0cb4ad2a3a78c11702a45a36c2.tar.gz
android_packages_providers_DownloadProvider-b759707b80987d0cb4ad2a3a78c11702a45a36c2.tar.bz2
android_packages_providers_DownloadProvider-b759707b80987d0cb4ad2a3a78c11702a45a36c2.zip
Enable search for Downloads.
Bug: 26524617 Change-Id: Ide23c822b97ccab29a341184f14698dc942e8e14
Diffstat (limited to 'src/com/android')
-rw-r--r--src/com/android/providers/downloads/DownloadProvider.java8
-rw-r--r--src/com/android/providers/downloads/DownloadStorageProvider.java26
2 files changed, 29 insertions, 5 deletions
diff --git a/src/com/android/providers/downloads/DownloadProvider.java b/src/com/android/providers/downloads/DownloadProvider.java
index 4b83cacb..aafcdbdc 100644
--- a/src/com/android/providers/downloads/DownloadProvider.java
+++ b/src/com/android/providers/downloads/DownloadProvider.java
@@ -42,6 +42,7 @@ import android.database.DatabaseUtils;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
+import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;
import android.os.Binder;
import android.os.ParcelFileDescriptor;
@@ -881,8 +882,6 @@ public final class DownloadProvider extends ContentProvider {
final String selection, final String[] selectionArgs,
final String sort) {
- Helpers.validateSelection(selection, sAppReadableColumnsSet);
-
SQLiteDatabase db = mOpenHelper.getReadableDatabase();
int match = sURIMatcher.match(uri);
@@ -929,7 +928,10 @@ public final class DownloadProvider extends ContentProvider {
logVerboseQueryInfo(projection, selection, selectionArgs, sort, db);
}
- Cursor ret = db.query(DB_TABLE, projection, fullSelection.getSelection(),
+ SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
+ builder.setTables(DB_TABLE);
+ builder.setStrict(true);
+ Cursor ret = builder.query(db, projection, fullSelection.getSelection(),
fullSelection.getParameters(), null, null, sort);
if (ret != null) {
diff --git a/src/com/android/providers/downloads/DownloadStorageProvider.java b/src/com/android/providers/downloads/DownloadStorageProvider.java
index e0bb7cd1..2898f852 100644
--- a/src/com/android/providers/downloads/DownloadStorageProvider.java
+++ b/src/com/android/providers/downloads/DownloadStorageProvider.java
@@ -99,8 +99,8 @@ public class DownloadStorageProvider extends DocumentsProvider {
final MatrixCursor result = new MatrixCursor(resolveRootProjection(projection));
final RowBuilder row = result.newRow();
row.add(Root.COLUMN_ROOT_ID, DOC_ID_ROOT);
- row.add(Root.COLUMN_FLAGS,
- Root.FLAG_LOCAL_ONLY | Root.FLAG_SUPPORTS_RECENTS | Root.FLAG_SUPPORTS_CREATE);
+ row.add(Root.COLUMN_FLAGS, Root.FLAG_LOCAL_ONLY | Root.FLAG_SUPPORTS_RECENTS
+ | Root.FLAG_SUPPORTS_CREATE | Root.FLAG_SUPPORTS_SEARCH);
row.add(Root.COLUMN_ICON, R.mipmap.ic_launcher_download);
row.add(Root.COLUMN_TITLE, getContext().getString(R.string.root_downloads));
row.add(Root.COLUMN_DOCUMENT_ID, DOC_ID_ROOT);
@@ -292,6 +292,28 @@ public class DownloadStorageProvider extends DocumentsProvider {
}
@Override
+ public Cursor querySearchDocuments(String rootId, String query, String[] projection)
+ throws FileNotFoundException {
+ final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));
+
+ // Delegate to real provider
+ final long token = Binder.clearCallingIdentity();
+ Cursor cursor = null;
+ try {
+ cursor = mDm.query(new DownloadManager.Query().setOnlyIncludeVisibleInDownloadsUi(true)
+ .setFilterByString(query));
+ copyNotificationUri(result, cursor);
+ while (cursor.moveToNext()) {
+ includeDownloadFromCursor(result, cursor);
+ }
+ } finally {
+ IoUtils.closeQuietly(cursor);
+ Binder.restoreCallingIdentity(token);
+ }
+ return result;
+ }
+
+ @Override
public ParcelFileDescriptor openDocument(String docId, String mode, CancellationSignal signal)
throws FileNotFoundException {
if (mArchiveHelper.isArchivedDocument(docId)) {