From 57390ef0203c30339d9b0728018d712ba92fd3c1 Mon Sep 17 00:00:00 2001 From: Jonathan Carter Date: Sun, 27 Dec 2015 00:25:28 -0800 Subject: [PATCH] Android implementation --- README.md | 2 +- .../java/com/microsoft/codepush/react/CodePush.java | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c4639d9..6fb997c 100644 --- a/README.md +++ b/README.md @@ -339,7 +339,7 @@ If you are using the `sync` function, and doing your update check on app start, codePush.restartApp(onlyIfUpdateIsPending: Boolean = false): void; ``` -Immediately restarts the app. If there is an update pending, it will be presented to the end user and the rollback timer (if specified when installing the update) will begin. Otherwise, calling this method simply has the same behavior as the end user killing and restarting the process. If a truthy value is passed to the `onlyIfUpdateIsPending` parameter, then the app will only be restarted if there is actually a pending update waiting to be applied. Otherwise, this method call will no-op. +Immediately restarts the app. If there is an update pending, it will be presented to the end user and the "rollback protection" feature will ensure it succeeds. Otherwise, calling this method simply has the same behavior as the end user killing and restarting the process. If a truthy value is passed to the `onlyIfUpdateIsPending` parameter, then the app will only be restarted if there is actually a pending update waiting to be applied. Otherwise, this method call will no-op. This method is for advanced scenarios, and is primarily useful when the following conditions are true: diff --git a/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java b/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java index bd9fc21..a9743d8 100644 --- a/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java +++ b/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java @@ -241,7 +241,7 @@ public class CodePush { try { boolean updateIsPending = pendingUpdate != null && pendingUpdate.getBoolean(PENDING_UPDATE_IS_LOADING_KEY) == false && - pendingUpdate.getString(PENDING_UPDATE_HASH_KEY).equals(packageHash); + (packageHash == null || pendingUpdate.getString(PENDING_UPDATE_HASH_KEY).equals(packageHash)); return updateIsPending; } catch (JSONException e) { @@ -483,8 +483,12 @@ public class CodePush { } @ReactMethod - public void restartApp() { - loadBundle(); + public void restartApp(boolean onlyIfUpdateIsPending) { + // If this is an unconditional restart request, or there + // is current pending update, then reload the app. + if (!onlyIfUpdateIsPending || CodePush.this.isPendingUpdate(null)) { + loadBundle(); + } } @ReactMethod