@@ -51,8 +51,6 @@ public class CodePush {
51
51
private final String ASSETS_BUNDLE_PREFIX = "assets://" ;
52
52
private final String BINARY_MODIFIED_TIME_KEY = "binaryModifiedTime" ;
53
53
private final String CODE_PUSH_PREFERENCES = "CodePush" ;
54
- private final String DEPLOYMENT_FAILED_STATUS = "DeploymentFailed" ;
55
- private final String DEPLOYMENT_SUCCEEDED_STATUS = "DeploymentSucceeded" ;
56
54
private final String DOWNLOAD_PROGRESS_EVENT_NAME = "CodePushDownloadProgress" ;
57
55
private final String FAILED_UPDATES_KEY = "CODE_PUSH_FAILED_UPDATES" ;
58
56
private final String PACKAGE_HASH_KEY = "packageHash" ;
@@ -429,85 +427,34 @@ protected Void doInBackground(Object... params) {
429
427
@ ReactMethod
430
428
public void getNewStatusReport (Promise promise ) {
431
429
if (needToReportRollback ) {
432
- // Check if there was a rollback that was not yet reported
433
430
needToReportRollback = false ;
434
431
JSONArray failedUpdates = getFailedUpdates ();
435
432
if (failedUpdates != null && failedUpdates .length () > 0 ) {
436
433
try {
437
434
JSONObject lastFailedPackageJSON = failedUpdates .getJSONObject (failedUpdates .length () - 1 );
438
435
WritableMap lastFailedPackage = CodePushUtils .convertJsonObjectToWriteable (lastFailedPackageJSON );
439
- WritableNativeMap reportMap = new WritableNativeMap ( );
440
- reportMap . putMap ( "package" , lastFailedPackage );
441
- reportMap . putString ( "status" , DEPLOYMENT_FAILED_STATUS );
442
- promise . resolve ( reportMap ) ;
443
- return ;
436
+ WritableMap failedStatusReport = codePushStatusReport . getFailedUpdateStatusReport ( lastFailedPackage );
437
+ if ( failedStatusReport != null ) {
438
+ promise . resolve ( failedStatusReport );
439
+ return ;
440
+ }
444
441
} catch (JSONException e ) {
445
442
throw new CodePushUnknownException ("Unable to read failed updates information stored in SharedPreferences." , e );
446
443
}
447
444
}
448
445
} else if (didUpdate ) {
449
- // Check if the current CodePush package has been reported
450
446
WritableMap currentPackage = codePushPackage .getCurrentPackage ();
451
447
if (currentPackage != null ) {
452
- String currentPackageIdentifier = codePushStatusReport .getPackageStatusReportIdentifier (currentPackage );
453
- String previousStatusReportIdentifier = codePushStatusReport .getPreviousStatusReportIdentifier ();
454
- if (currentPackageIdentifier != null ) {
455
- if (previousStatusReportIdentifier == null ) {
456
- codePushStatusReport .recordDeploymentStatusReported (currentPackageIdentifier );
457
- WritableNativeMap reportMap = new WritableNativeMap ();
458
- reportMap .putMap ("package" , currentPackage );
459
- reportMap .putString ("status" , DEPLOYMENT_SUCCEEDED_STATUS );
460
- promise .resolve (reportMap );
461
- return ;
462
- } else if (!previousStatusReportIdentifier .equals (currentPackageIdentifier )) {
463
- codePushStatusReport .recordDeploymentStatusReported (currentPackageIdentifier );
464
- if (codePushStatusReport .isStatusReportIdentifierCodePushLabel (previousStatusReportIdentifier )) {
465
- String previousDeploymentKey = codePushStatusReport .getDeploymentKeyFromStatusReportIdentifier (previousStatusReportIdentifier );
466
- String previousLabel = codePushStatusReport .getVersionLabelFromStatusReportIdentifier (previousStatusReportIdentifier );
467
- WritableNativeMap reportMap = new WritableNativeMap ();
468
- reportMap .putMap ("package" , currentPackage );
469
- reportMap .putString ("status" , DEPLOYMENT_SUCCEEDED_STATUS );
470
- reportMap .putString ("previousDeploymentKey" , previousDeploymentKey );
471
- reportMap .putString ("previousLabelOrAppVersion" , previousLabel );
472
- promise .resolve (reportMap );
473
- } else {
474
- // Previous status report was with a binary app version.
475
- WritableNativeMap reportMap = new WritableNativeMap ();
476
- reportMap .putMap ("package" , currentPackage );
477
- reportMap .putString ("status" , DEPLOYMENT_SUCCEEDED_STATUS );
478
- reportMap .putString ("previousLabelOrAppVersion" , previousStatusReportIdentifier );
479
- promise .resolve (reportMap );
480
- }
481
- return ;
482
- }
448
+ WritableMap newPackageStatusReport = codePushStatusReport .getNewPackageStatusReport (currentPackage );
449
+ if (newPackageStatusReport != null ) {
450
+ promise .resolve (newPackageStatusReport );
451
+ return ;
483
452
}
484
453
}
485
454
} else if (isRunningBinaryVersion ) {
486
- // Check if the current appVersion has been reported.
487
- String previousStatusReportIdentifier = codePushStatusReport .getPreviousStatusReportIdentifier ();
488
- if (previousStatusReportIdentifier == null ) {
489
- codePushStatusReport .recordDeploymentStatusReported (appVersion );
490
- WritableNativeMap reportMap = new WritableNativeMap ();
491
- reportMap .putString ("appVersion" , appVersion );
492
- promise .resolve (reportMap );
493
- return ;
494
- } else if (!previousStatusReportIdentifier .equals (appVersion )) {
495
- codePushStatusReport .recordDeploymentStatusReported (appVersion );
496
- if (codePushStatusReport .isStatusReportIdentifierCodePushLabel (previousStatusReportIdentifier )) {
497
- String previousDeploymentKey = codePushStatusReport .getDeploymentKeyFromStatusReportIdentifier (previousStatusReportIdentifier );
498
- String previousLabel = codePushStatusReport .getVersionLabelFromStatusReportIdentifier (previousStatusReportIdentifier );
499
- WritableNativeMap reportMap = new WritableNativeMap ();
500
- reportMap .putString ("appVersion" , appVersion );
501
- reportMap .putString ("previousDeploymentKey" , previousDeploymentKey );
502
- reportMap .putString ("previousLabelOrAppVersion" , previousLabel );
503
- promise .resolve (reportMap );
504
- } else {
505
- // Previous status report was with a binary app version.
506
- WritableNativeMap reportMap = new WritableNativeMap ();
507
- reportMap .putString ("appVersion" , appVersion );
508
- reportMap .putString ("previousLabelOrAppVersion" , previousStatusReportIdentifier );
509
- promise .resolve (reportMap );
510
- }
455
+ WritableMap newAppVersionStatusReport = codePushStatusReport .getNewAppVersionStatusReport (appVersion );
456
+ if (newAppVersionStatusReport != null ) {
457
+ promise .resolve (newAppVersionStatusReport );
511
458
return ;
512
459
}
513
460
}
0 commit comments