diff options
author | Ivan Chiang <chiangi@google.com> | 2018-11-28 12:47:38 +0800 |
---|---|---|
committer | Ivan Chiang <chiangi@google.com> | 2018-11-28 13:47:18 +0800 |
commit | 06e508bae18fa0ddf7b5a4896d6afec67a80a8a9 (patch) | |
tree | 2710340e07ffcf923666266271bcf01d64c4bff5 /src | |
parent | 95653601e1f03f6d9734b317fd746e74a4cf566f (diff) | |
download | android_packages_providers_DownloadProvider-06e508bae18fa0ddf7b5a4896d6afec67a80a8a9.tar.gz android_packages_providers_DownloadProvider-06e508bae18fa0ddf7b5a4896d6afec67a80a8a9.tar.bz2 android_packages_providers_DownloadProvider-06e508bae18fa0ddf7b5a4896d6afec67a80a8a9.zip |
Fix can't see download files in recent root in DocumentsUI
1. Fix issue of can't see download files in recent.
2. Implement the new queryRecentDocuments method to get query limit
from bundle.
Change-Id: Icb9db95065d27172cd86b482dd60e2fe5390ff0c
Fix: 118418471
Test: manual test in DocumentsUI
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/providers/downloads/DownloadStorageProvider.java | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/src/com/android/providers/downloads/DownloadStorageProvider.java b/src/com/android/providers/downloads/DownloadStorageProvider.java index 89c1a55a..81ba03fb 100644 --- a/src/com/android/providers/downloads/DownloadStorageProvider.java +++ b/src/com/android/providers/downloads/DownloadStorageProvider.java @@ -25,6 +25,7 @@ import android.database.Cursor; import android.database.MatrixCursor; import android.database.MatrixCursor.RowBuilder; import android.graphics.Point; +import android.media.MediaFile; import android.net.Uri; import android.os.Binder; import android.os.Bundle; @@ -297,30 +298,52 @@ public class DownloadStorageProvider extends FileSystemProvider { } @Override - public Cursor queryRecentDocuments(String rootId, String[] projection) + public Cursor queryRecentDocuments(String rootId, String[] projection, + @Nullable Bundle queryArgs, @Nullable CancellationSignal signal) throws FileNotFoundException { final DownloadsCursor result = new DownloadsCursor(projection, getContext().getContentResolver()); // Delegate to real provider final long token = Binder.clearCallingIdentity(); + + int limit = 12; + if (queryArgs != null) { + limit = queryArgs.getInt(ContentResolver.QUERY_ARG_LIMIT, -1); + + if (limit < 0) { + // Use default value, and no QUERY_ARG* is honored. + limit = 12; + } else { + // We are honoring the QUERY_ARG_LIMIT. + Bundle extras = new Bundle(); + result.setExtras(extras); + extras.putStringArray(ContentResolver.EXTRA_HONORED_ARGS, new String[]{ + ContentResolver.QUERY_ARG_LIMIT + }); + } + } + Cursor cursor = null; try { cursor = mDm.query(new DownloadManager.Query().setOnlyIncludeVisibleInDownloadsUi(true) .setFilterByStatus(DownloadManager.STATUS_SUCCESSFUL)); copyNotificationUri(result, cursor); - while (cursor.moveToNext() && result.getCount() < 12) { + Set<String> filePaths = new HashSet<>(); + while (cursor.moveToNext() && result.getCount() < limit) { final String mimeType = cursor.getString( cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_MEDIA_TYPE)); final String uri = cursor.getString( cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_MEDIAPROVIDER_URI)); - // Skip images that have been inserted into the MediaStore so we - // don't duplicate them in the recents list. - if (mimeType == null - || (mimeType.startsWith("image/") && !TextUtils.isEmpty(uri))) { + // Skip images and videos that have been inserted into the MediaStore so we + // don't duplicate them in the recent list. The audio root of + // MediaDocumentsProvider doesn't support recent, we add it into recent list. + if (mimeType == null || (MediaFile.isImageMimeType(mimeType) + || MediaFile.isVideoMimeType(mimeType)) && !TextUtils.isEmpty(uri)) { continue; } + includeDownloadFromCursor(result, cursor, filePaths, null /* queryArgs */); } } finally { IoUtils.closeQuietly(cursor); |