summaryrefslogtreecommitdiffstats
path: root/src/com/android/providers/downloads
diff options
context:
space:
mode:
authorJorge Gil <jorgegil@google.com>2016-08-01 16:21:33 -0700
committerSteve McKay <smckay@google.com>2016-08-29 19:33:25 +0000
commita4b509c30aaf1ec94a9ebed393a37c3d25540269 (patch)
treeb2e3899342f4c64f2ee3656b6261b7bda833ff92 /src/com/android/providers/downloads
parent465a080262d9d00116c43ab018f39d1481e4dc57 (diff)
downloadandroid_packages_providers_DownloadProvider-a4b509c30aaf1ec94a9ebed393a37c3d25540269.tar.gz
android_packages_providers_DownloadProvider-a4b509c30aaf1ec94a9ebed393a37c3d25540269.tar.bz2
android_packages_providers_DownloadProvider-a4b509c30aaf1ec94a9ebed393a37c3d25540269.zip
DO NOT MERGE: Check that file exists in disk in queryChildDocs
Check that files returned from querying DownloadManager in queryChildDocuments and queryChildDocumentsForManage still exist in External Storage. Bug: 28430547, 31108493 Change-Id: I4efe9f9ba79d41b3c3099fb96d18460880b742b5 (cherry picked from commit c45f4998c0b4f7ab44d3d2a180ca977ca2fa5ca8) (cherry picked from commit 314026d4e85d0d1d075d5de83038cec1e751ec64)
Diffstat (limited to 'src/com/android/providers/downloads')
-rw-r--r--src/com/android/providers/downloads/DownloadStorageProvider.java14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/com/android/providers/downloads/DownloadStorageProvider.java b/src/com/android/providers/downloads/DownloadStorageProvider.java
index e0bb7cd1..80d6ac79 100644
--- a/src/com/android/providers/downloads/DownloadStorageProvider.java
+++ b/src/com/android/providers/downloads/DownloadStorageProvider.java
@@ -325,6 +325,10 @@ public class DownloadStorageProvider extends DocumentsProvider {
Document.FLAG_DIR_PREFERS_LAST_MODIFIED | Document.FLAG_DIR_SUPPORTS_CREATE);
}
+ /**
+ * Adds the entry from the cursor to the result only if the entry is valid. That is,
+ * if the file exists in the file system.
+ */
private void includeDownloadFromCursor(MatrixCursor result, Cursor cursor) {
final long id = cursor.getLong(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_ID));
final String docId = String.valueOf(id);
@@ -344,12 +348,20 @@ public class DownloadStorageProvider extends DocumentsProvider {
if (size == -1) {
size = null;
}
+ String localFilePath = cursor.getString(
+ cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_LOCAL_FILENAME));
int extraFlags = Document.FLAG_PARTIAL;
final int status = cursor.getInt(
cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_STATUS));
switch (status) {
case DownloadManager.STATUS_SUCCESSFUL:
+ // Verify that the document still exists in external storage. This is necessary
+ // because files can be deleted from the file system without their entry being
+ // removed from DownloadsManager.
+ if (localFilePath == null || !new File(localFilePath).exists()) {
+ return;
+ }
extraFlags = Document.FLAG_SUPPORTS_RENAME; // only successful is non-partial
break;
case DownloadManager.STATUS_PAUSED:
@@ -400,8 +412,6 @@ public class DownloadStorageProvider extends DocumentsProvider {
row.add(Document.COLUMN_LAST_MODIFIED, lastModified);
}
- final String localFilePath = cursor.getString(
- cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_LOCAL_FILENAME));
if (localFilePath != null) {
row.add(DocumentArchiveHelper.COLUMN_LOCAL_FILE_PATH, localFilePath);
}