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.
This commit is contained in:
Gabriele M
2017-07-04 19:05:04 +02:00
parent fe3d8be858
commit f0940dafca

View File

@@ -295,14 +295,22 @@ public class UpdaterController implements UpdaterControllerInt {
return false; return false;
} }
UpdateDownload update = mDownloads.get(downloadId).mUpdate; UpdateDownload update = mDownloads.get(downloadId).mUpdate;
mDownloads.get(downloadId).mDownloadClient = File file = update.getFile();
DownloadClient.downloadFileResume(update.getDownloadUrl(), if (file.exists() && file.length() == update.getFileSize()) {
update.getFile(), Log.d(TAG, "File already downloaded, starting verification");
getDownloadCallback(downloadId), update.setStatus(UpdateStatus.VERIFYING);
getProgressListener(downloadId)); verifyUpdateAsync(downloadId);
update.setStatus(UpdateStatus.STARTING); notifyUpdateChange(downloadId);
notifyUpdateChange(downloadId); } else {
mWakeLock.acquire(); mDownloads.get(downloadId).mDownloadClient =
DownloadClient.downloadFileResume(update.getDownloadUrl(),
update.getFile(),
getDownloadCallback(downloadId),
getProgressListener(downloadId));
update.setStatus(UpdateStatus.STARTING);
notifyUpdateChange(downloadId);
mWakeLock.acquire();
}
return true; return true;
} }