Only report speeds from full samples windows.
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
diff --git a/src/com/android/providers/downloads/DownloadService.java b/src/com/android/providers/downloads/DownloadService.java
index 34b1b49..66d3be9 100644
--- a/src/com/android/providers/downloads/DownloadService.java
+++ b/src/com/android/providers/downloads/DownloadService.java
@@ -185,6 +185,7 @@
@Override
public void onDestroy() {
+ mUpdateThread.quit();
mScanner.shutdown();
getContentResolver().unregisterContentObserver(mObserver);
if (Constants.LOGVV) {
diff --git a/src/com/android/providers/downloads/DownloadThread.java b/src/com/android/providers/downloads/DownloadThread.java
index 95754a0..48eebfc 100644
--- a/src/com/android/providers/downloads/DownloadThread.java
+++ b/src/com/android/providers/downloads/DownloadThread.java
@@ -540,10 +540,13 @@
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 &&