diff --git a/mpmaster/build.gradle b/mpmaster/build.gradle
index f7745665..1e0ea991 100644
--- a/mpmaster/build.gradle
+++ b/mpmaster/build.gradle
@@ -4,7 +4,7 @@ plugins {
def AppMajorVersion = 1
def AppMinorVersion = 0
-def AppBuildNumber = 95
+def AppBuildNumber = 96
def AppVersionName = AppMajorVersion + "." + AppMinorVersion + "." + AppBuildNumber
def AppVersionCode = AppMajorVersion * 100000 + AppMinorVersion * 1000 + AppBuildNumber
@@ -14,8 +14,8 @@ android {
defaultConfig {
applicationId "com.xypower.mpmaster"
- minSdk COMPILE_MIN_SDK_VERSION as int
- targetSdk TARGET_SDK_VERSION as int
+ minSdk 28
+ targetSdk 28
versionCode AppVersionCode
versionName AppVersionName
diff --git a/mpmaster/src/main/AndroidManifest.xml b/mpmaster/src/main/AndroidManifest.xml
index 74f77bcb..2e8ff058 100644
--- a/mpmaster/src/main/AndroidManifest.xml
+++ b/mpmaster/src/main/AndroidManifest.xml
@@ -13,6 +13,8 @@
+
+
diff --git a/mpmaster/src/main/java/com/xypower/mpmaster/AppMaster.java b/mpmaster/src/main/java/com/xypower/mpmaster/AppMaster.java
index 357a275f..90b355c4 100644
--- a/mpmaster/src/main/java/com/xypower/mpmaster/AppMaster.java
+++ b/mpmaster/src/main/java/com/xypower/mpmaster/AppMaster.java
@@ -120,7 +120,7 @@ public class AppMaster {
return (System.currentTimeMillis() - SystemClock.elapsedRealtimeNanos() / 1000000) / 1000;
}
- public void start() {
+ public void start(final boolean isCriticalTime) {
new Thread(new Runnable() {
@@ -160,7 +160,7 @@ public class AppMaster {
}
try {
- runImpl();
+ runImpl(isCriticalTime);
} catch (Exception ex) {
ex.printStackTrace();
}
@@ -177,7 +177,7 @@ public class AppMaster {
}
} else {
try {
- runImpl();
+ runImpl(isCriticalTime);
} catch (Exception ex) {
ex.printStackTrace();
}
@@ -186,7 +186,7 @@ public class AppMaster {
}).start();
}
- private boolean runImpl() {
+ private boolean runImpl(final boolean isCriticalTime) {
String masterUrl = mMasterUrl;
if (TextUtils.isEmpty(masterUrl)) {
@@ -201,8 +201,10 @@ public class AppMaster {
now.setMinutes(0);
now.setSeconds(0);
- long startTime = now.getTime() / 1000;
- long endTime = startTime + 86400 - 1;
+ final long startTimeMs = now.getTime();
+ final long startTime = startTimeMs / 1000;
+ final long endTimeMs = startTimeMs + 86400000 - 1;
+ final long endTime = startTime + 86400 - 1;
String startTimeStr = Integer.toString(now.getYear()) + (now.getMonth() < 10 ? "0" : "") + Integer.toString(now.getMonth()) + (now.getDate() < 10 ? "0" : "") + Integer.toString(now.getDate());
@@ -231,13 +233,21 @@ public class AppMaster {
postParams.add(new Pair("signalLevel1", Integer.toString(MpMasterService.getSignalLevel(1))));
postParams.add(new Pair("signalLevel2", Integer.toString(MpMasterService.getSignalLevel(2))));
- // SysApi.
- postParams.add(new Pair("simcard1", mService.getIccid(1)));
- // if (mService.isSeparateNetwork()) {
- postParams.add(new Pair("simcard2", mService.getIccid(2)));
- // }
+ if (isCriticalTime) {
+ // SysApi.
+ postParams.add(new Pair("simcard1", mService.getIccid(1)));
+ // if (mService.isSeparateNetwork()) {
+ postParams.add(new Pair("simcard2", mService.getIccid(2)));
+
+ postParams.add(new Pair("freeROM", getFreeROM()));
- postParams.add(new Pair("freeROM", getFreeROM()));
+ /*
+ String crashTimes = getCrashTimes(startTimeMs, endTimeMs);
+ if (!TextUtils.isEmpty(crashTimes)) {
+ postParams.add(new Pair("crashes", crashTimes));
+ }
+ */
+ }
buildStats(startTime, postParams);
@@ -445,7 +455,7 @@ public class AppMaster {
ex.printStackTrace();
}
}
-
+
private String getCrashTimes(final long startTimeMs, final long endTimeMs) {
String path = "/data/system/dropbox/";
final String prefixFileName = "data_app_crash@";
@@ -475,6 +485,8 @@ public class AppMaster {
return ((cnts[0] == 0) && (cnts[1] == 0)) ? null : Integer.toString(cnts[0]) + " " + Integer.toString(cnts[1]);
}
+
+
private String getImei(int number) {
return (number == 1) ? SysApi.getImei(mService) : SysApi.getImei2(mService);
}
diff --git a/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java b/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java
index 380a9be0..5196e13d 100644
--- a/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java
+++ b/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java
@@ -14,6 +14,7 @@ import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.AssetManager;
import android.os.Build;
+import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.IBinder;
@@ -70,6 +71,8 @@ public class MpMasterService extends Service {
public static final String ACTION_STOP = "com.xypower.mpmaster.ACT_STOP";
public static final String ACTION_MAIN = "com.xypower.mpmaster.ACT_MAIN";
+ public static final String ACTION_REQ_RESTART_APP = "com.xypower.mpmaster.ACT_REQ_RST_APP";
+
public static final String ACTION_UPD_OTA = SysApi.OTA_RESULT_ACTION;
public static final String ACTION_INSTALL_RESULT = SysApi.INSTALL_RESULT_ACTION;
public static final String ACTION_UNINSTALL_RESULT = SysApi.UNINSTALL_RESULT_ACTION;
@@ -86,6 +89,7 @@ public class MpMasterService extends Service {
private SmsSendReceiver mSmsSnedReceiver;
private int mPrevDateForLogs = 0;
+ private int mMasterTimers = 0;
public static class STATE_SERVICE {
public static final int CONNECTED = 10;
@@ -244,6 +248,7 @@ public class MpMasterService extends Service {
intentFilter.addAction(ACTION_UPD_OTA);
intentFilter.addAction(ACTION_INSTALL_RESULT);
intentFilter.addAction(ACTION_UNINSTALL_RESULT);
+ intentFilter.addAction(ACTION_REQ_RESTART_APP);
intentFilter.addAction(MicroPhotoContext.ACTION_HEARTBEAT_MP);
registerReceiver(mAlarmReceiver, intentFilter);
@@ -390,64 +395,42 @@ public class MpMasterService extends Service {
final Context context = getApplicationContext();
long ts = System.currentTimeMillis();
- FileOutputStream runningFile = null;
- FileLock fileLock = null;
try {
- boolean isMpAppRunning = true;
- String mpappDir = MicroPhotoContext.buildMpAppDir(getApplicationContext());
- File file = new File(mpappDir);
- file = new File(file, "data/alive/running");
- if (file.exists()) {
- runningFile = new FileOutputStream(file);
- fileLock = runningFile.getChannel().tryLock();
- if (fileLock != null && fileLock.isValid()) {
- isMpAppRunning = false;
- }
+ boolean isMpAppRunning = detectMpAppRunning();
+ if (!isMpAppRunning) {
try {
- if (fileLock != null) {
- fileLock.close();
- fileLock = null;
- }
+ Thread.sleep(1000);
} catch (Exception ex) {
ex.printStackTrace();
}
- FilesUtils.closeFriendly(runningFile);
- } else {
- isMpAppRunning = false;
+ // Check twice
+ isMpAppRunning = detectMpAppRunning();
}
if (!isMpAppRunning) {
// Restart MpApp
MicroPhotoContext.restartMpApp(context, "MpMST Keep Alive Detection: NO Lock");
logger.warning("Restart MpAPP as There is NO Lock");
+ mTimeToStartMpApp = ts;
return;
}
} catch (Exception ex) {
ex.printStackTrace();
- } finally {
- try {
- if (fileLock != null) {
- fileLock.close();
- }
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- FilesUtils.closeFriendly(runningFile);
}
long tempduration = mMpHeartbeatDuration;
if(mMpHeartbeatDuration < 600000)
- tempduration = 300000;
+ tempduration = 290000;
if (mPreviousMpHbTime <= ts && ts - mPreviousMpHbTime > tempduration * 2) {
// MpApp is not running
if (ts - mTimeToStartMpApp >= 1800000) { // 30 minutes 30 * 60 * 1000
MicroPhotoContext.restartMpApp(context, "MpMST Keep Alive Detection");
+
logger.warning("Restart MpAPP as it is NOT Running Prev MPAPP HB=" +
Long.toString((ts - mPreviousMpHbTime) / 1000) + " MPAPP HBDuration=" + Long.toString(mMpHeartbeatDuration)
+ " Prev MpRestart Time=" + Long.toString(mTimeToStartMpApp) + " last MPAPPHB =" + (mPreviousMpHbTime/1000));
+
mTimeToStartMpApp = ts;
- logger.warning("Restart MpAPP as it is NOT Running Prev MPAPP HB=" +
- Long.toString((ts - mPreviousMpHbTime) / 1000) + " MPAPP HBDuration=" + Long.toString(mMpHeartbeatDuration));
} else {
logger.warning("MpAPP has restarted during 30min, skip the check.");
}
@@ -474,17 +457,54 @@ public class MpMasterService extends Service {
MicroPhotoContext.restartMpApp(context, msg, mDelayedRestartMpTime);
- int uniqueReqCode = reqCode.getAndIncrement();
- PendingIntent pendingIntent = PendingIntent.getBroadcast(this, uniqueReqCode, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
-
- alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, ts + mDelayedRestartMpTime, pendingIntent);
+ mTimeToStartMpApp = ts + mDelayedRestartMpTime / 1000;
+ }
+ }
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
- mTimeToStartMpApp = ts;
+ private boolean detectMpAppRunning() {
+ boolean isMpAppRunning = true;
+ FileOutputStream runningFile = null;
+ FileLock fileLock = null;
+ try {
+ String mpappDir = MicroPhotoContext.buildMpAppDir(getApplicationContext());
+ File file = new File(mpappDir);
+ file = new File(file, "data/alive/running");
+ if (file.exists()) {
+ runningFile = new FileOutputStream(file);
+ fileLock = runningFile.getChannel().tryLock();
+ if (fileLock != null && fileLock.isValid()) {
+ isMpAppRunning = false;
+ }
+ try {
+ if (fileLock != null) {
+ fileLock.close();
+ fileLock = null;
+ }
+ } catch (Exception ex) {
+ ex.printStackTrace();
}
+ FilesUtils.closeFriendly(runningFile);
+ } else {
+ isMpAppRunning = false;
}
} catch (Exception ex) {
ex.printStackTrace();
+ } finally {
+ try {
+ if (fileLock != null) {
+ fileLock.close();
+ }
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ FilesUtils.closeFriendly(runningFile);
}
+
+ return isMpAppRunning;
}
long getFileModificationTime(String path) {
@@ -570,6 +590,14 @@ public class MpMasterService extends Service {
}
}
+ public boolean isCriticalTime() {
+ if (mSeparateNetwork) {
+ return true;
+ }
+
+ return (mMasterTimers % 12) == 0;
+ }
+
private void startMaster(boolean bundleWithMpApp) {
String masterUrl = MicroPhotoContext.DEFAULT_MASTER_URL;
@@ -583,10 +611,6 @@ public class MpMasterService extends Service {
if (appConfig.heartbeat > 0) {
mMpHeartbeatDuration = appConfig.heartbeat * 60000;
}
- if(TextUtils.isEmpty(appConfig.cmdid))
- {
- appConfig.cmdid = SysApi.getSerialNo(getApplicationContext());
- }
logger.warning("Start Mntn report: " + masterUrl + " MntnMode=" + (mMntnMode ? "1" : "0") + " QuickHB=" + (mQuickHbMode ? "1" : "0"));
@@ -629,8 +653,6 @@ public class MpMasterService extends Service {
mService.detectMpAppAlive();
} else if (TextUtils.equals(MicroPhotoContext.ACTION_HEARTBEAT_MP, action)) {
-
-
if (intent.hasExtra("HeartbeatDuration")) {
int hbDuration = intent.getIntExtra("HeartbeatDuration", 600000);
mService.mMpHeartbeatDuration = hbDuration > 0 ? hbDuration : 600000;
@@ -692,6 +714,23 @@ public class MpMasterService extends Service {
String pkname = intent.getStringExtra("pkname");
String msg = intent.getStringExtra("msg");
mService.logger.warning("UNINSTALL APP result =" + bSucc + ",pkname=" + pkname + ",msg=" + msg);
+ } else if (TextUtils.equals(ACTION_REQ_RESTART_APP, action)) {
+
+ try {
+ String packageName = intent.getStringExtra("packageName");
+ Intent restartIntent = context.getPackageManager().getLaunchIntentForPackage(packageName);
+
+ Bundle bundle = intent.getExtras();
+ bundle.remove("packageName");
+ restartIntent.putExtras(bundle);
+ restartIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
+ context.startActivity(restartIntent);
+
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+
+
}
}
}
diff --git a/mpmaster/src/main/java/com/xypower/mpmaster/sms/SimUtil.java b/mpmaster/src/main/java/com/xypower/mpmaster/sms/SimUtil.java
index 9636e303..4dde7d55 100644
--- a/mpmaster/src/main/java/com/xypower/mpmaster/sms/SimUtil.java
+++ b/mpmaster/src/main/java/com/xypower/mpmaster/sms/SimUtil.java
@@ -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;
@@ -40,8 +38,10 @@ import org.json.JSONException;
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;
@@ -61,17 +61,19 @@ 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 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) {
+ sendmessage = null;
+ restartType = -1;
SmsMessageModel smsInfo = getSMSInfo(intent, smsMessage);
if (smsInfo != null) {
- String packageName = context.getApplicationContext().getPackageName();
String content = smsInfo.getContent();
int pos = content.lastIndexOf("##");
if (pos != -1) {
@@ -80,7 +82,6 @@ public class SimUtil {
int slot = smsInfo.getSlot();//那张卡收到的短信
String sender = smsInfo.getSender();//收到的短信的手机号
String sendmessage = "ERROR";//要回复的短信
- String sendtype = "";//收到的短信类型
List abslist = new ArrayList<>();//收到的短信内容拆分包装成数组
boolean ifmessageCorrect = false;//用来判断收到的短信内容是否正确
if (StringUtils.isEmpty(content)) {
@@ -717,171 +718,282 @@ public class SimUtil {
return result;
}
- private static void updateConfigFile(Context context, String content) {
- String result = "";
- Map fields = new HashMap<>();
- int rebootMpApp = 0;
+ //修改配置文件中参数
+ private static void updateConfig(String content) {
+ boolean ifmessageCorrect = true;
+ Map fields = new HashMap<>();
try {
- String[] parts = TextUtils.split(content.substring(SmsTypeEnum.UPD_CFG_FILE.value().length()), "(\\s|,|,)");
+ String[] parts = StringUtils.splitStringByDh(content.substring(SmsTypeEnum.UPD_CFG_FILE.value().length()));
int fileType = 0;
int numberOfFields = 0;
-
+ String filePath = null;
+ String fileName = 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 (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);
}
}
-
- String filePath = null;
- String fileName = null;
- switch (fileType) {
- case 1:
- filePath = MicroPhotoContext.buildMpAppDir(context) + "/data/";
- fileName = "App.json";
- break;
- case 2:
- filePath = MicroPhotoContext.buildMasterAppDir(context) + "/data/";
- fileName = "Master.json";
- break;
- case 91:
- case 92:
- case 93:
- case 94:
- case 95:
- case 96:
- case 97:
- case 98:
- case 99:
- filePath = MicroPhotoContext.buildMpAppDir(context) + "/data/channels/";
- fileName = Integer.toString(fileType - 90) + ".json";
- break;
- default:
- break;
- }
-
+ HashMap hashMap = ValueTypeUtil.checkFilePathAndName(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 == 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 if (configType == 3) { //数组
+ JSONArray objects = new JSONArray(configValue);
+ JSONUtils.updateConfigFile(filePath, fileName, configName, configType, objects);
+ }
} 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);
+// }
+ } else {
+ ifmessageCorrect = false;
+ }
+ } else {
+ ifmessageCorrect = false;
+ }
+ if (ifmessageCorrect) {
+ sendmessage = content + " OK";
+ } else {
+ sendmessage = content + " ERROR";
+ }
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+
+ }
- if (rebootMpApp != 0) {
- MicroPhotoContext.restartMpApp(context, "Config Updated From SMS");
+ //替换配置文件
+ private static void updateFile(String content) {
+ boolean ifmessageCorrect = true;
+ Map fields = new HashMap<>();
+ try {
+ String[] parts = StringUtils.splitStringByDh(content.substring(SmsTypeEnum.UPD_FILE.value().length()));
+ int fileType = 0;
+ int numberOfFields = 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, "v")) {
+ fileStr = value;
+ } else if (TextUtils.equals(key, "r")) {
+ restartType = Integer.parseInt(value);
+ } else if (TextUtils.equals(key, "p")) {
+ filePath = value;
+ }
+ }
+ if (StringUtils.isNotEmpty(fileStr)) {
+ if (StringUtils.isEmpty(filePath)) {
+ HashMap hashMap = ValueTypeUtil.checkFilePathAndName(fileType);
+ filePath = hashMap.get(UpdateSysConfigUtil.FILEPATH);
+ fileName = hashMap.get(UpdateSysConfigUtil.FILENAME);
+ if (StringUtils.isEmpty(filePath) || StringUtils.isEmpty(fileName)) {
+ ifmessageCorrect = false;
+ } else {
+ filePath += fileName;
+ }
+ }
+ if (StringUtils.isNotEmpty(filePath)) {
+ byte[] decode = Base64.decode(fileStr, Base64.NO_WRAP);
+ FilesUtils.writeFile(filePath, decode);
} 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;
}
+ } else {
+ ifmessageCorrect = false;
+ }
+ if (ifmessageCorrect) {
+ sendmessage = content + " OK";
+ } else {
+ sendmessage = content + " ERROR";
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
- private static String queryConfigFile(Context context, String content) {
- String result = "ERR";
-
+ //获取配置文件
+ private static void queryFile(String content) {
+ boolean ifmessageCorrect = true;
+ String result = null;
try {
- String[] parts = TextUtils.split(content.substring(SmsTypeEnum.UPD_CFG_FILE.value().length()), "(\\s|,|,)");
+ String[] parts = StringUtils.splitStringByDh(content.substring(SmsTypeEnum.GET_FILE.value().length()));
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;
}
}
-
- switch (fileType) {
- case 1:
- filePath = MicroPhotoContext.buildMpAppDir(context) + "/data/App.json";
- break;
- case 2:
- filePath = MicroPhotoContext.buildMasterAppDir(context) + "/data/Master.json";
- break;
- case 91:
- case 92:
- case 93:
- case 94:
- case 95:
- case 96:
- case 97:
- case 98:
- case 99:
- filePath = MicroPhotoContext.buildMpAppDir(context) + "/data/channels/" + Integer.toString(fileType - 90) + ".json";
- break;
- default:
- break;
- }
-
- if (!TextUtils.isEmpty(filePath)) {
- File file = new File(filePath);
+ HashMap hashMap = ValueTypeUtil.checkFilePathAndName(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 void queryConfig(String content) {
+ boolean ifmessageCorrect = true;
+ try {
+ String[] parts = StringUtils.splitStringByDh(content.substring(SmsTypeEnum.GET_CFG_FILE.value().length()));
+ int fileType = 0;
+ String filePath = null;
+ String fileName = null;
+ int numberOfFields = 0;
+ Map fields = 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")) {
+ fileType = Integer.parseInt(value);
+ } else if (TextUtils.equals(key, "c")) {
+ 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 hashMap = ValueTypeUtil.checkFilePathAndName(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++) {
+ 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);
+ content += (",t" + idxStr + "=" + i + "," + "v" + idxStr + "=" + o.toString());
+ }
+ }
+ }
+ }
+ } else {
+ ifmessageCorrect = false;
+ }
+ if (ifmessageCorrect) {
+ sendmessage = content;
+ } else {
+ sendmessage = content + " ERROR";
+ }
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
}
+
public static String getSimStateName(int simState) {
switch (simState) {
case TelephonyManager.SIM_STATE_UNKNOWN:
@@ -1043,7 +1155,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) {
@@ -1063,8 +1175,8 @@ public class SimUtil {
}
}
Intent itSend = new Intent(SMS_SEND_ACTION);
- itSend.putExtra(SMSTYPE, value);
- itSend.putExtra(SMSIFCORRECT, ifmessageCorrect);
+ itSend.putExtra(SMSRESTARTTYPE, restartType);
+// itSend.putExtra(SMSIFCORRECT, true);
// itSend.putExtra(SMSDATA, (Serializable) jsonArray);
//sendIntent参数为传送后接受的广播信息PendingIntent
PendingIntent sendPI = PendingIntent.getBroadcast(mContext, mRequestCode++, itSend, 0);
@@ -1074,7 +1186,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 msgs = smsManager.divideMessage(message);
ArrayList sentIntents = new ArrayList();
@@ -1195,6 +1307,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 getModelSlot(Context mContext) {
List data = new ArrayList<>();
diff --git a/mpmaster/src/main/java/com/xypower/mpmaster/sms/SmsSendReceiver.java b/mpmaster/src/main/java/com/xypower/mpmaster/sms/SmsSendReceiver.java
index a2b054fd..2e147017 100644
--- a/mpmaster/src/main/java/com/xypower/mpmaster/sms/SmsSendReceiver.java
+++ b/mpmaster/src/main/java/com/xypower/mpmaster/sms/SmsSendReceiver.java
@@ -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,11 +25,7 @@ public class SmsSendReceiver extends BroadcastReceiver {
}
if (SimUtil.SMS_SEND_ACTION.equals(action)) {
- final String type = intent.getStringExtra(SimUtil.SMSTYPE);
- if (TextUtils.isEmpty(type)) {
- return;
- }
-
+ int restartType = intent.getIntExtra(SimUtil.SMSRESTARTTYPE, -1);
Thread th = new Thread(new Runnable() {
@Override
public void run() {
@@ -44,7 +35,7 @@ public class SmsSendReceiver extends BroadcastReceiver {
ex.printStackTrace();
}
try {
- processSms(context, intent, action, type);
+ processSms(context, restartType);
} catch (Exception ex) {
ex.printStackTrace();
}
@@ -55,40 +46,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())) {
- MpMasterService.rebootDevice();
- } else if (type.contains(SmsTypeEnum.REBOOT2.value())) {
+ public void processSms(Context context, int restartType) {
+ if (restartType == 0) {
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);
+// }
}
}
\ No newline at end of file
diff --git a/mpmaster/src/main/java/com/xypower/mpmaster/sms/SmsTypeEnum.java b/mpmaster/src/main/java/com/xypower/mpmaster/sms/SmsTypeEnum.java
index beaa3439..c8de2819 100644
--- a/mpmaster/src/main/java/com/xypower/mpmaster/sms/SmsTypeEnum.java
+++ b/mpmaster/src/main/java/com/xypower/mpmaster/sms/SmsTypeEnum.java
@@ -65,8 +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_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数据获取
diff --git a/mpmaster/src/main/java/com/xypower/mpmaster/sms/StringUtils.java b/mpmaster/src/main/java/com/xypower/mpmaster/sms/StringUtils.java
index 7c37245a..2f249bb8 100644
--- a/mpmaster/src/main/java/com/xypower/mpmaster/sms/StringUtils.java
+++ b/mpmaster/src/main/java/com/xypower/mpmaster/sms/StringUtils.java
@@ -1,6 +1,8 @@
package com.xypower.mpmaster.sms;
+import android.text.TextUtils;
+
import java.util.*;
/**
@@ -341,6 +343,15 @@ public class StringUtils {
return temp;
}
+ /**
+ * 排除outStr字段后,按照,号切割字符串
+ */
+ public static String[] splitStringByDh(String content) {
+ String[] temp = null;
+ temp = TextUtils.split(content, "(\\s|,|,)");
+ return temp;
+ }
+
/**
* 将字符串转成Int类型
*/
diff --git a/mpmaster/src/main/java/com/xypower/mpmaster/sms/UpdateSysConfigUtil.java b/mpmaster/src/main/java/com/xypower/mpmaster/sms/UpdateSysConfigUtil.java
index 7f14cbbd..dccdc568 100644
--- a/mpmaster/src/main/java/com/xypower/mpmaster/sms/UpdateSysConfigUtil.java
+++ b/mpmaster/src/main/java/com/xypower/mpmaster/sms/UpdateSysConfigUtil.java
@@ -23,7 +23,6 @@ import java.util.List;
import java.util.Map;
public class UpdateSysConfigUtil {
- public static final String PACKAGE_NAME_MPAPP = "com.xypower.mpapp";
public static final String APP_ACTION_UPDATE_CONFIGS = "com.xypower.mpapp.ACT_UPD_CFG";
private static final String MASTER_ACTION_UPDATE_CONFIGS = "com.xypower.mpmaster.ACT_UPD_CFG";
@@ -42,6 +41,8 @@ public class UpdateSysConfigUtil {
public static String rightTop = "rightTop";
public static String leftBottom = "leftBottom";
public static String rightBottom = "rightBottom";
+ public static String FILEPATH = "filePath";
+ public static String FILENAME = "fileName";
//创建运维配置文件文件夹
public static String buildAppDir(String packageurl) {
@@ -61,11 +62,19 @@ public class UpdateSysConfigUtil {
//获取配置文件地址
public static String getChannelDir(int channel) {
- String appPath = buildAppDir(PACKAGE_NAME_MPAPP);
+ String appPath = buildAppDir(MicroPhotoContext.PACKAGE_NAME_MPAPP);
String path = appPath + "data/channels/" + channel + ".json";
return path;
}
+
+ //获取配置文件地址
+ public static String getMpAppDir() {
+ String appPath = buildAppDir(MicroPhotoContext.PACKAGE_NAME_MPAPP);
+ String content = FilesUtils.readTextFile(appPath + "data/Master.json");
+ return content;
+ }
+
//获取配置文件地址
public static String getSerialNo() {
String mSerialNo;
@@ -79,7 +88,7 @@ public class UpdateSysConfigUtil {
//获取配置文件地址
public static String getScheduleDir(int channel) {
- String appPath = buildAppDir(PACKAGE_NAME_MPAPP);
+ String appPath = buildAppDir(MicroPhotoContext.PACKAGE_NAME_MPAPP);
String path = appPath + "data/schedules/" + channel;
return path;
}
@@ -331,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 {
@@ -456,21 +465,107 @@ public class UpdateSysConfigUtil {
}
}
} else if (actType.toLowerCase().equalsIgnoreCase(SmsTypeEnum.GET.value().toLowerCase())) {
-
+ for (int i = 0; i < list.size(); i++) {
+ HashMap 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 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;
- }
-
}
diff --git a/mpmaster/src/main/java/com/xypower/mpmaster/sms/ValueTypeUtil.java b/mpmaster/src/main/java/com/xypower/mpmaster/sms/ValueTypeUtil.java
new file mode 100644
index 00000000..f9a8248d
--- /dev/null
+++ b/mpmaster/src/main/java/com/xypower/mpmaster/sms/ValueTypeUtil.java
@@ -0,0 +1,75 @@
+package com.xypower.mpmaster.sms;
+
+
+import com.xypower.common.MicroPhotoContext;
+
+import org.json.JSONArray;
+
+import java.util.HashMap;
+
+public class ValueTypeUtil {
+
+ /*
+ *
+ * 类型
+ 0:number
+ 1:string
+ 2:float
+ *
+ * */
+ public static int checkType(Object item) {
+ if (item instanceof String) {
+ return 1;
+ } else if (item instanceof Integer) {
+ return 0;
+ } else if (item instanceof Double) {
+ return 2;
+ } else if (item instanceof JSONArray) {
+ return 3;
+ } else {
+ return -1;
+ }
+
+ }
+
+ /*
+ * 根据短信类型来判断是修改哪个配置文件
+ *
+ * */
+ public static HashMap checkFilePathAndName( int fileType) {
+ HashMap hashMap = new HashMap<>();
+ String filePath = null;
+ String fileName = null;
+ switch (fileType) {
+ case 1:
+ filePath =MicroPhotoContext.PACKAGE_NAME_MPAPP + "/data/";
+ fileName = "App.json";
+ break;
+ case 2:
+ filePath =MicroPhotoContext.PACKAGE_NAME_MPMASTER + "/data/";
+ fileName = "Master.json";
+ break;
+ case 91:
+ case 92:
+ case 93:
+ case 94:
+ case 95:
+ case 96:
+ case 97:
+ case 98:
+ case 99:
+ filePath =MicroPhotoContext.PACKAGE_NAME_MPAPP + "/data/channels/";
+ fileName = Integer.toString(fileType - 90) + ".json";
+ break;
+ default:
+ break;
+
+ }
+
+ hashMap.put(UpdateSysConfigUtil.FILEPATH, filePath);
+ hashMap.put(UpdateSysConfigUtil.FILENAME, fileName);
+ return hashMap;
+ }
+
+
+}