|
|
|
@ -22,6 +22,7 @@ import com.xypower.common.MD5Util;
|
|
|
|
|
import com.xypower.common.MicroPhotoContext;
|
|
|
|
|
import com.xypower.common.ThermalInfoUtil;
|
|
|
|
|
import com.xypower.common.ZipUtils;
|
|
|
|
|
import com.xypower.mpmaster.sms.StringUtils;
|
|
|
|
|
|
|
|
|
|
import org.json.JSONArray;
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
@ -509,28 +510,26 @@ public class AppMaster {
|
|
|
|
|
if (TextUtils.isEmpty(content)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
mService.logger.info(content);
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = new JSONObject(content);
|
|
|
|
|
int isUpgrade = jsonObject.optInt("isUpgrade", 0);
|
|
|
|
|
String oldMd5 = jsonObject.optString("oldMd5");
|
|
|
|
|
String newMd5 = jsonObject.optString("newMd5");
|
|
|
|
|
String url = jsonObject.optString("url", null);
|
|
|
|
|
long cid = jsonObject.optLong("cid", 0);
|
|
|
|
|
|
|
|
|
|
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(cid, "upgrade", url);
|
|
|
|
|
} else if (isUpgrade == 2 && !TextUtils.isEmpty(url)) {
|
|
|
|
|
upgradeAppOta(cid,"upgrade",url,oldMd5,newMd5);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
processCmd(cid, jsonObject);
|
|
|
|
|
|
|
|
|
|
JSONArray cmdObjects = jsonObject.optJSONArray("cmds");
|
|
|
|
|
|
|
|
|
|
if (cmdObjects != null) {
|
|
|
|
|
int cnt = cmdObjects.length();
|
|
|
|
|
for (int idx = 0; idx < cnt; idx++) {
|
|
|
|
@ -541,11 +540,9 @@ public class AppMaster {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void sendResult(long cid, int result, String action, String content) {
|
|
|
|
@ -996,15 +993,12 @@ public class AppMaster {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void upgradeApp(long cid, String action, String url) {
|
|
|
|
|
|
|
|
|
|
mService.logger.warning("Recv Upgrade Cmd: url=" + url);
|
|
|
|
|
|
|
|
|
|
FileDownloader dl = new FileDownloader();
|
|
|
|
|
File path = new File(MicroPhotoContext.buildAppDir(mService.getApplicationContext()), "packages");
|
|
|
|
|
if (!path.exists()) {
|
|
|
|
|
path.mkdirs();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
File file = new File(path, "app.apk");
|
|
|
|
|
if (file.exists()) {
|
|
|
|
|
file.delete();
|
|
|
|
@ -1014,7 +1008,6 @@ public class AppMaster {
|
|
|
|
|
// sendResult(cid, 1, action, action + ":" + mCmdid);
|
|
|
|
|
Context context = mService.getApplicationContext();
|
|
|
|
|
mService.logger.info("Upgrade APP: " + url);
|
|
|
|
|
|
|
|
|
|
SysApi.installApk(context, apkPath, context.getPackageName(), true);
|
|
|
|
|
sendResult(cid, 1, action, action + ":" + mCmdid + " is installing");
|
|
|
|
|
} else {
|
|
|
|
@ -1023,6 +1016,57 @@ public class AppMaster {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void upgradeAppOta(long cid, String action, String url,String oldMd5,String newMd5) {
|
|
|
|
|
mService.logger.warning("Recv upgradeAppOta Cmd: url=" + url);
|
|
|
|
|
if (StringUtils.isEmpty(oldMd5)|| StringUtils.isEmpty(newMd5)) {
|
|
|
|
|
mService.logger.warning("upgradeAppOta oldMd5或者newMd5缺失");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Context context = mService.getApplicationContext();
|
|
|
|
|
String urlMd5 = MD5Util.md5(url);//获取URL的Md5
|
|
|
|
|
File path = new File(MicroPhotoContext.buildAppDir(mService.getApplicationContext()), "packages");
|
|
|
|
|
if (!path.exists()) {
|
|
|
|
|
path.mkdirs();
|
|
|
|
|
}
|
|
|
|
|
//Patch存储路径
|
|
|
|
|
File patchFile = new File(path, urlMd5+".PATCH");
|
|
|
|
|
if (patchFile.exists()) {
|
|
|
|
|
patchFile.delete();
|
|
|
|
|
}
|
|
|
|
|
String patchPath = patchFile.getAbsolutePath();
|
|
|
|
|
|
|
|
|
|
//老的Apk路径
|
|
|
|
|
File oldApk = new File(path, oldMd5 + ".apk");
|
|
|
|
|
if (!oldApk.exists()) {
|
|
|
|
|
mService.logger.warning("upgradeAppOta未找到对应apk:" + oldMd5);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
String oldApkPath = oldApk.getAbsolutePath();
|
|
|
|
|
|
|
|
|
|
//新的Apk路径
|
|
|
|
|
File newApk = new File(path, newMd5 + ".apk");
|
|
|
|
|
String newApkPath = newApk.getAbsolutePath();
|
|
|
|
|
|
|
|
|
|
//文件下载
|
|
|
|
|
FileDownloader dl = new FileDownloader();
|
|
|
|
|
if (dl.download(url, patchPath)) {
|
|
|
|
|
mService.logger.info("upgradeAppOta APP: " + url);
|
|
|
|
|
if (oldApk.exists()) {
|
|
|
|
|
boolean b = MpMasterService.applyPatch(oldApkPath, patchPath, newApkPath);
|
|
|
|
|
if (b ) {
|
|
|
|
|
String fileMd5 = MD5Util.getFileMd5(newApk.getAbsolutePath());
|
|
|
|
|
if (newMd5.equals(fileMd5)) {
|
|
|
|
|
SysApi.installApk(context, newApkPath, context.getPackageName(), true);
|
|
|
|
|
sendResult(cid, 1, action, action + ":" + mCmdid + " is installing");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
mService.logger.warning("Failed to Download:" + url);
|
|
|
|
|
sendResult(cid, 1, action, action + ":" + mCmdid + " download failed");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void upgradeOta(long cid, String action, String url, String fileName, String md5) {
|
|
|
|
|
|
|
|
|
|
mService.logger.warning("Recv Upgrade OTA: url=" + url);
|
|
|
|
|