Assign a null timestamp to active downloads.
Ben Kwa [Fri, 8 Jan 2016 23:38:55 +0000 (15:38 -0800)]
This makes it such that ordering downloads by timestamp doesn't
continually shuffle stuff around if the UI happens to be sorting files
by mod time.

BUG=26417297

Change-Id: Ibe51513ee5d27ff959f8e7a2a5bad7244c3a731f

src/com/android/providers/downloads/DownloadStorageProvider.java

index c8d942c..c626b4f 100644 (file)
@@ -372,8 +372,12 @@ public class DownloadStorageProvider extends DocumentsProvider {
         row.add(Document.COLUMN_SUMMARY, summary);
         row.add(Document.COLUMN_SIZE, size);
         row.add(Document.COLUMN_MIME_TYPE, mimeType);
-        row.add(Document.COLUMN_LAST_MODIFIED, lastModified);
         row.add(Document.COLUMN_FLAGS, flags);
+        // Incomplete downloads get a null timestamp.  This prevents thrashy UI when a bunch of
+        // active downloads get sorted by mod time.
+        if (status != DownloadManager.STATUS_RUNNING) {
+            row.add(Document.COLUMN_LAST_MODIFIED, lastModified);
+        }
 
         final String localFilePath = cursor.getString(
                 cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_LOCAL_FILENAME));