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.
This commit is contained in:
Gabriele M
2017-07-15 02:09:13 +02:00
parent 66ca7a79df
commit d30ba00a7b

View File

@@ -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);