@@ -107,10 +107,10 @@ public CodePush(String deploymentKey, Activity mainActivity, boolean isDebugMode
107
107
}
108
108
109
109
currentInstance = this ;
110
-
110
+
111
111
clearDebugCacheIfNeeded ();
112
112
}
113
-
113
+
114
114
private void clearDebugCacheIfNeeded () {
115
115
if (isDebugMode && isPendingUpdate (null )) {
116
116
// This needs to be kept in sync with https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManager.java#L78
@@ -120,7 +120,7 @@ private void clearDebugCacheIfNeeded() {
120
120
}
121
121
}
122
122
}
123
-
123
+
124
124
private long getBinaryResourcesModifiedTime () {
125
125
ZipFile applicationFile = null ;
126
126
try {
@@ -144,15 +144,15 @@ private long getBinaryResourcesModifiedTime() {
144
144
public static String getBundleUrl () {
145
145
return getBundleUrl (DEFAULT_JS_BUNDLE_NAME );
146
146
}
147
-
147
+
148
148
public static String getBundleUrl (String assetsBundleFileName ) {
149
149
if (currentInstance == null ) {
150
150
throw new CodePushNotInitializedException ("A CodePush instance has not been created yet. Have you added it to your app's list of ReactPackages?" );
151
151
}
152
152
153
153
return currentInstance .getBundleUrlInternal (assetsBundleFileName );
154
154
}
155
-
155
+
156
156
public String getBundleUrlInternal (String assetsBundleFileName ) {
157
157
this .assetsBundleFileName = assetsBundleFileName ;
158
158
String binaryJsBundleUrl = ASSETS_BUNDLE_PREFIX + assetsBundleFileName ;
@@ -230,7 +230,7 @@ private JSONObject getPendingUpdate() {
230
230
return null ;
231
231
}
232
232
}
233
-
233
+
234
234
private void initializeUpdateAfterRestart () {
235
235
JSONObject pendingUpdate = getPendingUpdate ();
236
236
if (pendingUpdate != null ) {
@@ -277,7 +277,7 @@ private boolean isFailedHash(String packageHash) {
277
277
278
278
private boolean isPendingUpdate (String packageHash ) {
279
279
JSONObject pendingUpdate = getPendingUpdate ();
280
-
280
+
281
281
try {
282
282
return pendingUpdate != null &&
283
283
!pendingUpdate .getBoolean (PENDING_UPDATE_IS_LOADING_KEY ) &&
@@ -297,7 +297,7 @@ private void removePendingUpdate() {
297
297
SharedPreferences settings = applicationContext .getSharedPreferences (CODE_PUSH_PREFERENCES , 0 );
298
298
settings .edit ().remove (PENDING_UPDATE_KEY ).commit ();
299
299
}
300
-
300
+
301
301
private void rollbackPackage () {
302
302
WritableMap failedPackage = codePushPackage .getCurrentPackage ();
303
303
saveFailedUpdate (failedPackage );
@@ -357,47 +357,47 @@ public void clearUpdates() {
357
357
private class CodePushNativeModule extends ReactContextBaseJavaModule {
358
358
private LifecycleEventListener lifecycleEventListener = null ;
359
359
private int minimumBackgroundDuration = 0 ;
360
-
360
+
361
361
public CodePushNativeModule (ReactApplicationContext reactContext ) {
362
362
super (reactContext );
363
363
}
364
-
364
+
365
365
@ Override
366
366
public Map <String , Object > getConstants () {
367
367
final Map <String , Object > constants = new HashMap <>();
368
-
368
+
369
369
constants .put ("codePushInstallModeImmediate" , CodePushInstallMode .IMMEDIATE .getValue ());
370
370
constants .put ("codePushInstallModeOnNextRestart" , CodePushInstallMode .ON_NEXT_RESTART .getValue ());
371
371
constants .put ("codePushInstallModeOnNextResume" , CodePushInstallMode .ON_NEXT_RESUME .getValue ());
372
-
372
+
373
373
constants .put ("codePushUpdateStateRunning" , CodePushUpdateState .RUNNING .getValue ());
374
374
constants .put ("codePushUpdateStatePending" , CodePushUpdateState .PENDING .getValue ());
375
375
constants .put ("codePushUpdateStateLatest" , CodePushUpdateState .LATEST .getValue ());
376
-
376
+
377
377
return constants ;
378
378
}
379
379
380
380
@ Override
381
381
public String getName () {
382
382
return "CodePush" ;
383
383
}
384
-
384
+
385
385
@ Override
386
386
public void initialize () {
387
387
CodePush .this .initializeUpdateAfterRestart ();
388
388
}
389
-
389
+
390
390
private void loadBundleLegacy () {
391
391
Intent intent = mainActivity .getIntent ();
392
392
mainActivity .finish ();
393
393
mainActivity .startActivity (intent );
394
-
394
+
395
395
currentInstance = null ;
396
396
}
397
-
397
+
398
398
private void loadBundle () {
399
399
CodePush .this .clearDebugCacheIfNeeded ();
400
-
400
+
401
401
try {
402
402
// #1) Get the private ReactInstanceManager, which is what includes
403
403
// the logic to reload the current React context.
@@ -410,7 +410,7 @@ private void loadBundle() {
410
410
Field jsBundleField = instanceManager .getClass ().getDeclaredField ("mJSBundleFile" );
411
411
jsBundleField .setAccessible (true );
412
412
jsBundleField .set (instanceManager , latestJSBundleFile );
413
-
413
+
414
414
// #3) Get the context creation method and fire it on the UI thread (which RN enforces)
415
415
final Method recreateMethod = instanceManager .getClass ().getMethod ("recreateReactContextInBackground" );
416
416
mainActivity .runOnUiThread (new Runnable () {
@@ -488,14 +488,14 @@ public void getConfiguration(Promise promise) {
488
488
489
489
promise .resolve (configMap );
490
490
}
491
-
491
+
492
492
@ ReactMethod
493
493
public void getUpdateMetadata (final int updateState , final Promise promise ) {
494
494
AsyncTask <Void , Void , Void > asyncTask = new AsyncTask <Void , Void , Void >() {
495
495
@ Override
496
496
protected Void doInBackground (Void ... params ) {
497
497
WritableMap currentPackage = codePushPackage .getCurrentPackage ();
498
-
498
+
499
499
if (currentPackage == null ) {
500
500
promise .resolve ("" );
501
501
return null ;
@@ -507,7 +507,7 @@ protected Void doInBackground(Void... params) {
507
507
String currentHash = currentPackage .getString (PACKAGE_HASH_KEY );
508
508
currentUpdateIsPending = CodePush .this .isPendingUpdate (currentHash );
509
509
}
510
-
510
+
511
511
if (updateState == CodePushUpdateState .PENDING .getValue () && !currentUpdateIsPending ) {
512
512
// The caller wanted a pending update
513
513
// but there isn't currently one.
@@ -532,7 +532,7 @@ protected Void doInBackground(Void... params) {
532
532
currentPackage .putBoolean ("isPending" , currentUpdateIsPending );
533
533
promise .resolve (currentPackage );
534
534
}
535
-
535
+
536
536
return null ;
537
537
}
538
538
};
@@ -615,7 +615,11 @@ protected Void doInBackground(Void... params) {
615
615
public void onHostResume () {
616
616
// Determine how long the app was in the background and ensure
617
617
// that it meets the minimum duration amount of time.
618
- long durationInBackground = (new Date ().getTime () - lastPausedDate .getTime ()) / 1000 ;
618
+ long durationInBackground = 0 ;
619
+ if (lastPausedDate != null ) {
620
+ durationInBackground = (new Date ().getTime () - lastPausedDate .getTime ()) / 1000 ;
621
+ }
622
+
619
623
if (durationInBackground >= CodePushNativeModule .this .minimumBackgroundDuration ) {
620
624
loadBundle ();
621
625
}
@@ -645,7 +649,7 @@ public void onHostDestroy() {
645
649
646
650
asyncTask .execute ();
647
651
}
648
-
652
+
649
653
@ ReactMethod
650
654
public void isFailedUpdate (String packageHash , Promise promise ) {
651
655
promise .resolve (isFailedHash (packageHash ));
@@ -665,7 +669,7 @@ public void notifyApplicationReady(Promise promise) {
665
669
removePendingUpdate ();
666
670
promise .resolve ("" );
667
671
}
668
-
672
+
669
673
@ ReactMethod
670
674
public void restartApp (boolean onlyIfUpdateIsPending ) {
671
675
// If this is an unconditional restart request, or there
0 commit comments