mirror of
https://github.com/zhigang1992/react-native-code-push.git
synced 2026-06-11 08:04:23 +08:00
CodePushStatusReport -> CodePushTelemetryManager
This commit is contained in:
@@ -65,7 +65,7 @@ public class CodePush {
|
||||
// Helper classes.
|
||||
private CodePushPackage codePushPackage;
|
||||
private CodePushReactPackage codePushReactPackage;
|
||||
private CodePushStatusReport codePushStatusReport;
|
||||
private CodePushTelemetryManager codePushTelemetryManager;
|
||||
private CodePushNativeModule codePushNativeModule;
|
||||
|
||||
// Config properties.
|
||||
@@ -86,7 +86,7 @@ public class CodePush {
|
||||
SoLoader.init(mainActivity, false);
|
||||
this.applicationContext = mainActivity.getApplicationContext();
|
||||
this.codePushPackage = new CodePushPackage(mainActivity.getFilesDir().getAbsolutePath());
|
||||
this.codePushStatusReport = new CodePushStatusReport(this.applicationContext, CODE_PUSH_PREFERENCES);
|
||||
this.codePushTelemetryManager = new CodePushTelemetryManager(this.applicationContext, CODE_PUSH_PREFERENCES);
|
||||
this.deploymentKey = deploymentKey;
|
||||
this.isDebugMode = isDebugMode;
|
||||
this.mainActivity = mainActivity;
|
||||
@@ -433,7 +433,7 @@ public class CodePush {
|
||||
try {
|
||||
JSONObject lastFailedPackageJSON = failedUpdates.getJSONObject(failedUpdates.length() - 1);
|
||||
WritableMap lastFailedPackage = CodePushUtils.convertJsonObjectToWriteable(lastFailedPackageJSON);
|
||||
WritableMap failedStatusReport = codePushStatusReport.getFailedUpdateStatusReport(lastFailedPackage);
|
||||
WritableMap failedStatusReport = codePushTelemetryManager.getRollbackReport(lastFailedPackage);
|
||||
if (failedStatusReport != null) {
|
||||
promise.resolve(failedStatusReport);
|
||||
return;
|
||||
@@ -445,14 +445,14 @@ public class CodePush {
|
||||
} else if (didUpdate) {
|
||||
WritableMap currentPackage = codePushPackage.getCurrentPackage();
|
||||
if (currentPackage != null) {
|
||||
WritableMap newPackageStatusReport = codePushStatusReport.getNewPackageStatusReport(currentPackage);
|
||||
WritableMap newPackageStatusReport = codePushTelemetryManager.getUpdateReport(currentPackage);
|
||||
if (newPackageStatusReport != null) {
|
||||
promise.resolve(newPackageStatusReport);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if (isRunningBinaryVersion) {
|
||||
WritableMap newAppVersionStatusReport = codePushStatusReport.getNewAppVersionStatusReport(appVersion);
|
||||
WritableMap newAppVersionStatusReport = codePushTelemetryManager.getBinaryUpdateReport(appVersion);
|
||||
if (newAppVersionStatusReport != null) {
|
||||
promise.resolve(newAppVersionStatusReport);
|
||||
return;
|
||||
|
||||
@@ -6,7 +6,7 @@ import android.content.SharedPreferences;
|
||||
import com.facebook.react.bridge.WritableMap;
|
||||
import com.facebook.react.bridge.WritableNativeMap;
|
||||
|
||||
public class CodePushStatusReport {
|
||||
public class CodePushTelemetryManager {
|
||||
|
||||
private Context applicationContext;
|
||||
private final String CODE_PUSH_PREFERENCES;
|
||||
@@ -16,28 +16,46 @@ public class CodePushStatusReport {
|
||||
private final String LABEL_KEY = "label";
|
||||
private final String LAST_DEPLOYMENT_REPORT_KEY = "CODE_PUSH_LAST_DEPLOYMENT_REPORT";
|
||||
|
||||
public CodePushStatusReport(Context applicationContext, String codePushPreferencesKey) {
|
||||
public CodePushTelemetryManager(Context applicationContext, String codePushPreferencesKey) {
|
||||
this.applicationContext = applicationContext;
|
||||
this.CODE_PUSH_PREFERENCES = codePushPreferencesKey;
|
||||
}
|
||||
|
||||
public String getDeploymentKeyFromStatusReportIdentifier(String statusReportIdentifier) {
|
||||
String[] parsedIdentifier = statusReportIdentifier.split(":");
|
||||
if (parsedIdentifier.length > 0) {
|
||||
return parsedIdentifier[0];
|
||||
} else {
|
||||
return null;
|
||||
public WritableMap getBinaryUpdateReport(String appVersion) {
|
||||
String previousStatusReportIdentifier = this.getPreviousStatusReportIdentifier();
|
||||
if (previousStatusReportIdentifier == null) {
|
||||
this.recordDeploymentStatusReported(appVersion);
|
||||
WritableNativeMap reportMap = new WritableNativeMap();
|
||||
reportMap.putString("appVersion", appVersion);
|
||||
return reportMap;
|
||||
} else if (!previousStatusReportIdentifier.equals(appVersion)) {
|
||||
this.recordDeploymentStatusReported(appVersion);
|
||||
WritableNativeMap reportMap = new WritableNativeMap();
|
||||
if (this.isStatusReportIdentifierCodePushLabel(previousStatusReportIdentifier)) {
|
||||
String previousDeploymentKey = this.getDeploymentKeyFromStatusReportIdentifier(previousStatusReportIdentifier);
|
||||
String previousLabel = this.getVersionLabelFromStatusReportIdentifier(previousStatusReportIdentifier);
|
||||
reportMap.putString("appVersion", appVersion);
|
||||
reportMap.putString("previousDeploymentKey", previousDeploymentKey);
|
||||
reportMap.putString("previousLabelOrAppVersion", previousLabel);
|
||||
} else {
|
||||
// Previous status report was with a binary app version.
|
||||
reportMap.putString("appVersion", appVersion);
|
||||
reportMap.putString("previousLabelOrAppVersion", previousStatusReportIdentifier);
|
||||
}
|
||||
return reportMap;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public WritableMap getFailedUpdateStatusReport(WritableMap lastFailedPackage) {
|
||||
public WritableMap getRollbackReport(WritableMap lastFailedPackage) {
|
||||
WritableNativeMap reportMap = new WritableNativeMap();
|
||||
reportMap.putMap("package", lastFailedPackage);
|
||||
reportMap.putString("status", DEPLOYMENT_FAILED_STATUS);
|
||||
return reportMap;
|
||||
}
|
||||
|
||||
public WritableMap getNewPackageStatusReport(WritableMap currentPackage) {
|
||||
public WritableMap getUpdateReport(WritableMap currentPackage) {
|
||||
String currentPackageIdentifier = this.getPackageStatusReportIdentifier(currentPackage);
|
||||
String previousStatusReportIdentifier = this.getPreviousStatusReportIdentifier();
|
||||
if (currentPackageIdentifier != null) {
|
||||
@@ -72,34 +90,16 @@ public class CodePushStatusReport {
|
||||
return null;
|
||||
}
|
||||
|
||||
public WritableMap getNewAppVersionStatusReport(String appVersion) {
|
||||
String previousStatusReportIdentifier = this.getPreviousStatusReportIdentifier();
|
||||
if (previousStatusReportIdentifier == null) {
|
||||
this.recordDeploymentStatusReported(appVersion);
|
||||
WritableNativeMap reportMap = new WritableNativeMap();
|
||||
reportMap.putString("appVersion", appVersion);
|
||||
return reportMap;
|
||||
} else if (!previousStatusReportIdentifier.equals(appVersion)) {
|
||||
this.recordDeploymentStatusReported(appVersion);
|
||||
WritableNativeMap reportMap = new WritableNativeMap();
|
||||
if (this.isStatusReportIdentifierCodePushLabel(previousStatusReportIdentifier)) {
|
||||
String previousDeploymentKey = this.getDeploymentKeyFromStatusReportIdentifier(previousStatusReportIdentifier);
|
||||
String previousLabel = this.getVersionLabelFromStatusReportIdentifier(previousStatusReportIdentifier);
|
||||
reportMap.putString("appVersion", appVersion);
|
||||
reportMap.putString("previousDeploymentKey", previousDeploymentKey);
|
||||
reportMap.putString("previousLabelOrAppVersion", previousLabel);
|
||||
} else {
|
||||
// Previous status report was with a binary app version.
|
||||
reportMap.putString("appVersion", appVersion);
|
||||
reportMap.putString("previousLabelOrAppVersion", previousStatusReportIdentifier);
|
||||
}
|
||||
return reportMap;
|
||||
private String getDeploymentKeyFromStatusReportIdentifier(String statusReportIdentifier) {
|
||||
String[] parsedIdentifier = statusReportIdentifier.split(":");
|
||||
if (parsedIdentifier.length > 0) {
|
||||
return parsedIdentifier[0];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getPackageStatusReportIdentifier(WritableMap updatePackage) {
|
||||
private String getPackageStatusReportIdentifier(WritableMap updatePackage) {
|
||||
// Because deploymentKeys can be dynamically switched, we use a
|
||||
// combination of the deploymentKey and label as the packageIdentifier.
|
||||
String deploymentKey = CodePushUtils.tryGetString(updatePackage, DEPLOYMENT_KEY_KEY);
|
||||
@@ -111,12 +111,12 @@ public class CodePushStatusReport {
|
||||
}
|
||||
}
|
||||
|
||||
public String getPreviousStatusReportIdentifier() {
|
||||
private String getPreviousStatusReportIdentifier() {
|
||||
SharedPreferences settings = applicationContext.getSharedPreferences(CODE_PUSH_PREFERENCES, 0);
|
||||
return settings.getString(LAST_DEPLOYMENT_REPORT_KEY, null);
|
||||
}
|
||||
|
||||
public String getVersionLabelFromStatusReportIdentifier(String statusReportIdentifier) {
|
||||
private String getVersionLabelFromStatusReportIdentifier(String statusReportIdentifier) {
|
||||
String[] parsedIdentifier = statusReportIdentifier.split(":");
|
||||
if (parsedIdentifier.length > 1) {
|
||||
return parsedIdentifier[1];
|
||||
@@ -125,11 +125,11 @@ public class CodePushStatusReport {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isStatusReportIdentifierCodePushLabel(String statusReportIdentifier) {
|
||||
private boolean isStatusReportIdentifierCodePushLabel(String statusReportIdentifier) {
|
||||
return statusReportIdentifier != null && statusReportIdentifier.contains(":");
|
||||
}
|
||||
|
||||
public void recordDeploymentStatusReported(String appVersionOrPackageIdentifier) {
|
||||
private void recordDeploymentStatusReported(String appVersionOrPackageIdentifier) {
|
||||
SharedPreferences settings = applicationContext.getSharedPreferences(CODE_PUSH_PREFERENCES, 0);
|
||||
settings.edit().putString(LAST_DEPLOYMENT_REPORT_KEY, appVersionOrPackageIdentifier).commit();
|
||||
}
|
||||
Reference in New Issue
Block a user