Only report speeds from full samples windows.
Jeff Sharkey [Wed, 20 Feb 2013 01:11:41 +0000 (17:11 -0800)]
Wait until we've passed a full sample window (500ms) before reporting
an estimated speed.  This avoid showing skewed times like "900 hours
remaining."

Also remember to clean up the UpdateThread.

Bug: 8176417
Change-Id: I851e0abcbb443114abe9c22f4650fee7a9bc3aaa

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

index 34b1b49..66d3be9 100644 (file)
@@ -185,6 +185,7 @@ public class DownloadService extends Service {
 
     @Override
     public void onDestroy() {
+        mUpdateThread.quit();
         mScanner.shutdown();
         getContentResolver().unregisterContentObserver(mObserver);
         if (Constants.LOGVV) {
index 95754a0..48eebfc 100644 (file)
@@ -540,10 +540,13 @@ public class DownloadThread implements Runnable {
                 state.mSpeed = ((state.mSpeed * 3) + sampleSpeed) / 4;
             }
 
+            // Only notify once we have a full sample window
+            if (state.mSpeedSampleStart != 0) {
+                mNotifier.notifyDownloadSpeed(mInfo.mId, state.mSpeed);
+            }
+
             state.mSpeedSampleStart = now;
             state.mSpeedSampleBytes = state.mCurrentBytes;
-
-            mNotifier.notifyDownloadSpeed(mInfo.mId, state.mSpeed);
         }
 
         if (state.mCurrentBytes - state.mBytesNotified > Constants.MIN_PROGRESS_STEP &&