Merge pull request #447 from Microsoft/override-app-version

Allow an app's binary version to be manually specified
This commit is contained in:
Richard Hua
2016-08-01 18:28:29 -07:00
committed by GitHub
5 changed files with 40 additions and 13 deletions

View File

@@ -29,6 +29,7 @@ public class CodePush implements ReactPackage {
private static boolean sIsRunningBinaryVersion = false;
private static boolean sNeedToReportRollback = false;
private static boolean sTestConfigurationFlag = false;
private static String sAppVersion = null;
private boolean mDidUpdate = false;
@@ -40,7 +41,6 @@ public class CodePush implements ReactPackage {
private SettingsManager mSettingsManager;
// Config properties.
private String mAppVersion;
private String mDeploymentKey;
private String mServerUrl = "https://codepush.azurewebsites.net/";
@@ -63,11 +63,13 @@ public class CodePush implements ReactPackage {
mIsDebugMode = isDebugMode;
mSettingsManager = new SettingsManager(mContext);
try {
PackageInfo pInfo = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0);
mAppVersion = pInfo.versionName;
} catch (PackageManager.NameNotFoundException e) {
throw new CodePushUnknownException("Unable to get package info for " + mContext.getPackageName(), e);
if (sAppVersion == null) {
try {
PackageInfo pInfo = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0);
sAppVersion = pInfo.versionName;
} catch (PackageManager.NameNotFoundException e) {
throw new CodePushUnknownException("Unable to get package info for " + mContext.getPackageName(), e);
}
}
mCurrentInstance = this;
@@ -96,7 +98,7 @@ public class CodePush implements ReactPackage {
}
public String getAppVersion() {
return mAppVersion;
return sAppVersion;
}
public String getAssetsBundleFileName() {
@@ -177,14 +179,14 @@ public class CodePush implements ReactPackage {
String packageAppVersion = CodePushUtils.tryGetString(packageMetadata, "appVersion");
if (binaryModifiedDateDuringPackageInstall != null &&
binaryModifiedDateDuringPackageInstall == binaryResourcesModifiedTime &&
(isUsingTestConfiguration() || this.mAppVersion.equals(packageAppVersion))) {
(isUsingTestConfiguration() || sAppVersion.equals(packageAppVersion))) {
CodePushUtils.logBundleUrl(packageFilePath);
sIsRunningBinaryVersion = false;
return packageFilePath;
} else {
// The binary version is newer.
this.mDidUpdate = false;
if (!this.mIsDebugMode || !this.mAppVersion.equals(packageAppVersion)) {
if (!this.mIsDebugMode || !sAppVersion.equals(packageAppVersion)) {
this.clearUpdates();
}
@@ -249,6 +251,10 @@ public class CodePush implements ReactPackage {
return sNeedToReportRollback;
}
public static void overrideAppVersion(String appVersionOverride) {
sAppVersion = appVersionOverride;
}
private void rollbackPackage() {
WritableMap failedPackage = mUpdateManager.getCurrentPackage();
mSettingsManager.saveFailedUpdate(failedPackage);
@@ -280,7 +286,7 @@ public class CodePush implements ReactPackage {
CodePushNativeModule codePushModule = new CodePushNativeModule(reactApplicationContext, this, mUpdateManager, mTelemetryManager, mSettingsManager);
CodePushDialog dialogModule = new CodePushDialog(reactApplicationContext);
List<NativeModule> nativeModules = new ArrayList<>();
List<NativeModule> nativeModules = new ArrayList<>();
nativeModules.add(codePushModule);
nativeModules.add(dialogModule);
return nativeModules;