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/DownloadNotifier.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/DownloadNotifier.java')
-rw-r--r-- | src/com/android/providers/downloads/DownloadNotifier.java | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/com/android/providers/downloads/DownloadNotifier.java b/src/com/android/providers/downloads/DownloadNotifier.java index f6e7a2ee..f89d2d02 100644 --- a/src/com/android/providers/downloads/DownloadNotifier.java +++ b/src/com/android/providers/downloads/DownloadNotifier.java @@ -163,23 +163,24 @@ public class DownloadNotifier { long current = 0; long total = 0; - long remainingMillis = -1; + long speed = 0; for (DownloadInfo info : cluster) { if (info.mTotalBytes != -1) { current += info.mCurrentBytes; total += info.mTotalBytes; - remainingMillis = Math.max( - handler.getRemainingMillis(info.mId), remainingMillis); + speed += handler.getCurrentSpeed(info.mId); } } if (total > 0) { final int percent = (int) ((current * 100) / total); - if (remainingMillis != -1) { + percentText = res.getString(R.string.download_percent, percent); + + if (speed > 0) { + final long remainingMillis = ((total - current) * 1000) / speed; remainingText = res.getString(R.string.download_remaining, DateUtils.formatDuration(remainingMillis)); } - percentText = res.getString(R.string.download_percent, percent); builder.setProgress(100, percent, false); } else { |