From e82ebbd3c5dc5744e796a5049bdd962715571c6f Mon Sep 17 00:00:00 2001 From: Stanislav Baranov Date: Wed, 9 Jan 2019 17:29:04 -0800 Subject: [PATCH] Simplify rollback of dynamic patches (flutter/engine#7432) --- .../io/flutter/view/ResourceUpdater.java | 35 +++++++++---------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/engine/src/flutter/shell/platform/android/io/flutter/view/ResourceUpdater.java b/engine/src/flutter/shell/platform/android/io/flutter/view/ResourceUpdater.java index b6a0c39025..8690fbdb6c 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/view/ResourceUpdater.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/view/ResourceUpdater.java @@ -104,26 +104,23 @@ public final class ResourceUpdater { connection.setIfModifiedSince(lastDownloadTime); } + URL resolvedURL = connection.getURL(); + Log.i(TAG, "Resolved update URL " + resolvedURL); + + 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()) { - 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; - } - } - - if (connection.getResponseCode() == HttpURLConnection.HTTP_NOT_MODIFIED) { - Log.i(TAG, "Already have latest update"); - return null; - } - Log.i(TAG, "Downloading update " + unresolvedURL); try (OutputStream output = new FileOutputStream(localFile)) { int count;