Skip to content

Commit 23e7b18

Browse files
author
Richard Hua
committed
Refactor app version into single variable
1 parent 6170c0c commit 23e7b18

File tree

1 file changed

+12
-11
lines changed
  • android/app/src/main/java/com/microsoft/codepush/react

1 file changed

+12
-11
lines changed

android/app/src/main/java/com/microsoft/codepush/react/CodePush.java

+12-11
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class CodePush implements ReactPackage {
2929
private static boolean sIsRunningBinaryVersion = false;
3030
private static boolean sNeedToReportRollback = false;
3131
private static boolean sTestConfigurationFlag = false;
32-
private static String sAppVersionOverride = null;
32+
private static String sAppVersion = null;
3333

3434
private boolean mDidUpdate = false;
3535

@@ -41,7 +41,6 @@ public class CodePush implements ReactPackage {
4141
private SettingsManager mSettingsManager;
4242

4343
// Config properties.
44-
private String mPListAppVersion;
4544
private String mDeploymentKey;
4645
private String mServerUrl = "https://codepush.azurewebsites.net/";
4746

@@ -64,11 +63,13 @@ public CodePush(String deploymentKey, Context context, boolean isDebugMode) {
6463
mIsDebugMode = isDebugMode;
6564
mSettingsManager = new SettingsManager(mContext);
6665

67-
try {
68-
PackageInfo pInfo = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0);
69-
mPListAppVersion = pInfo.versionName;
70-
} catch (PackageManager.NameNotFoundException e) {
71-
throw new CodePushUnknownException("Unable to get package info for " + mContext.getPackageName(), e);
66+
if (sAppVersion == null) {
67+
try {
68+
PackageInfo pInfo = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0);
69+
sAppVersion = pInfo.versionName;
70+
} catch (PackageManager.NameNotFoundException e) {
71+
throw new CodePushUnknownException("Unable to get package info for " + mContext.getPackageName(), e);
72+
}
7273
}
7374

7475
mCurrentInstance = this;
@@ -97,7 +98,7 @@ public boolean didUpdate() {
9798
}
9899

99100
public String getAppVersion() {
100-
return sAppVersionOverride == null ? mPListAppVersion : sAppVersionOverride;
101+
return sAppVersion;
101102
}
102103

103104
public String getAssetsBundleFileName() {
@@ -178,14 +179,14 @@ public String getJSBundleFileInternal(String assetsBundleFileName) {
178179
String packageAppVersion = CodePushUtils.tryGetString(packageMetadata, "appVersion");
179180
if (binaryModifiedDateDuringPackageInstall != null &&
180181
binaryModifiedDateDuringPackageInstall == binaryResourcesModifiedTime &&
181-
(isUsingTestConfiguration() || this.getAppVersion().equals(packageAppVersion))) {
182+
(isUsingTestConfiguration() || sAppVersion.equals(packageAppVersion))) {
182183
CodePushUtils.logBundleUrl(packageFilePath);
183184
sIsRunningBinaryVersion = false;
184185
return packageFilePath;
185186
} else {
186187
// The binary version is newer.
187188
this.mDidUpdate = false;
188-
if (!this.mIsDebugMode || !this.getAppVersion().equals(packageAppVersion)) {
189+
if (!this.mIsDebugMode || !sAppVersion.equals(packageAppVersion)) {
189190
this.clearUpdates();
190191
}
191192

@@ -251,7 +252,7 @@ boolean needToReportRollback() {
251252
}
252253

253254
public static void overrideAppVersion(String appVersionOverride) {
254-
sAppVersionOverride = appVersionOverride;
255+
sAppVersion = appVersionOverride;
255256
}
256257

257258
private void rollbackPackage() {

0 commit comments

Comments
 (0)