Sanity check only after updating from file size.
Jeff Sharkey [Mon, 24 Oct 2011 22:15:54 +0000 (15:15 -0700)]
Database values can be stale, so delay sanity check until after
updating from file size on disk.

Bug: 5484249
Change-Id: Ia648a575d4a3a391a1f06a866c8282f2d569f15e

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

index 63a51a8..9080e72 100644 (file)
@@ -162,13 +162,6 @@ public class DownloadThread extends Thread {
 
             boolean finished = false;
             while(!finished) {
-                if (state.mCurrentBytes == state.mTotalBytes) {
-                    Log.i(Constants.TAG, "Skipping initiating request for download " +
-                          mInfo.mId + "; already completed");
-                    finished = true;
-                    break;
-                }
-
                 Log.i(Constants.TAG, "Initiating request for download " + mInfo.mId);
                 // Set or unset proxy, which may have changed since last GET request.
                 // setDefaultProxy() supports null as proxy parameter.
@@ -243,6 +236,13 @@ public class DownloadThread extends Thread {
         setupDestinationFile(state, innerState);
         addRequestHeaders(state, request);
 
+        // skip when already finished; remove after fixing race in 5217390
+        if (state.mCurrentBytes == state.mTotalBytes) {
+            Log.i(Constants.TAG, "Skipping initiating request for download " +
+                  mInfo.mId + "; already completed");
+            return;
+        }
+
         // check just before sending the request to avoid using an invalid connection at all
         checkConnectivity();