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 :/