短信通用版本修改中:修改配置文件参数设置数组时全是字符串类型的bug,修复发送短信空指针的bug

streaming
liuguijing 4 months ago
parent 874f7db0cd
commit de466ba891

@ -83,7 +83,7 @@ public class MicroPhotoContext {
public static String getPrimaryStoragePath(Context context) {
try {
StorageManager sm = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
Method getVolumePathsMethod = StorageManager.class.getMethod("getVolumePaths", (Class<?>[])null);
Method getVolumePathsMethod = StorageManager.class.getMethod("getVolumePaths", (Class<?>[]) null);
Object[] args = null;
String[] paths = (String[]) getVolumePathsMethod.invoke(sm, args);
// first element in paths[] is primary storage path
@ -99,7 +99,7 @@ public class MicroPhotoContext {
public static String getSecondaryStoragePath(Context context) {
try {
StorageManager sm = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
Method getVolumePathsMethod = StorageManager.class.getMethod("getVolumePaths", (Class<?>[])null);
Method getVolumePathsMethod = StorageManager.class.getMethod("getVolumePaths", (Class<?>[]) null);
Object[] args = null;
String[] paths = (String[]) getVolumePathsMethod.invoke(sm, args);
// second element in paths[] is secondary storage path
@ -114,7 +114,7 @@ public class MicroPhotoContext {
public String getStorageState(Context context, String path) {
try {
StorageManager sm = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
Method getVolumeStateMethod = StorageManager.class.getMethod("getVolumeState", new Class[] {String.class});
Method getVolumeStateMethod = StorageManager.class.getMethod("getVolumeState", new Class[]{String.class});
String state = (String) getVolumeStateMethod.invoke(sm, path);
return state;
} catch (Exception e) {
@ -399,7 +399,7 @@ public class MicroPhotoContext {
}
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent restartIntent = PendingIntent.getActivity(context, 0, intent, 0);
AlarmManager mgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
AlarmManager mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
mgr.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + delayedTimeMs, restartIntent);
}

@ -28,14 +28,18 @@ 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.mpmaster.MpMasterService;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.File;
import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@ -55,9 +59,12 @@ public class SimUtil {
// 自定义ACTION常数 作为广播的IntentFilter识别常数
public static String SMS_SEND_ACTION = "com.xypower.mpmaster.SMS_SEND_ACTION";
public static String RESTARTTYPE = "restartType";
public static String SMSRESTARTTYPE = "restartType";
private static int mRequestCode = 1;
private static String sendmessage = null;//要回复的短信
private static int restartType = -1;//重启类型
//短信解析
public static void analysisSMSInfo(final Context context, final Intent intent, final SmsMessage smsMessage) {
@ -70,19 +77,18 @@ public class SimUtil {
}
int slot = smsInfo.getSlot();//那张卡收到的短信
String sender = smsInfo.getSender();//收到的短信的手机号
String sendmessage = null;//要回复的短信
int restartType = 0;//重启类型
if (StringUtils.isEmpty(content)) {
return;
}
if (content.toLowerCase().contains(SmsTypeEnum.UPD_CFG_FILE.value().toLowerCase())) { //修改配置文件中参数
updateConfig(sendmessage, restartType, context, content);
updateConfig(context, content);
} else if (content.toLowerCase().contains(SmsTypeEnum.GET_CFG_FILE.value().toLowerCase())) {//获取配置文件中参数
queryConfig(sendmessage, restartType, context, content);
queryConfig(context, content);
} else if (content.toLowerCase().contains(SmsTypeEnum.UPD_FILE.value().toLowerCase())) {//替换配置文件
updateFile(sendmessage, restartType, context, content);
updateFile(context, content);
} else if (content.toLowerCase().contains(SmsTypeEnum.GET_FILE.value().toLowerCase())) {//获取整个配置文件
queryFile(sendmessage, restartType, context, content);
queryFile(context, content);
}
sendSms(context, slot, sender, sendmessage, restartType);
@ -801,11 +807,11 @@ public class SimUtil {
//修改配置文件中参数
private static void updateConfig(String sendmessage, int restartType, Context context, String content) {
private static void updateConfig(Context context, String content) {
boolean ifmessageCorrect = true;
Map<String, String> fields = new HashMap<>();
try {
String[] parts = StringUtils.splitStringByDh(SmsTypeEnum.UPD_CFG_FILE.value(), content);
String[] parts = StringUtils.splitStringByDh(content.substring(SmsTypeEnum.UPD_CFG_FILE.value().length()));
int fileType = 0;
int numberOfFields = 0;
String filePath = null;
@ -847,11 +853,14 @@ public class SimUtil {
if (configType == 0) { // Number
Long val = Long.parseLong(configValue);
JSONUtils.updateConfigFile(filePath, fileName, configName, configType, val);
} else if (configType == 1) {
JSONUtils.updateConfigFile(filePath, fileName, configName, configType, configValue);
} 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 if (configType == 3) { //数组
JSONArray objects = new JSONArray(configValue);
JSONUtils.updateConfigFile(filePath, fileName, configName, configType, objects);
}
} else {
ifmessageCorrect = false;
@ -883,11 +892,11 @@ public class SimUtil {
}
//替换配置文件
private static void updateFile(String sendmessage, int restartType, Context context, String content) {
private static void updateFile(Context context, String content) {
boolean ifmessageCorrect = true;
Map<String, String> fields = new HashMap<>();
try {
String[] parts = StringUtils.splitStringByDh(SmsTypeEnum.UPD_FILE.value(), content);
String[] parts = StringUtils.splitStringByDh(content.substring(SmsTypeEnum.UPD_FILE.value().length()));
int fileType = 0;
int numberOfFields = 0;
String filePath = null;
@ -948,11 +957,11 @@ public class SimUtil {
}
//获取配置文件
private static void queryFile(String sendmessage, int restartType, Context context, String content) {
private static void queryFile(Context context, String content) {
boolean ifmessageCorrect = true;
String result = null;
try {
String[] parts = StringUtils.splitStringByDh(SmsTypeEnum.GET_FILE.value(), content);
String[] parts = StringUtils.splitStringByDh(content.substring(SmsTypeEnum.GET_FILE.value().length()));
int fileType = 0;
String filePath = null;
String fileName = null;
@ -1008,10 +1017,10 @@ public class SimUtil {
}
//获取配置文件参数
private static void queryConfig(String sendmessage, int restartType, Context context, String content) {
private static void queryConfig(Context context, String content) {
boolean ifmessageCorrect = true;
try {
String[] parts = StringUtils.splitStringByDh(SmsTypeEnum.GET_CFG_FILE.value(), content);
String[] parts = StringUtils.splitStringByDh(content.substring(SmsTypeEnum.GET_CFG_FILE.value().length()));
int fileType = 0;
String filePath = null;
String fileName = null;
@ -1253,7 +1262,8 @@ public class SimUtil {
}
}
Intent itSend = new Intent(SMS_SEND_ACTION);
itSend.putExtra(RESTARTTYPE, restartType);
itSend.putExtra(SMSRESTARTTYPE, restartType);
// itSend.putExtra(SMSIFCORRECT, true);
// itSend.putExtra(SMSDATA, (Serializable) jsonArray);
//sendIntent参数为传送后接受的广播信息PendingIntent
PendingIntent sendPI = PendingIntent.getBroadcast(mContext, mRequestCode++, itSend, 0);
@ -1263,7 +1273,7 @@ public class SimUtil {
// PendingIntent deliverPI = PendingIntent.getBroadcast(mContext,0,itDeliver,0);
if (simInfoAnother != null) {
SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(simInfoAnother.getSubscriptionId());
if (message.length() > 70) {
if (message != null && message.length() > 70) {
ArrayList<String> msgs = smsManager.divideMessage(message);
ArrayList<PendingIntent> sentIntents = new ArrayList<PendingIntent>();
@ -1384,6 +1394,29 @@ public class SimUtil {
return getIcc(subID, getModelSlot(mContext));
}
// public static int saveConfig(Context mContext) {
// JSONObject jsonObject = MicroPhotoContext.getJsonObject(mContext);
// Field[] fields = masterConfig.getClass().getDeclaredFields();
// for (Field field : fields) {
// 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(mContext, masterConfig);
// }
//获取对应的卡槽ID和iccID 关联
private static List<ModelSlotAndSub> getModelSlot(Context mContext) {
List<ModelSlotAndSub> data = new ArrayList<>();

@ -25,11 +25,7 @@ public class SmsSendReceiver extends BroadcastReceiver {
}
if (SimUtil.SMS_SEND_ACTION.equals(action)) {
int restartType = intent.getIntExtra(SimUtil.RESTARTTYPE, -1);
if (restartType == -1) {
return;
}
int restartType = intent.getIntExtra(SimUtil.SMSRESTARTTYPE, -1);
Thread th = new Thread(new Runnable() {
@Override
public void run() {

@ -346,9 +346,9 @@ public class StringUtils {
/**
* outStr,
*/
public static String[] splitStringByDh(String outStr, String content) {
public static String[] splitStringByDh(String content) {
String[] temp = null;
temp = TextUtils.split(content.substring(outStr.length()), "(\\s|,|)");
temp = TextUtils.split(content, "(\\s|,|)");
return temp;
}

@ -340,7 +340,7 @@ public class UpdateSysConfigUtil {
Intent intent = new Intent(MicroPhotoContext.ACTION_RESTART_MP);
intent.putExtra("noDelay", 1);
intent.setPackage(PACKAGE_NAME_MPAPP);
intent.setPackage(MicroPhotoContext.PACKAGE_NAME_MPAPP);
context.sendBroadcast(intent);
try {
@ -411,161 +411,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())) {
//
// }
//
// }
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