diff options
Diffstat (limited to 'src/com/android')
-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 2898f852..0ef187ea 100644 --- a/src/com/android/providers/downloads/DownloadStorageProvider.java +++ b/src/com/android/providers/downloads/DownloadStorageProvider.java @@ -347,6 +347,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); @@ -366,12 +370,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 (!new File(localFilePath).exists()) { + return; + } extraFlags = Document.FLAG_SUPPORTS_RENAME; // only successful is non-partial break; case DownloadManager.STATUS_PAUSED: @@ -422,8 +434,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); } |