2016-08-02 135 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用戶也是如此。