|
|
@ -81,6 +81,8 @@ public class AppMaster {
|
|
|
|
public static final String CMD_START_FRP = "yw_cmd_start_frpc";
|
|
|
|
public static final String CMD_START_FRP = "yw_cmd_start_frpc";
|
|
|
|
public static final String CMD_STOP_FRP = "yw_cmd_stop_frpc";
|
|
|
|
public static final String CMD_STOP_FRP = "yw_cmd_stop_frpc";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static final String CMD_APP_UPD_OTA = "yw_app_upd_ota";
|
|
|
|
|
|
|
|
|
|
|
|
public static final String CMD_IMPORT_PUB_KEY = "imp_pub_key";
|
|
|
|
public static final String CMD_IMPORT_PUB_KEY = "imp_pub_key";
|
|
|
|
|
|
|
|
|
|
|
|
public AppMaster(MpMasterService service, String masterUrl, String cmdid, boolean bundleWithMpApp) {
|
|
|
|
public AppMaster(MpMasterService service, String masterUrl, String cmdid, boolean bundleWithMpApp) {
|
|
|
@ -162,12 +164,12 @@ public class AppMaster {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int masterHttpstatus = 0;//0--接口请求正常但未处理 1--访问运维服务器正常,处理也正常 -1----访问运维服务器异常
|
|
|
|
int masterHttpstatus = 0;//0--接口请求正常但未处理 1--访问运维服务器正常,处理也正常 -1----访问运维服务器异常
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
masterHttpstatus= runImpl(isCriticalTime);
|
|
|
|
masterHttpstatus = runImpl(isCriticalTime);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
ex.printStackTrace();
|
|
|
|
}finally {
|
|
|
|
} finally {
|
|
|
|
if (masterHttpstatus == -1) {
|
|
|
|
if (masterHttpstatus == -1) {
|
|
|
|
mService.setMntnMode(false,false);
|
|
|
|
mService.setMntnMode(false, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception ex) {
|
|
|
|
} catch (Exception ex) {
|
|
|
@ -514,8 +516,6 @@ public class AppMaster {
|
|
|
|
mService.logger.info(content);
|
|
|
|
mService.logger.info(content);
|
|
|
|
JSONObject jsonObject = new JSONObject(content);
|
|
|
|
JSONObject jsonObject = new JSONObject(content);
|
|
|
|
int isUpgrade = jsonObject.optInt("isUpgrade", 0);
|
|
|
|
int isUpgrade = jsonObject.optInt("isUpgrade", 0);
|
|
|
|
String oldMd5 = jsonObject.optString("oldMd5");
|
|
|
|
|
|
|
|
String newMd5 = jsonObject.optString("newMd5");
|
|
|
|
|
|
|
|
String url = jsonObject.optString("url", null);
|
|
|
|
String url = jsonObject.optString("url", null);
|
|
|
|
long cid = jsonObject.optLong("cid", 0);
|
|
|
|
long cid = jsonObject.optLong("cid", 0);
|
|
|
|
int mntnMode = jsonObject.optInt("yw", 0);
|
|
|
|
int mntnMode = jsonObject.optInt("yw", 0);
|
|
|
@ -524,8 +524,6 @@ public class AppMaster {
|
|
|
|
mService.setMntnMode(mntnMode != 0, quickHbMode != 0);
|
|
|
|
mService.setMntnMode(mntnMode != 0, quickHbMode != 0);
|
|
|
|
if (isUpgrade == 1 && !TextUtils.isEmpty(url)) {
|
|
|
|
if (isUpgrade == 1 && !TextUtils.isEmpty(url)) {
|
|
|
|
upgradeApp(cid, "upgrade", url);
|
|
|
|
upgradeApp(cid, "upgrade", url);
|
|
|
|
} else if (isUpgrade == 2 && !TextUtils.isEmpty(url)) {
|
|
|
|
|
|
|
|
upgradeAppOta(cid,"upgrade",url,oldMd5,newMd5);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
processCmd(cid, jsonObject);
|
|
|
|
processCmd(cid, jsonObject);
|
|
|
@ -713,9 +711,26 @@ public class AppMaster {
|
|
|
|
startFrp(jsonObject);
|
|
|
|
startFrp(jsonObject);
|
|
|
|
} else if (TextUtils.equals(cmd, CMD_STOP_FRP)) {
|
|
|
|
} else if (TextUtils.equals(cmd, CMD_STOP_FRP)) {
|
|
|
|
stopFrp(jsonObject);
|
|
|
|
stopFrp(jsonObject);
|
|
|
|
|
|
|
|
} else if (TextUtils.equals(cmd, CMD_APP_UPD_OTA)) {
|
|
|
|
|
|
|
|
String otaurl = jsonObject.optString("otaurl", null);
|
|
|
|
|
|
|
|
String oldurl = jsonObject.optString("oldurl", null);
|
|
|
|
|
|
|
|
String appurl = jsonObject.optString("appurl", null);
|
|
|
|
|
|
|
|
String checkMd5 = jsonObject.optString("checkMd5", null);
|
|
|
|
|
|
|
|
if (!TextUtils.isEmpty(otaurl)) {
|
|
|
|
|
|
|
|
upgradeAppOta(cid, cmd, otaurl, oldurl, appurl, checkMd5);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* cmd: yw_app_upd_ota //App增量更新
|
|
|
|
|
|
|
|
* oldurl: //老版本Apk的url
|
|
|
|
|
|
|
|
* otaurl: //新版本Apk的Md5
|
|
|
|
|
|
|
|
* appurl: //新版本Apk的Md5
|
|
|
|
|
|
|
|
* checkMd5: //增量包的下载URL
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* */
|
|
|
|
private void startFrp(JSONObject jsonObject) {
|
|
|
|
private void startFrp(JSONObject jsonObject) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// SysApi.forceStopApp(context, packageName);
|
|
|
|
// SysApi.forceStopApp(context, packageName);
|
|
|
@ -1016,56 +1031,67 @@ public class AppMaster {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void upgradeAppOta(long cid, String action, String url,String oldMd5,String newMd5) {
|
|
|
|
private void upgradeAppOta(long cid, String action, String otaurl, String oldurl, String newurl, String checkMd5) {
|
|
|
|
mService.logger.warning("Recv upgradeAppOta Cmd: url=" + url);
|
|
|
|
mService.logger.warning("Recv upgradeAppOta Cmd: url=" + otaurl);
|
|
|
|
if (StringUtils.isEmpty(oldMd5)|| StringUtils.isEmpty(newMd5)) {
|
|
|
|
if (StringUtils.isEmpty(otaurl) || StringUtils.isEmpty(oldurl) || StringUtils.isEmpty(newurl)) {
|
|
|
|
mService.logger.warning("upgradeAppOta oldMd5或者newMd5缺失");
|
|
|
|
mService.logger.warning("upgradeAppOta otaurl,oldurl或者newurl缺失");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Context context = mService.getApplicationContext();
|
|
|
|
Context context = mService.getApplicationContext();
|
|
|
|
String urlMd5 = MD5Util.md5(url);//获取URL的Md5
|
|
|
|
String otaurlMd5 = MD5Util.md5(otaurl);//获取URL的Md5
|
|
|
|
File path = new File(MicroPhotoContext.buildAppDir(mService.getApplicationContext()), "packages");
|
|
|
|
File path = new File(MicroPhotoContext.buildAppDir(mService.getApplicationContext()), "packages");
|
|
|
|
if (!path.exists()) {
|
|
|
|
if (!path.exists()) {
|
|
|
|
path.mkdirs();
|
|
|
|
path.mkdirs();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//Patch存储路径
|
|
|
|
//Patch存储路径
|
|
|
|
File patchFile = new File(path, urlMd5+".PATCH");
|
|
|
|
File patchFile = new File(path, otaurlMd5 + ".PATCH");
|
|
|
|
if (patchFile.exists()) {
|
|
|
|
if (patchFile.exists()) {
|
|
|
|
patchFile.delete();
|
|
|
|
patchFile.delete();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String patchPath = patchFile.getAbsolutePath();
|
|
|
|
String patchPath = patchFile.getAbsolutePath();
|
|
|
|
|
|
|
|
|
|
|
|
//老的Apk路径
|
|
|
|
//老的Apk路径
|
|
|
|
File oldApk = new File(path, oldMd5 + ".apk");
|
|
|
|
String oldurlMd5 = MD5Util.md5(oldurl);//获取URL的Md5
|
|
|
|
if (!oldApk.exists()) {
|
|
|
|
File oldApk = new File(path, oldurlMd5 + ".apk");
|
|
|
|
mService.logger.warning("upgradeAppOta未找到对应apk:" + oldMd5);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String oldApkPath = oldApk.getAbsolutePath();
|
|
|
|
String oldApkPath = oldApk.getAbsolutePath();
|
|
|
|
|
|
|
|
|
|
|
|
//新的Apk路径
|
|
|
|
//新的Apk路径
|
|
|
|
File newApk = new File(path, newMd5 + ".apk");
|
|
|
|
String newurlMd5 = MD5Util.md5(newurl);//获取URL的Md5
|
|
|
|
|
|
|
|
File newApk = new File(path, newurlMd5 + ".apk");
|
|
|
|
String newApkPath = newApk.getAbsolutePath();
|
|
|
|
String newApkPath = newApk.getAbsolutePath();
|
|
|
|
|
|
|
|
|
|
|
|
//文件下载
|
|
|
|
|
|
|
|
FileDownloader dl = new FileDownloader();
|
|
|
|
FileDownloader dl = new FileDownloader();
|
|
|
|
if (dl.download(url, patchPath)) {
|
|
|
|
if (!oldApk.exists()) {
|
|
|
|
mService.logger.info("upgradeAppOta APP: " + url);
|
|
|
|
mService.logger.warning("upgradeAppOta未找到对应apk:" + oldurlMd5);
|
|
|
|
|
|
|
|
//文件下载
|
|
|
|
|
|
|
|
if (dl.download(newurl, patchPath)) {
|
|
|
|
|
|
|
|
mService.logger.info("upgradeAppOta TOTAL_APP: " + newurl);
|
|
|
|
|
|
|
|
String fileMd5 = MD5Util.getFileMd5(newApk.getAbsolutePath());
|
|
|
|
|
|
|
|
if (checkMd5.equals(fileMd5)) {
|
|
|
|
|
|
|
|
SysApi.installApk(context, newApkPath, context.getPackageName(), true);
|
|
|
|
|
|
|
|
sendResult(cid, 1, action, action + ":" + mCmdid + " is installing");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
//文件下载
|
|
|
|
|
|
|
|
if (dl.download(otaurl, patchPath)) {
|
|
|
|
|
|
|
|
mService.logger.info("upgradeAppOta OTA_APP: " + otaurl);
|
|
|
|
if (oldApk.exists()) {
|
|
|
|
if (oldApk.exists()) {
|
|
|
|
boolean b = MpMasterService.applyPatch(oldApkPath, patchPath, newApkPath);
|
|
|
|
boolean b = MpMasterService.applyPatch(oldApkPath, patchPath, newApkPath);
|
|
|
|
if (b ) {
|
|
|
|
if (b) {
|
|
|
|
String fileMd5 = MD5Util.getFileMd5(newApk.getAbsolutePath());
|
|
|
|
String fileMd5 = MD5Util.getFileMd5(newApk.getAbsolutePath());
|
|
|
|
if (newMd5.equals(fileMd5)) {
|
|
|
|
if (checkMd5.equals(fileMd5)) {
|
|
|
|
SysApi.installApk(context, newApkPath, context.getPackageName(), true);
|
|
|
|
SysApi.installApk(context, newApkPath, context.getPackageName(), true);
|
|
|
|
sendResult(cid, 1, action, action + ":" + mCmdid + " is installing");
|
|
|
|
sendResult(cid, 1, action, action + ":" + mCmdid + " is installing");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
mService.logger.warning("Failed to Download:" + url);
|
|
|
|
mService.logger.warning("Failed to Download:" + otaurl);
|
|
|
|
sendResult(cid, 1, action, action + ":" + mCmdid + " download failed");
|
|
|
|
sendResult(cid, 1, action, action + ":" + mCmdid + " download failed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void upgradeOta(long cid, String action, String url, String fileName, String md5) {
|
|
|
|
private void upgradeOta(long cid, String action, String url, String fileName, String md5) {
|
|
|
|
|
|
|
|
|
|
|
|