时间表运维和下载更新

serial
liuguijing 1 year ago
parent aef5c13b93
commit 0f8951df6f

@ -0,0 +1,152 @@
package com.xypower.common;
import java.util.regex.Pattern;
public final class RegexUtil {
/**
* Email
*
* @param email emailzhangsan@sina.comzhangsan@xxx.com.cnxxx
* @return truefalse
*/
public static boolean checkEmail(String email) {
String regex = "\\w+@\\w+\\.[a-z]+(\\.[a-z]+)?";
return Pattern.matches(regex, email);
}
/**
*
*
* @param idCard 1518
* @return truefalse
*/
public static boolean checkIdCard(String idCard) {
String regex = "[1-9]\\d{13,16}[a-zA-Z0-9]{1}";
return Pattern.matches(regex, idCard);
}
/**
* +86135xxxx...+00852137xxxx...
*
* @param mobile
* <p>134(0-8)135136137138139147TD
* 150151152157TD158159187188TD</p>
* <p>1301311321551561851863g</p>
* <p>133153180189</p>
* @return truefalse
*/
public static boolean checkMobile(String mobile) {
String regex = "(\\+\\d+)?1[3458]\\d{9}$";
return Pattern.matches(regex, mobile);
}
/**
*
*
* @param phone + + +8602085588447
* <p><b> </b> 0 9
* </p>
* <p><b></b> 0 9
* 使</p>
* <p><b></b> 0 9 </p>
* @return truefalse
*/
public static boolean checkPhone(String phone) {
String regex = "(\\+\\d+)?(\\d{3,4}\\-?)?\\d{7,8}$";
return Pattern.matches(regex, phone);
}
/**
*
*
* @param digit 0-9
* @return truefalse
*/
public static boolean checkDigit(String digit) {
String regex = "\\-?[1-9]\\d+";
return Pattern.matches(regex, digit);
}
/**
*
*
* @param decimals 0-91.23233.30
* @return truefalse
*/
public static boolean checkDecimals(String decimals) {
String regex = "\\-?[1-9]\\d+(\\.\\d+)?";
return Pattern.matches(regex, decimals);
}
/**
*
*
* @param blankSpace \t\n\r\f\x0B
* @return truefalse
*/
public static boolean checkBlankSpace(String blankSpace) {
String regex = "\\s+";
return Pattern.matches(regex, blankSpace);
}
/**
*
*
* @param chinese
* @return truefalse
*/
public static boolean checkChinese(String chinese) {
String regex = "^[\u4E00-\u9FA5]+$";
return Pattern.matches(regex, chinese);
}
/**
*
*
* @param birthday 1992-09-031992.09.03
* @return truefalse
*/
public static boolean checkBirthday(String birthday) {
String regex = "[1-9]{4}([-./])\\d{1,2}\\1\\d{1,2}";
return Pattern.matches(regex, birthday);
}
/**
* URL
*
* @param url http://blog.csdn.net:80/xyang81/article/details/7705960? 或 http://www.csdn.net:80
* @return truefalse
*/
public static boolean checkURL(String url) {
String regex = "(https?://(w{3}\\.)?)?\\w+\\.\\w+(\\.[a-zA-Z]+)*(:\\d{1,5})?(/\\w*)*(\\??(.+=.*)?(&.+=.*)?)?";
return Pattern.matches(regex, url);
}
/**
*
*
* @param postcode
* @return truefalse
*/
public static boolean checkPostcode(String postcode) {
String regex = "[1-9]\\d{5}";
return Pattern.matches(regex, postcode);
}
/**
* IP(192.168.1.1127.0.0.1IP)
*
* @param ipAddress IPv4
* @return truefalse
*/
public static boolean checkIpAddress(String ipAddress) {
if (ipAddress != null) {
String regex = "[1-9](\\d{1,2})?\\.(0|([1-9](\\d{1,2})?))\\.(0|([1-9](\\d{1,2})?))\\.(0|([1-9](\\d{1,2})?))";
return Pattern.matches(regex, ipAddress);
} else {
return false;
}
}
}

