From d30ba00a7b1d57542560d767fd68b67e5d0a3078 Mon Sep 17 00:00:00 2001 From: Gabriele M Date: Sat, 15 Jul 2017 02:09:13 +0200 Subject: [PATCH] Update download size only if it was unknown The returned content-length depends on the requested range, therefore when resuming download the reported size is smaller than the actual file size and we should not update it. --- .../updater/controller/UpdaterController.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/org/lineageos/updater/controller/UpdaterController.java b/src/org/lineageos/updater/controller/UpdaterController.java index 058df107..2ec776b5 100644 --- a/src/org/lineageos/updater/controller/UpdaterController.java +++ b/src/org/lineageos/updater/controller/UpdaterController.java @@ -152,15 +152,17 @@ public class UpdaterController implements UpdaterControllerInt { @Override public void onResponse(int statusCode, String url, DownloadClient.Headers headers) { final UpdateDownload update = mDownloads.get(downloadId).mUpdate; - String contentLenght = headers.get("Content-Length"); - if (contentLenght != null) { - try { - long size = Long.parseLong(contentLenght); - if (size > 0) { - update.setFileSize(size); + if (update.getFileSize() <= 0) { + String contentLenght = headers.get("Content-Length"); + if (contentLenght != null) { + try { + long size = Long.parseLong(contentLenght); + if (size > 0) { + update.setFileSize(size); + } + } catch (NumberFormatException e) { + Log.e(TAG, "Could not get content-length"); } - } catch (NumberFormatException e) { - Log.e(TAG, "Could not get content-length"); } } update.setStatus(UpdateStatus.DOWNLOADING);