2016-08-02 138 views
0

我有root权限,我正在为我的应用测试一个新功能,包括访问和编辑Android系统文件夹。访问根级系统文件夹Android

但是我的代码似乎没有改变任何东西。上Marshmallow CM 13.

Process p; 
    try { 
     // Preform su to get root privileges 
     p = Runtime.getRuntime().exec("su"); 

     // Attempt to write a file to a root-only 
     DataOutputStream os = new DataOutputStream(p.getOutputStream()); 
     os.writeBytes("echo \"Do I have root?\" >/system/etc/temporary.txt\n"); 

     // Close the terminal 
     os.writeBytes("exit\n"); 
     os.flush(); 
     try { 
      p.waitFor(); 
      if (p.exitValue() != 255) { 
       // TODO Code to run on success 
       toastMessage("root"); 
      } 
      else { 
       // TODO Code to run on unsuccessful 
       toastMessage("not root"); 
      } 
     } catch (InterruptedException e) { 
      // TODO Code to run in interrupted exception 
      toastMessage("not root"); 
     } 
    } catch (IOException e) { 
     // TODO Code to run in input/output exception 
     toastMessage("not root"); 
    } 
+0

而是尝试首先打印权限 – Shriram

+0

@Shriram通过adb shell? – silberbaum

回答

2

/system IM安装​​点被默认安装RO。即使使用根级权限,写入它的唯一方法也是将其重新挂载为RW。此外,您可能仍会遇到SE Android(SE Linux for Android)的一些问题,该问题目前以及自Lollipop以来处于完全执行模式。平台中可能会安装SE Android安全策略,这将限制对文件系统某些部分的访问,即使对于root用户也是如此。