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/DownloadHandler.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/DownloadHandler.java')
-rw-r--r-- | src/com/android/providers/downloads/DownloadHandler.java | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/src/com/android/providers/downloads/DownloadHandler.java b/src/com/android/providers/downloads/DownloadHandler.java index dff09eb0..2f02864e 100644 --- a/src/com/android/providers/downloads/DownloadHandler.java +++ b/src/com/android/providers/downloads/DownloadHandler.java @@ -37,7 +37,7 @@ public class DownloadHandler { private final HashMap<Long, DownloadInfo> mDownloadsInProgress = new HashMap<Long, DownloadInfo>(); @GuardedBy("this") - private final LongSparseArray<Long> mRemainingMillis = new LongSparseArray<Long>(); + private final LongSparseArray<Long> mCurrentSpeed = new LongSparseArray<Long>(); private final int mMaxConcurrentDownloadsAllowed = Resources.getSystem().getInteger( com.android.internal.R.integer.config_MaxConcurrentDownloadsAllowed); @@ -82,23 +82,19 @@ public class DownloadHandler { public synchronized void dequeueDownload(long id) { mDownloadsInProgress.remove(id); - mRemainingMillis.remove(id); + mCurrentSpeed.remove(id); startDownloadThreadLocked(); if (mDownloadsInProgress.size() == 0 && mDownloadsQueue.size() == 0) { notifyAll(); } } - public synchronized void setRemainingMillis(long id, long millis) { - mRemainingMillis.put(id, millis); + public synchronized void setCurrentSpeed(long id, long speed) { + mCurrentSpeed.put(id, speed); } - /** - * Return remaining time until given {@link DownloadInfo} finishes, in - * milliseconds, or -1 if unknown. - */ - public synchronized long getRemainingMillis(long id) { - return mRemainingMillis.get(id, -1L); + public synchronized long getCurrentSpeed(long id) { + return mCurrentSpeed.get(id, -1L); } // right now this is only used by tests. but there is no reason why it can't be used |