diff --git a/mpmaster/src/main/java/com/xypower/mpmaster/AppMaster.java b/mpmaster/src/main/java/com/xypower/mpmaster/AppMaster.java index fb2ce6ce..fcd356ce 100644 --- a/mpmaster/src/main/java/com/xypower/mpmaster/AppMaster.java +++ b/mpmaster/src/main/java/com/xypower/mpmaster/AppMaster.java @@ -75,6 +75,8 @@ 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 static final String CMD_UPD_OTA = "yw_upd_ota"; + 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_IMPORT_PUB_KEY = "imp_pub_key"; @@ -631,7 +633,7 @@ public class AppMaster { mService.logger.warning("Recv Del File: " + path); deleteFile(path); } else if (TextUtils.equals(cmd, CMD_IMPORT_PUB_KEY)) { - + importPublicKey(jsonObject); } else if (TextUtils.equals(cmd, CMD_UPD_OTA)) { String url = jsonObject.optString("url", null); String fileName = jsonObject.optString("fileName", null); @@ -640,9 +642,32 @@ public class AppMaster { if (!TextUtils.isEmpty(url)) { upgradeOta(cid, cmd, url, fileName, md5); } + } else if (TextUtils.equals(cmd, CMD_START_FRP)) { + startFrp(jsonObject); + } else if (TextUtils.equals(cmd, CMD_STOP_FRP)) { + stopFrp(jsonObject); + } + } + + private void startFrp(JSONObject jsonObject) { + try { + // SysApi.forceStopApp(context, packageName); + Context context = mService.getApplicationContext(); + Intent intent = context.getPackageManager().getLaunchIntentForPackage("io.github.acedroidx.frp"); + if (intent != null) { + intent.putExtra("startFrp", 1); + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + context.startActivity(intent); + } + } catch (Exception e) { + e.printStackTrace(); } } + private void stopFrp(JSONObject jsonObject) { + + } + private void importPublicKey(JSONObject jsonObject) { String content = jsonObject.optString("pubkey", null); String md5 = jsonObject.optString("md5", null); @@ -784,6 +809,7 @@ public class AppMaster { MicroPhotoContext.AppConfig appConfig = MicroPhotoContext.getMpAppConfig(mService.getApplicationContext()); if (TextUtils.equals(ip, appConfig.server) && port == appConfig.port) { + mService.logger.info("New CMA is not changed"); return true; } @@ -792,7 +818,20 @@ public class AppMaster { MicroPhotoContext.saveMpAppConfig(mService.getApplicationContext(), appConfig); - MicroPhotoContext.restartMpApp(mService.getApplicationContext()); + mService.logger.warning("Restart MpAPP for CMA changing"); + Thread th = new Thread(new Runnable() { + @Override + public void run() { + try { + Thread.sleep(1000); + } catch (Exception ex) { + + } + MicroPhotoContext.restartMpApp(mService.getApplicationContext()); + } + }); + + th.start(); return true; }