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

streaming
liuguijing 4 months ago
parent becda30777
commit 30e4562f1d

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

@ -4,12 +4,7 @@ import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
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;
/**
@ -30,8 +25,8 @@ public class SmsSendReceiver extends BroadcastReceiver {
}
if (SimUtil.SMS_SEND_ACTION.equals(action)) {
final String type = intent.getStringExtra(SimUtil.SMSTYPE);
if (TextUtils.isEmpty(type)) {
int restartType = intent.getIntExtra(SimUtil.RESTARTTYPE, -1);
if (restartType == -1) {
return;
}
@ -44,7 +39,7 @@ public class SmsSendReceiver extends BroadcastReceiver {
ex.printStackTrace();
}
try {
processSms(context, intent, action, type);
processSms(context, restartType);
} catch (Exception ex) {
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) {
if (type.contains(SmsTypeEnum.REBOOT1.value())) {
public void processSms(Context context, int restartType) {
if (restartType == 0) {
MpMasterService.rebootDevice();
} else if (type.contains(SmsTypeEnum.REBOOT2.value())) {
MpMasterService.rebootDevice();
} else if (type.contains(SmsTypeEnum.RESTART_MP.value())) {
} else if (restartType == 1) {
UpdateSysConfigUtil.restartApp(context);
} else if (type.contains(SmsTypeEnum.RESTART_MPMST.value())) {
} else if (restartType == 2) {
UpdateSysConfigUtil.restartMasterApp(context);
} else if (type.contains(SmsTypeEnum.RESTART_BOTH_APPS.value())) {
} else if (restartType == 3) {
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);
}
// 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"), //清除图片、视频、日志
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/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]
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]
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]
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_GPS("yw+at+getGPS");//GPS数据获取

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

Loading…
Cancel
Save