From 7169f1829ec4ae8191887afcc38561789d7c843d Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 6 Aug 2024 16:01:56 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=9A=E8=BF=87=E7=9F=AD=E4=BF=A1=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E6=A0=A1=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit at-auto-time act=on type=net 打开网络对时 at-auto-time act=off type=net 关闭网络对时 type可以设置为 gps,说明是用gps对时 at-auto-time后面没有参数,或者参数不正确,或者设置成功了,都会返回当前的值 --- .../com/xypower/mpmaster/sms/SimUtil.java | 62 +++++++++++++++++++ .../com/xypower/mpmaster/sms/SmsTypeEnum.java | 1 + 2 files changed, 63 insertions(+) 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 40280db3..531da187 100644 --- a/mpmaster/src/main/java/com/xypower/mpmaster/sms/SimUtil.java +++ b/mpmaster/src/main/java/com/xypower/mpmaster/sms/SimUtil.java @@ -449,6 +449,10 @@ public class SimUtil { sendtype = SmsTypeEnum.SIMCARD.value(); ifmessageCorrect = true; sendmessage = getSimcardInfo(context); + } else if (content.contains(SmsTypeEnum.SET_AUTO_TIME.value())) { + sendtype = SmsTypeEnum.SIMCARD.value(); + ifmessageCorrect = true; + sendmessage = setAutoTime(context, content); } else if (content.contains(SmsTypeEnum.SET_TP.value())) { sendtype = SmsTypeEnum.SET_TP.value(); String[] split1 = StringUtils.splitString1(content); @@ -620,6 +624,64 @@ public class SimUtil { return result.toString().trim(); } + private static String setAutoTime(Context context, String content) { + String result; + try { + String[] parts = TextUtils.split(content.substring(SmsTypeEnum.SET_AUTO_TIME.value().length()), "(\\s|,|,)"); + if (parts != null) { + int autoTimeType = 0; + boolean onOff = false; + 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, "act")) { + if (TextUtils.equals(value, "on")) { + onOff = true; + } + } + else if (TextUtils.equals(key, "type")) { + if (TextUtils.equals(value, "net")) { + autoTimeType = 1; + } else if (TextUtils.equals(value, "gps")) { + autoTimeType = 2; + } + } + } + + if (autoTimeType != 0) { + if (autoTimeType == 1) { + SysApi.setGlobalInt(context, "auto_time", onOff ? 1 : 0); + } else if (autoTimeType == 2) { + SysApi.setGlobalInt(context, "auto_time_gps", onOff ? 1 : 0); + } + } + // query the value + } + } catch (Exception ex) { + ex.printStackTrace(); + } + + try { + int autoTime = SysApi.getGlobalInt(context, "auto_time"); + int autoTimeGps = SysApi.getGlobalInt(context, "auto_time_gps"); + + result = "auto_time=" + Integer.toString(autoTime) + " auto_time_gps" + Integer.toString(autoTimeGps); + } catch (Exception ex) { + ex.printStackTrace(); + } + + return result; + } + 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 208c04cd..c8538fb8 100644 --- a/mpmaster/src/main/java/com/xypower/mpmaster/sms/SmsTypeEnum.java +++ b/mpmaster/src/main/java/com/xypower/mpmaster/sms/SmsTypeEnum.java @@ -45,6 +45,7 @@ public enum SmsTypeEnum { CLEAR_ALL("yw+at+clearAll"), //清除图片、视频、日志 RESTORE("yw+at+Restore"), //恢复出厂设置 SIMCARD("at+str=sim"), + SET_AUTO_TIME("at-auto-time "), // act=[on/off] type=[net/gps] GET_GPS("yw+at+getGPS");//GPS数据获取