32
32
import java .util .Map ;
33
33
34
34
public class CodePushNativeModule extends ReactContextBaseJavaModule {
35
+ private String mBinaryContentsHash = null ;
35
36
private String mClientUniqueId = null ;
36
37
private LifecycleEventListener mLifecycleEventListener = null ;
37
38
private int mMinimumBackgroundDuration = 0 ;
@@ -52,6 +53,8 @@ public CodePushNativeModule(ReactApplicationContext reactContext, CodePush codeP
52
53
mTelemetryManager = codePushTelemetryManager ;
53
54
mUpdateManager = codePushUpdateManager ;
54
55
56
+ // Initialize module state while we have a reference to the current context.
57
+ mBinaryContentsHash = CodePushUpdateUtils .getHashForBinaryContents (reactContext , mCodePush .isDebugMode ());
55
58
mClientUniqueId = Settings .Secure .getString (reactContext .getContentResolver (), Settings .Secure .ANDROID_ID );
56
59
}
57
60
@@ -251,14 +254,9 @@ public void getConfiguration(Promise promise) {
251
254
configMap .putString ("deploymentKey" , mCodePush .getDeploymentKey ());
252
255
configMap .putString ("serverUrl" , mCodePush .getServerUrl ());
253
256
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 );
262
260
}
263
261
264
262
promise .resolve (configMap );
0 commit comments