File device = new File(PropertiesHelper.getValue(Constants.SERIAL_PORT_DEVICE_FILE));
if (!device.canRead() || !device.canWrite()) {
/* Missing read/write permission, trying to chmod the file */
Process su = Runtime.getRuntime().exec("/system/bin/su");
String cmd = "chmod 666 " + device.getAbsolutePath() + "\n" + "exit\n";
su.getOutputStream().write(cmd.getBytes());
if ((su.waitFor() != 0) || !device.canRead() || !device.canWrite()) {
throw new SecurityException();
}
}`
android在apk中获取root权限,并执行命令(改变文件权读写限)
最新推荐文章于 2025-04-24 12:03:15 发布