Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 8ad33eb

Browse files
committed
Guarding against NPEs
1 parent c4db3d8 commit 8ad33eb

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ private boolean isReactApplication(Context context) {
8080
}
8181

8282
private void loadBundleLegacy(final Activity currentActivity) {
83+
CodePushUtils.log("Legacy restart logic being used");
84+
8385
mCodePush.invalidateCurrentInstance();
8486

8587
currentActivity.runOnUiThread(new Runnable() {
@@ -240,19 +242,23 @@ public void dispatchDownloadProgressEvent() {
240242

241243
@ReactMethod
242244
public void getConfiguration(Promise promise) {
243-
Activity currentActivity = getCurrentActivity();
244245
WritableNativeMap configMap = new WritableNativeMap();
245246
configMap.putString("appVersion", mCodePush.getAppVersion());
246247
configMap.putString("deploymentKey", mCodePush.getDeploymentKey());
247248
configMap.putString("serverUrl", mCodePush.getServerUrl());
248-
configMap.putString("clientUniqueId",
249-
Settings.Secure.getString(currentActivity.getContentResolver(),
250-
android.provider.Settings.Secure.ANDROID_ID));
251-
String binaryHash = CodePushUpdateUtils.getHashForBinaryContents(currentActivity, mCodePush.isDebugMode());
252-
if (binaryHash != null) {
253-
// binaryHash will be null if the React Native assets were not bundled into the APK
254-
// (e.g. in Debug builds)
255-
configMap.putString(CodePushConstants.PACKAGE_HASH_KEY, binaryHash);
249+
250+
Activity currentActivity = getCurrentActivity();
251+
if (currentActivity != null) {
252+
configMap.putString("clientUniqueId",
253+
Settings.Secure.getString(currentActivity.getContentResolver(),
254+
android.provider.Settings.Secure.ANDROID_ID));
255+
256+
String binaryHash = CodePushUpdateUtils.getHashForBinaryContents(currentActivity, mCodePush.isDebugMode());
257+
if (binaryHash != null) {
258+
// binaryHash will be null if the React Native assets were not bundled into the APK
259+
// (e.g. in Debug builds)
260+
configMap.putString(CodePushConstants.PACKAGE_HASH_KEY, binaryHash);
261+
}
256262
}
257263

258264
promise.resolve(configMap);

0 commit comments

Comments
 (0)