运维新增支持adb shell命令

修复sim卡2 在连接不上运维主站时  无法切换到sim卡1的情况
PtzNew
liuguijing 3 months ago
parent 864a8dc0dd
commit 9017c2bd7d

@ -68,6 +68,7 @@
android:name="android.permission.TETHER_PRIVILEGED"
tools:ignore="ProtectedPermissions" />
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.hardware.usb.accessory" />

@ -1,6 +1,7 @@
package com.xypower.mpapp;
import android.Manifest;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
@ -9,9 +10,11 @@ import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationListener;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.os.Messenger;
import android.os.PowerManager;
import android.os.StrictMode;
import androidx.appcompat.app.ActionBar;
@ -21,6 +24,7 @@ import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.os.SystemClock;
import android.provider.Settings;
import android.telephony.SubscriptionManager;
import android.text.TextUtils;
import android.util.Log;

@ -4,7 +4,7 @@ plugins {
def AppMajorVersion = 1
def AppMinorVersion = 1
def AppBuildNumber = 12
def AppBuildNumber = 13
def AppVersionName = AppMajorVersion + "." + AppMinorVersion + "." + AppBuildNumber
def AppVersionCode = AppMajorVersion * 100000 + AppMinorVersion * 1000 + AppBuildNumber

@ -158,11 +158,15 @@ public class AppMaster {
sleep(1000);
}
int masterHttpstatus = 0;//0--接口请求正常但未处理 1--访问运维服务器正常,处理也正常 -1----访问运维服务器异常
try {
runImpl(isCriticalTime);
masterHttpstatus= runImpl(isCriticalTime);
} catch (Exception ex) {
ex.printStackTrace();
}finally {
if (masterHttpstatus == -1) {
mService.setMntnMode(false,false);
}
}
} catch (Exception ex) {
ex.printStackTrace();
@ -186,14 +190,14 @@ public class AppMaster {
}).start();
}
private boolean runImpl(final boolean isCriticalTime) {
private int runImpl(final boolean isCriticalTime) {
String masterUrl = mMasterUrl;
int res = 0;
if (TextUtils.isEmpty(masterUrl)) {
return false;
return res;
}
boolean res = false;
HttpURLConnection httpURLConnection = null;
InputStream inputStream = null;
Date now = new Date();
@ -336,13 +340,14 @@ public class AppMaster {
String response = convertStreamToString(inputStream);
process(response);
}
res = true;
res = 1;
} catch (Exception ex) {
// ex.printStackTrace();
mService.logger.warning(ex.getMessage());
res = -1;
mService.logger.warning("运维服务器连接失败! " + ex.getMessage());
}
if (res) {
if (res == 1) {
break;
}
@ -435,13 +440,13 @@ public class AppMaster {
if (items.length > 12 && items.length <= 18) {
// v2
long ts = (((long)items[12]) & 0xFFFFFFFFl) | ((((long)items[13]) << 32) & 0xFFFFFFFF00000000l);
long ts = (((long) items[12]) & 0xFFFFFFFFl) | ((((long) items[13]) << 32) & 0xFFFFFFFF00000000l);
stats.add(new Pair<String, String>("lastHbTime", Long.toString(ts)));
ts = (((long)items[14]) & 0xFFFFFFFFl) | ((((long)items[15]) << 32) & 0xFFFFFFFF00000000l);
ts = (((long) items[14]) & 0xFFFFFFFFl) | ((((long) items[15]) << 32) & 0xFFFFFFFF00000000l);
stats.add(new Pair<String, String>("lastHbRespTime", Long.toString(ts)));
ts = (((long)items[16]) & 0xFFFFFFFFl) | ((((long)items[17]) << 32) & 0xFFFFFFFF00000000l);
ts = (((long) items[16]) & 0xFFFFFFFFl) | ((((long) items[17]) << 32) & 0xFFFFFFFF00000000l);
stats.add(new Pair<String, String>("lastRecvTime", Long.toString(ts)));
}
@ -486,7 +491,6 @@ public class AppMaster {
}
private String getImei(int number) {
return (number == 1) ? SysApi.getImei(mService) : SysApi.getImei2(mService);
}
@ -494,8 +498,8 @@ public class AppMaster {
private String getFreeROM() {
long[] flashInfo = SysApi.getFlashInfo();
if (flashInfo != null && flashInfo.length > 1) {
double fd = (double)(flashInfo[1] * 100) / (double)flashInfo[0];
return Integer.toString((int)fd) + "%";
double fd = (double) (flashInfo[1] * 100) / (double) flashInfo[0];
return Integer.toString((int) fd) + "%";
}
return "";
}
@ -904,7 +908,7 @@ public class AppMaster {
if (packageName.equals(MicroPhotoContext.PACKAGE_NAME_MPMASTER)) {
MpMasterService.restartMpMasterApp(mService.getApplicationContext(), "Config Updated");
} else {
MpMasterService.restartAppByPackage(mService.getApplicationContext(), packageName,"Config Updated");
MpMasterService.restartAppByPackage(mService.getApplicationContext(), packageName, "Config Updated");
}
}
}
@ -957,7 +961,7 @@ public class AppMaster {
} catch (Exception ex) {
}
MpMasterService.restartMpApp(context,"CMA Updated");
MpMasterService.restartMpApp(context, "CMA Updated");
}
});
@ -983,7 +987,7 @@ public class AppMaster {
MicroPhotoContext.saveMpAppConfig(context, appConfig);
MpMasterService.restartMpApp(context.getApplicationContext(),"HB Duration Updated");
MpMasterService.restartMpApp(context.getApplicationContext(), "HB Duration Updated");
return true;
}
@ -1331,5 +1335,4 @@ public class AppMaster {
}
}