@ -25,6 +25,7 @@ import com.dev.devapi.api.SysApi;
import com.xypower.common.HotspotManager; import com.xypower.common.HotspotManager;
import com.xypower.common.MicroPhotoContext; import com.xypower.common.MicroPhotoContext;
import java.io.IOException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
@ -161,7 +162,8 @@ public class MainActivity extends AppCompatActivity {
// } // }
// }); // });
SysApi.reboot(MainActivity.this); // SysApi.reboot(MainActivity.this);
} }
}); });
@ -174,7 +176,6 @@ public class MainActivity extends AppCompatActivity {
startMicroPhotoService(getApplicationContext()); startMicroPhotoService(getApplicationContext());
} }
private void requestPermissions() { private void requestPermissions() {
String[] accessPermissions = new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.FOREGROUND_SERVICE, Manifest.permission.READ_PHONE_STATE, String[] accessPermissions = new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.FOREGROUND_SERVICE, Manifest.permission.READ_PHONE_STATE,
/*Manifest.permission.PACKAGE_USAGE_STATS,*/ /*Manifest.permission.PACKAGE_USAGE_STATS,*/

@ -0,0 +1,75 @@
package com.xypower.mpmaster.sms;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Environment;
import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class DownloadFileTask extends AsyncTask <String, Integer, String> {
private Context mContext;
public DownloadFileTask(Context context) {
mContext = context;
}
@Override
protected String doInBackground(String... params) {
String fileUrl = params[0];
String fileName = params[1];
try {
URL url = new URL(fileUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.connect();
// 获取文件大小
int fileLength = connection.getContentLength();
// 创建输入流
InputStream input = new BufferedInputStream(url.openStream());
// 创建输出流
OutputStream output = new FileOutputStream(Environment.getExternalStorageDirectory() + "/" + fileName);
byte[] data = new byte[1024];
int total = 0;
int count;
while ((count = input.read(data)) != -1) {
total += count;
// 发布进度信息
publishProgress((int) (total * 100 / fileLength));
output.write(data, 0, count);
}
// 关闭流
output.flush();
output.close();
input.close();
} catch (Exception e) {
e.printStackTrace();
return "下载失败";
}
return "下载成功";
}
@Override
protected void onPostExecute(String result) {
// Toast.makeText(mContext, result, Toast.LENGTH_SHORT).show();
}
@Override
protected void onProgressUpdate(Integer... progress) {
// 更新下载进度
// Log.d("Download progress", progress[0] + "%");
}
}

@ -0,0 +1,135 @@
package com.xypower.mpmaster.sms;
import android.app.DownloadManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.widget.Toast;
import java.io.File;
import java.io.IOException;
/**
* author: Created by lixiaotong on 2018/10/17
* e-mail: 516030811@qq.com
*/
public class DownloadUtils {
//下载器
private DownloadManager downloadManager;
private Context mContext;
//下载的ID
private long downloadId;
private String name;
private String pathstr;
public DownloadUtils(Context context, String url, String name) {
this.mContext = context;
downloadAPK(url, name);
this.name = name;
}
//下载apk
private void downloadAPK(String url, String name) {
//创建下载任务
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
//移动网络情况下是否允许漫游
request.setAllowedOverRoaming(false);
//在通知栏中显示,默认就是显示的
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE);
request.setTitle("通知标题,随意修改");
request.setDescription("新版***下载中...");
request.setVisibleInDownloadsUi(true);
//设置下载的路径
File file = new File(mContext.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), name);
request.setDestinationUri(Uri.fromFile(file));
pathstr = file.getAbsolutePath();
//获取DownloadManager
if (downloadManager == null)
downloadManager = (DownloadManager) mContext.getSystemService(Context.DOWNLOAD_SERVICE);
//将下载请求加入下载队列加入下载队列后会给该任务返回一个long型的id通过该id可以取消任务重启任务、获取下载的文件等等
if (downloadManager != null) {
downloadId = downloadManager.enqueue(request);
}
//注册广播接收者,监听下载状态
mContext.registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
}
//广播监听下载的各个状态
private BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
checkStatus();
}
};
//检查下载状态
private void checkStatus() {
DownloadManager.Query query = new DownloadManager.Query();
//通过下载的id查找
query.setFilterById(downloadId);
Cursor cursor = downloadManager.query(query);
if (cursor.moveToFirst()) {
int status = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS));
switch (status) {
//下载暂停
case DownloadManager.STATUS_PAUSED:
break;
//下载延迟
case DownloadManager.STATUS_PENDING:
break;
//正在下载
case DownloadManager.STATUS_RUNNING:
break;
//下载完成
case DownloadManager.STATUS_SUCCESSFUL:
//下载完成安装APK
// installAPK();
cursor.close();
break;
//下载失败
case DownloadManager.STATUS_FAILED:
Toast.makeText(mContext, "下载失败", Toast.LENGTH_SHORT).show();
cursor.close();
mContext.unregisterReceiver(receiver);
break;
}
}
}
// private void installAPK() {
// setPermission(pathstr);
// Intent intent = new Intent(Intent.ACTION_VIEW);
// // 由于没有在Activity环境下启动Activity,设置下面的标签
// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// //Android 7.0以上要使用FileProvider
// if (Build.VERSION.SDK_INT >= 24) {
// File file = (new File(pathstr));
// //参数1 上下文, 参数2 Provider主机地址 和配置文件中保持一致 参数3 共享的文件
// Uri apkUri = FileProvider.getUriForFile(mContext, "com.lxtwsw.weather.fileprovider", file);
// //添加这一句表示对目标应用临时授权该Uri所代表的文件
// intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
// intent.setDataAndType(apkUri, "application/vnd.android.package-archive");
// } else {
// intent.setDataAndType(Uri.fromFile(new File(Environment.DIRECTORY_DOWNLOADS, name)), "application/vnd.android.package-archive");
// }
// mContext.startActivity(intent);
// }
//修改文件权限
// private void setPermission(String absolutePath) {
// String command = "chmod " + "777" + " " + absolutePath;
// Runtime runtime = Runtime.getRuntime();
// try {
// runtime.exec(command);
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
}

