parent
864a8dc0dd
commit
9017c2bd7d
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue