|
|
|
@ -34,6 +34,7 @@ import java.util.List;
|
|
|
|
|
public class AppMaster {
|
|
|
|
|
|
|
|
|
|
private MpMasterService mService;
|
|
|
|
|
private String mMasterUrl;
|
|
|
|
|
private String mCmdid;
|
|
|
|
|
private PowerManager.WakeLock mWakelock;
|
|
|
|
|
|
|
|
|
@ -49,13 +50,19 @@ public class AppMaster {
|
|
|
|
|
public static final String CMD_ENABLE_GPS = "yw_cmd_enable_gps";
|
|
|
|
|
public static final String CMD_ENABLE_OTG = "yw_cmd_enable_otg";
|
|
|
|
|
|
|
|
|
|
public AppMaster(MpMasterService service) {
|
|
|
|
|
|
|
|
|
|
PowerManager powerManager = (PowerManager) service.getSystemService(Context.POWER_SERVICE);
|
|
|
|
|
mWakelock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "com.xinyingpower.microphoto:Upgrader");
|
|
|
|
|
public AppMaster(MpMasterService service, String masterUrl, String cmdid) {
|
|
|
|
|
|
|
|
|
|
mService = service;
|
|
|
|
|
// mCmdid = cmdid;
|
|
|
|
|
mMasterUrl = masterUrl;
|
|
|
|
|
mCmdid = cmdid;
|
|
|
|
|
mWakelock = null;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
PowerManager powerManager = (PowerManager) service.getSystemService(Context.POWER_SERVICE);
|
|
|
|
|
mWakelock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "com.xypower.mpmaster:MpMaster");
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -79,18 +86,7 @@ public class AppMaster {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
|
|
|
|
|
String masterUrl = MicroPhotoContext.DEFAULT_MASTER_URL;
|
|
|
|
|
|
|
|
|
|
String path = mService.buildAppDir();
|
|
|
|
|
path += "data/Master.json";
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = JSONUtils.loadJson(path);
|
|
|
|
|
if (jsonObject != null && jsonObject.has("url")) {
|
|
|
|
|
masterUrl = jsonObject.optString("url");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MicroPhotoContext.AppConfig appConfig = MicroPhotoContext.getMpAppConfig(mService.getApplicationContext());
|
|
|
|
|
mCmdid = appConfig.cmdid;
|
|
|
|
|
String masterUrl = mMasterUrl;
|
|
|
|
|
|
|
|
|
|
if (TextUtils.isEmpty(masterUrl)) {
|
|
|
|
|
return;
|
|
|
|
@ -151,6 +147,11 @@ public class AppMaster {
|
|
|
|
|
String url = jsonObject.optString("url", null);
|
|
|
|
|
String cmd = jsonObject.optString("cmd", "");
|
|
|
|
|
|
|
|
|
|
int mntnMode = jsonObject.optInt("yw", 0);
|
|
|
|
|
int quickHbMode = jsonObject.optInt("kxt", 0);
|
|
|
|
|
|
|
|
|
|
mService.setMntnMode(mntnMode != 0, quickHbMode != 0);
|
|
|
|
|
|
|
|
|
|
if (isUpgrade == 1 && !TextUtils.isEmpty(url)) {
|
|
|
|
|
upgradeApp(url);
|
|
|
|
|
} else if (TextUtils.equals(cmd, CMD_REBOOT_DEV)) {
|
|
|
|
@ -164,7 +165,10 @@ public class AppMaster {
|
|
|
|
|
} else if (TextUtils.equals(cmd, CMD_SET_MNTN)) {
|
|
|
|
|
String ip = jsonObject.optString("value_str", null);
|
|
|
|
|
int port = jsonObject.optInt("value_int", 0);
|
|
|
|
|
updateMntnServer(ip, port);
|
|
|
|
|
String newUrl = buildMntnServer(ip, port);
|
|
|
|
|
if (newUrl != null) {
|
|
|
|
|
mService.updateMntn(newUrl);
|
|
|
|
|
}
|
|
|
|
|
} else if (TextUtils.equals(cmd, CMD_UPDATE_CONFIG)) {
|
|
|
|
|
String path = jsonObject.optString("path", null);
|
|
|
|
|
String fileName = jsonObject.optString("fileName", null);
|
|
|
|
@ -230,9 +234,9 @@ public class AppMaster {
|
|
|
|
|
return JSONUtils.saveJson(configFile.getAbsolutePath(), jsonObject);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean updateMntnServer(String server, int port) {
|
|
|
|
|
private String buildMntnServer(String server, int port) {
|
|
|
|
|
if (TextUtils.isEmpty(server) && port == 0) {
|
|
|
|
|
return false;
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String url = null;
|
|
|
|
@ -244,13 +248,7 @@ public class AppMaster {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (url == null) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mService.updateMntn(url);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
return url;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean updateCma(String ip, int port) {
|
|
|
|
|