public class RootShellCmd {
/**
* 打开蜂鸣器
*/
public static void openBuzzer_new() {
exec("echo 1> /
sys / class / leds / beep / brightness ");
}
/**
* 关闭蜂鸣器
*/
public static void closeBuzzer_new() {
exec("echo 0> /
sys / class / leds / beep / brightness ");
}
public static void hide_statusbar() {
exec("am broadcast -a action.HIDE_STATUSBAR");
}
/**
* 显示状态栏
*/
public static void show_statusbar() {
exec("am broadcast -a action.SHOW_STATUSBAR");
}
/**
* 请求ROOT权限后执行命令
*/
public static void exec(final String cmd) {
new Thread(new Runnable() {
@Override
public void run() {
Process process =
null;
DataOutputStreamos = null;
try {
try {
process = Runtime.getRuntime().exec("su");
} catch (IOException e) {
e.printStackTrace();
process = Runtime.getRuntime().exec("sh");
}
os = new DataOutputStream(process.getOutputStream());
os.writeBytes(cmd + "\n");
os.writeBytes("exit\n");
process.waitFor();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (os != null) {
os.flush();
os.close();
}
process.destroy();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}).start();
}
public static void exec(String...cmds) {
StringBuilder command = new StringBuilder();
if (cmds.length <= 0) {
return;
}
for (String cmd: cmds) {
command.append(cmd).append("\n");
}
exec(command.toString());
}
}