@@ -105,7 +105,7 @@ long getBinaryResourcesModifiedTime() {
105
105
int codePushApkBuildTimeId = this .mContext .getResources ().getIdentifier (CodePushConstants .CODE_PUSH_APK_BUILD_TIME_KEY , "string" , packageName );
106
106
String codePushApkBuildTime = this .mContext .getResources ().getString (codePushApkBuildTimeId );
107
107
return Long .parseLong (codePushApkBuildTime );
108
- } catch (Exception e ) {
108
+ } catch (Exception e ) {
109
109
throw new CodePushUnknownException ("Error in getting binary resources modified time" , e );
110
110
}
111
111
}
@@ -143,44 +143,30 @@ public static String getJSBundleFile(String assetsBundleFileName) {
143
143
public String getJSBundleFileInternal (String assetsBundleFileName ) {
144
144
this .mAssetsBundleFileName = assetsBundleFileName ;
145
145
String binaryJsBundleUrl = CodePushConstants .ASSETS_BUNDLE_PREFIX + assetsBundleFileName ;
146
- long binaryResourcesModifiedTime = this .getBinaryResourcesModifiedTime ();
147
146
148
- try {
149
- String packageFilePath = mUpdateManager .getCurrentPackageBundlePath (this .mAssetsBundleFileName );
150
- if (packageFilePath == null ) {
151
- // There has not been any downloaded updates.
152
- CodePushUtils .logBundleUrl (binaryJsBundleUrl );
153
- sIsRunningBinaryVersion = true ;
154
- return binaryJsBundleUrl ;
155
- }
147
+ String packageFilePath = mUpdateManager .getCurrentPackageBundlePath (this .mAssetsBundleFileName );
148
+ if (packageFilePath == null ) {
149
+ // There has not been any downloaded updates.
150
+ CodePushUtils .logBundleUrl (binaryJsBundleUrl );
151
+ sIsRunningBinaryVersion = true ;
152
+ return binaryJsBundleUrl ;
153
+ }
156
154
157
- JSONObject packageMetadata = this .mUpdateManager .getCurrentPackage ();
158
- Long binaryModifiedDateDuringPackageInstall = null ;
159
- String binaryModifiedDateDuringPackageInstallString = packageMetadata .optString (CodePushConstants .BINARY_MODIFIED_TIME_KEY , null );
160
- if (binaryModifiedDateDuringPackageInstallString != null ) {
161
- binaryModifiedDateDuringPackageInstall = Long .parseLong (binaryModifiedDateDuringPackageInstallString );
155
+ JSONObject packageMetadata = this .mUpdateManager .getCurrentPackage ();
156
+ if (isPackageBundleLatest (packageMetadata )) {
157
+ CodePushUtils .logBundleUrl (packageFilePath );
158
+ sIsRunningBinaryVersion = false ;
159
+ return packageFilePath ;
160
+ } else {
161
+ // The binary version is newer.
162
+ this .mDidUpdate = false ;
163
+ if (!this .mIsDebugMode || hasBinaryVersionChanged (packageMetadata )) {
164
+ this .clearUpdates ();
162
165
}
163
166
164
- String packageAppVersion = packageMetadata .optString ("appVersion" , null );
165
- if (binaryModifiedDateDuringPackageInstall != null &&
166
- binaryModifiedDateDuringPackageInstall == binaryResourcesModifiedTime &&
167
- (isUsingTestConfiguration () || sAppVersion .equals (packageAppVersion ))) {
168
- CodePushUtils .logBundleUrl (packageFilePath );
169
- sIsRunningBinaryVersion = false ;
170
- return packageFilePath ;
171
- } else {
172
- // The binary version is newer.
173
- this .mDidUpdate = false ;
174
- if (!this .mIsDebugMode || !sAppVersion .equals (packageAppVersion )) {
175
- this .clearUpdates ();
176
- }
177
-
178
- CodePushUtils .logBundleUrl (binaryJsBundleUrl );
179
- sIsRunningBinaryVersion = true ;
180
- return binaryJsBundleUrl ;
181
- }
182
- } catch (NumberFormatException e ) {
183
- throw new CodePushUnknownException ("Error in reading binary modified date from package metadata" , e );
167
+ CodePushUtils .logBundleUrl (binaryJsBundleUrl );
168
+ sIsRunningBinaryVersion = true ;
169
+ return binaryJsBundleUrl ;
184
170
}
185
171
}
186
172
@@ -195,6 +181,12 @@ void initializeUpdateAfterRestart() {
195
181
196
182
JSONObject pendingUpdate = mSettingsManager .getPendingUpdate ();
197
183
if (pendingUpdate != null ) {
184
+ JSONObject packageMetadata = this .mUpdateManager .getCurrentPackage ();
185
+ if (!isPackageBundleLatest (packageMetadata ) && hasBinaryVersionChanged (packageMetadata )) {
186
+ CodePushUtils .log ("Skipping initializeUpdateAfterRestart(), binary version is newer" );
187
+ return ;
188
+ }
189
+
198
190
try {
199
191
boolean updateIsLoading = pendingUpdate .getBoolean (CodePushConstants .PENDING_UPDATE_IS_LOADING_KEY );
200
192
if (updateIsLoading ) {
@@ -232,6 +224,28 @@ boolean isRunningBinaryVersion() {
232
224
return sIsRunningBinaryVersion ;
233
225
}
234
226
227
+ private boolean isPackageBundleLatest (JSONObject packageMetadata ) {
228
+ try {
229
+ Long binaryModifiedDateDuringPackageInstall = null ;
230
+ String binaryModifiedDateDuringPackageInstallString = packageMetadata .optString (CodePushConstants .BINARY_MODIFIED_TIME_KEY , null );
231
+ if (binaryModifiedDateDuringPackageInstallString != null ) {
232
+ binaryModifiedDateDuringPackageInstall = Long .parseLong (binaryModifiedDateDuringPackageInstallString );
233
+ }
234
+ String packageAppVersion = packageMetadata .optString ("appVersion" , null );
235
+ long binaryResourcesModifiedTime = this .getBinaryResourcesModifiedTime ();
236
+ return binaryModifiedDateDuringPackageInstall != null &&
237
+ binaryModifiedDateDuringPackageInstall == binaryResourcesModifiedTime &&
238
+ (isUsingTestConfiguration () || sAppVersion .equals (packageAppVersion ));
239
+ } catch (NumberFormatException e ) {
240
+ throw new CodePushUnknownException ("Error in reading binary modified date from package metadata" , e );
241
+ }
242
+ }
243
+
244
+ private boolean hasBinaryVersionChanged (JSONObject packageMetadata ) {
245
+ String packageAppVersion = packageMetadata .optString ("appVersion" , null );
246
+ return !sAppVersion .equals (packageAppVersion );
247
+ }
248
+
235
249
boolean needToReportRollback () {
236
250
return sNeedToReportRollback ;
237
251
}
@@ -276,7 +290,7 @@ static ReactInstanceManager getReactInstanceManager() {
276
290
}
277
291
return mReactInstanceHolder .getReactInstanceManager ();
278
292
}
279
-
293
+
280
294
@ Override
281
295
public List <NativeModule > createNativeModules (ReactApplicationContext reactApplicationContext ) {
282
296
CodePushNativeModule codePushModule = new CodePushNativeModule (reactApplicationContext , this , mUpdateManager , mTelemetryManager , mSettingsManager );
0 commit comments