修复938下无法执行shell命令的bug,宁夏版本同样问题

nx2024
liuguijing 3 months ago
parent a5f1697856
commit 635b2bf04a

@ -25,32 +25,43 @@ public class AdbUtil {
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");
for (String cmd : shellList) {
Process process = Runtime.getRuntime().exec(cmd);
// 处理输出和错误流
process.waitFor();
}
// 执行命令(例如:列出 /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) {
} catch (Exception e) {
e.printStackTrace();
}
// try {
// // 使用 su 获取 root 权限
// Process process = Runtime.getRuntime().exec();
//
// // 获取输出流,用于发送命令
// 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();
// }
}
}

@ -565,30 +565,32 @@ public class SimUtil {
} 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);
int startindex = content.indexOf("=");
if (startindex != -1) {
String value = content.substring(startindex + 1);
int endindex = value.lastIndexOf(",");
if (endindex != -1) {
String substring = value.substring(0, endindex);
String[] strings = StringUtils.splitString2(substring);
if (strings != null && strings.length > 0) {
for (int i = 0; i < strings.length; i++) {
shellList.add(strings[i]);
}
}).start();
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);
}
}
sendmessage = getSendString(content, ifmessageCorrect);
}
sendSms(context, slot, sender, sendmessage, restartType);
}

Loading…
Cancel
Save