@@ -178,13 +178,10 @@ public String getBundleUrl(String assetsBundleFileName) {
178178 }
179179 }
180180
181- private String getPackageStatusReportIdentifier (WritableMap updatePackage ) {
182- // Because deploymentKeys can be dynamically switched, we use a
183- // combination of the deploymentKey and label as the packageIdentifier.
184- String deploymentKey = CodePushUtils .tryGetString (updatePackage , DEPLOYMENT_KEY_KEY );
185- String label = CodePushUtils .tryGetString (updatePackage , LABEL_KEY );
186- if (deploymentKey != null && label != null ) {
187- return deploymentKey + ":" + label ;
181+ private String getDeploymentKeyFromStatusReportIdentifier (String statusReportIdentifier ) {
182+ String [] parsedIdentifier = statusReportIdentifier .split (":" );
183+ if (parsedIdentifier .length > 0 ) {
184+ return parsedIdentifier [0 ];
188185 } else {
189186 return null ;
190187 }
@@ -208,6 +205,18 @@ private JSONArray getFailedUpdates() {
208205 }
209206 }
210207
208+ private String getPackageStatusReportIdentifier (WritableMap updatePackage ) {
209+ // Because deploymentKeys can be dynamically switched, we use a
210+ // combination of the deploymentKey and label as the packageIdentifier.
211+ String deploymentKey = CodePushUtils .tryGetString (updatePackage , DEPLOYMENT_KEY_KEY );
212+ String label = CodePushUtils .tryGetString (updatePackage , LABEL_KEY );
213+ if (deploymentKey != null && label != null ) {
214+ return deploymentKey + ":" + label ;
215+ } else {
216+ return null ;
217+ }
218+ }
219+
211220 private JSONObject getPendingUpdate () {
212221 SharedPreferences settings = applicationContext .getSharedPreferences (CODE_PUSH_PREFERENCES , 0 );
213222 String pendingUpdateString = settings .getString (PENDING_UPDATE_KEY , null );
@@ -226,6 +235,20 @@ private JSONObject getPendingUpdate() {
226235 }
227236 }
228237
238+ private String getPreviousStatusReportIdentifier () {
239+ SharedPreferences settings = applicationContext .getSharedPreferences (CODE_PUSH_PREFERENCES , 0 );
240+ return settings .getString (LAST_DEPLOYMENT_REPORT_KEY , null );
241+ }
242+
243+ private String getVersionLabelFromStatusReportIdentifier (String statusReportIdentifier ) {
244+ String [] parsedIdentifier = statusReportIdentifier .split (":" );
245+ if (parsedIdentifier .length > 1 ) {
246+ return parsedIdentifier [1 ];
247+ } else {
248+ return null ;
249+ }
250+ }
251+
229252 public ReactPackage getReactPackage () {
230253 if (codePushReactPackage == null ) {
231254 codePushReactPackage = new CodePushReactPackage ();
@@ -262,16 +285,6 @@ private void initializeUpdateAfterRestart() {
262285 }
263286 }
264287
265- private boolean isDeploymentStatusNotYetReported (String appVersionOrPackageIdentifier ) {
266- SharedPreferences settings = applicationContext .getSharedPreferences (CODE_PUSH_PREFERENCES , 0 );
267- String lastDeploymentReportIdentifier = settings .getString (LAST_DEPLOYMENT_REPORT_KEY , null );
268- if (lastDeploymentReportIdentifier == null ) {
269- return true ;
270- } else {
271- return !lastDeploymentReportIdentifier .equals (appVersionOrPackageIdentifier );
272- }
273- }
274-
275288 private boolean isFailedHash (String packageHash ) {
276289 JSONArray failedUpdates = getFailedUpdates ();
277290 if (packageHash != null ) {
@@ -306,6 +319,10 @@ private boolean isPendingUpdate(String packageHash) {
306319 }
307320 }
308321
322+ private boolean isStatusReportIdentifierCodePushLabel (String statusReportIdentifier ) {
323+ return statusReportIdentifier != null && statusReportIdentifier .contains (":" );
324+ }
325+
309326 private void recordDeploymentStatusReported (String appVersionOrPackageIdentifier ) {
310327 SharedPreferences settings = applicationContext .getSharedPreferences (CODE_PUSH_PREFERENCES , 0 );
311328 settings .edit ().putString (LAST_DEPLOYMENT_REPORT_KEY , appVersionOrPackageIdentifier ).commit ();
@@ -465,7 +482,8 @@ public void getNewStatusReport(Promise promise) {
465482 JSONObject lastFailedPackageJSON = failedUpdates .getJSONObject (failedUpdates .length () - 1 );
466483 WritableMap lastFailedPackage = CodePushUtils .convertJsonObjectToWriteable (lastFailedPackageJSON );
467484 String lastFailedPackageIdentifier = getPackageStatusReportIdentifier (lastFailedPackage );
468- if (lastFailedPackage != null && isDeploymentStatusNotYetReported (lastFailedPackageIdentifier )) {
485+ String previousStatusReportIdentifier = getPreviousStatusReportIdentifier ();
486+ if (lastFailedPackage != null && (previousStatusReportIdentifier == null || !previousStatusReportIdentifier .equals (lastFailedPackageIdentifier ))) {
469487 recordDeploymentStatusReported (lastFailedPackageIdentifier );
470488 WritableNativeMap reportMap = new WritableNativeMap ();
471489 reportMap .putMap ("package" , lastFailedPackage );
@@ -482,24 +500,65 @@ public void getNewStatusReport(Promise promise) {
482500 WritableMap currentPackage = codePushPackage .getCurrentPackage ();
483501 if (currentPackage != null ) {
484502 String currentPackageIdentifier = getPackageStatusReportIdentifier (currentPackage );
485- if (currentPackageIdentifier != null && isDeploymentStatusNotYetReported (currentPackageIdentifier )) {
486- recordDeploymentStatusReported (currentPackageIdentifier );
487- WritableNativeMap reportMap = new WritableNativeMap ();
488- reportMap .putMap ("package" , currentPackage );
489- reportMap .putString ("status" , DEPLOYMENT_SUCCEEDED_STATUS );
490- promise .resolve (reportMap );
491- return ;
503+ String previousStatusReportIdentifier = getPreviousStatusReportIdentifier ();
504+ if (currentPackageIdentifier != null ) {
505+ if (previousStatusReportIdentifier == null ) {
506+ recordDeploymentStatusReported (currentPackageIdentifier );
507+ WritableNativeMap reportMap = new WritableNativeMap ();
508+ reportMap .putMap ("package" , currentPackage );
509+ reportMap .putString ("status" , DEPLOYMENT_SUCCEEDED_STATUS );
510+ promise .resolve (reportMap );
511+ return ;
512+ } else if (!previousStatusReportIdentifier .equals (currentPackageIdentifier )) {
513+ recordDeploymentStatusReported (currentPackageIdentifier );
514+ if (isStatusReportIdentifierCodePushLabel (previousStatusReportIdentifier )) {
515+ String fromDeploymentKey = getDeploymentKeyFromStatusReportIdentifier (previousStatusReportIdentifier );
516+ String fromLabel = getVersionLabelFromStatusReportIdentifier (previousStatusReportIdentifier );
517+ WritableNativeMap reportMap = new WritableNativeMap ();
518+ reportMap .putMap ("package" , currentPackage );
519+ reportMap .putString ("status" , DEPLOYMENT_SUCCEEDED_STATUS );
520+ reportMap .putString ("fromDeploymentKey" , fromDeploymentKey );
521+ reportMap .putString ("fromLabelOrAppVersion" , fromLabel );
522+ promise .resolve (reportMap );
523+ } else {
524+ // Previous status report was with a binary app version.
525+ WritableNativeMap reportMap = new WritableNativeMap ();
526+ reportMap .putMap ("package" , currentPackage );
527+ reportMap .putString ("status" , DEPLOYMENT_SUCCEEDED_STATUS );
528+ reportMap .putString ("fromLabelOrAppVersion" , previousStatusReportIdentifier );
529+ promise .resolve (reportMap );
530+ }
531+ return ;
532+ }
492533 }
493534 }
494535 } else if (isRunningBinaryVersion ) {
495536 // Check if the current appVersion has been reported.
496- String binaryIdentifier = "" + getBinaryResourcesModifiedTime ();
497- if (isDeploymentStatusNotYetReported ( binaryIdentifier ) ) {
498- recordDeploymentStatusReported (binaryIdentifier );
537+ String previousStatusReportIdentifier = getPreviousStatusReportIdentifier ();
538+ if (previousStatusReportIdentifier == null ) {
539+ recordDeploymentStatusReported (appVersion );
499540 WritableNativeMap reportMap = new WritableNativeMap ();
500541 reportMap .putString ("appVersion" , appVersion );
501542 promise .resolve (reportMap );
502543 return ;
544+ } else if (!previousStatusReportIdentifier .equals (appVersion )) {
545+ recordDeploymentStatusReported (appVersion );
546+ if (isStatusReportIdentifierCodePushLabel (previousStatusReportIdentifier )) {
547+ String fromDeploymentKey = getDeploymentKeyFromStatusReportIdentifier (previousStatusReportIdentifier );
548+ String fromLabel = getVersionLabelFromStatusReportIdentifier (previousStatusReportIdentifier );
549+ WritableNativeMap reportMap = new WritableNativeMap ();
550+ reportMap .putString ("appVersion" , appVersion );
551+ reportMap .putString ("fromDeploymentKey" , fromDeploymentKey );
552+ reportMap .putString ("fromLabelOrAppVersion" , fromLabel );
553+ promise .resolve (reportMap );
554+ } else {
555+ // Previous status report was with a binary app version.
556+ WritableNativeMap reportMap = new WritableNativeMap ();
557+ reportMap .putString ("appVersion" , appVersion );
558+ reportMap .putString ("fromLabelOrAppVersion" , previousStatusReportIdentifier );
559+ promise .resolve (reportMap );
560+ }
561+ return ;
503562 }
504563 }
505564
0 commit comments