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

Commit d26188f

Browse files
committed
Pre-computing binary hash
1 parent 71eea17 commit d26188f

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.Map;
3333

3434
public class CodePushNativeModule extends ReactContextBaseJavaModule {
35+
private String mBinaryContentsHash = null;
3536
private String mClientUniqueId = null;
3637
private LifecycleEventListener mLifecycleEventListener = null;
3738
private int mMinimumBackgroundDuration = 0;
@@ -52,6 +53,8 @@ public CodePushNativeModule(ReactApplicationContext reactContext, CodePush codeP
5253
mTelemetryManager = codePushTelemetryManager;
5354
mUpdateManager = codePushUpdateManager;
5455

56+
// Initialize module state while we have a reference to the current context.
57+
mBinaryContentsHash = CodePushUpdateUtils.getHashForBinaryContents(reactContext, mCodePush.isDebugMode());
5558
mClientUniqueId = Settings.Secure.getString(reactContext.getContentResolver(), Settings.Secure.ANDROID_ID);
5659
}
5760

@@ -251,14 +254,9 @@ public void getConfiguration(Promise promise) {
251254
configMap.putString("deploymentKey", mCodePush.getDeploymentKey());
252255
configMap.putString("serverUrl", mCodePush.getServerUrl());
253256

254-
Activity currentActivity = getCurrentActivity();
255-
if (currentActivity != null) {
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-
}
257+
// The binary hash may be null in debug builds
258+
if (mBinaryContentsHash != null) {
259+
configMap.putString(CodePushConstants.PACKAGE_HASH_KEY, mBinaryContentsHash);
262260
}
263261

264262
promise.resolve(configMap);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.microsoft.codepush.react;
22

3-
import android.app.Activity;
3+
import android.content.Context;
44

55
import com.facebook.react.bridge.ReadableArray;
66
import com.facebook.react.bridge.WritableMap;
@@ -98,9 +98,9 @@ public static String findJSBundleInUpdateContents(String folderPath, String expe
9898
return null;
9999
}
100100

101-
public static String getHashForBinaryContents(Activity mainActivity, boolean isDebugMode) {
101+
public static String getHashForBinaryContents(Context context, boolean isDebugMode) {
102102
try {
103-
return CodePushUtils.getStringFromInputStream(mainActivity.getAssets().open(CodePushConstants.CODE_PUSH_HASH_FILE_NAME));
103+
return CodePushUtils.getStringFromInputStream(context.getAssets().open(CodePushConstants.CODE_PUSH_HASH_FILE_NAME));
104104
} catch (IOException e) {
105105
if (!isDebugMode) {
106106
// Only print this message in "Release" mode. In "Debug", we may not have the
@@ -128,4 +128,4 @@ public static void verifyHashForDiffUpdate(String folderPath, String expectedHas
128128
throw new CodePushInvalidUpdateException("The update contents failed the data integrity check.");
129129
}
130130
}
131-
}
131+
}

0 commit comments

Comments
 (0)