Matthew 1 month ago
commit cc55b5aa4d

@ -24,44 +24,46 @@ public class AdbUtil {
} }
public static void ShellList(ArrayList<String> shellList) { public static void ShellList(ArrayList<String> shellList) {
try {
for (String cmd : shellList) {
Process process = Runtime.getRuntime().exec(cmd);
// 处理输出和错误流
process.waitFor();
}
} catch (Exception e) {
e.printStackTrace();
}
// try { // try {
// // 使用 su 获取 root 权限 // for (String cmd : shellList) {
// Process process = Runtime.getRuntime().exec(); // Process process = Runtime.getRuntime().exec(cmd);
// // // 处理输出和错误流
// // 获取输出流,用于发送命令 // int i = process.waitFor();
// DataOutputStream outputStream = new DataOutputStream(process.getOutputStream()); // System.out.println(""+i);
//
// for (int i = 0; i < shellList.size()-1; i++) {
// outputStream.writeBytes(shellList.get(i)+"\n");
// } // }
// // 执行命令(例如:列出 /data 目录) // } catch (Exception e) {
//
// 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(); // e.printStackTrace();
// } // }
try {
// 使用 su 获取 root 权限
Process process = Runtime.getRuntime().exec("su");
// 获取输出流,用于发送命令
DataOutputStream outputStream = new DataOutputStream(process.getOutputStream());
for (int i = 0; i < shellList.size(); i++) {
outputStream.writeBytes(shellList.get(i)+"\n");
}
// 执行命令(例如:列出 /data 目录)
outputStream.writeBytes("exit\n"); // 退出 su
outputStream.flush();
outputStream.close();
// 读取命令输出
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();
}
} }
} }

Loading…
Cancel
Save