代码中获取root权限并随意修改根目录文件

//如果需要修改文件权限则 将 以下字符串传入以下方法  777则是 rwx-rwx-rwx权限
//String cmd= "chmod 777 " + java.io.File.separator + "data"
                                //+ java.io.File.separator + "system" + java.io.File.separator
                                //+ "accounts.db";

public boolean RootCommand(String command) {
                Process process = null;
                DataOutputStream os = null;
                try {
                        process = Runtime.getRuntime().exec("su");
                        os = new DataOutputStream(process.getOutputStream());
                        os.writeBytes(command + "\n");
                        os.writeBytes("exit\n");
                        os.flush();
                        process.waitFor();
                } catch (Exception e) {
                        Log.d("*** DEBUG ***", "ROOT REE"
                                        + e.getMessage());
                        return false;
                } finally {
                        try {
                                if (os != null) {
                                        os.close();
                                }
                                process.destroy();
                        } catch (Exception e) {
                                // nothing
                        }
                }
                
                Log.d("*** DEBUG ***", "Root SUC ");
                return true;

        }

你可能感兴趣的:(代码中获取root权限并随意修改根目录文件)