From f68567d21d3b16789dff9d14edd507fa44c11bd7 Mon Sep 17 00:00:00 2001 From: Matthew Date: Sat, 10 Aug 2024 19:31:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E9=80=9A=E8=BF=87=E7=9F=AD?= =?UTF-8?q?=E4=BF=A1=E4=BF=AE=E6=94=B9=E9=85=8D=E7=BD=AE=E7=9A=84=E9=80=9A?= =?UTF-8?q?=E7=94=A8=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/xypower/common/MicroPhotoContext.java | 1 + .../com/xypower/mpmaster/MpMasterService.java | 2 +- .../com/xypower/mpmaster/sms/SimUtil.java | 106 +++++++++++++++++- .../com/xypower/mpmaster/sms/SmsTypeEnum.java | 1 + 4 files changed, 108 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/com/xypower/common/MicroPhotoContext.java b/common/src/main/java/com/xypower/common/MicroPhotoContext.java index d21ee354..8646f3c8 100644 --- a/common/src/main/java/com/xypower/common/MicroPhotoContext.java +++ b/common/src/main/java/com/xypower/common/MicroPhotoContext.java @@ -31,6 +31,7 @@ public class MicroPhotoContext { public static final String PACKAGE_NAME_MPMASTER = "com.xypower.mpmaster"; public static final String ACTION_HEARTBEAT_MP = "com.xypower.mpapp.ACT_HB"; public static final String ACTION_RESTART_MP = "com.xypower.mpapp.ACT_RESTART"; + public static final String ACTION_UPDATE_CONFIGS_MP = "com.xypower.mpapp.ACT_UPD_CFG"; public final static String DEFAULT_MASTER_SERVER = "61.169.135.150"; public final static int DEFAULT_MASTER_PORT = 40101; diff --git a/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java b/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java index f7d0c82c..026c976d 100644 --- a/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java +++ b/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java @@ -1032,7 +1032,7 @@ public class MpMasterService extends Service { public void reloadMpAppConfigs() { Intent intent = new Intent(); - intent.setAction(ACTION_UPDATE_CONFIGS); + intent.setAction(MicroPhotoContext.ACTION_UPDATE_CONFIGS_MP); intent.setPackage(MicroPhotoContext.PACKAGE_NAME_MPAPP); sendBroadcast(intent); } diff --git a/mpmaster/src/main/java/com/xypower/mpmaster/sms/SimUtil.java b/mpmaster/src/main/java/com/xypower/mpmaster/sms/SimUtil.java index ac889771..43e065a1 100644 --- a/mpmaster/src/main/java/com/xypower/mpmaster/sms/SimUtil.java +++ b/mpmaster/src/main/java/com/xypower/mpmaster/sms/SimUtil.java @@ -28,11 +28,14 @@ import androidx.core.app.ActivityCompat; import com.dev.devapi.api.SysApi; import com.xypower.common.FilesUtils; +import com.xypower.common.JSONUtils; import com.xypower.common.MicroPhotoContext; import com.xypower.common.NetworkUtils; import com.xypower.common.RegexUtil; import com.xypower.mpmaster.MpMasterService; +import org.json.JSONObject; + import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; @@ -40,6 +43,7 @@ import java.util.Base64; import java.util.Date; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.TimeZone; import java.util.concurrent.ExecutionException; @@ -454,9 +458,14 @@ public class SimUtil { ifmessageCorrect = true; sendmessage = getSimcardInfo(context); } else if (content.contains(SmsTypeEnum.SET_AUTO_TIME.value())) { - sendtype = SmsTypeEnum.SIMCARD.value(); + sendtype = SmsTypeEnum.SET_AUTO_TIME.value(); ifmessageCorrect = true; sendmessage = setAutoTime(context, content); + } else if (content.contains(SmsTypeEnum.UPD_CFG_FILE.value())) { + sendtype = SmsTypeEnum.UPD_CFG_FILE.value(); + ifmessageCorrect = true; + sendmessage = " OK"; + updateConfigFile(context, content); } else if (content.contains(SmsTypeEnum.SET_TP.value())) { sendtype = SmsTypeEnum.SET_TP.value(); String[] split1 = StringUtils.splitString1(content); @@ -686,6 +695,101 @@ public class SimUtil { return result; } + private static void updateConfigFile(Context context, String content) { + String result = ""; + Map fields = new HashMap<>(); + int rebootMpApp = 0; + + try { + String[] parts = TextUtils.split(content.substring(SmsTypeEnum.UPD_CFG_FILE.value().length()), "(\\s|,|,)"); + int fileType = 0; + int numberOfFields = 0; + + if (parts != null) { + for (String part : parts) { + if (TextUtils.isEmpty(part)) { + continue; + } + + int pos = part.indexOf("="); + if (pos == -1) { + continue; + } + + String key = part.substring(0, pos); + String value = part.substring(pos + 1); + if (TextUtils.equals(key, "f")) { + fileType = Integer.parseInt(value); + } else if (TextUtils.equals(key, "c")) { + numberOfFields = Integer.parseInt(value); + } else if (TextUtils.equals(key, "r")) { + rebootMpApp = Integer.parseInt(value); + } else { + fields.put(key, value); + } + } + + String filePath = null; + String fileName = null; + switch (fileType) { + case 1: + filePath = MicroPhotoContext.buildMpAppDir(context) + "/data/"; + fileName = "App.json"; + break; + case 2: + filePath = MicroPhotoContext.buildMasterAppDir(context) + "/data/"; + fileName = "Master.json"; + break; + case 91: + case 92: + case 93: + case 94: + case 95: + case 96: + case 97: + case 98: + case 99: + filePath = MicroPhotoContext.buildMpAppDir(context) + "/data/channels/"; + fileName = Integer.toString(fileType - 90) + ".json"; + break; + default: + break; + } + + if (!TextUtils.isEmpty(filePath) && !TextUtils.isEmpty(fileName) && numberOfFields > 0) { + for (int idx = 0; idx <= numberOfFields; idx++) { + String idxStr = Integer.toString(idx); + // JSONObject jsonConfig = jsonConfigs.getJSONObject(idx); + String configName = fields.containsKey("n" + idxStr) ? fields.get("n" + idxStr) : null; + int configType = fields.containsKey("t" + idxStr) ? Integer.parseInt(fields.get("t" + idxStr)) : 0; + String configValue = fields.containsKey("v" + idxStr) ? fields.get("v" + idxStr) : null; + + if (configType == 0) { // Number + Long val = Long.parseLong(configValue); + JSONUtils.updateConfigFile(filePath, fileName, configName, configType, val); + } else if (configType == 2) { // Float + Float val = Float.parseFloat(configValue); + JSONUtils.updateConfigFile(filePath, fileName, configName, configType, val); + } else { + JSONUtils.updateConfigFile(filePath, fileName, configName, configType, configValue); + } + } + + if (rebootMpApp != 0) { + MicroPhotoContext.restartMpApp(context); + } else { + Intent intent = new Intent(); + intent.setAction(MicroPhotoContext.ACTION_UPDATE_CONFIGS_MP); + intent.setPackage(MicroPhotoContext.PACKAGE_NAME_MPAPP); + context.sendBroadcast(intent); + } + } + } + } catch (Exception ex) { + ex.printStackTrace(); + } + } + public static String getSimStateName(int simState) { switch (simState) { case TelephonyManager.SIM_STATE_UNKNOWN: diff --git a/mpmaster/src/main/java/com/xypower/mpmaster/sms/SmsTypeEnum.java b/mpmaster/src/main/java/com/xypower/mpmaster/sms/SmsTypeEnum.java index dd44b4de..7ab4bf73 100644 --- a/mpmaster/src/main/java/com/xypower/mpmaster/sms/SmsTypeEnum.java +++ b/mpmaster/src/main/java/com/xypower/mpmaster/sms/SmsTypeEnum.java @@ -46,6 +46,7 @@ public enum SmsTypeEnum { RESTORE("yw+at+Restore"), //恢复出厂设置 SIMCARD("at+str=sim"), SET_AUTO_TIME("at-auto-time"), // act=[on/off] type=[net/gps] + UPD_CFG_FILE("at-updcfg"), // f=[1/2/3] c=[field count] n1=[field name] t1=[0/1/2] v1= GET_GPS("yw+at+getGPS");//GPS数据获取