1. 程式人生 > >android在apk中獲取root許可權,並執行命令(改變檔案權讀寫限)

android在apk中獲取root許可權,並執行命令(改變檔案權讀寫限)

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(); } }`