diff options
author | Steve McKay <smckay@google.com> | 2016-08-23 21:00:42 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2016-08-23 21:00:42 +0000 |
commit | 4093cb5adb59c42aebf0aa664894d3d6a82c9ee8 (patch) | |
tree | 4268d629dbf6051b3b3fe3fcfd941e02b594d35c /src/com/android/providers | |
parent | f4607cbdb81dc7461204acf6e1db033b7bbface5 (diff) | |
parent | 314026d4e85d0d1d075d5de83038cec1e751ec64 (diff) | |
download | android_packages_providers_DownloadProvider-4093cb5adb59c42aebf0aa664894d3d6a82c9ee8.tar.gz android_packages_providers_DownloadProvider-4093cb5adb59c42aebf0aa664894d3d6a82c9ee8.tar.bz2 android_packages_providers_DownloadProvider-4093cb5adb59c42aebf0aa664894d3d6a82c9ee8.zip |
Merge "DO NOT MERGE: Check that file exists in disk in queryChildDocs" into nyc-mr1-dev
Diffstat (limited to 'src/com/android/providers')
-rw-r--r-- | src/com/android/providers/downloads/DownloadStorageProvider.java | 14 |
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); } |