diff --git a/common/src/main/java/com/xypower/common/FilesUtils.java b/common/src/main/java/com/xypower/common/FilesUtils.java index 24645db2..ac9926b8 100644 --- a/common/src/main/java/com/xypower/common/FilesUtils.java +++ b/common/src/main/java/com/xypower/common/FilesUtils.java @@ -14,6 +14,10 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.UnsupportedEncodingException; +import java.nio.channels.Channels; +import java.nio.channels.SeekableByteChannel; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -216,4 +220,20 @@ public class FilesUtils { return TextUtils.split(output,"\n"); } + + public static byte[] readAllBytes(File file) { + byte[] bytes = null; + FileInputStream fileInputStream = null; + try { + bytes = new byte[(int)file.length()]; + fileInputStream = new FileInputStream(file); + fileInputStream.read(bytes); + } catch (Exception ex) { + ex.printStackTrace(); + } finally { + closeFriendly(fileInputStream); + } + + return bytes; + } } 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 43e065a1..e4d57968 100644 --- a/mpmaster/src/main/java/com/xypower/mpmaster/sms/SimUtil.java +++ b/mpmaster/src/main/java/com/xypower/mpmaster/sms/SimUtil.java @@ -23,6 +23,7 @@ import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.text.TextUtils; import android.util.Log; +import android.util.Base64; import androidx.core.app.ActivityCompat; @@ -34,19 +35,15 @@ import com.xypower.common.NetworkUtils; import com.xypower.common.RegexUtil; import com.xypower.mpmaster.MpMasterService; -import org.json.JSONObject; - +import java.io.File; import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Base64; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; import java.util.TimeZone; -import java.util.concurrent.ExecutionException; /* @@ -466,6 +463,10 @@ public class SimUtil { ifmessageCorrect = true; sendmessage = " OK"; updateConfigFile(context, content); + } else if (content.contains(SmsTypeEnum.GET_CFG_FILE.value())) { + sendtype = SmsTypeEnum.GET_CFG_FILE.value(); + ifmessageCorrect = true; + sendmessage = queryConfigFile(context, content); } else if (content.contains(SmsTypeEnum.SET_TP.value())) { sendtype = SmsTypeEnum.SET_TP.value(); String[] split1 = StringUtils.splitString1(content); @@ -790,6 +791,76 @@ public class SimUtil { } } + private static String queryConfigFile(Context context, String content) { + String result = ""; + + try { + String[] parts = TextUtils.split(content.substring(SmsTypeEnum.UPD_CFG_FILE.value().length()), "(\\s|,|,)"); + int fileType = 0; + String filePath = 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, "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); + if (file.exists()) { + try { + result = Base64.encodeToString(FilesUtils.readAllBytes(file), Base64.NO_WRAP); + } catch (Exception ex) { + ex.printStackTrace(); + } + } else { + result = "NOT Existed"; + } + } + } + } catch (Exception ex) { + ex.printStackTrace(); + } + + return result; + } + public static String getSimStateName(int simState) { switch (simState) { case TelephonyManager.SIM_STATE_UNKNOWN: 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 7ab4bf73..951ad2b3 100644 --- a/mpmaster/src/main/java/com/xypower/mpmaster/sms/SmsTypeEnum.java +++ b/mpmaster/src/main/java/com/xypower/mpmaster/sms/SmsTypeEnum.java @@ -46,7 +46,8 @@ public enum SmsTypeEnum { 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/3] 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_GPS("yw+at+getGPS");//GPS数据获取