From 8ad33ebc2dd454a31bb9e9789b9e0c9c1b330cce Mon Sep 17 00:00:00 2001 From: Jonathan Carter Date: Tue, 5 Jul 2016 17:50:39 -0700 Subject: [PATCH] Guarding against NPEs --- .../codepush/react/CodePushNativeModule.java | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java b/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java index 1e733a9..1079987 100644 --- a/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java +++ b/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java @@ -80,6 +80,8 @@ public class CodePushNativeModule extends ReactContextBaseJavaModule { } private void loadBundleLegacy(final Activity currentActivity) { + CodePushUtils.log("Legacy restart logic being used"); + mCodePush.invalidateCurrentInstance(); currentActivity.runOnUiThread(new Runnable() { @@ -240,19 +242,23 @@ public class CodePushNativeModule extends ReactContextBaseJavaModule { @ReactMethod public void getConfiguration(Promise promise) { - Activity currentActivity = getCurrentActivity(); WritableNativeMap configMap = new WritableNativeMap(); configMap.putString("appVersion", mCodePush.getAppVersion()); configMap.putString("deploymentKey", mCodePush.getDeploymentKey()); configMap.putString("serverUrl", mCodePush.getServerUrl()); - configMap.putString("clientUniqueId", - Settings.Secure.getString(currentActivity.getContentResolver(), - android.provider.Settings.Secure.ANDROID_ID)); - String binaryHash = CodePushUpdateUtils.getHashForBinaryContents(currentActivity, mCodePush.isDebugMode()); - if (binaryHash != null) { - // binaryHash will be null if the React Native assets were not bundled into the APK - // (e.g. in Debug builds) - configMap.putString(CodePushConstants.PACKAGE_HASH_KEY, binaryHash); + + Activity currentActivity = getCurrentActivity(); + if (currentActivity != null) { + configMap.putString("clientUniqueId", + Settings.Secure.getString(currentActivity.getContentResolver(), + android.provider.Settings.Secure.ANDROID_ID)); + + String binaryHash = CodePushUpdateUtils.getHashForBinaryContents(currentActivity, mCodePush.isDebugMode()); + if (binaryHash != null) { + // binaryHash will be null if the React Native assets were not bundled into the APK + // (e.g. in Debug builds) + configMap.putString(CodePushConstants.PACKAGE_HASH_KEY, binaryHash); + } } promise.resolve(configMap);