同步Main的分支的改动

nx2024
Matthew 4 months ago
parent 4ff46f6eab
commit f968778915

@ -4,7 +4,7 @@ plugins {
def AppMajorVersion = 1 def AppMajorVersion = 1
def AppMinorVersion = 0 def AppMinorVersion = 0
def AppBuildNumber = 95 def AppBuildNumber = 96
def AppVersionName = AppMajorVersion + "." + AppMinorVersion + "." + AppBuildNumber def AppVersionName = AppMajorVersion + "." + AppMinorVersion + "." + AppBuildNumber
def AppVersionCode = AppMajorVersion * 100000 + AppMinorVersion * 1000 + AppBuildNumber def AppVersionCode = AppMajorVersion * 100000 + AppMinorVersion * 1000 + AppBuildNumber
@ -14,8 +14,8 @@ android {
defaultConfig { defaultConfig {
applicationId "com.xypower.mpmaster" applicationId "com.xypower.mpmaster"
minSdk COMPILE_MIN_SDK_VERSION as int minSdk 28
targetSdk TARGET_SDK_VERSION as int targetSdk 28
versionCode AppVersionCode versionCode AppVersionCode
versionName AppVersionName versionName AppVersionName

@ -13,6 +13,8 @@
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" /> <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_LOGS" />
<uses-permission android:name="android.permission.PACKAGE_USAGE_STATS" />
<uses-permission <uses-permission
android:name="android.permission.FORCE_STOP_PACKAGES" android:name="android.permission.FORCE_STOP_PACKAGES"
tools:ignore="ProtectedPermissions" /> tools:ignore="ProtectedPermissions" />

@ -120,7 +120,7 @@ public class AppMaster {
return (System.currentTimeMillis() - SystemClock.elapsedRealtimeNanos() / 1000000) / 1000; return (System.currentTimeMillis() - SystemClock.elapsedRealtimeNanos() / 1000000) / 1000;
} }
public void start() { public void start(final boolean isCriticalTime) {
new Thread(new Runnable() { new Thread(new Runnable() {
@ -160,7 +160,7 @@ public class AppMaster {
} }
try { try {
runImpl(); runImpl(isCriticalTime);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
@ -177,7 +177,7 @@ public class AppMaster {
} }
} else { } else {
try { try {
runImpl(); runImpl(isCriticalTime);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
@ -186,7 +186,7 @@ public class AppMaster {
}).start(); }).start();
} }
private boolean runImpl() { private boolean runImpl(final boolean isCriticalTime) {
String masterUrl = mMasterUrl; String masterUrl = mMasterUrl;
if (TextUtils.isEmpty(masterUrl)) { if (TextUtils.isEmpty(masterUrl)) {
@ -201,8 +201,10 @@ public class AppMaster {
now.setMinutes(0); now.setMinutes(0);
now.setSeconds(0); now.setSeconds(0);
long startTime = now.getTime() / 1000; final long startTimeMs = now.getTime();
long endTime = startTime + 86400 - 1; 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()); 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<String, String>("signalLevel1", Integer.toString(MpMasterService.getSignalLevel(1)))); postParams.add(new Pair<String, String>("signalLevel1", Integer.toString(MpMasterService.getSignalLevel(1))));
postParams.add(new Pair<String, String>("signalLevel2", Integer.toString(MpMasterService.getSignalLevel(2)))); postParams.add(new Pair<String, String>("signalLevel2", Integer.toString(MpMasterService.getSignalLevel(2))));
// SysApi. if (isCriticalTime) {
postParams.add(new Pair<String, String>("simcard1", mService.getIccid(1))); // SysApi.
// if (mService.isSeparateNetwork()) { postParams.add(new Pair<String, String>("simcard1", mService.getIccid(1)));
postParams.add(new Pair<String, String>("simcard2", mService.getIccid(2))); // if (mService.isSeparateNetwork()) {
// } postParams.add(new Pair<String, String>("simcard2", mService.getIccid(2)));
postParams.add(new Pair<String, String>("freeROM", getFreeROM()));
postParams.add(new Pair<String, String>("freeROM", getFreeROM())); /*
String crashTimes = getCrashTimes(startTimeMs, endTimeMs);
if (!TextUtils.isEmpty(crashTimes)) {
postParams.add(new Pair<String, String>("crashes", crashTimes));
}
*/
}
buildStats(startTime, postParams); buildStats(startTime, postParams);
@ -445,7 +455,7 @@ public class AppMaster {
ex.printStackTrace(); ex.printStackTrace();
} }
} }
private String getCrashTimes(final long startTimeMs, final long endTimeMs) { private String getCrashTimes(final long startTimeMs, final long endTimeMs) {
String path = "/data/system/dropbox/"; String path = "/data/system/dropbox/";
final String prefixFileName = "data_app_crash@"; 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]); return ((cnts[0] == 0) && (cnts[1] == 0)) ? null : Integer.toString(cnts[0]) + " " + Integer.toString(cnts[1]);
} }
private String getImei(int number) { private String getImei(int number) {
return (number == 1) ? SysApi.getImei(mService) : SysApi.getImei2(mService); return (number == 1) ? SysApi.getImei(mService) : SysApi.getImei2(mService);
} }

@ -14,6 +14,7 @@ import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.res.AssetManager; import android.content.res.AssetManager;
import android.os.Build; import android.os.Build;
import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import android.os.Handler; import android.os.Handler;
import android.os.IBinder; 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_STOP = "com.xypower.mpmaster.ACT_STOP";
public static final String ACTION_MAIN = "com.xypower.mpmaster.ACT_MAIN"; 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_UPD_OTA = SysApi.OTA_RESULT_ACTION;
public static final String ACTION_INSTALL_RESULT = SysApi.INSTALL_RESULT_ACTION; public static final String ACTION_INSTALL_RESULT = SysApi.INSTALL_RESULT_ACTION;
public static final String ACTION_UNINSTALL_RESULT = SysApi.UNINSTALL_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 SmsSendReceiver mSmsSnedReceiver;
private int mPrevDateForLogs = 0; private int mPrevDateForLogs = 0;
private int mMasterTimers = 0;
public static class STATE_SERVICE { public static class STATE_SERVICE {
public static final int CONNECTED = 10; public static final int CONNECTED = 10;
@ -244,6 +248,7 @@ public class MpMasterService extends Service {
intentFilter.addAction(ACTION_UPD_OTA); intentFilter.addAction(ACTION_UPD_OTA);
intentFilter.addAction(ACTION_INSTALL_RESULT); intentFilter.addAction(ACTION_INSTALL_RESULT);
intentFilter.addAction(ACTION_UNINSTALL_RESULT); intentFilter.addAction(ACTION_UNINSTALL_RESULT);
intentFilter.addAction(ACTION_REQ_RESTART_APP);
intentFilter.addAction(MicroPhotoContext.ACTION_HEARTBEAT_MP); intentFilter.addAction(MicroPhotoContext.ACTION_HEARTBEAT_MP);
registerReceiver(mAlarmReceiver, intentFilter); registerReceiver(mAlarmReceiver, intentFilter);
@ -390,64 +395,42 @@ public class MpMasterService extends Service {
final Context context = getApplicationContext(); final Context context = getApplicationContext();
long ts = System.currentTimeMillis(); long ts = System.currentTimeMillis();
FileOutputStream runningFile = null;
FileLock fileLock = null;
try { try {
boolean isMpAppRunning = true; boolean isMpAppRunning = detectMpAppRunning();
String mpappDir = MicroPhotoContext.buildMpAppDir(getApplicationContext()); if (!isMpAppRunning) {
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 { try {
if (fileLock != null) { Thread.sleep(1000);
fileLock.close();
fileLock = null;
}
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
FilesUtils.closeFriendly(runningFile); // Check twice
} else { isMpAppRunning = detectMpAppRunning();
isMpAppRunning = false;
} }
if (!isMpAppRunning) { if (!isMpAppRunning) {
// Restart MpApp // Restart MpApp
MicroPhotoContext.restartMpApp(context, "MpMST Keep Alive Detection: NO Lock"); MicroPhotoContext.restartMpApp(context, "MpMST Keep Alive Detection: NO Lock");
logger.warning("Restart MpAPP as There is NO Lock"); logger.warning("Restart MpAPP as There is NO Lock");
mTimeToStartMpApp = ts;
return; return;
} }
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} finally {
try {
if (fileLock != null) {
fileLock.close();
}
} catch (Exception ex) {
ex.printStackTrace();
}
FilesUtils.closeFriendly(runningFile);
} }
long tempduration = mMpHeartbeatDuration; long tempduration = mMpHeartbeatDuration;
if(mMpHeartbeatDuration < 600000) if(mMpHeartbeatDuration < 600000)
tempduration = 300000; tempduration = 290000;
if (mPreviousMpHbTime <= ts && ts - mPreviousMpHbTime > tempduration * 2) { if (mPreviousMpHbTime <= ts && ts - mPreviousMpHbTime > tempduration * 2) {
// MpApp is not running // MpApp is not running
if (ts - mTimeToStartMpApp >= 1800000) { // 30 minutes 30 * 60 * 1000 if (ts - mTimeToStartMpApp >= 1800000) { // 30 minutes 30 * 60 * 1000
MicroPhotoContext.restartMpApp(context, "MpMST Keep Alive Detection"); MicroPhotoContext.restartMpApp(context, "MpMST Keep Alive Detection");
logger.warning("Restart MpAPP as it is NOT Running Prev MPAPP HB=" + logger.warning("Restart MpAPP as it is NOT Running Prev MPAPP HB=" +
Long.toString((ts - mPreviousMpHbTime) / 1000) + " MPAPP HBDuration=" + Long.toString(mMpHeartbeatDuration) Long.toString((ts - mPreviousMpHbTime) / 1000) + " MPAPP HBDuration=" + Long.toString(mMpHeartbeatDuration)
+ " Prev MpRestart Time=" + Long.toString(mTimeToStartMpApp) + " last MPAPPHB =" + (mPreviousMpHbTime/1000)); + " Prev MpRestart Time=" + Long.toString(mTimeToStartMpApp) + " last MPAPPHB =" + (mPreviousMpHbTime/1000));
mTimeToStartMpApp = ts; 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 { } else {
logger.warning("MpAPP has restarted during 30min, skip the check."); logger.warning("MpAPP has restarted during 30min, skip the check.");
} }
@ -474,17 +457,54 @@ public class MpMasterService extends Service {
MicroPhotoContext.restartMpApp(context, msg, mDelayedRestartMpTime); MicroPhotoContext.restartMpApp(context, msg, mDelayedRestartMpTime);
int uniqueReqCode = reqCode.getAndIncrement(); mTimeToStartMpApp = ts + mDelayedRestartMpTime / 1000;
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, uniqueReqCode, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); }
}
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, ts + mDelayedRestartMpTime, pendingIntent); } 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) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} finally {
try {
if (fileLock != null) {
fileLock.close();
}
} catch (Exception ex) {
ex.printStackTrace();
}
FilesUtils.closeFriendly(runningFile);
} }
return isMpAppRunning;
} }
long getFileModificationTime(String path) { 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) { private void startMaster(boolean bundleWithMpApp) {
String masterUrl = MicroPhotoContext.DEFAULT_MASTER_URL; String masterUrl = MicroPhotoContext.DEFAULT_MASTER_URL;
@ -583,10 +611,6 @@ public class MpMasterService extends Service {
if (appConfig.heartbeat > 0) { if (appConfig.heartbeat > 0) {
mMpHeartbeatDuration = appConfig.heartbeat * 60000; 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")); 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(); mService.detectMpAppAlive();
} else if (TextUtils.equals(MicroPhotoContext.ACTION_HEARTBEAT_MP, action)) { } else if (TextUtils.equals(MicroPhotoContext.ACTION_HEARTBEAT_MP, action)) {
if (intent.hasExtra("HeartbeatDuration")) { if (intent.hasExtra("HeartbeatDuration")) {
int hbDuration = intent.getIntExtra("HeartbeatDuration", 600000); int hbDuration = intent.getIntExtra("HeartbeatDuration", 600000);
mService.mMpHeartbeatDuration = hbDuration > 0 ? hbDuration : 600000; mService.mMpHeartbeatDuration = hbDuration > 0 ? hbDuration : 600000;
@ -692,6 +714,23 @@ public class MpMasterService extends Service {
String pkname = intent.getStringExtra("pkname"); String pkname = intent.getStringExtra("pkname");
String msg = intent.getStringExtra("msg"); String msg = intent.getStringExtra("msg");
mService.logger.warning("UNINSTALL APP result =" + bSucc + ",pkname=" + pkname + ",msg=" + 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();
}
} }
} }
} }

@ -11,8 +11,6 @@ import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.database.Cursor; import android.database.Cursor;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkInfo;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
@ -40,8 +38,10 @@ import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.File; import java.io.File;
import java.lang.reflect.Field;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -61,17 +61,19 @@ public class SimUtil {
// 自定义ACTION常数 作为广播的IntentFilter识别常数 // 自定义ACTION常数 作为广播的IntentFilter识别常数
public static String SMS_SEND_ACTION = "com.xypower.mpmaster.SMS_SEND_ACTION"; public static String SMS_SEND_ACTION = "com.xypower.mpmaster.SMS_SEND_ACTION";
public static String SMSTYPE = "smstype"; public static String SMSRESTARTTYPE = "restartType";
public static String SMSIFCORRECT = "smsifcorrect";
private static int mRequestCode = 1; 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) { public static void analysisSMSInfo(final Context context, final Intent intent, final SmsMessage smsMessage) {
sendmessage = null;
restartType = -1;
SmsMessageModel smsInfo = getSMSInfo(intent, smsMessage); SmsMessageModel smsInfo = getSMSInfo(intent, smsMessage);
if (smsInfo != null) { if (smsInfo != null) {
String packageName = context.getApplicationContext().getPackageName();
String content = smsInfo.getContent(); String content = smsInfo.getContent();
int pos = content.lastIndexOf("##"); int pos = content.lastIndexOf("##");
if (pos != -1) { if (pos != -1) {
@ -80,7 +82,6 @@ public class SimUtil {
int slot = smsInfo.getSlot();//那张卡收到的短信 int slot = smsInfo.getSlot();//那张卡收到的短信
String sender = smsInfo.getSender();//收到的短信的手机号 String sender = smsInfo.getSender();//收到的短信的手机号
String sendmessage = "ERROR";//要回复的短信 String sendmessage = "ERROR";//要回复的短信
String sendtype = "";//收到的短信类型
List<Integer> abslist = new ArrayList<>();//收到的短信内容拆分包装成数组 List<Integer> abslist = new ArrayList<>();//收到的短信内容拆分包装成数组
boolean ifmessageCorrect = false;//用来判断收到的短信内容是否正确 boolean ifmessageCorrect = false;//用来判断收到的短信内容是否正确
if (StringUtils.isEmpty(content)) { if (StringUtils.isEmpty(content)) {
@ -717,171 +718,282 @@ public class SimUtil {
return result; return result;
} }
private static void updateConfigFile(Context context, String content) {
String result = "";
Map<String, String> fields = new HashMap<>();
int rebootMpApp = 0;
//修改配置文件中参数
private static void updateConfig(String content) {
boolean ifmessageCorrect = true;
Map<String, String> fields = new HashMap<>();
try { 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 fileType = 0;
int numberOfFields = 0; int numberOfFields = 0;
String filePath = null;
String fileName = null;
if (parts != null) { if (parts != null) {
for (String part : parts) { for (String part : parts) {
if (TextUtils.isEmpty(part)) { if (TextUtils.isEmpty(part)) {
continue; continue;
} }
int pos = part.indexOf("="); int pos = part.indexOf("=");
if (pos == -1) { if (pos == -1) {
continue; continue;
} }
String key = part.substring(0, pos); String key = part.substring(0, pos);
String value = part.substring(pos + 1); String value = part.substring(pos + 1);
if (value.contains("&&")) {
value = value.replace("&&", ",");
}
if (TextUtils.equals(key, "f")) { if (TextUtils.equals(key, "f")) {
fileType = Integer.parseInt(value); fileType = Integer.parseInt(value);
} else if (TextUtils.equals(key, "c")) { } else if (TextUtils.equals(key, "c")) {
numberOfFields = Integer.parseInt(value); numberOfFields = Integer.parseInt(value);
} else if (TextUtils.equals(key, "r")) { } else if (TextUtils.equals(key, "r")) {
rebootMpApp = Integer.parseInt(value); restartType = Integer.parseInt(value);
} else { } else {
fields.put(key, value); fields.put(key, value);
} }
} }
HashMap<String, String> hashMap = ValueTypeUtil.checkFilePathAndName(fileType);
String filePath = null; filePath = hashMap.get(UpdateSysConfigUtil.FILEPATH);
String fileName = null; fileName = hashMap.get(UpdateSysConfigUtil.FILENAME);
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;
}
if (!TextUtils.isEmpty(filePath) && !TextUtils.isEmpty(fileName) && numberOfFields > 0) { if (!TextUtils.isEmpty(filePath) && !TextUtils.isEmpty(fileName) && numberOfFields > 0) {
for (int idx = 0; idx <= numberOfFields; idx++) { for (int idx = 0; idx < numberOfFields; idx++) {
String idxStr = Integer.toString(idx); String idxStr = Integer.toString(idx);
// JSONObject jsonConfig = jsonConfigs.getJSONObject(idx);
String configName = fields.containsKey("n" + idxStr) ? fields.get("n" + idxStr) : null; String configName = fields.containsKey("n" + idxStr) ? fields.get("n" + idxStr) : null;
int configType = fields.containsKey("t" + idxStr) ? Integer.parseInt(fields.get("t" + idxStr)) : 0; int configType = fields.containsKey("t" + idxStr) ? Integer.parseInt(fields.get("t" + idxStr)) : 0;
String configValue = fields.containsKey("v" + idxStr) ? fields.get("v" + idxStr) : null; String configValue = fields.containsKey("v" + idxStr) ? fields.get("v" + idxStr) : null;
if (StringUtils.isNotEmpty(configValue)) {
if (configType == 0) { // Number if (configType == 0) { // Number
Long val = Long.parseLong(configValue); Long val = Long.parseLong(configValue);
JSONUtils.updateConfigFile(filePath, fileName, configName, configType, val); JSONUtils.updateConfigFile(filePath, fileName, configName, configType, val);
} else if (configType == 2) { // Float } else if (configType == 1) {
Float val = Float.parseFloat(configValue); JSONUtils.updateConfigFile(filePath, fileName, configName, configType, 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 if (configType == 3) { //数组
JSONArray objects = new JSONArray(configValue);
JSONUtils.updateConfigFile(filePath, fileName, configName, configType, objects);
}
} else { } 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<String, String> 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<String, String> 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 { } else {
Intent intent = new Intent(); ifmessageCorrect = false;
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) { } catch (Exception ex) {
ex.printStackTrace(); 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 { 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; int fileType = 0;
String filePath = null; String filePath = null;
String fileName = null;
String fileStr = null;
if (parts != null) { if (parts != null) {
for (String part : parts) { for (String part : parts) {
if (TextUtils.isEmpty(part)) { if (TextUtils.isEmpty(part)) {
continue; continue;
} }
int pos = part.indexOf("="); int pos = part.indexOf("=");
if (pos == -1) { if (pos == -1) {
continue; continue;
} }
String key = part.substring(0, pos); String key = part.substring(0, pos);
String value = part.substring(pos + 1); String value = part.substring(pos + 1);
if (TextUtils.equals(key, "f")) { if (TextUtils.equals(key, "f")) {
fileType = Integer.parseInt(value); fileType = Integer.parseInt(value);
} else if (TextUtils.equals(key, "r")) {
restartType = Integer.parseInt(value);
} else if (TextUtils.equals(key, "p")) { } else if (TextUtils.equals(key, "p")) {
filePath = value; filePath = value;
} }
} }
HashMap<String, String> hashMap = ValueTypeUtil.checkFilePathAndName(fileType);
switch (fileType) { filePath = hashMap.get(UpdateSysConfigUtil.FILEPATH);
case 1: fileName = hashMap.get(UpdateSysConfigUtil.FILENAME);
filePath = MicroPhotoContext.buildMpAppDir(context) + "/data/App.json"; if (!TextUtils.isEmpty(filePath + fileName)) {
break; File file = new File(filePath + fileName);
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);
if (file.exists()) { if (file.exists()) {
try { try {
result = Base64.encodeToString(FilesUtils.readAllBytes(file), Base64.NO_WRAP); fileStr = Base64.encodeToString(FilesUtils.readAllBytes(file), Base64.NO_WRAP);
if (StringUtils.isEmpty(fileStr)) {
ifmessageCorrect = false;
}
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ifmessageCorrect = false;
} }
} else { } else {
result = "NOT Existed"; ifmessageCorrect = false;
} }
} }
} else {
ifmessageCorrect = false;
}
if (ifmessageCorrect) {
sendmessage = content + ",v=" + fileStr;
} else {
sendmessage = content + " ERROR";
} }
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
}
return result; //获取配置文件参数
private static 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<String, String> 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<String, String> 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) { public static String getSimStateName(int simState) {
switch (simState) { switch (simState) {
case TelephonyManager.SIM_STATE_UNKNOWN: case TelephonyManager.SIM_STATE_UNKNOWN:
@ -1043,7 +1155,7 @@ public class SimUtil {
} }
//指定sim卡位置发送短信 //指定sim卡位置发送短信
public static void sendSms(Context mContext, int slot, String sender, String message, String value, boolean ifmessageCorrect) { public static void sendSms(Context mContext, int slot, String sender, String message, int restartType) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
SubscriptionManager localSubscriptionManager = SubscriptionManager.from(mContext); SubscriptionManager localSubscriptionManager = SubscriptionManager.from(mContext);
if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) { if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
@ -1063,8 +1175,8 @@ public class SimUtil {
} }
} }
Intent itSend = new Intent(SMS_SEND_ACTION); Intent itSend = new Intent(SMS_SEND_ACTION);
itSend.putExtra(SMSTYPE, value); itSend.putExtra(SMSRESTARTTYPE, restartType);
itSend.putExtra(SMSIFCORRECT, ifmessageCorrect); // itSend.putExtra(SMSIFCORRECT, true);
// itSend.putExtra(SMSDATA, (Serializable) jsonArray); // itSend.putExtra(SMSDATA, (Serializable) jsonArray);
//sendIntent参数为传送后接受的广播信息PendingIntent //sendIntent参数为传送后接受的广播信息PendingIntent
PendingIntent sendPI = PendingIntent.getBroadcast(mContext, mRequestCode++, itSend, 0); PendingIntent sendPI = PendingIntent.getBroadcast(mContext, mRequestCode++, itSend, 0);
@ -1074,7 +1186,7 @@ public class SimUtil {
// PendingIntent deliverPI = PendingIntent.getBroadcast(mContext,0,itDeliver,0); // PendingIntent deliverPI = PendingIntent.getBroadcast(mContext,0,itDeliver,0);
if (simInfoAnother != null) { if (simInfoAnother != null) {
SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(simInfoAnother.getSubscriptionId()); SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(simInfoAnother.getSubscriptionId());
if (message.length() > 70) { if (message != null && message.length() > 70) {
ArrayList<String> msgs = smsManager.divideMessage(message); ArrayList<String> msgs = smsManager.divideMessage(message);
ArrayList<PendingIntent> sentIntents = new ArrayList<PendingIntent>(); ArrayList<PendingIntent> sentIntents = new ArrayList<PendingIntent>();
@ -1195,6 +1307,29 @@ public class SimUtil {
return getIcc(subID, getModelSlot(mContext)); 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 关联 //获取对应的卡槽ID和iccID 关联
private static List<ModelSlotAndSub> getModelSlot(Context mContext) { private static List<ModelSlotAndSub> getModelSlot(Context mContext) {
List<ModelSlotAndSub> data = new ArrayList<>(); List<ModelSlotAndSub> data = new ArrayList<>();

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

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

@ -1,6 +1,8 @@
package com.xypower.mpmaster.sms; package com.xypower.mpmaster.sms;
import android.text.TextUtils;
import java.util.*; import java.util.*;
/** /**
@ -341,6 +343,15 @@ public class StringUtils {
return temp; return temp;
} }
/**
* outStr,
*/
public static String[] splitStringByDh(String content) {
String[] temp = null;
temp = TextUtils.split(content, "(\\s|,|)");
return temp;
}
/** /**
* Int * Int
*/ */

@ -23,7 +23,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
public class UpdateSysConfigUtil { 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"; 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"; 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 rightTop = "rightTop";
public static String leftBottom = "leftBottom"; public static String leftBottom = "leftBottom";
public static String rightBottom = "rightBottom"; public static String rightBottom = "rightBottom";
public static String FILEPATH = "filePath";
public static String FILENAME = "fileName";
//创建运维配置文件文件夹 //创建运维配置文件文件夹
public static String buildAppDir(String packageurl) { public static String buildAppDir(String packageurl) {
@ -61,11 +62,19 @@ public class UpdateSysConfigUtil {
//获取配置文件地址 //获取配置文件地址
public static String getChannelDir(int channel) { 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"; String path = appPath + "data/channels/" + channel + ".json";
return path; 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() { public static String getSerialNo() {
String mSerialNo; String mSerialNo;
@ -79,7 +88,7 @@ public class UpdateSysConfigUtil {
//获取配置文件地址 //获取配置文件地址
public static String getScheduleDir(int channel) { 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; String path = appPath + "data/schedules/" + channel;
return path; return path;
} }
@ -331,7 +340,7 @@ public class UpdateSysConfigUtil {
Intent intent = new Intent(MicroPhotoContext.ACTION_RESTART_MP); Intent intent = new Intent(MicroPhotoContext.ACTION_RESTART_MP);
intent.putExtra("noDelay", 1); intent.putExtra("noDelay", 1);
intent.setPackage(PACKAGE_NAME_MPAPP); intent.setPackage(MicroPhotoContext.PACKAGE_NAME_MPAPP);
context.sendBroadcast(intent); context.sendBroadcast(intent);
try { try {
@ -456,21 +465,107 @@ public class UpdateSysConfigUtil {
} }
} }
} else if (actType.toLowerCase().equalsIgnoreCase(SmsTypeEnum.GET.value().toLowerCase())) { } else if (actType.toLowerCase().equalsIgnoreCase(SmsTypeEnum.GET.value().toLowerCase())) {
for (int i = 0; i < list.size(); i++) {
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())) { } 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())) { } 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;
}
} }

@ -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 {
/*
*
*
0number
1string
2float
*
* */
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<String, String> 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;
}
}
Loading…
Cancel
Save