Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ long getBinaryResourcesModifiedTime() {
int codePushApkBuildTimeId = this.mContext.getResources().getIdentifier(CodePushConstants.CODE_PUSH_APK_BUILD_TIME_KEY, "string", packageName);
String codePushApkBuildTime = this.mContext.getResources().getString(codePushApkBuildTimeId);
return Long.parseLong(codePushApkBuildTime);
} catch (Exception e) {
} catch (Exception e) {
throw new CodePushUnknownException("Error in getting binary resources modified time", e);
}
}
Expand Down Expand Up @@ -143,44 +143,30 @@ public static String getJSBundleFile(String assetsBundleFileName) {
public String getJSBundleFileInternal(String assetsBundleFileName) {
this.mAssetsBundleFileName = assetsBundleFileName;
String binaryJsBundleUrl = CodePushConstants.ASSETS_BUNDLE_PREFIX + assetsBundleFileName;
long binaryResourcesModifiedTime = this.getBinaryResourcesModifiedTime();

try {
String packageFilePath = mUpdateManager.getCurrentPackageBundlePath(this.mAssetsBundleFileName);
if (packageFilePath == null) {
// There has not been any downloaded updates.
CodePushUtils.logBundleUrl(binaryJsBundleUrl);
sIsRunningBinaryVersion = true;
return binaryJsBundleUrl;
}
String packageFilePath = mUpdateManager.getCurrentPackageBundlePath(this.mAssetsBundleFileName);
if (packageFilePath == null) {
// There has not been any downloaded updates.
CodePushUtils.logBundleUrl(binaryJsBundleUrl);
sIsRunningBinaryVersion = true;
return binaryJsBundleUrl;
}

JSONObject packageMetadata = this.mUpdateManager.getCurrentPackage();
Long binaryModifiedDateDuringPackageInstall = null;
String binaryModifiedDateDuringPackageInstallString = packageMetadata.optString(CodePushConstants.BINARY_MODIFIED_TIME_KEY, null);
if (binaryModifiedDateDuringPackageInstallString != null) {
binaryModifiedDateDuringPackageInstall = Long.parseLong(binaryModifiedDateDuringPackageInstallString);
JSONObject packageMetadata = this.mUpdateManager.getCurrentPackage();
if (isPackageBundleLatest(packageMetadata)) {
CodePushUtils.logBundleUrl(packageFilePath);
sIsRunningBinaryVersion = false;
return packageFilePath;
} else {
// The binary version is newer.
this.mDidUpdate = false;
if (!this.mIsDebugMode || hasBinaryVersionChanged(packageMetadata)) {
this.clearUpdates();
}

String packageAppVersion = packageMetadata.optString("appVersion", null);
if (binaryModifiedDateDuringPackageInstall != null &&
binaryModifiedDateDuringPackageInstall == binaryResourcesModifiedTime &&
(isUsingTestConfiguration() || sAppVersion.equals(packageAppVersion))) {
CodePushUtils.logBundleUrl(packageFilePath);
sIsRunningBinaryVersion = false;
return packageFilePath;
} else {
// The binary version is newer.
this.mDidUpdate = false;
if (!this.mIsDebugMode || !sAppVersion.equals(packageAppVersion)) {
this.clearUpdates();
}

CodePushUtils.logBundleUrl(binaryJsBundleUrl);
sIsRunningBinaryVersion = true;
return binaryJsBundleUrl;
}
} catch (NumberFormatException e) {
throw new CodePushUnknownException("Error in reading binary modified date from package metadata", e);
CodePushUtils.logBundleUrl(binaryJsBundleUrl);
sIsRunningBinaryVersion = true;
return binaryJsBundleUrl;
}
}

Expand All @@ -195,6 +181,12 @@ void initializeUpdateAfterRestart() {

JSONObject pendingUpdate = mSettingsManager.getPendingUpdate();
if (pendingUpdate != null) {
JSONObject packageMetadata = this.mUpdateManager.getCurrentPackage();
if (!isPackageBundleLatest(packageMetadata) && hasBinaryVersionChanged(packageMetadata)) {
CodePushUtils.log("Skipping initializeUpdateAfterRestart(), binary version is newer");
return;
}

try {
boolean updateIsLoading = pendingUpdate.getBoolean(CodePushConstants.PENDING_UPDATE_IS_LOADING_KEY);
if (updateIsLoading) {
Expand Down Expand Up @@ -232,6 +224,28 @@ boolean isRunningBinaryVersion() {
return sIsRunningBinaryVersion;
}

private boolean isPackageBundleLatest(JSONObject packageMetadata) {
try {
Long binaryModifiedDateDuringPackageInstall = null;
String binaryModifiedDateDuringPackageInstallString = packageMetadata.optString(CodePushConstants.BINARY_MODIFIED_TIME_KEY, null);
if (binaryModifiedDateDuringPackageInstallString != null) {
binaryModifiedDateDuringPackageInstall = Long.parseLong(binaryModifiedDateDuringPackageInstallString);
}
String packageAppVersion = packageMetadata.optString("appVersion", null);
long binaryResourcesModifiedTime = this.getBinaryResourcesModifiedTime();
return binaryModifiedDateDuringPackageInstall != null &&
binaryModifiedDateDuringPackageInstall == binaryResourcesModifiedTime &&
(isUsingTestConfiguration() || sAppVersion.equals(packageAppVersion));
} catch (NumberFormatException e) {
throw new CodePushUnknownException("Error in reading binary modified date from package metadata", e);
}
}

private boolean hasBinaryVersionChanged(JSONObject packageMetadata) {
String packageAppVersion = packageMetadata.optString("appVersion", null);
return !sAppVersion.equals(packageAppVersion);
}

boolean needToReportRollback() {
return sNeedToReportRollback;
}
Expand Down Expand Up @@ -276,7 +290,7 @@ static ReactInstanceManager getReactInstanceManager() {
}
return mReactInstanceHolder.getReactInstanceManager();
}

@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactApplicationContext) {
CodePushNativeModule codePushModule = new CodePushNativeModule(reactApplicationContext, this, mUpdateManager, mTelemetryManager, mSettingsManager);
Expand Down