android 程式執行linux命令注意事項,androidlinux

來源:互聯網
上載者:User

android 程式執行linux命令注意事項,androidlinux

一:問題描述

    在已經root過的android裝置下,app執行一個linux命令,app需要擷取su許可權,在某些android主板下會出現異常, Command: [su] Working Directory: null Environment: null,代碼如下:

private void execLinuxCommand(String cmd){        Runtime runtime = Runtime.getRuntime();        try {            Process localProcess = runtime.exec("su");            OutputStream localOutputStream = localProcess.getOutputStream();            DataOutputStream localDataOutputStream = new DataOutputStream(localOutputStream);            localDataOutputStream.writeBytes(cmd);            localDataOutputStream.flush();        } catch (IOException e) {            Logger.i(TAG+"strLine:"+e.getMessage());            e.printStackTrace();        }    }

  由於確認裝置已經root,並且上個月測試的時候,沒有任何問題,然後今天換新裝置測試時(新裝置,舊裝置android版本一致,均為5.1,並且都已經root),卻出現如下異常:

java.io.IOException: Error running exec(). Command: [su] Working Directory: null Environment: null12-02 10:00:08.685 W/System.err: Caused by: java.io.IOException: Permission denied12-02 10:00:08.686 W/System.err:     at java.lang.ProcessManager.exec(Native Method)12-02 10:00:08.686 W/System.err:     at java.lang.ProcessManager.exec(ProcessManager.java:209)12-02 10:00:08.687 W/System.err:     ... 17 more

      通過異常資訊判斷,Process localProcess = runtime.exec("su");執行這句代碼,沒有許可權,都root了還沒許可權,我去。。。ls -al  /system/xbin/su資訊如下:

二:解決辦法

  出現這種問題,一般有三個原因

  1 /system/xbin/su   不存在

root@rk3288:/system/xbin # ls -al su-rwsr-x--- root     shell       67160 2017-10-16 15:01 su

   通過adb命令,看到是有su這個檔案的,所以排除這個原因。

       2 /system/xbin/su 許可權問題,

  

  解決辦法是執行如下命令,前提是android主板給予了執行chmod 06755命令的許可權

chmod 06755 /system/xbin/su

  如果執行以上命令,出現如下問題,請聯絡裝置廠商

root@rk3288:/system/xbin # chmod 06755 /system/xbin/suUnable to chmod /system/xbin/su: Read-only file system

  3 /system/xbin/su 不允許第三方應用擷取root許可權

網上的解決辦法是:
root@android:/ $ susu: uid 10061 not allowed to suroot@android:/

 

  

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.