From 4f7db45fa61a8c367357c2376f1e01ed35dfc1b2 Mon Sep 17 00:00:00 2001 From: Gabriele M Date: Sat, 28 Apr 2018 15:34:02 +0200 Subject: [PATCH] Use Content-Length if greater than current size The server may temporarily report an incorrect size that is smaller than the actual size. Content-Length is expected to always be accurate, but its value does not correspond to the full file size when resuming downloads. Use Content-Length only if it's bigger than the currently known size. Change-Id: I2cc06bfbd2349f21528047b4840f549fbe84964e --- .../updater/controller/UpdaterController.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/org/lineageos/updater/controller/UpdaterController.java b/src/org/lineageos/updater/controller/UpdaterController.java index 97c939d..faa7306 100644 --- a/src/org/lineageos/updater/controller/UpdaterController.java +++ b/src/org/lineageos/updater/controller/UpdaterController.java @@ -157,17 +157,15 @@ public class UpdaterController implements Controller { @Override public void onResponse(int statusCode, String url, DownloadClient.Headers headers) { final Update update = mDownloads.get(downloadId).mUpdate; - if (update.getFileSize() <= 0) { - String contentLength = headers.get("Content-Length"); - if (contentLength != null) { - try { - long size = Long.parseLong(contentLength); - if (size > 0) { - update.setFileSize(size); - } - } catch (NumberFormatException e) { - Log.e(TAG, "Could not get content-length"); + String contentLength = headers.get("Content-Length"); + if (contentLength != null) { + try { + long size = Long.parseLong(contentLength); + if (update.getFileSize() < size) { + update.setFileSize(size); } + } catch (NumberFormatException e) { + Log.e(TAG, "Could not get content-length"); } } update.setStatus(UpdateStatus.DOWNLOADING);