@ -16,8 +16,14 @@ import android.text.TextUtils;
import androidx.core.app.ActivityCompat; import androidx.core.app.ActivityCompat;
import com.dev.devapi.api.SysApi;
import com.xypower.common.RegexUtil;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException;
import java.io.IOException;
import java.io.Serializable;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
@ -37,39 +43,48 @@ 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 SMSTYPE = "smstype";
public static String SMSDATA = "smsdata";
public static String SMSIFCORRECT = "smsifcorrect";
//短信解析 //短信解析
public static void analysisSMSInfo(Intent intent, Context context) { public static void analysisSMSInfo(Intent intent, Context context) {
SmsMessageModel smsInfo = getSMSInfo(intent); SmsMessageModel smsInfo = getSMSInfo(intent);
if (smsInfo != null) { if (smsInfo != null) {
String packageName = context.getApplicationContext().getPackageName();
String content = smsInfo.getContent(); String content = smsInfo.getContent();
int slot = smsInfo.getSlot(); int slot = smsInfo.getSlot();//那张卡收到的短信
String sender = smsInfo.getSender(); String sender = smsInfo.getSender();//收到的短信的手机号
String sendmessage = ""; String sendmessage = "";//要回复的短信
String sendtype = ""; String sendtype = "";//收到的短信类型
JSONArray jsonArray = new JSONArray();//收到的短信内容拆分包装成数组
boolean ifmessageCorrect = false;//用来判断收到的短信内容是否正确
if (StringUtils.isEmpty(content)) { if (StringUtils.isEmpty(content)) {
return; return;
} }
if (content.contains(SmsTypeEnum.REBOOT1.value())) { if (content.contains(SmsTypeEnum.REBOOT1.value())) {
ifmessageCorrect = true;
sendmessage = content + " OK"; sendmessage = content + " OK";
sendtype = SmsTypeEnum.REBOOT1.value(); sendtype = SmsTypeEnum.REBOOT1.value();
} else if (content.contains(SmsTypeEnum.REBOOT2.value())) { } else if (content.contains(SmsTypeEnum.REBOOT2.value())) {
ifmessageCorrect = true;
sendmessage = content + " OK"; sendmessage = content + " OK";
sendtype = SmsTypeEnum.REBOOT2.value(); sendtype = SmsTypeEnum.REBOOT2.value();
} else if (content.contains(SmsTypeEnum.SET_YW_SCHEDULE.value())) { } else if (content.contains(SmsTypeEnum.SET_YW_SCHEDULE.value())) {
String packageName = context.getApplicationContext().getPackageName();
String[] split1 = StringUtils.splitString1(content); String[] split1 = StringUtils.splitString1(content);
if (split1 != null && split1.length > 1) { if (split1 != null && split1.length > 1) {
String s = split1[1]; String s = split1[1];
String[] split2 = StringUtils.splitString2(s); String[] split2 = StringUtils.splitString2(s);
if (split2 != null && split2.length >= 1) { if (split2 != null && split2.length >= 1) {
int length = split2.length;
if (length % 2 == 1) {
String num = split2[0]; String num = split2[0];
Integer integer = StringUtils.convert2Int(num); Integer integer = StringUtils.convert2Int(num);
if (integer != null) { if (integer != null) {
if (integer == 0) {//删除所有运维 if (integer == 0) {//删除所有运维
UpdateSysConfigUtil.updateAbsHeartbeats(packageName, new JSONArray()); ifmessageCorrect = true;
} else { } else {
JSONArray jsonArray = new JSONArray(); if (length == integer + 1) {
int times = 0; int times = 0;
for (int i = 0; i < split2.length; i++) { for (int i = 0; i < split2.length; i++) {
if (i == 0) { if (i == 0) {
@ -78,22 +93,135 @@ public class SimUtil {
String ts = split2[i]; String ts = split2[i];
Integer time = StringUtils.convert2Int(ts); Integer time = StringUtils.convert2Int(ts);
if (i % 2 == 1) { if (i % 2 == 1) {
time = 0; if (time > 23) {
ifmessageCorrect = false;
break;
}
times = time * 3600; times = time * 3600;
} else { } else {
if (time > 59) {
ifmessageCorrect = false;
break;
}
times += time * 60; times += time * 60;
jsonArray.put(times); jsonArray.put(times);
} }
} }
}
} }
if (ifmessageCorrect) {
UpdateSysConfigUtil.setAbsHeartbeats(packageName, jsonArray);
} }
} }
} }
sendmessage = content + " OK";
sendtype = SmsTypeEnum.REBOOT2.value();
} }
sendSms(context, slot, sender, sendmessage, sendtype);
} }
String menssageBack = "";
if (ifmessageCorrect) {
menssageBack = " OK";
} else {
menssageBack = " ERROR";
}
sendmessage = content + menssageBack;
sendtype = SmsTypeEnum.SET_YW_SCHEDULE.value();
} else if (content.contains(SmsTypeEnum.GET_YW_SCHEDULE.value())) {
ifmessageCorrect = true;
JSONArray absHeartbeats = UpdateSysConfigUtil.getAbsHeartbeats(packageName);
if (absHeartbeats == null || absHeartbeats.length() == 0) {
sendmessage = SmsTypeEnum.GET_YW_SCHEDULE.value() + "=0";
} else {
int length = absHeartbeats.length();
sendmessage = SmsTypeEnum.GET_YW_SCHEDULE.value() + "=" + length;
for (int i = 0; i < length; i++) {
int mAbsHeartbeatTime = 0;
try {
mAbsHeartbeatTime = absHeartbeats.getInt(i);
} catch (JSONException e) {
throw new RuntimeException(e);
}
int hour = mAbsHeartbeatTime / 3600;
int leftsecond = mAbsHeartbeatTime % 3600;
int minute = leftsecond / 3600;
sendmessage += "," + hour + "," + minute;
}
}
} else if (content.contains(SmsTypeEnum.SET_OPERATE.value())) {
sendtype = SmsTypeEnum.SET_OPERATE.value();
String[] split1 = StringUtils.splitString1(content);
if (split1 != null && split1.length > 1) {
String s = split1[1];
Integer integer = StringUtils.convert2Int(s);
if (integer != null) {
if (integer == 0 || integer == 1) {
ifmessageCorrect = true;
UpdateSysConfigUtil.setMntnMode(packageName, integer);
}
}
}
String menssageBack = "";
if (ifmessageCorrect) {
menssageBack = " OK";
} else {
menssageBack = " ERROR";
}
sendmessage = content + menssageBack;
} else if (content.contains(SmsTypeEnum.GET_OPERATE.value())) {
sendtype = SmsTypeEnum.GET_OPERATE.value();
ifmessageCorrect = true;
int mntnMode = UpdateSysConfigUtil.getMntnMode(packageName);
sendmessage = SmsTypeEnum.GET_OPERATE + "=" + mntnMode;
} else if (content.contains(SmsTypeEnum.SET_OPERATE_URL.value())) {
sendtype = SmsTypeEnum.SET_OPERATE_URL.value();
String[] split1 = StringUtils.splitString1(content);
if (split1 != null && split1.length > 1) {
String s = split1[1];
String[] split2 = StringUtils.splitString1(s);
if (split2 != null && split2.length == 2) {
String ipAddress = split2[0];
String port = split2[1];
boolean b = RegexUtil.checkIpAddress(ipAddress);
if (b) {
Integer integer = StringUtils.convert2Int(port);
if (integer != null) {
ifmessageCorrect = true;
UpdateSysConfigUtil.setMntnServer(packageName, ipAddress, integer);
}
}
}
}
String menssageBack = "";
if (ifmessageCorrect) {
menssageBack = " OK";
} else {
menssageBack = " ERROR";
}
sendmessage = content + menssageBack;
} else if (content.contains(SmsTypeEnum.GET_OPERATE_URL.value())) {
sendtype = SmsTypeEnum.GET_OPERATE.value();
ifmessageCorrect = true;
String mntnServer = UpdateSysConfigUtil.getMntnServer(packageName);
sendmessage = SmsTypeEnum.GET_OPERATE + "=" + mntnServer;
} else if (content.contains(SmsTypeEnum.UPDATE.value())) {
sendtype = SmsTypeEnum.UPDATE.value();
String[] split1 = StringUtils.splitString1(content);
if (split1 != null && split1.length == 2) {
ifmessageCorrect = true;
String s = split1[1];
}
String menssageBack = "";
if (ifmessageCorrect) {
menssageBack = " OK";
} else {
menssageBack = " ERROR";
}
sendmessage = content + menssageBack;
}
sendSms(context, slot, sender, sendmessage, sendtype, ifmessageCorrect, jsonArray);
}
} }
//短信解析 //短信解析
@ -173,7 +301,7 @@ public class SimUtil {
} }
//指定sim卡位置发送短信 //指定sim卡位置发送短信
public static void sendSms(Context mContext, int slot, String sender, String message, String value) { public static void sendSms(Context mContext, int slot, String sender, String message, String value, boolean ifmessageCorrect, JSONArray jsonArray) {
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) {
@ -192,6 +320,8 @@ public class SimUtil {
} }
Intent itSend = new Intent(SMS_SEND_ACTION); Intent itSend = new Intent(SMS_SEND_ACTION);
itSend.putExtra(SMSTYPE, value); itSend.putExtra(SMSTYPE, value);
itSend.putExtra(SMSIFCORRECT, ifmessageCorrect);
itSend.putExtra(SMSDATA, (Serializable) jsonArray);
//sendIntent参数为传送后接受的广播信息PendingIntent //sendIntent参数为传送后接受的广播信息PendingIntent
PendingIntent sendPI = PendingIntent.getBroadcast(mContext, 0, itSend, 0); PendingIntent sendPI = PendingIntent.getBroadcast(mContext, 0, itSend, 0);

@ -1,12 +1,14 @@
package com.xypower.mpmaster.sms; package com.xypower.mpmaster.sms;
import android.app.DownloadManager;
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 com.dev.devapi.api.SysApi; import com.dev.devapi.api.SysApi;
import org.json.JSONArray;
/** /**
* 广 * 广
@ -22,7 +24,18 @@ public class SmsSendReceiver extends BroadcastReceiver {
String type = intent.getStringExtra(SimUtil.SMSTYPE); String type = intent.getStringExtra(SimUtil.SMSTYPE);
if (type.contains(SmsTypeEnum.REBOOT1.value())) { if (type.contains(SmsTypeEnum.REBOOT1.value())) {
SysApi.reboot(context); SysApi.reboot(context);
} else if (type.contains(SmsTypeEnum.REBOOT2.value())) {
SysApi.reboot(context);
} }
// else if (type.contains(SmsTypeEnum.SET_YW_SCHEDULE.value())) {
// if (jsonArray != null) {
// String packageName = context.getApplicationContext().getPackageName();
// UpdateSysConfigUtil.setAbsHeartbeats(packageName, jsonArray);
// }
// }
} }
} }

@ -4,8 +4,10 @@ public enum SmsTypeEnum {
REBOOT1("yw+at+stw21"), REBOOT2("at+stw21"), //重启命令 REBOOT1("yw+at+stw21"), REBOOT2("at+stw21"), //重启命令
SET_YW_SCHEDULE("yw+at+stw51"), //拍照时间表设置 SET_YW_SCHEDULE("yw+at+stw51"), //拍照时间表设置
GET_YW_SCHEDULE("yw+at+str51"), //查询拍照时间表 GET_YW_SCHEDULE("yw+at+str51"), //查询拍照时间表
OPERATE("yw+at+stw52"), //运维开关 SET_OPERATE("yw+at+stw52"), //设置运维开关
OPERATE_URL("yw+at+stw53"), //运维地址 GET_OPERATE("yw+at+str52"), //查询运维开关
SET_OPERATE_URL("yw+at+stw53"), //设置运维地址
GET_OPERATE_URL("yw+at+str53"), //查询运维地址
ADB("yw+at+ds"), //开关adb ADB("yw+at+ds"), //开关adb
UPDATE("yw+at+update"), //远程升级 UPDATE("yw+at+update"), //远程升级
READ_CMDID("at+str01"), //读取设备编号 READ_CMDID("at+str01"), //读取设备编号

@ -1,8 +1,6 @@
package com.xypower.mpmaster.sms; package com.xypower.mpmaster.sms;
import android.content.Context;
import android.os.Environment; import android.os.Environment;
import android.text.TextUtils;
import com.xypower.common.JSONUtils; import com.xypower.common.JSONUtils;
@ -38,7 +36,7 @@ public class UpdateSysConfigUtil {
} }
//修改运维时间表 //修改运维时间表
public static boolean updateAbsHeartbeats(String packageurl, JSONArray jsonArray) { public static boolean setAbsHeartbeats(String packageurl, JSONArray jsonArray) {
String path = getAppDir(packageurl); String path = getAppDir(packageurl);
JSONObject jsonObject = JSONUtils.loadJson(path); JSONObject jsonObject = JSONUtils.loadJson(path);
try { try {
@ -49,28 +47,69 @@ public class UpdateSysConfigUtil {
return JSONUtils.saveJson(path, jsonObject); return JSONUtils.saveJson(path, jsonObject);
} }
//获取运维时间表
public static JSONArray getAbsHeartbeats(String packageurl) {
JSONArray absHeartbeats = new JSONArray();
String path = getAppDir(packageurl);
JSONObject jsonObject = JSONUtils.loadJson(path);
try {
absHeartbeats = jsonObject.getJSONArray("absHeartbeats");
} catch (JSONException e) {
throw new RuntimeException(e);
}
return absHeartbeats;
}
//修改运维状态 TODO //修改运维状态 TODO
public boolean updateMntn(String packageurl, String url) { public static boolean setMntnMode(String packageurl, int mntnMode) {
if (TextUtils.isEmpty(url)) { String path = getAppDir(packageurl);
return false; JSONObject jsonObject = JSONUtils.loadJson(path);
try {
jsonObject.put("mntnMode", mntnMode);
} catch (Exception ex) {
ex.printStackTrace();
} }
return JSONUtils.saveJson(path, jsonObject);
}
//查询运维状态 TODO
public static int getMntnMode(String packageurl) {
int mntnMode = -1;
String path = getAppDir(packageurl); String path = getAppDir(packageurl);
JSONObject jsonObject = JSONUtils.loadJson(path); JSONObject jsonObject = JSONUtils.loadJson(path);
String oldUrl = null;
try { try {
oldUrl = jsonObject.getString("url"); mntnMode = jsonObject.getInt("mntnMode");
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
if (TextUtils.equals(url, oldUrl)) { return mntnMode;
return true;
} }
//修改运维状态 TODO
public static boolean setMntnServer(String packageurl, String server, int port) {
String path = getAppDir(packageurl);
JSONObject jsonObject = JSONUtils.loadJson(path);
try { try {
jsonObject.put("url", url); jsonObject.put("server", server);
jsonObject.put("port", port);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
return JSONUtils.saveJson(path, jsonObject); return JSONUtils.saveJson(path, jsonObject);
} }
//查询运维状态 TODO
public static String getMntnServer(String packageurl) {
String server = "";
int port = 0;
String path = getAppDir(packageurl);
JSONObject jsonObject = JSONUtils.loadJson(path);
try {
server = jsonObject.getString("server");
port = jsonObject.getInt("port");
} catch (Exception ex) {
ex.printStackTrace();
}
return server + "," + port;
}
} }

Loading…
Cancel
Save