summaryrefslogtreecommitdiffstats
path: root/src/com/android/providers/downloads/DownloadThread.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/providers/downloads/DownloadThread.java')
-rw-r--r--src/com/android/providers/downloads/DownloadThread.java28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/com/android/providers/downloads/DownloadThread.java b/src/com/android/providers/downloads/DownloadThread.java
index e74d5c72..34bc8e34 100644
--- a/src/com/android/providers/downloads/DownloadThread.java
+++ b/src/com/android/providers/downloads/DownloadThread.java
@@ -29,6 +29,7 @@ import android.net.http.AndroidHttpClient;
import android.os.FileUtils;
import android.os.PowerManager;
import android.os.Process;
+import android.os.SystemClock;
import android.provider.Downloads;
import android.text.TextUtils;
import android.util.Log;
@@ -100,6 +101,13 @@ public class DownloadThread extends Thread {
public long mBytesNotified = 0;
public long mTimeLastNotification = 0;
+ /** Historical bytes/second speed of this download. */
+ public long mSpeed;
+ /** Time when current sample started. */
+ public long mSpeedSampleStart;
+ /** Bytes transferred since current sample started. */
+ public long mSpeedSampleBytes;
+
public State(DownloadInfo info) {
mMimeType = Intent.normalizeMimeType(info.mMimeType);
mRequestUri = info.mUri;
@@ -423,7 +431,25 @@ public class DownloadThread extends Thread {
* Report download progress through the database if necessary.
*/
private void reportProgress(State state, InnerState innerState) {
- long now = mSystemFacade.currentTimeMillis();
+ final long now = SystemClock.elapsedRealtime();
+
+ final long sampleDelta = now - state.mSpeedSampleStart;
+ if (sampleDelta > 500) {
+ final long sampleSpeed = ((state.mCurrentBytes - state.mSpeedSampleBytes) * 1000)
+ / sampleDelta;
+
+ if (state.mSpeed == 0) {
+ state.mSpeed = sampleSpeed;
+ } else {
+ state.mSpeed = ((state.mSpeed * 3) + sampleSpeed) / 4;
+ }
+
+ state.mSpeedSampleStart = now;
+ state.mSpeedSampleBytes = state.mCurrentBytes;
+
+ DownloadHandler.getInstance().setCurrentSpeed(mInfo.mId, state.mSpeed);
+ }
+
if (state.mCurrentBytes - state.mBytesNotified > Constants.MIN_PROGRESS_STEP &&
now - state.mTimeLastNotification > Constants.MIN_PROGRESS_TIME) {
ContentValues values = new ContentValues();