From f0940dafca7eaf08f40523f435bf8bbf4e0a2094 Mon Sep 17 00:00:00 2001 From: Gabriele M Date: Tue, 4 Jul 2017 19:05:04 +0200 Subject: [PATCH] Verify package when resuming a completed download It's possible to resume already completed downloads. When this happens, starts verifying the package. Otherwise we won't be able to resume the download since the server will likely reply with 416. --- .../updater/controller/UpdaterController.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/org/lineageos/updater/controller/UpdaterController.java b/src/org/lineageos/updater/controller/UpdaterController.java index 3e47ff3..5e59cf4 100644 --- a/src/org/lineageos/updater/controller/UpdaterController.java +++ b/src/org/lineageos/updater/controller/UpdaterController.java @@ -295,14 +295,22 @@ public class UpdaterController implements UpdaterControllerInt { return false; } UpdateDownload update = mDownloads.get(downloadId).mUpdate; - mDownloads.get(downloadId).mDownloadClient = - DownloadClient.downloadFileResume(update.getDownloadUrl(), - update.getFile(), - getDownloadCallback(downloadId), - getProgressListener(downloadId)); - update.setStatus(UpdateStatus.STARTING); - notifyUpdateChange(downloadId); - mWakeLock.acquire(); + File file = update.getFile(); + if (file.exists() && file.length() == update.getFileSize()) { + Log.d(TAG, "File already downloaded, starting verification"); + update.setStatus(UpdateStatus.VERIFYING); + verifyUpdateAsync(downloadId); + notifyUpdateChange(downloadId); + } else { + mDownloads.get(downloadId).mDownloadClient = + DownloadClient.downloadFileResume(update.getDownloadUrl(), + update.getFile(), + getDownloadCallback(downloadId), + getProgressListener(downloadId)); + update.setStatus(UpdateStatus.STARTING); + notifyUpdateChange(downloadId); + mWakeLock.acquire(); + } return true; }