From fe3d8be858b0dd03fa7cd083d1a9d95862844d62 Mon Sep 17 00:00:00 2001 From: Gabriele M Date: Tue, 4 Jul 2017 19:05:04 +0200 Subject: [PATCH] Download file only if the server replies with success code --- src/org/lineageos/updater/DownloadClient.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/org/lineageos/updater/DownloadClient.java b/src/org/lineageos/updater/DownloadClient.java index bad5e158..277d7c5c 100644 --- a/src/org/lineageos/updater/DownloadClient.java +++ b/src/org/lineageos/updater/DownloadClient.java @@ -154,6 +154,10 @@ public class DownloadClient { downloadFileInternalCommon(request, destination, callback, progressListener); } + private boolean isSuccessful(int statusCode) { + return (statusCode / 100) == 2; + } + private void downloadFileInternalCommon(final Request request, final File destination, final DownloadCallback callback, final ProgressListener progressListener) { @@ -185,6 +189,10 @@ public class DownloadClient { if (resume) { mResumeOffset = destination.length(); Log.d(TAG, "The server fulfilled the partial content request"); + } else if (!isSuccessful(response.code())) { + Log.e(TAG, "The server replied with code " + response.code()); + callback.onFailure(); + return; } callback.onResponse(response.code(), response.request().urlString(),