summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKweku Adams <kwekua@google.com>2023-05-23 20:34:56 +0000
committerKweku Adams <kwekua@google.com>2023-05-23 20:38:22 +0000
commit9312afe513440f2a7df365a6b1f7adc604a640de (patch)
treedff31328a3073efa87182d5bcc11a61768980d64
parent37178d4407bc46e5b981a8a163852c4c7923109f (diff)
downloadDownloadProvider-9312afe513440f2a7df365a6b1f7adc604a640de.tar.gz
Avoid setting negative bytes.
When DownloadManager has downloaded more than expected, mark the remaining amount as unknown instead of providing a negative value. Bug: 281914862 Test: N/A Change-Id: I2fdd5a5466d9d5f6790713d7945fc5265ef9846b
-rw-r--r--src/com/android/providers/downloads/Helpers.java10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/com/android/providers/downloads/Helpers.java b/src/com/android/providers/downloads/Helpers.java
index 11f81c54..9b99e477 100644
--- a/src/com/android/providers/downloads/Helpers.java
+++ b/src/com/android/providers/downloads/Helpers.java
@@ -203,7 +203,15 @@ public class Helpers {
if (info.mCurrentBytes > 0 && !TextUtils.isEmpty(info.mETag)) {
// If we're resuming an in-progress download, we only need to
// download the remaining bytes.
- builder.setEstimatedNetworkBytes(info.mTotalBytes - info.mCurrentBytes,
+ final long remainingBytes;
+ if (info.mTotalBytes > info.mCurrentBytes) {
+ remainingBytes = info.mTotalBytes - info.mCurrentBytes;
+ } else {
+ // We've downloaded more than we expected. We no longer know how much is left.
+ Log.i(TAG, "Downloaded more than expected during previous executions");
+ remainingBytes = JobInfo.NETWORK_BYTES_UNKNOWN;
+ }
+ builder.setEstimatedNetworkBytes(remainingBytes,
JobInfo.NETWORK_BYTES_UNKNOWN);
} else {
builder.setEstimatedNetworkBytes(info.mTotalBytes, JobInfo.NETWORK_BYTES_UNKNOWN);