@@ -353,9 +353,15 @@ public CodePushNativeModule(ReactApplicationContext reactContext) {
353
353
@ Override
354
354
public Map <String , Object > getConstants () {
355
355
final Map <String , Object > constants = new HashMap <>();
356
+
356
357
constants .put ("codePushInstallModeImmediate" , CodePushInstallMode .IMMEDIATE .getValue ());
357
358
constants .put ("codePushInstallModeOnNextRestart" , CodePushInstallMode .ON_NEXT_RESTART .getValue ());
358
359
constants .put ("codePushInstallModeOnNextResume" , CodePushInstallMode .ON_NEXT_RESUME .getValue ());
360
+
361
+ constants .put ("codePushUpdateStateRunning" , CodePushUpdateState .RUNNING .getValue ());
362
+ constants .put ("codePushUpdateStatePending" , CodePushUpdateState .PENDING .getValue ());
363
+ constants .put ("codePushUpdateStateLatest" , CodePushUpdateState .LATEST .getValue ());
364
+
359
365
return constants ;
360
366
}
361
367
@@ -481,31 +487,53 @@ public void getConfiguration(Promise promise) {
481
487
482
488
promise .resolve (configMap );
483
489
}
484
-
490
+
485
491
@ ReactMethod
486
- public void getCurrentPackage ( final Promise promise ) {
492
+ public void getUpdateMetadata ( final int updateState , final Promise promise ) {
487
493
AsyncTask <Void , Void , Void > asyncTask = new AsyncTask <Void , Void , Void >() {
488
494
@ Override
489
495
protected Void doInBackground (Void ... params ) {
490
496
WritableMap currentPackage = codePushPackage .getCurrentPackage ();
497
+
491
498
if (currentPackage == null ) {
492
499
promise .resolve ("" );
493
500
return null ;
494
501
}
495
502
496
- if (isRunningBinaryVersion ) {
497
- currentPackage .putBoolean ("_isDebugOnly" , true );
498
- }
499
-
500
- Boolean isPendingUpdate = false ;
503
+ Boolean currentUpdateIsPending = false ;
501
504
502
505
if (currentPackage .hasKey (PACKAGE_HASH_KEY )) {
503
506
String currentHash = currentPackage .getString (PACKAGE_HASH_KEY );
504
- isPendingUpdate = CodePush .this .isPendingUpdate (currentHash );
507
+ currentUpdateIsPending = CodePush .this .isPendingUpdate (currentHash );
505
508
}
509
+
510
+ if (updateState == CodePushUpdateState .PENDING .getValue () && !currentUpdateIsPending ) {
511
+ // The caller wanted a pending update
512
+ // but there isn't currently one.
513
+ promise .resolve ("" );
514
+ } else if (updateState == CodePushUpdateState .RUNNING .getValue () && currentUpdateIsPending ) {
515
+ // The caller wants the running update, but the current
516
+ // one is pending, so we need to grab the previous.
517
+ promise .resolve (codePushPackage .getPreviousPackage ());
518
+ } else {
519
+ // The current package satisfies the request:
520
+ // 1) Caller wanted a pending, and there is a pending update
521
+ // 2) Caller wanted the running update, and there isn't a pending
522
+ // 3) Calers wants the latest update, regardless if it's pending or not
523
+
524
+ if (isRunningBinaryVersion ) {
525
+ // This only matters in Debug builds. Since we do not clear "outdated" updates,
526
+ // we need to indicate to the JS side that somehow we have a current update on
527
+ // disk that is not actually running.
528
+ currentPackage .putBoolean ("_isDebugOnly" , true );
529
+ }
506
530
507
- currentPackage .putBoolean ("isPending" , isPendingUpdate );
508
- promise .resolve (currentPackage );
531
+ // To support differentiating pending vs. non-pending updates
532
+ // when request an update state of LATEST, provide an isPending flag
533
+ currentPackage .putBoolean ("isPending" , currentUpdateIsPending );
534
+ promise .resolve (currentPackage );
535
+ }
536
+
509
537
return null ;
510
538
}
511
539
};
0 commit comments