From f496f0d0e7217e9616db52b73fd6fb36bd9b7548 Mon Sep 17 00:00:00 2001 From: Gabriele M Date: Mon, 17 Jul 2017 12:25:49 +0200 Subject: [PATCH] Don't set status of download to unknown when download fail The controller should report the actual status of the downloads, let the clients handle the special cases. Also, don't try to resume downloads whose destination doesn't exist. This partially reverts 7369e9cea939bb715243293cedc693b049a3e770 ("Set the status of paused downloads to unknown if no file exists"). --- .../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 7518d12..a5f565b 100644 --- a/src/org/lineageos/updater/controller/UpdaterController.java +++ b/src/org/lineageos/updater/controller/UpdaterController.java @@ -194,11 +194,7 @@ public class UpdaterController implements UpdaterControllerInt { UpdateDownload update = mDownloads.get(downloadId).mUpdate; if (cancelled) { Log.d(TAG, "Download cancelled"); - if (update.getFile() != null && update.getFile().length() > 0) { - update.setStatus(UpdateStatus.PAUSED); - } else { - update.setStatus(UpdateStatus.UNKNOWN); - } + update.setStatus(UpdateStatus.PAUSED); // Already notified } else { Log.e(TAG, "Download failed"); @@ -391,6 +387,12 @@ public class UpdaterController implements UpdaterControllerInt { } UpdateDownload update = mDownloads.get(downloadId).mUpdate; File file = update.getFile(); + if (file == null || !file.exists()) { + Log.e(TAG, "The destination file of " + downloadId + " doesn't exist, can't resume"); + update.setStatus(UpdateStatus.PAUSED_ERROR); + notifyUpdateChange(downloadId); + return false; + } if (file.exists() && update.getFileSize() > 0 && file.length() >= update.getFileSize()) { Log.d(TAG, "File already downloaded, starting verification"); update.setStatus(UpdateStatus.VERIFYING); @@ -422,11 +424,7 @@ public class UpdaterController implements UpdaterControllerInt { DownloadEntry entry = mDownloads.get(downloadId); entry.mDownloadClient.cancel(); removeDownloadClient(entry); - if (entry.mUpdate.getFile() != null && entry.mUpdate.getFile().length() > 0) { - entry.mUpdate.setStatus(UpdateStatus.PAUSED); - } else { - entry.mUpdate.setStatus(UpdateStatus.UNKNOWN); - } + entry.mUpdate.setStatus(UpdateStatus.PAUSED); entry.mUpdate.setEta(0); entry.mUpdate.setSpeed(0); notifyUpdateChange(downloadId);