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数据获取