|
|
|
@ -569,32 +569,7 @@ public class AppMaster {
|
|
|
|
|
mService.updateMntn(newUrl);
|
|
|
|
|
}
|
|
|
|
|
} else if (TextUtils.equals(cmd, CMD_UPDATE_CONFIG)) {
|
|
|
|
|
JSONArray jsonConfigs = null;
|
|
|
|
|
try {
|
|
|
|
|
jsonConfigs = jsonObject.getJSONArray("configs");
|
|
|
|
|
String path = jsonObject.optString("path", null);
|
|
|
|
|
String fileName = jsonObject.optString("fileName", null);
|
|
|
|
|
|
|
|
|
|
mService.logger.warning("Recv Update Config: " + path + " " + fileName);
|
|
|
|
|
|
|
|
|
|
if (jsonConfigs != null) {
|
|
|
|
|
|
|
|
|
|
for (int idx = 0; idx < jsonConfigs.length(); idx++) {
|
|
|
|
|
JSONObject jsonConfig = jsonConfigs.getJSONObject(idx);
|
|
|
|
|
String configName = jsonConfig.optString("name", null);
|
|
|
|
|
int fieldType = jsonConfig.optInt("type", 0);
|
|
|
|
|
Object val = jsonConfig.opt("value");
|
|
|
|
|
|
|
|
|
|
updateConfig(path, fileName, configName, fieldType, val);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String packageName = jsonObject.optString("packageName", null);
|
|
|
|
|
if (packageName != null) {
|
|
|
|
|
MicroPhotoContext.restartApp(mService.getApplicationContext(), packageName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
}
|
|
|
|
|
updateConfigs(jsonObject);
|
|
|
|
|
} else if (TextUtils.equals(cmd, CMD_PUSH_FILE)) {
|
|
|
|
|
|
|
|
|
|
String path = jsonObject.optString("path", null);
|
|
|
|
@ -837,40 +812,33 @@ public class AppMaster {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean updateConfig(String path, String fileName, String name, int fieldType, Object val) {
|
|
|
|
|
private void updateConfigs(JSONObject jsonObject) {
|
|
|
|
|
JSONArray jsonConfigs = null;
|
|
|
|
|
try {
|
|
|
|
|
jsonConfigs = jsonObject.getJSONArray("configs");
|
|
|
|
|
String path = jsonObject.optString("path", null);
|
|
|
|
|
String fileName = jsonObject.optString("fileName", null);
|
|
|
|
|
|
|
|
|
|
if (name == null) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
mService.logger.warning("Recv Update Config: " + path + " " + fileName);
|
|
|
|
|
|
|
|
|
|
File configFile = new File(Environment.getExternalStorageDirectory(), path);
|
|
|
|
|
if (!configFile.exists()) {
|
|
|
|
|
if (val == null) {
|
|
|
|
|
// Should delete the config field
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (jsonConfigs != null) {
|
|
|
|
|
|
|
|
|
|
configFile.mkdirs();
|
|
|
|
|
}
|
|
|
|
|
for (int idx = 0; idx < jsonConfigs.length(); idx++) {
|
|
|
|
|
JSONObject jsonConfig = jsonConfigs.getJSONObject(idx);
|
|
|
|
|
String configName = jsonConfig.optString("name", null);
|
|
|
|
|
int fieldType = jsonConfig.optInt("type", 0);
|
|
|
|
|
Object val = jsonConfig.opt("value");
|
|
|
|
|
|
|
|
|
|
configFile = new File(configFile, fileName);
|
|
|
|
|
if (!configFile.exists() && val == null) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
JSONUtils.updateConfigFile(path, fileName, configName, fieldType, val);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = JSONUtils.loadJson(configFile.getAbsolutePath());
|
|
|
|
|
if (jsonObject == null) {
|
|
|
|
|
if (val == null) {
|
|
|
|
|
return true;
|
|
|
|
|
String packageName = jsonObject.optString("packageName", null);
|
|
|
|
|
if (packageName != null) {
|
|
|
|
|
MicroPhotoContext.restartApp(mService.getApplicationContext(), packageName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
jsonObject = new JSONObject();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!JSONUtils.updateJsonProperty(jsonObject, name, fieldType, val)) {
|
|
|
|
|
return false;
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return JSONUtils.saveJson(configFile.getAbsolutePath(), jsonObject);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String buildMntnServer(String server, int port) {
|
|
|
|
|