Precautions for running linux commands in android: androidlinux

Source: Internet
Author: User

Precautions for running linux commands in android: androidlinux

I. Problem Description

On an android device that has already been root, the app executes a linux Command. The app needs to obtain the su permission. Exceptions may occur on some android boards. Command: [su] Working Directory: null Environment: null, the Code is as follows:

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();        }    }

Because the device is already root and there is no problem during the last month's test, and then the new device is tested today (the android version of the new device and old device are the same, both are 5.1 and all are root ), but the following exception occurs:

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

Judging from the exception information, Process localProcess = runtime.exe c ("su"); execution of this Code has no permission. It is root and has no permission. I will go... The ls-al/system/xbin/su information is as follows:

Ii. Solution

There are generally three reasons for this problem.

1/system/xbin/su does not exist

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

Through the adb command, we can see that there is a file named su, so we can exclude this reason.

2/system/xbin/su permission problems,

  

The solution is to execute the following command, provided that the android board has the permission to execute the chmod 06755 command.

chmod 06755 /system/xbin/su

If the following problem occurs when executing the preceding command, contact the device manufacturer.

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

3/system/xbin/su: third-party applications are not allowed to obtain root permissions.

The solution on the internet is:
Root @ android:/$ susu: uid 10061 not allowed to suroot @ android :/

 

  

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.