实现OTA升级

serial
Matthew 1 year ago
parent fae787835c
commit 12ecd9cbd1

@ -68,6 +68,7 @@ public class AppMaster {
public static final String CMD_HOT_SPOT = "yw_cmd_hot_spot";
public static final String CMD_ENABLE_GPS = "yw_cmd_enable_gps";
public static final String CMD_ENABLE_OTG = "yw_cmd_enable_otg";
public static final String CMD_UPD_OTA = "yw_upd_ota";
public static final String CMD_IMPORT_PUB_KEY = "imp_pub_key";
@ -513,6 +514,13 @@ public class AppMaster {
deleteFile(path);
} else if (TextUtils.equals(cmd, CMD_IMPORT_PUB_KEY)) {
} else if (TextUtils.equals(cmd, CMD_UPD_OTA)) {
String url = jsonObject.optString("url", null);
String fileName = jsonObject.optString("fileName", null);
String md5 = jsonObject.optString("md5", null);
if (!TextUtils.isEmpty(url)) {
upgradeOta(cid, cmd, url, fileName, md5);
}
}
}
@ -693,6 +701,30 @@ public class AppMaster {
}
}
private void upgradeOta(long cid, String action, String url, String fileName, String md5) {
mService.logger.warning("Recv Upgrade OTA: url=" + url);
FileDownloader dl = new FileDownloader();
File path = new File(MicroPhotoContext.buildAppDir(mService.getApplicationContext()), "ota");
if (!path.exists()) {
path.mkdirs();
}
File file = new File(path, fileName == null ? "ota.zip" : fileName);
if (file.exists()) {
file.delete();
}
String otaPath = file.getAbsolutePath();
if (dl.download(url, otaPath)) {
sendResult(cid, 1, action, action + ":" + mCmdid);
Context context = mService.getApplicationContext();
mService.logger.info("Upgrade OTA: " + url);
SysApi.installOTA(context, context.getPackageName(), otaPath);
}
}
private void uploadLogs(String url) {
String appDir = mService.buildAppDir();

@ -69,7 +69,9 @@ public class MpMasterService extends Service {
public static final String ACTION_STOP = "com.xypower.mpmaster.ACT_STOP";
public static final String ACTION_MAIN = "com.xypower.mpmaster.ACT_MAIN";
public static final String ACTION_UPD_OTA = "com.xy.otaupdateresult";
public static final String ACTION_UPD_OTA = SysApi.OTA_RESULT_ACTION;
public static final String ACTION_INSTALL_RESULT = SysApi.INSTALL_RESULT_ACTION;
public static final String ACTION_UNINSTALL_RESULT = SysApi.UNINSTALL_RESULT_ACTION;
private static final String ACTION_UPDATE_CONFIGS = "com.xypower.mpmaster.ACT_UPD_CFG";
@ -207,6 +209,8 @@ public class MpMasterService extends Service {
intentFilter.addAction(ACTION_MSG_BROADCAST);
intentFilter.addAction(ACTION_UPDATE_CONFIGS);
intentFilter.addAction(ACTION_UPD_OTA);
intentFilter.addAction(ACTION_INSTALL_RESULT);
intentFilter.addAction(ACTION_UNINSTALL_RESULT);
if (!mSeparateNetwork) {
intentFilter.addAction(MicroPhotoContext.ACTION_HEARTBEAT_MP);
}
@ -470,6 +474,48 @@ public class MpMasterService extends Service {
}
} else if (TextUtils.equals(ACTION_UPD_OTA, action)) {
String cmd = intent.getStringExtra("cmd");
String msg = intent.getStringExtra("msg");
// Log.e("_otg_","cmd="+cmd);
if("write".equals(cmd))
{
// int progress = Integer.parseInt(msg);
}
else if("update".equals(cmd))
{
// int progress = Integer.parseInt(msg);
}
else if("info".equals(cmd))
{
}
else if("error".equals(cmd))
{
mService.logger.warning("UPD OTA Failed");
}
else if("success".equals(cmd))
{
//confirm to reboot device ??
mService.logger.warning("UPD OTA Succeeded, will RESET dev");
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
SysApi.reboot(context);
}
}, 1000);
}
} else if (TextUtils.equals(ACTION_INSTALL_RESULT, action)) {
boolean bSucc = intent.getBooleanExtra("succ", false);
String pkname = intent.getStringExtra("pkname");
String msg = intent.getStringExtra("msg");
// Log.e("_otg_","install result bsuc="+bSucc+",pkname="+pkname+",msg="+msg);
mService.logger.warning("INSTALL APP result =" + bSucc + ",pkname=" + pkname + ",msg=" + msg);
} else if (TextUtils.equals(ACTION_UNINSTALL_RESULT, action)) {
boolean bSucc = intent.getBooleanExtra("succ", false);
String pkname = intent.getStringExtra("pkname");
String msg = intent.getStringExtra("msg");
mService.logger.warning("UNINSTALL APP result =" + bSucc + ",pkname=" + pkname + ",msg=" + msg);
}
}
}
@ -787,11 +833,12 @@ public class MpMasterService extends Service {
@Override
public void run() {
if (rebootType == 0) {
logger.warning("Recv REBOOT MpMst APP cmd");
Context context = MpMasterService.this.getApplicationContext();
restartApp(context, context.getPackageName());
} else {
Log.w(TAG, "Recv REBOOT command");
logger.warning("Recv RESET cmd");
SysApi.reboot(MpMasterService.this.getApplicationContext());
}
}
@ -820,6 +867,7 @@ public class MpMasterService extends Service {
}
public void selectSimCard(int num) {
logger.warning("Select SimCard: " + Integer.toString(num));
SysApi.selectSimCard4Data(getApplicationContext(), num);
}

Loading…
Cancel
Save