短信通用版本修改中:新增文件替换,文件获取,文件参数修改

streaming
liuguijing 4 months ago
parent becda30777
commit 30e4562f1d

@ -11,8 +11,6 @@ import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.database.Cursor; import android.database.Cursor;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkInfo;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
@ -30,12 +28,9 @@ import androidx.core.app.ActivityCompat;
import com.dev.devapi.api.SysApi; import com.dev.devapi.api.SysApi;
import com.xypower.common.FilesUtils; import com.xypower.common.FilesUtils;
import com.xypower.common.JSONUtils; import com.xypower.common.JSONUtils;
import com.xypower.common.MicroPhotoContext;
import com.xypower.common.NetworkUtils; import com.xypower.common.NetworkUtils;
import com.xypower.common.RegexUtil;
import com.xypower.mpmaster.MpMasterService; import com.xypower.mpmaster.MpMasterService;
import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.File; import java.io.File;
@ -60,9 +55,7 @@ public class SimUtil {
// 自定义ACTION常数 作为广播的IntentFilter识别常数 // 自定义ACTION常数 作为广播的IntentFilter识别常数
public static String SMS_SEND_ACTION = "com.xypower.mpmaster.SMS_SEND_ACTION"; public static String SMS_SEND_ACTION = "com.xypower.mpmaster.SMS_SEND_ACTION";
public static String SMSTYPE = "smstype"; public static String RESTARTTYPE = "restartType";
public static String SMSIFCORRECT = "smsifcorrect";
private static int mRequestCode = 1; private static int mRequestCode = 1;
@ -77,25 +70,21 @@ public class SimUtil {
} }
int slot = smsInfo.getSlot();//那张卡收到的短信 int slot = smsInfo.getSlot();//那张卡收到的短信
String sender = smsInfo.getSender();//收到的短信的手机号 String sender = smsInfo.getSender();//收到的短信的手机号
String sendmessage = "ERROR";//要回复的短信 String sendmessage = null;//要回复的短信
String sendtype = "";//收到的短信类型 int restartType = 0;//重启类型
List<Integer> abslist = new ArrayList<>();//收到的短信内容拆分包装成数组
boolean ifmessageCorrect = false;//用来判断收到的短信内容是否正确
if (StringUtils.isEmpty(content)) { if (StringUtils.isEmpty(content)) {
return; return;
} }
if (content.toLowerCase().contains(SmsTypeEnum.UPD_CFG_FILE.value().toLowerCase())) { //修改配置文件中参数 if (content.toLowerCase().contains(SmsTypeEnum.UPD_CFG_FILE.value().toLowerCase())) { //修改配置文件中参数
updateConfigFile(ifmessageCorrect, context, content); updateConfig(sendmessage, restartType, context, content);
} else if (content.toLowerCase().contains(SmsTypeEnum.GET_CFG_FILE.value().toLowerCase())) {//获取配置文件中参数 } else if (content.toLowerCase().contains(SmsTypeEnum.GET_CFG_FILE.value().toLowerCase())) {//获取配置文件中参数
queryConfig(ifmessageCorrect, context, content); queryConfig(sendmessage, restartType, context, content);
} else if (content.toLowerCase().contains(SmsTypeEnum.UPD_FILE.value().toLowerCase())) {//替换配置文件 } else if (content.toLowerCase().contains(SmsTypeEnum.UPD_FILE.value().toLowerCase())) {//替换配置文件
setConfigFile(ifmessageCorrect, context, content); updateFile(sendmessage, restartType, context, content);
} else if (content.toLowerCase().contains(SmsTypeEnum.GET_FILE.value().toLowerCase())) {//获取整个配置文件 } else if (content.toLowerCase().contains(SmsTypeEnum.GET_FILE.value().toLowerCase())) {//获取整个配置文件
queryConfigFile(ifmessageCorrect, context, content); queryFile(sendmessage, restartType, context, content);
} }
sendSms(context, slot, sender, sendmessage, sendtype, ifmessageCorrect); sendSms(context, slot, sender, sendmessage, restartType);
// if (content.toLowerCase().contains(SmsTypeEnum.ACT.value().toLowerCase())) { // if (content.toLowerCase().contains(SmsTypeEnum.ACT.value().toLowerCase())) {
// String[] cmdSpilt = StringUtils.splitString2(content); // String[] cmdSpilt = StringUtils.splitString2(content);
@ -810,9 +799,11 @@ public class SimUtil {
return result; return result;
} }
private static void updateConfigFile(boolean ifmessageCorrect, Context context, String content) {
//修改配置文件中参数
private static void updateConfig(String sendmessage, int restartType, Context context, String content) {
boolean ifmessageCorrect = true;
Map<String, String> fields = new HashMap<>(); Map<String, String> fields = new HashMap<>();
int rebootMpApp = 0;
try { try {
String[] parts = StringUtils.splitStringByDh(SmsTypeEnum.UPD_CFG_FILE.value(), content); String[] parts = StringUtils.splitStringByDh(SmsTypeEnum.UPD_CFG_FILE.value(), content);
int fileType = 0; int fileType = 0;
@ -824,68 +815,79 @@ public class SimUtil {
if (TextUtils.isEmpty(part)) { if (TextUtils.isEmpty(part)) {
continue; continue;
} }
int pos = part.indexOf("="); int pos = part.indexOf("=");
if (pos == -1) { if (pos == -1) {
continue; continue;
} }
String key = part.substring(0, pos); String key = part.substring(0, pos);
String value = part.substring(pos + 1); String value = part.substring(pos + 1);
if (value.contains("&&")) {
value = value.replace("&&", ",");
}
if (TextUtils.equals(key, "f")) { if (TextUtils.equals(key, "f")) {
fileType = Integer.parseInt(value); fileType = Integer.parseInt(value);
} else if (TextUtils.equals(key, "c")) { } else if (TextUtils.equals(key, "c")) {
numberOfFields = Integer.parseInt(value); numberOfFields = Integer.parseInt(value);
} else if (TextUtils.equals(key, "r")) { } else if (TextUtils.equals(key, "r")) {
rebootMpApp = Integer.parseInt(value); restartType = Integer.parseInt(value);
} else { } else {
fields.put(key, value); fields.put(key, value);
} }
} }
HashMap<String, String> hashMap = ValueTypeUtil.checkFilePathAndName(context, fileType); HashMap<String, String> hashMap = ValueTypeUtil.checkFilePathAndName(context, fileType);
filePath = hashMap.get(UpdateSysConfigUtil.FILEPATH); filePath = hashMap.get(UpdateSysConfigUtil.FILEPATH);
fileName = hashMap.get(UpdateSysConfigUtil.FILENAME); fileName = hashMap.get(UpdateSysConfigUtil.FILENAME);
if (!TextUtils.isEmpty(filePath) && !TextUtils.isEmpty(fileName) && numberOfFields > 0) { if (!TextUtils.isEmpty(filePath) && !TextUtils.isEmpty(fileName) && numberOfFields > 0) {
for (int idx = 0; idx <= numberOfFields; idx++) { for (int idx = 0; idx < numberOfFields; idx++) {
String idxStr = Integer.toString(idx); String idxStr = Integer.toString(idx);
// JSONObject jsonConfig = jsonConfigs.getJSONObject(idx);
String configName = fields.containsKey("n" + idxStr) ? fields.get("n" + idxStr) : null; String configName = fields.containsKey("n" + idxStr) ? fields.get("n" + idxStr) : null;
int configType = fields.containsKey("t" + idxStr) ? Integer.parseInt(fields.get("t" + idxStr)) : 0; int configType = fields.containsKey("t" + idxStr) ? Integer.parseInt(fields.get("t" + idxStr)) : 0;
String configValue = fields.containsKey("v" + idxStr) ? fields.get("v" + idxStr) : null; String configValue = fields.containsKey("v" + idxStr) ? fields.get("v" + idxStr) : null;
if (StringUtils.isNotEmpty(configValue)) {
if (configType == 0) { // Number if (configType == 0) { // Number
Long val = Long.parseLong(configValue); Long val = Long.parseLong(configValue);
JSONUtils.updateConfigFile(filePath, fileName, configName, configType, val); JSONUtils.updateConfigFile(filePath, fileName, configName, configType, val);
} else if (configType == 2) { // Float } else if (configType == 2) { // Float
Float val = Float.parseFloat(configValue); Float val = Float.parseFloat(configValue);
JSONUtils.updateConfigFile(filePath, fileName, configName, configType, val); JSONUtils.updateConfigFile(filePath, fileName, configName, configType, val);
} else {
JSONUtils.updateConfigFile(filePath, fileName, configName, configType, configValue);
}
} else { } else {
JSONUtils.updateConfigFile(filePath, fileName, configName, configType, configValue); ifmessageCorrect = false;
} }
} }
if (rebootMpApp != 0) { // if (rebootMpApp != 0) {
MicroPhotoContext.restartMpApp(context, "Config Updated From SMS"); // MicroPhotoContext.restartMpApp(context, "Config Updated From SMS");
} else { // } else {
Intent intent = new Intent(); // Intent intent = new Intent();
intent.setAction(MicroPhotoContext.ACTION_UPDATE_CONFIGS_MP); // intent.setAction(MicroPhotoContext.ACTION_UPDATE_CONFIGS_MP);
intent.setPackage(MicroPhotoContext.PACKAGE_NAME_MPAPP); // intent.setPackage(MicroPhotoContext.PACKAGE_NAME_MPAPP);
context.sendBroadcast(intent); // context.sendBroadcast(intent);
} // }
} else {
ifmessageCorrect = false;
} }
} else {
ifmessageCorrect = false;
} }
} catch ( if (ifmessageCorrect) {
Exception ex) { sendmessage = content + " OK";
} else {
sendmessage = content + " ERROR";
}
} catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
} }
private static void setConfigFile(boolean ifmessageCorrect, Context context, String content) { //替换配置文件
private static void updateFile(String sendmessage, int restartType, Context context, String content) {
boolean ifmessageCorrect = true;
Map<String, String> fields = new HashMap<>(); Map<String, String> fields = new HashMap<>();
int rebootMpApp = 0;
try { try {
String[] parts = TextUtils.split(content.substring(SmsTypeEnum.UPD_FILE.value().length()), "(\\s|,|)"); String[] parts = StringUtils.splitStringByDh(SmsTypeEnum.UPD_FILE.value(), content);
int fileType = 0; int fileType = 0;
int numberOfFields = 0; int numberOfFields = 0;
String filePath = null; String filePath = null;
@ -896,18 +898,18 @@ public class SimUtil {
if (TextUtils.isEmpty(part)) { if (TextUtils.isEmpty(part)) {
continue; continue;
} }
int pos = part.indexOf("="); int pos = part.indexOf("=");
if (pos == -1) { if (pos == -1) {
continue; continue;
} }
String key = part.substring(0, pos); String key = part.substring(0, pos);
String value = part.substring(pos + 1); String value = part.substring(pos + 1);
if (TextUtils.equals(key, "f")) { if (TextUtils.equals(key, "f")) {
fileType = Integer.parseInt(value); fileType = Integer.parseInt(value);
} else if (TextUtils.equals(key, "v")) { } else if (TextUtils.equals(key, "v")) {
fileStr = value; fileStr = value;
} else if (TextUtils.equals(key, "r")) {
restartType = Integer.parseInt(value);
} else if (TextUtils.equals(key, "p")) { } else if (TextUtils.equals(key, "p")) {
filePath = value; filePath = value;
} }
@ -926,89 +928,104 @@ public class SimUtil {
if (StringUtils.isNotEmpty(filePath)) { if (StringUtils.isNotEmpty(filePath)) {
byte[] decode = Base64.decode(fileStr, Base64.NO_WRAP); byte[] decode = Base64.decode(fileStr, Base64.NO_WRAP);
FilesUtils.writeFile(filePath, decode); FilesUtils.writeFile(filePath, decode);
} else {
ifmessageCorrect = false;
} }
} else { } else {
ifmessageCorrect = false; ifmessageCorrect = false;
} }
} else {
ifmessageCorrect = false;
}
if (ifmessageCorrect) {
sendmessage = content + " OK";
} else {
sendmessage = content + " ERROR";
} }
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
} }
private static String queryConfigFile(boolean ifmessageCorrect, Context context, String content) { //获取配置文件
String result = "ERR"; private static void queryFile(String sendmessage, int restartType, Context context, String content) {
boolean ifmessageCorrect = true;
String result = null;
try { try {
String[] parts = TextUtils.split(content.substring(SmsTypeEnum.GET_CFG_FILE.value().length()), "(\\s|,|)"); String[] parts = StringUtils.splitStringByDh(SmsTypeEnum.GET_FILE.value(), content);
int fileType = 0; int fileType = 0;
String filePath = null; String filePath = null;
String fileName = null; String fileName = null;
String fileStr = null;
if (parts != null) { if (parts != null) {
for (String part : parts) { for (String part : parts) {
if (TextUtils.isEmpty(part)) { if (TextUtils.isEmpty(part)) {
continue; continue;
} }
int pos = part.indexOf("="); int pos = part.indexOf("=");
if (pos == -1) { if (pos == -1) {
continue; continue;
} }
String key = part.substring(0, pos); String key = part.substring(0, pos);
String value = part.substring(pos + 1); String value = part.substring(pos + 1);
if (TextUtils.equals(key, "f")) { if (TextUtils.equals(key, "f")) {
fileType = Integer.parseInt(value); fileType = Integer.parseInt(value);
} else if (TextUtils.equals(key, "r")) {
restartType = Integer.parseInt(value);
} else if (TextUtils.equals(key, "p")) { } else if (TextUtils.equals(key, "p")) {
filePath = value; filePath = value;
} }
} }
HashMap<String, String> hashMap = ValueTypeUtil.checkFilePathAndName(context, fileType); HashMap<String, String> hashMap = ValueTypeUtil.checkFilePathAndName(context, fileType);
filePath = hashMap.get(UpdateSysConfigUtil.FILEPATH); filePath = hashMap.get(UpdateSysConfigUtil.FILEPATH);
fileName = hashMap.get(UpdateSysConfigUtil.FILENAME); fileName = hashMap.get(UpdateSysConfigUtil.FILENAME);
if (!TextUtils.isEmpty(filePath + fileName)) { if (!TextUtils.isEmpty(filePath + fileName)) {
File file = new File(filePath + fileName); File file = new File(filePath + fileName);
if (file.exists()) { if (file.exists()) {
try { try {
result = Base64.encodeToString(FilesUtils.readAllBytes(file), Base64.NO_WRAP); fileStr = Base64.encodeToString(FilesUtils.readAllBytes(file), Base64.NO_WRAP);
if (StringUtils.isEmpty(fileStr)) {
ifmessageCorrect = false;
}
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ifmessageCorrect = false;
} }
} else { } else {
result = "NOT Existed"; ifmessageCorrect = false;
} }
} }
} else {
ifmessageCorrect = false;
}
if (ifmessageCorrect) {
sendmessage = content + ",v=" + fileStr;
} else {
sendmessage = content + " ERROR";
} }
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
return result;
} }
private static String queryConfig(boolean ifmessageCorrect, Context context, String content) { //获取配置文件参数
String result = "ERR"; private static void queryConfig(String sendmessage, int restartType, Context context, String content) {
boolean ifmessageCorrect = true;
try { try {
String[] parts = TextUtils.split(content.substring(SmsTypeEnum.GET_CFG_FILE.value().length()), "(\\s|,|)"); String[] parts = StringUtils.splitStringByDh(SmsTypeEnum.GET_CFG_FILE.value(), content);
int fileType = 0; int fileType = 0;
String filePath = null; String filePath = null;
String fileName = null; String fileName = null;
int numberOfFields = 0; int numberOfFields = 0;
Map<String, String> fields = new HashMap<>(); Map<String, String> fields = new HashMap<>();
Map<String, String> outfields = new HashMap<>();
if (parts != null) { if (parts != null) {
for (String part : parts) { for (String part : parts) {
if (TextUtils.isEmpty(part)) { if (TextUtils.isEmpty(part)) {
continue; continue;
} }
int pos = part.indexOf("="); int pos = part.indexOf("=");
if (pos == -1) { if (pos == -1) {
continue; continue;
} }
String key = part.substring(0, pos); String key = part.substring(0, pos);
String value = part.substring(pos + 1); String value = part.substring(pos + 1);
if (TextUtils.equals(key, "f")) { if (TextUtils.equals(key, "f")) {
@ -1017,48 +1034,41 @@ public class SimUtil {
numberOfFields = Integer.parseInt(value); numberOfFields = Integer.parseInt(value);
} else if (TextUtils.equals(key, "p")) { } else if (TextUtils.equals(key, "p")) {
filePath = value; filePath = value;
} else if (TextUtils.equals(key, "r")) {
restartType = Integer.parseInt(value);
} else { } else {
fields.put(key, value); fields.put(key, value);
} }
} }
HashMap<String, String> hashMap = ValueTypeUtil.checkFilePathAndName(context, fileType); HashMap<String, String> hashMap = ValueTypeUtil.checkFilePathAndName(context, fileType);
filePath = hashMap.get(UpdateSysConfigUtil.FILEPATH); filePath = hashMap.get(UpdateSysConfigUtil.FILEPATH);
fileName = hashMap.get(UpdateSysConfigUtil.FILENAME); fileName = hashMap.get(UpdateSysConfigUtil.FILENAME);
JSONObject jsonObject = JSONUtils.getConfigFile(filePath, fileName); JSONObject jsonObject = JSONUtils.getConfigFile(filePath, fileName);
if (jsonObject != null) { if (jsonObject != null) {
for (int idx = 0; idx <= numberOfFields; idx++) { for (int idx = 0; idx < numberOfFields; idx++) {
String idxStr = Integer.toString(idx); String idxStr = Integer.toString(idx);
String configName = fields.containsKey("n" + idxStr) ? fields.get("n" + idxStr) : null; String configName = fields.containsKey("n" + idxStr) ? fields.get("n" + idxStr) : null;
if (StringUtils.isNotEmpty(configName)) { if (StringUtils.isNotEmpty(configName)) {
Object o = jsonObject.get(configName); Object o = jsonObject.get(configName);
if (o != null) { if (o != null) {
int i = ValueTypeUtil.checkType(o); int i = ValueTypeUtil.checkType(o);
outfields.put("n" + idxStr, configName); content += (",t" + idxStr + "=" + i + "," + "v" + idxStr + "=" + o.toString());
outfields.put("t" + idxStr, i + "");
outfields.put("v" + idxStr, o.toString());
} }
} }
} }
} }
if (!TextUtils.isEmpty(filePath)) { } else {
File file = new File(filePath); ifmessageCorrect = false;
if (file.exists()) { }
try { if (ifmessageCorrect) {
result = Base64.encodeToString(FilesUtils.readAllBytes(file), Base64.NO_WRAP); sendmessage = content;
} catch (Exception ex) { } else {
ex.printStackTrace(); sendmessage = content + " ERROR";
}
} else {
result = "NOT Existed";
}
}
} }
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
return result;
} }
@ -1223,7 +1233,7 @@ public class SimUtil {
} }
//指定sim卡位置发送短信 //指定sim卡位置发送短信
public static void sendSms(Context mContext, int slot, String sender, String message, String value, boolean ifmessageCorrect) { public static void sendSms(Context mContext, int slot, String sender, String message, int restartType) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
SubscriptionManager localSubscriptionManager = SubscriptionManager.from(mContext); SubscriptionManager localSubscriptionManager = SubscriptionManager.from(mContext);
if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) { if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
@ -1243,8 +1253,7 @@ public class SimUtil {
} }
} }
Intent itSend = new Intent(SMS_SEND_ACTION); Intent itSend = new Intent(SMS_SEND_ACTION);
itSend.putExtra(SMSTYPE, value); itSend.putExtra(RESTARTTYPE, restartType);
itSend.putExtra(SMSIFCORRECT, ifmessageCorrect);
// itSend.putExtra(SMSDATA, (Serializable) jsonArray); // itSend.putExtra(SMSDATA, (Serializable) jsonArray);
//sendIntent参数为传送后接受的广播信息PendingIntent //sendIntent参数为传送后接受的广播信息PendingIntent
PendingIntent sendPI = PendingIntent.getBroadcast(mContext, mRequestCode++, itSend, 0); PendingIntent sendPI = PendingIntent.getBroadcast(mContext, mRequestCode++, itSend, 0);

@ -4,12 +4,7 @@ import android.app.Activity;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.text.TextUtils;
import android.util.Log;
import com.dev.devapi.api.SysApi;
import com.xypower.mpmaster.MpMasterService; import com.xypower.mpmaster.MpMasterService;
/** /**
@ -30,8 +25,8 @@ public class SmsSendReceiver extends BroadcastReceiver {
} }
if (SimUtil.SMS_SEND_ACTION.equals(action)) { if (SimUtil.SMS_SEND_ACTION.equals(action)) {
final String type = intent.getStringExtra(SimUtil.SMSTYPE); int restartType = intent.getIntExtra(SimUtil.RESTARTTYPE, -1);
if (TextUtils.isEmpty(type)) { if (restartType == -1) {
return; return;
} }
@ -44,7 +39,7 @@ public class SmsSendReceiver extends BroadcastReceiver {
ex.printStackTrace(); ex.printStackTrace();
} }
try { try {
processSms(context, intent, action, type); processSms(context, restartType);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
@ -55,40 +50,51 @@ public class SmsSendReceiver extends BroadcastReceiver {
} }
} }
public void processSms(final Context context, Intent intent, final String action, final String type) { public void processSms(Context context, int restartType) {
if (type.contains(SmsTypeEnum.REBOOT1.value())) { if (restartType == 0) {
MpMasterService.rebootDevice(); MpMasterService.rebootDevice();
} else if (type.contains(SmsTypeEnum.REBOOT2.value())) { } else if (restartType == 1) {
MpMasterService.rebootDevice();
} else if (type.contains(SmsTypeEnum.RESTART_MP.value())) {
UpdateSysConfigUtil.restartApp(context); UpdateSysConfigUtil.restartApp(context);
} else if (type.contains(SmsTypeEnum.RESTART_MPMST.value())) { } else if (restartType == 2) {
UpdateSysConfigUtil.restartMasterApp(context); UpdateSysConfigUtil.restartMasterApp(context);
} else if (type.contains(SmsTypeEnum.RESTART_BOTH_APPS.value())) { } else if (restartType == 3) {
UpdateSysConfigUtil.restartApp(context); UpdateSysConfigUtil.restartApp(context);
UpdateSysConfigUtil.restartMasterApp(context); UpdateSysConfigUtil.restartMasterApp(context);
} else if (type.contains(SmsTypeEnum.SET_YW_SCHEDULE.value())) {
UpdateSysConfigUtil.restartMasterApp(context);
} else if (type.contains(SmsTypeEnum.SET_OPERATE.value())) {
UpdateSysConfigUtil.restartMasterApp(context);
} else if (type.contains(SmsTypeEnum.SET_OPERATE_URL.value())) {
UpdateSysConfigUtil.restartMasterApp(context);
} else if (type.contains(SmsTypeEnum.SET_CMDID.value())) {
UpdateSysConfigUtil.restartApp(context);
} else if (type.contains(SmsTypeEnum.SET_IP.value())) {
UpdateSysConfigUtil.restartApp(context);
} else if (type.contains(SmsTypeEnum.SET_OSD.value())) {
UpdateSysConfigUtil.restartApp(context);
} else if (type.contains(SmsTypeEnum.SET_PHOTO_SCHEDULE_LIST.value())) {
UpdateSysConfigUtil.restartApp(context);
} else if (type.contains(SmsTypeEnum.SET_RESOLUTION.value())) {
UpdateSysConfigUtil.restartApp(context);
} else if (type.contains(SmsTypeEnum.SET_HEART.value())) {
UpdateSysConfigUtil.restartApp(context);
} else if (type.contains(SmsTypeEnum.SET_TP.value())) {
UpdateSysConfigUtil.restartApp(context);
} else if (type.contains(SmsTypeEnum.SET_PACKAGE.value())) {
UpdateSysConfigUtil.restartApp(context);
} }
// if (type.contains(SmsTypeEnum.REBOOT1.value())) {
// MpMasterService.rebootDevice();
// } else if (type.contains(SmsTypeEnum.REBOOT2.value())) {
// MpMasterService.rebootDevice();
// } else if (type.contains(SmsTypeEnum.RESTART_MP.value())) {
// UpdateSysConfigUtil.restartApp(context);
// } else if (type.contains(SmsTypeEnum.RESTART_MPMST.value())) {
// UpdateSysConfigUtil.restartMasterApp(context);
// } else if (type.contains(SmsTypeEnum.RESTART_BOTH_APPS.value())) {
// UpdateSysConfigUtil.restartApp(context);
// UpdateSysConfigUtil.restartMasterApp(context);
// } else if (type.contains(SmsTypeEnum.SET_YW_SCHEDULE.value())) {
// UpdateSysConfigUtil.restartMasterApp(context);
// } else if (type.contains(SmsTypeEnum.SET_OPERATE.value())) {
// UpdateSysConfigUtil.restartMasterApp(context);
// } else if (type.contains(SmsTypeEnum.SET_OPERATE_URL.value())) {
// UpdateSysConfigUtil.restartMasterApp(context);
// } else if (type.contains(SmsTypeEnum.SET_CMDID.value())) {
// UpdateSysConfigUtil.restartApp(context);
// } else if (type.contains(SmsTypeEnum.SET_IP.value())) {
// UpdateSysConfigUtil.restartApp(context);
// } else if (type.contains(SmsTypeEnum.SET_OSD.value())) {
// UpdateSysConfigUtil.restartApp(context);
// } else if (type.contains(SmsTypeEnum.SET_PHOTO_SCHEDULE_LIST.value())) {
// UpdateSysConfigUtil.restartApp(context);
// } else if (type.contains(SmsTypeEnum.SET_RESOLUTION.value())) {
// UpdateSysConfigUtil.restartApp(context);
// } else if (type.contains(SmsTypeEnum.SET_HEART.value())) {
// UpdateSysConfigUtil.restartApp(context);
// } else if (type.contains(SmsTypeEnum.SET_TP.value())) {
// UpdateSysConfigUtil.restartApp(context);
// } else if (type.contains(SmsTypeEnum.SET_PACKAGE.value())) {
// UpdateSysConfigUtil.restartApp(context);
// }
} }
} }

@ -65,10 +65,10 @@ public enum SmsTypeEnum {
CLEAR_ALL("yw+at+clearAll"), //清除图片、视频、日志 CLEAR_ALL("yw+at+clearAll"), //清除图片、视频、日志
RESTORE("yw+at+Restore"), //恢复出厂设置 RESTORE("yw+at+Restore"), //恢复出厂设置
SIMCARD("at+str=sim"), SET_AUTO_TIME("at-auto-time"), // act=[on/off] type=[net/gps] SIMCARD("at+str=sim"), SET_AUTO_TIME("at-auto-time"), // act=[on/off] type=[net/gps]
UPD_CFG_FILE("at-updcfg"), // f=[1/2/91-99] c=[field count] n1=[field name] t1=[0/1/2] v1= UPD_CFG_FILE("at-updcfg"),//修改配置文件参数 // f=[1/2/91-99] c=[field count] n1=[field name] t1=[0/1/2] v1=
GET_CFG_FILE("at-getcfg"), // f=[0/1/2/91-99] p=[Absolute Path] GET_CFG_FILE("at-getcfg"), //获取配置文件参数// f=[0/1/2/91-99] p=[Absolute Path]
UPD_FILE("at-updfile"), // f=[0/1/2/91-99] p=[Absolute Path] UPD_FILE("at-updfile"),//替换配置文件 // f=[0/1/2/91-99] p=[Absolute Path]
GET_FILE("at-getfile"), // f=[0/1/2/91-99] p=[Absolute Path] GET_FILE("at-getfile"), //获取配置文件 // f=[0/1/2/91-99] p=[Absolute Path]
GET_GPS("yw+at+getGPS");//GPS数据获取 GET_GPS("yw+at+getGPS");//GPS数据获取

@ -412,169 +412,161 @@ public class UpdateSysConfigUtil {
return msg; return msg;
} }
public static void setCommon(Context context, String actType, ArrayList<HashMap> list, String restartType) { // public static void setCommon(Context context, String actType, ArrayList<HashMap> list, String restartType) {
if (actType.toLowerCase().equalsIgnoreCase(SmsTypeEnum.SET.value().toLowerCase())) { // if (actType.toLowerCase().equalsIgnoreCase(SmsTypeEnum.SET.value().toLowerCase())) {
for (int i = 0; i < list.size(); i++) { // for (int i = 0; i < list.size(); i++) {
HashMap<String, String> hashMap = list.get(i); // HashMap<String, String> hashMap = list.get(i);
String s = (String) hashMap.get(SmsTypeEnum.CFGFILE.value()); // String s = (String) hashMap.get(SmsTypeEnum.CFGFILE.value());
if (s.equalsIgnoreCase(SmsTypeEnum.APP.value())) { // if (s.equalsIgnoreCase(SmsTypeEnum.APP.value())) {
MicroPhotoContext.AppConfig mpAppConfig = MicroPhotoContext.getMpAppConfig(context); // MicroPhotoContext.AppConfig mpAppConfig = MicroPhotoContext.getMpAppConfig(context);
Field[] fields = mpAppConfig.getClass().getDeclaredFields(); // Field[] fields = mpAppConfig.getClass().getDeclaredFields();
for (Field field : fields) { // for (Field field : fields) {
hashMap.forEach((key, value) -> { // hashMap.forEach((key, value) -> {
if (key.equalsIgnoreCase(field.getName()) && !key.equalsIgnoreCase(SmsTypeEnum.CFGFILE.value())) { // if (key.equalsIgnoreCase(field.getName()) && !key.equalsIgnoreCase(SmsTypeEnum.CFGFILE.value())) {
if (value != null) { // if (value != null) {
try { // try {
if (field.getType() == String.class) { // if (field.getType() == String.class) {
field.set(mpAppConfig, value); // field.set(mpAppConfig, value);
} else if (field.getType() == int.class) { // } else if (field.getType() == int.class) {
Integer num = StringUtils.convert2Int(value); // Integer num = StringUtils.convert2Int(value);
if (num != null) { // if (num != null) {
field.set(mpAppConfig, num.intValue()); // field.set(mpAppConfig, num.intValue());
} // }
} // }
} catch (IllegalAccessException e) { // } catch (IllegalAccessException e) {
} // }
} // }
} // }
}); // });
} // }
MicroPhotoContext.saveMpAppConfig(context, mpAppConfig); // MicroPhotoContext.saveMpAppConfig(context, mpAppConfig);
} else if (s.equalsIgnoreCase(SmsTypeEnum.MASTER.value())) { // } else if (s.equalsIgnoreCase(SmsTypeEnum.MASTER.value())) {
MicroPhotoContext.MasterConfig masterConfig = MicroPhotoContext.getMasterConfig(context); // MicroPhotoContext.MasterConfig masterConfig = MicroPhotoContext.getMasterConfig(context);
Field[] fields = masterConfig.getClass().getDeclaredFields(); // Field[] fields = masterConfig.getClass().getDeclaredFields();
for (Field field : fields) { // for (Field field : fields) {
hashMap.forEach((key, value) -> { // hashMap.forEach((key, value) -> {
if (key.equalsIgnoreCase(field.getName()) && !key.equalsIgnoreCase(SmsTypeEnum.CFGFILE.value())) { // if (key.equalsIgnoreCase(field.getName()) && !key.equalsIgnoreCase(SmsTypeEnum.CFGFILE.value())) {
if (value != null) { // if (value != null) {
try { // try {
if (field.getType() == String.class) { // if (field.getType() == String.class) {
field.set(masterConfig, value); // field.set(masterConfig, value);
} else if (field.getType() == int.class) { // } else if (field.getType() == int.class) {
Integer num = StringUtils.convert2Int(value); // Integer num = StringUtils.convert2Int(value);
if (num != null) { // if (num != null) {
field.set(masterConfig, num.intValue()); // field.set(masterConfig, num.intValue());
} // }
} // }
} catch (IllegalAccessException e) { // } catch (IllegalAccessException e) {
} // }
} // }
} // }
}); // });
} // }
MicroPhotoContext.saveMasterConfig(context, masterConfig); // MicroPhotoContext.saveMasterConfig(context, masterConfig);
} // }
} // }
} else if (actType.toLowerCase().equalsIgnoreCase(SmsTypeEnum.GET.value().toLowerCase())) { // } else if (actType.toLowerCase().equalsIgnoreCase(SmsTypeEnum.GET.value().toLowerCase())) {
for (int i = 0; i < list.size(); i++) { // for (int i = 0; i < list.size(); i++) {
HashMap<String, String> hashMap = list.get(i); // HashMap<String, String> hashMap = list.get(i);
String s = (String) hashMap.get(SmsTypeEnum.CFGFILE.value()); // String s = (String) hashMap.get(SmsTypeEnum.CFGFILE.value());
if (s.equalsIgnoreCase(SmsTypeEnum.APP.value())) { // if (s.equalsIgnoreCase(SmsTypeEnum.APP.value())) {
MicroPhotoContext.AppConfig mpAppConfig = MicroPhotoContext.getMpAppConfig(context); // MicroPhotoContext.AppConfig mpAppConfig = MicroPhotoContext.getMpAppConfig(context);
Field[] fields = mpAppConfig.getClass().getDeclaredFields(); // Field[] fields = mpAppConfig.getClass().getDeclaredFields();
for (Field field : fields) { // for (Field field : fields) {
hashMap.forEach((key, value) -> { // hashMap.forEach((key, value) -> {
if (key.equalsIgnoreCase(field.getName()) && !key.equalsIgnoreCase(SmsTypeEnum.CFGFILE.value())) { // if (key.equalsIgnoreCase(field.getName()) && !key.equalsIgnoreCase(SmsTypeEnum.CFGFILE.value())) {
try { // try {
if (field.getType() == String.class) { // if (field.getType() == String.class) {
value = (String) field.get(mpAppConfig); // value = (String) field.get(mpAppConfig);
} else if (field.getType() == int.class) { // } else if (field.getType() == int.class) {
Integer num = StringUtils.convert2Int(value); // Integer num = StringUtils.convert2Int(value);
if (num != null) { // if (num != null) {
value = (String) field.get(mpAppConfig); // value = (String) field.get(mpAppConfig);
} // }
} // }
} catch (IllegalAccessException e) { // } catch (IllegalAccessException e) {
} // }
} // }
}); // });
} // }
} else if (s.equalsIgnoreCase(SmsTypeEnum.MASTER.value())) { // } else if (s.equalsIgnoreCase(SmsTypeEnum.MASTER.value())) {
MicroPhotoContext.MasterConfig masterConfig = MicroPhotoContext.getMasterConfig(context); // MicroPhotoContext.MasterConfig masterConfig = MicroPhotoContext.getMasterConfig(context);
Field[] fields = masterConfig.getClass().getDeclaredFields(); // Field[] fields = masterConfig.getClass().getDeclaredFields();
for (Field field : fields) { // for (Field field : fields) {
hashMap.forEach((key, value) -> { // hashMap.forEach((key, value) -> {
if (key.equalsIgnoreCase(field.getName()) && !key.equalsIgnoreCase(SmsTypeEnum.CFGFILE.value())) { // if (key.equalsIgnoreCase(field.getName()) && !key.equalsIgnoreCase(SmsTypeEnum.CFGFILE.value())) {
try { // try {
if (field.getType() == String.class) { // if (field.getType() == String.class) {
value = (String) field.get(masterConfig); // value = (String) field.get(masterConfig);
} else if (field.getType() == int.class) { // } else if (field.getType() == int.class) {
Integer num = StringUtils.convert2Int(value); // Integer num = StringUtils.convert2Int(value);
if (num != null) { // if (num != null) {
value = (String) field.get(masterConfig); // value = (String) field.get(masterConfig);
} // }
} // }
} catch (IllegalAccessException e) { // } catch (IllegalAccessException e) {
} // }
} // }
}); // });
} // }
} // }
} // }
} else if (actType.toLowerCase().equalsIgnoreCase(SmsTypeEnum.SETFILE.value().toLowerCase())) { // } else if (actType.toLowerCase().equalsIgnoreCase(SmsTypeEnum.SETFILE.value().toLowerCase())) {
for (int i = 0; i < list.size(); i++) { // for (int i = 0; i < list.size(); i++) {
HashMap<String, String> hashMap = list.get(i); // HashMap<String, String> hashMap = list.get(i);
String s = (String) hashMap.get(SmsTypeEnum.CFGFILE.value()); // String s = (String) hashMap.get(SmsTypeEnum.CFGFILE.value());
if (s.equalsIgnoreCase(SmsTypeEnum.APP.value())) { // if (s.equalsIgnoreCase(SmsTypeEnum.APP.value())) {
//
//
MicroPhotoContext.AppConfig mpAppConfig = MicroPhotoContext.getMpAppConfig(context); // MicroPhotoContext.AppConfig mpAppConfig = MicroPhotoContext.getMpAppConfig(context);
Field[] fields = mpAppConfig.getClass().getDeclaredFields(); // Field[] fields = mpAppConfig.getClass().getDeclaredFields();
for (Field field : fields) { // for (Field field : fields) {
hashMap.forEach((key, value) -> { // hashMap.forEach((key, value) -> {
if (key.equalsIgnoreCase(field.getName()) && !key.equalsIgnoreCase(SmsTypeEnum.CFGFILE.value())) { // if (key.equalsIgnoreCase(field.getName()) && !key.equalsIgnoreCase(SmsTypeEnum.CFGFILE.value())) {
if (value != null) { // if (value != null) {
try { // try {
if (field.getType() == String.class) { // if (field.getType() == String.class) {
value = (String) field.get(mpAppConfig); // value = (String) field.get(mpAppConfig);
} else if (field.getType() == int.class) { // } else if (field.getType() == int.class) {
Integer num = StringUtils.convert2Int(value); // Integer num = StringUtils.convert2Int(value);
if (num != null) { // if (num != null) {
value = (String) field.get(mpAppConfig); // value = (String) field.get(mpAppConfig);
} // }
} // }
} catch (IllegalAccessException e) { // } catch (IllegalAccessException e) {
} // }
} // }
} // }
}); // });
} // }
} else if (s.equalsIgnoreCase(SmsTypeEnum.MASTER.value())) { // } else if (s.equalsIgnoreCase(SmsTypeEnum.MASTER.value())) {
MicroPhotoContext.MasterConfig masterConfig = MicroPhotoContext.getMasterConfig(context); // MicroPhotoContext.MasterConfig masterConfig = MicroPhotoContext.getMasterConfig(context);
Field[] fields = masterConfig.getClass().getDeclaredFields(); // Field[] fields = masterConfig.getClass().getDeclaredFields();
for (Field field : fields) { // for (Field field : fields) {
hashMap.forEach((key, value) -> { // hashMap.forEach((key, value) -> {
if (key.equalsIgnoreCase(field.getName()) && !key.equalsIgnoreCase(SmsTypeEnum.CFGFILE.value())) { // if (key.equalsIgnoreCase(field.getName()) && !key.equalsIgnoreCase(SmsTypeEnum.CFGFILE.value())) {
if (value != null) { // if (value != null) {
try { // try {
if (field.getType() == String.class) { // if (field.getType() == String.class) {
value = (String) field.get(masterConfig); // value = (String) field.get(masterConfig);
} else if (field.getType() == int.class) { // } else if (field.getType() == int.class) {
Integer num = StringUtils.convert2Int(value); // Integer num = StringUtils.convert2Int(value);
if (num != null) { // if (num != null) {
value = (String) field.get(masterConfig); // value = (String) field.get(masterConfig);
} // }
} // }
} catch (IllegalAccessException e) { // } catch (IllegalAccessException e) {
} // }
} // }
} // }
}); // });
} // }
} // }
} // }
} else if (actType.toLowerCase().equalsIgnoreCase(SmsTypeEnum.GETFILE.value().toLowerCase())) { // } else if (actType.toLowerCase().equalsIgnoreCase(SmsTypeEnum.GETFILE.value().toLowerCase())) {
//
} // }
//
} // }
//获取app的心跳
public static int getCommon(Context context) {
MicroPhotoContext.AppConfig mpAppConfig = MicroPhotoContext.getMpAppConfig(context);
int heartbeat = mpAppConfig.heartbeat;
return heartbeat;
}
} }

Loading…
Cancel
Save