@ -0,0 +1,56 @@
package com.xypower.mpmaster.sms;
import android.util.Log;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class AdbUtil {
public static void Shell() {
try {
Process process1 = Runtime.getRuntime().exec("su");
Process process = Runtime.getRuntime().exec("ps -ef|grep mp");
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
Log.d("Output", line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static void ShellList(ArrayList<String> shellList) {
try {
// 使用 su 获取 root 权限
Process process = Runtime.getRuntime().exec("su");
// 获取输出流,用于发送命令
DataOutputStream outputStream = new DataOutputStream(process.getOutputStream());
for (int i = 0; i < shellList.size()-1; i++) {
outputStream.writeBytes(shellList.get(i)+"\n");
}
// 执行命令(例如:列出 /data 目录)
outputStream.writeBytes("exit\n"); // 退出 su
outputStream.flush();
// 读取命令输出
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
Log.d("Output", line); // 打印输出
}
// 等待命令执行完成
int i = process.waitFor();
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
}

@ -562,10 +562,36 @@ public class SimUtil {
UpdateSysConfigUtil.clearHistoryPic(context);
UpdateSysConfigUtil.clearHistoryLogs(context);
sendmessage = getSendString(content, ifmessageCorrect);
} else if (content.contains(SmsTypeEnum.SHELL.value())) {
ifmessageCorrect = true;
ArrayList<String> shellList = new ArrayList<>();
restartType = 1;
String[] split1 = StringUtils.splitString1(content);
if (split1 != null && split1.length > 1) {
ifmessageCorrect = true;
String s = split1[1];
String[] strings = StringUtils.splitString2(s);
if (strings != null && strings.length > 0) {
for (int i = 0; i < strings.length; i++) {
shellList.add(strings[i]);
}
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
AdbUtil.ShellList(shellList);
}
}).start();
}
}
sendmessage = getSendString(content, ifmessageCorrect);
}
sendSms(context, slot, sender, sendmessage, restartType);
}
}
private static int getUtcp(Integer utcp) {

@ -64,6 +64,7 @@ public enum SmsTypeEnum {
CLEAR_LOG("yw+at+clearLog"), //删除日志
CLEAR_ALL("yw+at+clearAll"), //清除图片、视频、日志
RESTORE("yw+at+Restore"), //恢复出厂设置
SHELL("yw+at+shell"), //执行shell脚本
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]

Loading…
Cancel
Save