From 8fe119bdf42212afda3d14762c54125f9bc4c8c2 Mon Sep 17 00:00:00 2001 From: Stanislav Baranov Date: Wed, 9 Jan 2019 13:57:57 -0800 Subject: [PATCH] simplify patch rollback --- .../io/flutter/view/ResourceUpdater.java | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/shell/platform/android/io/flutter/view/ResourceUpdater.java b/shell/platform/android/io/flutter/view/ResourceUpdater.java index b6a0c39025451..8690fbdb6c8f3 100644 --- a/shell/platform/android/io/flutter/view/ResourceUpdater.java +++ b/shell/platform/android/io/flutter/view/ResourceUpdater.java @@ -104,26 +104,23 @@ protected Void doInBackground(String... unused) { connection.setIfModifiedSince(lastDownloadTime); } - try (InputStream input = connection.getInputStream()) { - URL resolvedURL = connection.getURL(); - Log.i(TAG, "Resolved update URL " + resolvedURL); - - if (connection.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { - if (resolvedURL.equals(unresolvedURL)) { - Log.i(TAG, "Rolled back all updates"); - localFile.delete(); - return null; - } else { - Log.i(TAG, "Latest update not found"); - return null; - } - } + URL resolvedURL = connection.getURL(); + Log.i(TAG, "Resolved update URL " + resolvedURL); - if (connection.getResponseCode() == HttpURLConnection.HTTP_NOT_MODIFIED) { - Log.i(TAG, "Already have latest update"); - return null; - } + int responseCode = connection.getResponseCode(); + Log.i(TAG, "HTTP response code " + responseCode); + + if (responseCode == HttpURLConnection.HTTP_NOT_FOUND) { + Log.i(TAG, "Latest update not found"); + return null; + } + + if (responseCode == HttpURLConnection.HTTP_NOT_MODIFIED) { + Log.i(TAG, "Already have latest update"); + return null; + } + try (InputStream input = connection.getInputStream()) { Log.i(TAG, "Downloading update " + unresolvedURL); try (OutputStream output = new FileOutputStream(localFile)) { int count;