运维新增支持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" android:name="android.permission.TETHER_PRIVILEGED"
tools:ignore="ProtectedPermissions" /> tools:ignore="ProtectedPermissions" />
<uses-feature android:name="android.hardware.camera" /> <uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.hardware.usb.accessory" /> <uses-permission android:name="android.hardware.usb.accessory" />

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

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

@ -158,11 +158,15 @@ public class AppMaster {
sleep(1000); sleep(1000);
} }
int masterHttpstatus = 0;//0--接口请求正常但未处理 1--访问运维服务器正常,处理也正常 -1----访问运维服务器异常
try { try {
runImpl(isCriticalTime); masterHttpstatus= runImpl(isCriticalTime);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
}finally {
if (masterHttpstatus == -1) {
mService.setMntnMode(false,false);
}
} }
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
@ -186,14 +190,14 @@ public class AppMaster {
}).start(); }).start();
} }
private boolean runImpl(final boolean isCriticalTime) { private int runImpl(final boolean isCriticalTime) {
String masterUrl = mMasterUrl; String masterUrl = mMasterUrl;
int res = 0;
if (TextUtils.isEmpty(masterUrl)) { if (TextUtils.isEmpty(masterUrl)) {
return false; return res;
} }
boolean res = false;
HttpURLConnection httpURLConnection = null; HttpURLConnection httpURLConnection = null;
InputStream inputStream = null; InputStream inputStream = null;
Date now = new Date(); Date now = new Date();
@ -336,13 +340,14 @@ public class AppMaster {
String response = convertStreamToString(inputStream); String response = convertStreamToString(inputStream);
process(response); process(response);
} }
res = true; res = 1;
} catch (Exception ex) { } catch (Exception ex) {
// ex.printStackTrace(); // ex.printStackTrace();
mService.logger.warning(ex.getMessage()); res = -1;
mService.logger.warning("运维服务器连接失败! " + ex.getMessage());
} }
if (res) { if (res == 1) {
break; break;
} }
@ -486,7 +491,6 @@ public class AppMaster {
} }
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);
} }
@ -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.clearHistoryPic(context);
UpdateSysConfigUtil.clearHistoryLogs(context); UpdateSysConfigUtil.clearHistoryLogs(context);
sendmessage = getSendString(content, ifmessageCorrect); 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); sendSms(context, slot, sender, sendmessage, restartType);
} }
} }
private static int getUtcp(Integer utcp) { private static int getUtcp(Integer utcp) {

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

Loading…
Cancel
Save