Make scanning decisions based on latest data.
Jeff Sharkey [Sat, 25 Jun 2016 00:13:22 +0000 (18:13 -0600)]
When deciding to kick off a media scan of a newly-downloaded file,
use the latest values from InfoDelta, instead of stale values from
the last database read, which may lead us to skip the scan.

Bug: 29234780
Change-Id: I7ffbcdd1edb9965999b7f5f100f57a9c2933f3a5

src/com/android/providers/downloads/DownloadInfo.java
src/com/android/providers/downloads/DownloadThread.java

index 00a2dd7..c571de4 100644 (file)
@@ -448,12 +448,12 @@ public class DownloadInfo {
     /**
      * Returns whether a file should be scanned
      */
-    public boolean shouldScanFile() {
+    public boolean shouldScanFile(int status) {
         return (mMediaScanned == 0)
                 && (mDestination == Downloads.Impl.DESTINATION_EXTERNAL ||
                         mDestination == Downloads.Impl.DESTINATION_FILE_URI ||
                         mDestination == Downloads.Impl.DESTINATION_NON_DOWNLOADMANAGER_DOWNLOAD)
-                && Downloads.Impl.isStatusSuccess(mStatus);
+                && Downloads.Impl.isStatusSuccess(status);
     }
 
     /**
index 60a04ff..4019403 100644 (file)
@@ -383,8 +383,9 @@ public class DownloadThread extends Thread {
 
         if (Downloads.Impl.isStatusCompleted(mInfoDelta.mStatus)) {
             mInfo.sendIntentIfRequested();
-            if (mInfo.shouldScanFile()) {
-                DownloadScanner.requestScanBlocking(mContext, mInfo);
+            if (mInfo.shouldScanFile(mInfoDelta.mStatus)) {
+                DownloadScanner.requestScanBlocking(mContext, mInfo.mId, mInfoDelta.mFileName,
+                        mInfoDelta.mMimeType);
             }
         } else if (mInfoDelta.mStatus == STATUS_WAITING_TO_RETRY
                 || mInfoDelta.mStatus == STATUS_WAITING_FOR_NETWORK