diff options
author | Jeff Sharkey <jsharkey@android.com> | 2012-11-28 14:35:40 -0800 |
---|---|---|
committer | Jeff Sharkey <jsharkey@android.com> | 2012-11-28 14:35:42 -0800 |
commit | fec5f50a85e1bfc7bb4fa12d04ffa7526c79fad7 (patch) | |
tree | 93926fa30b621cdce8b93ba8382580f9bc0f96d3 /src/com/android/providers/downloads/DownloadThread.java | |
parent | f818eecf1b60ddba2854314863243d6aa87707b0 (diff) | |
download | android_packages_providers_DownloadProvider-fec5f50a85e1bfc7bb4fa12d04ffa7526c79fad7.tar.gz android_packages_providers_DownloadProvider-fec5f50a85e1bfc7bb4fa12d04ffa7526c79fad7.tar.bz2 android_packages_providers_DownloadProvider-fec5f50a85e1bfc7bb4fa12d04ffa7526c79fad7.zip |
Improve download remaining time calculation.
Calculate remaining time in DownloadNotifier so we always use the
most recent progress data, which avoids showing stale times.
Weight speed calculation to prefer historical data so remaining time
is smoother on bumpy network connections.
Bug: 7631948
Change-Id: I497be0899e65086356745340b19d3987c6185bdd
Diffstat (limited to 'src/com/android/providers/downloads/DownloadThread.java')
-rw-r--r-- | src/com/android/providers/downloads/DownloadThread.java | 13 |
1 files changed, 2 insertions, 11 deletions
diff --git a/src/com/android/providers/downloads/DownloadThread.java b/src/com/android/providers/downloads/DownloadThread.java index 2bd3d362..34bc8e34 100644 --- a/src/com/android/providers/downloads/DownloadThread.java +++ b/src/com/android/providers/downloads/DownloadThread.java @@ -107,8 +107,6 @@ public class DownloadThread extends Thread { public long mSpeedSampleStart; /** Bytes transferred since current sample started. */ public long mSpeedSampleBytes; - /** Estimated time until finished. */ - public long mRemainingMillis; public State(DownloadInfo info) { mMimeType = Intent.normalizeMimeType(info.mMimeType); @@ -443,20 +441,13 @@ public class DownloadThread extends Thread { if (state.mSpeed == 0) { state.mSpeed = sampleSpeed; } else { - state.mSpeed = (state.mSpeed + sampleSpeed) / 2; + state.mSpeed = ((state.mSpeed * 3) + sampleSpeed) / 4; } state.mSpeedSampleStart = now; state.mSpeedSampleBytes = state.mCurrentBytes; - if (state.mSpeed != 0) { - state.mRemainingMillis = ((state.mTotalBytes - state.mCurrentBytes) * 1000) - / state.mSpeed; - } else { - state.mRemainingMillis = -1; - } - - DownloadHandler.getInstance().setRemainingMillis(mInfo.mId, state.mRemainingMillis); + DownloadHandler.getInstance().setCurrentSpeed(mInfo.mId, state.mSpeed); } if (state.mCurrentBytes - state.mBytesNotified > Constants.MIN_PROGRESS_STEP && |