手机ROOT 后,程序中申请ROOT权限失败,该如何处理

手机ROOT 后,程序中申请ROOT权限失败
大家帮看下为什么调用chmodInput后会提示Root error ,手机已root。 

  public static boolean execRootCommand(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();
            Log.d(TAG, "--------------Root------------ ");
            // 1 is success
            if (process.waitFor() == 1) {
                Log.d(TAG, "Root SUCCESS ");
                return true;
            } else {
             Log.d(TAG, "Root error ");
                return false;
            }
        } catch (Exception e) {
            Log.d(TAG, "ROOT ERR:" + e.getMessage());
            return false;
        } finally {
            try {
                if (os != null) {
                    os.close();
                }
                process.destroy();
            } catch (Exception e) {
            }
        }
    }
    
    public static boolean chmodInput() {
        // exec "chmod 666 /dev/input/*"
        String command = "chmod 666 /dev/input/*";
        Log.d(TAG, "chmodInput!");
        return execRootCommand(command);
    }
    

------解决方案--------------------
楼主没必要去判断waitFor的返回值,直接捕获异常就行。


   
public static boolean execRootCommand(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();
            Log.d(TAG, "--------------Root------------ ");
            process.waitFor();
        } catch (Exception e) {
            Log.d(TAG, "ROOT ERROR:" + e.getMessage());
            return false;
        } finally {