|
32 | 32 | import java.util.Map;
|
33 | 33 |
|
34 | 34 | public class CodePushNativeModule extends ReactContextBaseJavaModule {
|
| 35 | + private String mBinaryContentsHash = null; |
| 36 | + private String mClientUniqueId = null; |
35 | 37 | private LifecycleEventListener mLifecycleEventListener = null;
|
36 | 38 | private int mMinimumBackgroundDuration = 0;
|
| 39 | + |
37 | 40 | private CodePush mCodePush;
|
38 |
| - private CodePushUpdateManager mUpdateManager; |
39 |
| - private CodePushTelemetryManager mTelemetryManager; |
40 | 41 | private SettingsManager mSettingsManager;
|
| 42 | + private CodePushTelemetryManager mTelemetryManager; |
| 43 | + private CodePushUpdateManager mUpdateManager; |
41 | 44 |
|
42 | 45 | private static final String REACT_APPLICATION_CLASS_NAME = "com.facebook.react.ReactApplication";
|
43 | 46 | private static final String REACT_NATIVE_HOST_CLASS_NAME = "com.facebook.react.ReactNativeHost";
|
44 | 47 |
|
45 | 48 | public CodePushNativeModule(ReactApplicationContext reactContext, CodePush codePush, CodePushUpdateManager codePushUpdateManager, CodePushTelemetryManager codePushTelemetryManager, SettingsManager settingsManager) {
|
46 | 49 | super(reactContext);
|
| 50 | + |
47 | 51 | mCodePush = codePush;
|
48 |
| - mUpdateManager = codePushUpdateManager; |
49 |
| - mTelemetryManager = codePushTelemetryManager; |
50 | 52 | mSettingsManager = settingsManager;
|
| 53 | + mTelemetryManager = codePushTelemetryManager; |
| 54 | + mUpdateManager = codePushUpdateManager; |
| 55 | + |
| 56 | + // Initialize module state while we have a reference to the current context. |
| 57 | + mBinaryContentsHash = CodePushUpdateUtils.getHashForBinaryContents(reactContext, mCodePush.isDebugMode()); |
| 58 | + mClientUniqueId = Settings.Secure.getString(reactContext.getContentResolver(), Settings.Secure.ANDROID_ID); |
51 | 59 | }
|
52 | 60 |
|
53 | 61 | @Override
|
@@ -240,19 +248,15 @@ public void dispatchDownloadProgressEvent() {
|
240 | 248 |
|
241 | 249 | @ReactMethod
|
242 | 250 | public void getConfiguration(Promise promise) {
|
243 |
| - Activity currentActivity = getCurrentActivity(); |
244 | 251 | WritableNativeMap configMap = new WritableNativeMap();
|
245 | 252 | configMap.putString("appVersion", mCodePush.getAppVersion());
|
| 253 | + configMap.putString("clientUniqueId", mClientUniqueId); |
246 | 254 | configMap.putString("deploymentKey", mCodePush.getDeploymentKey());
|
247 | 255 | 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); |
| 256 | + |
| 257 | + // The binary hash may be null in debug builds |
| 258 | + if (mBinaryContentsHash != null) { |
| 259 | + configMap.putString(CodePushConstants.PACKAGE_HASH_KEY, mBinaryContentsHash); |
256 | 260 | }
|
257 | 261 |
|
258 | 262 | promise.resolve(configMap);
|
|
0 commit comments