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 7369e9cea9
("Set the status of paused downloads to unknown if no file exists").
This commit is contained in:
Gabriele M
2017-07-17 12:25:49 +02:00
parent fcce65d4ed
commit f496f0d0e7

View File

@@ -194,11 +194,7 @@ public class UpdaterController implements UpdaterControllerInt {
UpdateDownload update = mDownloads.get(downloadId).mUpdate; UpdateDownload update = mDownloads.get(downloadId).mUpdate;
if (cancelled) { if (cancelled) {
Log.d(TAG, "Download cancelled"); Log.d(TAG, "Download cancelled");
if (update.getFile() != null && update.getFile().length() > 0) { update.setStatus(UpdateStatus.PAUSED);
update.setStatus(UpdateStatus.PAUSED);
} else {
update.setStatus(UpdateStatus.UNKNOWN);
}
// Already notified // Already notified
} else { } else {
Log.e(TAG, "Download failed"); Log.e(TAG, "Download failed");
@@ -391,6 +387,12 @@ public class UpdaterController implements UpdaterControllerInt {
} }
UpdateDownload update = mDownloads.get(downloadId).mUpdate; UpdateDownload update = mDownloads.get(downloadId).mUpdate;
File file = update.getFile(); 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()) { if (file.exists() && update.getFileSize() > 0 && file.length() >= update.getFileSize()) {
Log.d(TAG, "File already downloaded, starting verification"); Log.d(TAG, "File already downloaded, starting verification");
update.setStatus(UpdateStatus.VERIFYING); update.setStatus(UpdateStatus.VERIFYING);
@@ -422,11 +424,7 @@ public class UpdaterController implements UpdaterControllerInt {
DownloadEntry entry = mDownloads.get(downloadId); DownloadEntry entry = mDownloads.get(downloadId);
entry.mDownloadClient.cancel(); entry.mDownloadClient.cancel();
removeDownloadClient(entry); removeDownloadClient(entry);
if (entry.mUpdate.getFile() != null && entry.mUpdate.getFile().length() > 0) { entry.mUpdate.setStatus(UpdateStatus.PAUSED);
entry.mUpdate.setStatus(UpdateStatus.PAUSED);
} else {
entry.mUpdate.setStatus(UpdateStatus.UNKNOWN);
}
entry.mUpdate.setEta(0); entry.mUpdate.setEta(0);
entry.mUpdate.setSpeed(0); entry.mUpdate.setSpeed(0);
notifyUpdateChange(downloadId); notifyUpdateChange(downloadId);