@@ -265,52 +265,61 @@ private void loadBundle() {
265265 }
266266
267267 @ ReactMethod
268- public void installUpdate (ReadableMap updatePackage , int rollbackTimeout , int installMode , Promise promise ) {
269- try {
270- codePushPackage .installPackage (updatePackage );
271-
272- String pendingHash = CodePushUtils .tryGetString (updatePackage , codePushPackage .PACKAGE_HASH_KEY );
273- if (pendingHash == null ) {
274- throw new CodePushUnknownException ("Update package to be installed has no hash." );
275- } else {
276- savePendingUpdate (pendingHash , rollbackTimeout );
277- }
278-
279- if (installMode == CodePushInstallMode .IMMEDIATE .getValue ()) {
280- loadBundle ();
281- } else if (installMode == CodePushInstallMode .ON_NEXT_RESUME .getValue ()) {
282- // Ensure we do not add the listener twice.
283- if (lifecycleEventListener == null ) {
284- lifecycleEventListener = new LifecycleEventListener () {
285- @ Override
286- public void onHostResume () {
287- loadBundle ();
288- }
289-
290- @ Override
291- public void onHostPause () {
268+ public void installUpdate (final ReadableMap updatePackage , final int rollbackTimeout , final int installMode , final Promise promise ) {
269+ AsyncTask asyncTask = new AsyncTask () {
270+ @ Override
271+ protected Void doInBackground (Object [] params ) {
272+ try {
273+ codePushPackage .installPackage (updatePackage );
274+
275+ String pendingHash = CodePushUtils .tryGetString (updatePackage , codePushPackage .PACKAGE_HASH_KEY );
276+ if (pendingHash == null ) {
277+ throw new CodePushUnknownException ("Update package to be installed has no hash." );
278+ } else {
279+ savePendingUpdate (pendingHash , rollbackTimeout );
280+ }
281+
282+ if (installMode == CodePushInstallMode .IMMEDIATE .getValue ()) {
283+ loadBundle ();
284+ } else if (installMode == CodePushInstallMode .ON_NEXT_RESUME .getValue ()) {
285+ // Ensure we do not add the listener twice.
286+ if (lifecycleEventListener == null ) {
287+ lifecycleEventListener = new LifecycleEventListener () {
288+ @ Override
289+ public void onHostResume () {
290+ loadBundle ();
291+ }
292+
293+ @ Override
294+ public void onHostPause () {
295+ }
296+
297+ @ Override
298+ public void onHostDestroy () {
299+ }
300+ };
301+ getReactApplicationContext ().addLifecycleEventListener (lifecycleEventListener );
292302 }
303+ }
293304
294- @ Override
295- public void onHostDestroy () {
296- }
297- };
298- getReactApplicationContext ().addLifecycleEventListener (lifecycleEventListener );
305+ promise .resolve ("" );
306+ } catch (IOException e ) {
307+ e .printStackTrace ();
308+ promise .reject (e .getMessage ());
299309 }
310+
311+ return null ;
300312 }
313+ };
301314
302- promise .resolve ("" );
303- } catch (IOException e ) {
304- e .printStackTrace ();
305- promise .reject (e .getMessage ());
306- }
315+ asyncTask .execute ();
307316 }
308317
309318 @ ReactMethod
310319 public void downloadUpdate (final ReadableMap updatePackage , final Promise promise ) {
311320 AsyncTask asyncTask = new AsyncTask () {
312321 @ Override
313- protected Object doInBackground (Object [] params ) {
322+ protected Void doInBackground (Object [] params ) {
314323 try {
315324 codePushPackage .downloadPackage (applicationContext , updatePackage , new DownloadProgressCallback () {
316325 @ Override
@@ -327,9 +336,11 @@ public void call(DownloadProgress downloadProgress) {
327336 e .printStackTrace ();
328337 promise .reject (e .getMessage ());
329338 }
339+
330340 return null ;
331341 }
332342 };
343+
333344 asyncTask .execute ();
334345 }
335346
@@ -344,13 +355,22 @@ public void getConfiguration(Promise promise) {
344355 }
345356
346357 @ ReactMethod
347- public void getCurrentPackage (Promise promise ) {
348- try {
349- promise .resolve (codePushPackage .getCurrentPackage ());
350- } catch (IOException e ) {
351- e .printStackTrace ();
352- promise .reject (e .getMessage ());
353- }
358+ public void getCurrentPackage (final Promise promise ) {
359+ AsyncTask asyncTask = new AsyncTask () {
360+ @ Override
361+ protected Void doInBackground (Object [] params ) {
362+ try {
363+ promise .resolve (codePushPackage .getCurrentPackage ());
364+ } catch (IOException e ) {
365+ e .printStackTrace ();
366+ promise .reject (e .getMessage ());
367+ }
368+
369+ return null ;
370+ }
371+ };
372+
373+ asyncTask .execute ();
354374 }
355375
356376 @ ReactMethod
0 commit comments