4646import java .util .UUID ;
4747
4848@ OptIn (markerClass = UnstableReactNativeAPI .class )
49- public class CodePushNativeModule extends BaseJavaModule {
49+ public class CodePushNativeModule extends CodePushNativeModuleSpec {
5050 private String mBinaryContentsHash = null ;
5151 private String mClientUniqueId = null ;
5252 private LifecycleEventListener mLifecycleEventListener = null ;
@@ -82,6 +82,11 @@ public CodePushNativeModule(ReactApplicationContext reactContext, CodePush codeP
8282
8383 @ Override
8484 public Map <String , Object > getConstants () {
85+ return getTypedExportedConstants ();
86+ }
87+
88+ @ Override
89+ public Map <String , Object > getTypedExportedConstants () {
8590 final Map <String , Object > constants = new HashMap <>();
8691
8792 constants .put ("codePushInstallModeImmediate" , CodePushInstallMode .IMMEDIATE .getValue ());
@@ -500,8 +505,9 @@ public void getConfiguration(Promise promise) {
500505 }
501506 }
502507
508+ @ Override
503509 @ ReactMethod
504- public void getUpdateMetadata (final int updateState , final Promise promise ) {
510+ public void getUpdateMetadata (final double updateState , final Promise promise ) {
505511 AsyncTask <Void , Void , Void > asyncTask = new AsyncTask <Void , Void , Void >() {
506512 @ Override
507513 protected Void doInBackground (Void ... params ) {
@@ -520,11 +526,11 @@ protected Void doInBackground(Void... params) {
520526 currentUpdateIsPending = mSettingsManager .isPendingUpdate (currentHash );
521527 }
522528
523- if (updateState == CodePushUpdateState .PENDING .getValue () && !currentUpdateIsPending ) {
529+ if (( int ) updateState == CodePushUpdateState .PENDING .getValue () && !currentUpdateIsPending ) {
524530 // The caller wanted a pending update
525531 // but there isn't currently one.
526532 promise .resolve (null );
527- } else if (updateState == CodePushUpdateState .RUNNING .getValue () && currentUpdateIsPending ) {
533+ } else if (( int ) updateState == CodePushUpdateState .RUNNING .getValue () && currentUpdateIsPending ) {
528534 // The caller wants the running update, but the current
529535 // one is pending, so we need to grab the previous.
530536 JSONObject previousPackage = mUpdateManager .getPreviousPackage ();
@@ -625,8 +631,9 @@ protected Void doInBackground(Void... params) {
625631 asyncTask .executeOnExecutor (AsyncTask .THREAD_POOL_EXECUTOR );
626632 }
627633
634+ @ Override
628635 @ ReactMethod
629- public void installUpdate (final ReadableMap updatePackage , final int installMode , final int minimumBackgroundDuration , final Promise promise ) {
636+ public void installUpdate (final ReadableMap updatePackage , final double installMode , final double minimumBackgroundDuration , final Promise promise ) {
630637 AsyncTask <Void , Void , Void > asyncTask = new AsyncTask <Void , Void , Void >() {
631638 @ Override
632639 protected Void doInBackground (Void ... params ) {
@@ -640,17 +647,17 @@ protected Void doInBackground(Void... params) {
640647 mSettingsManager .savePendingUpdate (pendingHash , /* isLoading */ false );
641648 }
642649
643- if (installMode == CodePushInstallMode .ON_NEXT_RESUME .getValue () ||
650+ if (( int ) installMode == CodePushInstallMode .ON_NEXT_RESUME .getValue () ||
644651 // We also add the resume listener if the installMode is IMMEDIATE, because
645652 // if the current activity is backgrounded, we want to reload the bundle when
646653 // it comes back into the foreground.
647- installMode == CodePushInstallMode .IMMEDIATE .getValue () ||
648- installMode == CodePushInstallMode .ON_NEXT_SUSPEND .getValue ()) {
654+ ( int ) installMode == CodePushInstallMode .IMMEDIATE .getValue () ||
655+ ( int ) installMode == CodePushInstallMode .ON_NEXT_SUSPEND .getValue ()) {
649656
650657 // Store the minimum duration on the native module as an instance
651658 // variable instead of relying on a closure below, so that any
652659 // subsequent resume-based installs could override it.
653- CodePushNativeModule .this .mMinimumBackgroundDuration = minimumBackgroundDuration ;
660+ CodePushNativeModule .this .mMinimumBackgroundDuration = ( int ) minimumBackgroundDuration ;
654661
655662 if (mLifecycleEventListener == null ) {
656663 // Ensure we do not add the listener twice.
@@ -672,7 +679,7 @@ public void onHostResume() {
672679 // the foreground, so explicitly wait for it to be backgrounded first
673680 if (lastPausedDate != null ) {
674681 long durationInBackground = (new Date ().getTime () - lastPausedDate .getTime ()) / 1000 ;
675- if (installMode == CodePushInstallMode .IMMEDIATE .getValue ()
682+ if (( int ) installMode == CodePushInstallMode .IMMEDIATE .getValue ()
676683 || durationInBackground >= CodePushNativeModule .this .mMinimumBackgroundDuration ) {
677684 CodePushUtils .log ("Loading bundle on resume" );
678685 restartAppInternal (false );
@@ -686,8 +693,8 @@ public void onHostPause() {
686693 // resumed, we can detect how long it was in the background.
687694 lastPausedDate = new Date ();
688695
689- if (installMode == CodePushInstallMode .ON_NEXT_SUSPEND .getValue () && mSettingsManager .isPendingUpdate (null )) {
690- appSuspendHandler .postDelayed (loadBundleRunnable , minimumBackgroundDuration * 1000 );
696+ if (( int ) installMode == CodePushInstallMode .ON_NEXT_SUSPEND .getValue () && mSettingsManager .isPendingUpdate (null )) {
697+ appSuspendHandler .postDelayed (loadBundleRunnable , ( int ) minimumBackgroundDuration * 1000 );
691698 }
692699 }
693700
@@ -700,7 +707,11 @@ public void onHostDestroy() {
700707 }
701708 }
702709
703- promise .resolve ("" );
710+ if ((int )installMode == CodePushInstallMode .IMMEDIATE .getValue ()) {
711+ loadBundle ();
712+ }
713+
714+ promise .resolve (null );
704715 } catch (CodePushUnknownException e ) {
705716 CodePushUtils .log (e );
706717 promise .reject (e );
@@ -822,13 +833,15 @@ public void clearUpdates() {
822833 mCodePush .clearUpdates ();
823834 }
824835
836+ @ Override
825837 @ ReactMethod
826838 public void addListener (String eventName ) {
827839 // Set up any upstream listeners or background tasks as necessary
828840 }
829841
842+ @ Override
830843 @ ReactMethod
831- public void removeListeners (Integer count ) {
844+ public void removeListeners (double count ) {
832845 // Remove upstream listeners, stop unnecessary background tasks
833846 }
834847
0 commit comments