|
|
|
@ -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,36 +815,35 @@ 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 (StringUtils.isNotEmpty(configValue)) {
|
|
|
|
|
if (configType == 0) { // Number
|
|
|
|
|
Long val = Long.parseLong(configValue);
|
|
|
|
|
JSONUtils.updateConfigFile(filePath, fileName, configName, configType, val);
|
|
|
|
@ -863,29 +853,41 @@ public class SimUtil {
|
|
|
|
|
} else {
|
|
|
|
|
JSONUtils.updateConfigFile(filePath, fileName, configName, configType, configValue);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
ifmessageCorrect = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (rebootMpApp != 0) {
|
|
|
|
|
MicroPhotoContext.restartMpApp(context, "Config Updated From SMS");
|
|
|
|
|
// 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 {
|
|
|
|
|
Intent intent = new Intent();
|
|
|
|
|
intent.setAction(MicroPhotoContext.ACTION_UPDATE_CONFIGS_MP);
|
|
|
|
|
intent.setPackage(MicroPhotoContext.PACKAGE_NAME_MPAPP);
|
|
|
|
|
context.sendBroadcast(intent);
|
|
|
|
|
ifmessageCorrect = false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
ifmessageCorrect = false;
|
|
|
|
|
}
|
|
|
|
|
if (ifmessageCorrect) {
|
|
|
|
|
sendmessage = content + " OK";
|
|
|
|
|
} else {
|
|
|
|
|
sendmessage = content + " ERROR";
|
|
|
|
|
}
|
|
|
|
|
} catch (
|
|
|
|
|
Exception ex) {
|
|
|
|
|
} 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";
|
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|