Caused by: java.io.IOException: Permission denied

  1. find where su is, for instance: /system/xbin/su
  2. check su's file permission: ls -al /system/xbin/su
  3. change mod if necessary: chmod 4755 su
  4. try again.
Answer from meng yang on Stack Overflow
🌐
Stack Overflow
stackoverflow.com › questions › 32792908 › permission-denied-while-using-runtime-in-android-application
Permission denied while using runtime in android application - Stack Overflow
When trying to execute shell commands on Lollipop I am getting permission denied error. Runtime.getRuntime().exec("su") I do have super user permission in the manifest · <uses-permission android:name="android.permission.ACCESS_SUPERUSER"/> The device is rooted.
🌐
Stack Overflow
stackoverflow.com › questions › 38719124 › android-app-run-custom-executable-permission-denied
java - Android app run custom executable - permission denied - Stack Overflow
private void runSingleCommand(){ try { Process process = Runtime.getRuntime().exec("rexx", null, new File("/data/local/myfolder/")); //Permission denied exception InputStreamReader reader = new InputStreamReader(process.getInputStream()); BufferedReader bufferedReader = new BufferedReader(reader); int numRead; char[] buffer = new char[5000]; StringBuffer commandOutput = new StringBuffer(); while ((numRead = bufferedReader.read(buffer)) > 0) { commandOutput.append(buffer, 0, numRead); } bufferedReader.close(); process.waitFor(); System.out.println("--> Output: "+commandOutput.toString()); } catch (IOException e) { throw new RuntimeException(e); } catch (InterruptedException e) { throw new RuntimeException(e); } } Executing this code I get following Exception ·
🌐
XDA Forums
xdaforums.com › home › general development › legacy & low activity devices › htc dream: g1 › g1 android development
Execute root commands in app - permission denied | XDA Forums
March 24, 2010 - This is so easy I want to cry. http://developer.android.com/reference/java/io/File.html#delete() 5. The few commands you need root to run, and you need them to be shell scripts (you can't run Java stuff as root as far as I've harshly found out), you write them this way: ... try { // You previously found out which is the right path for the su binary, // being it /system/bin/su or /system/xbin/su Process suProcess = Runtime.getRuntime().exec(suBinaryPath); DataOutputStream dos = new DataOutputStream(suProcess.getOutputStream()); dos.writeBytes("flash_image boot " + sdcardPath + "2.img\n"); dos.flush(); dos.writeBytes("cp " +sdcardPath + "2.ko /system/lib/modules/wlan.ko\n"); dos.flush(); dos.writeBytes("exit\n"); dos.flush(); suProcess.waitFor(); } catch (Exception ex) { // Please do something, don't let Exceptions be raised and silently trapped.
Find elsewhere
Top answer
1 of 1
11

https://developer.android.com/about/versions/10/behavior-changes-10#execute-permission

When targeting API 29 (Android 10 / Q) or above, it is not possible anymore to have execute permission for files stored within the app's home directory (data), which is exactly what you are describing (/data/data/%package%/).

This Android 10 modification was introduced in commit: https://android-review.googlesource.com/c/platform/system/sepolicy/+/804149 and was then confirmed officially by Google here: https://issuetracker.google.com/issues/128554619

This significant change is being discussed by various projects, in termux/termux-app#1072 for instance. One recommended and (hopefully) future-proof way is to extract program binaries into the application's native lib directory (with android:extractNativeLibs=true), where files can still be executed but are stored read-only for improved security.

Here are examples showing how to handle this change, in Termux with commit f6c3b6f in the android-10 branch or in this other project showing how to run the Erlang runtime on Android by exctrating all the files from a .zip archive into the jniLibs/"abi" subdirectory ("abi" being arm64-v8a for 64-bit ARM, armeabi-v7a for 32-bit ARM, etc.) with the imposed lib___.so filename format expected by the Android platform. Executable files can simply be moved in the right project folder manually, the important part is to use the lib___.so format for the filenames.

In the Android Manifest file, setting the attribute android:extractNativeLibs="true" will get these lib___.so files extracted at installation time in the right native lib directory, with support for execute permission. Symlinks can finally be created if needed in the usual app directory to use the regular executable names, instead of the harder-to-manipulate lib___.so versions.

Thanks, Jérôme

🌐
Stack Exchange
android.stackexchange.com › questions › 58383 › permission-denied-when-trying-to-mount-usb-storage
rooting - Permission denied when trying to mount USB storage - Android Enthusiasts Stack Exchange
September 8, 2014 - But I get a permission denied message. I've tried different su binaries. One of them is: http://e2e.ti.com/support/embedded/android/f/509/t/279726.aspx · The shell command which I'm using is working in adb, but I have to execute it within an app. Without permissions, I cannot do that. ... I finally found the solution. Yes ADB of Beaglebone is rooted but there isn't a SU binary. So I wasn't able to execute this code within my app: Process proc = Runtime.getRuntime().exec("su mount -t vfat -o rw /dev/block/sd* /storage/usb1");
🌐
cl-xml
runtime.getruntime.exec.android.permission.denied.cl-xml.org
Runtime.getruntime.exec Android Permission Denied
Some runtime.getruntime.exec errors may sometimes occur because of runtime.getruntime.exec android permission within the running program itself. Check for patches or bug fixes that might be available for your program. Always keep your programs updated with the latest release of patches and ...
🌐
Stack Overflow
stackoverflow.com › questions › 64017722 › java-android-runtime-getruntime-exec
Java Android Runtime.getRuntime().exec() - Stack Overflow
Apparently: Input event injection from pid 9182 permission denied Meaning it was indeed a permission problem..
🌐
Stack Overflow
stackoverflow.com › questions › 9927766 › how-to-change-permissions-to-file-with-runtime-getruntime-exec
android ndk - How to change permissions to file with Runtime.getRuntime().exec - Stack Overflow
private boolean isSu() throws IOException, InterruptedException { Process p; try { // Preform su to get root privledges 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/sd/temporary.txt\n"); // Close the terminal os.writeBytes("exit\n"); os.flush(); try { p.waitFor(); if (p.exitValue() != 255) { toastMessage("root"); return true; } else { toastMessage("not root"); } } catch (InterruptedException e) { toastMessage("not root"); } } catch (IOException e) { toastMessage("not root"); } return false; }
🌐
Stack Overflow
stackoverflow.com › questions › 78962396 › unable-to-execute-openjdk-binary-on-android-11-permission-denied-error
java - Unable to Execute OpenJDK Binary on Android 11: "Permission Denied" Error - Stack Overflow
September 8, 2024 - If you want to execute something save it in the app-private directory /data/data/<packagename> at least on Android 11 it should be possible to execute somethin there. Note that Standard Linux Java binaries won't work on Android because of problems with certain standard libraries. ... How to solve FileSystemException: Cannot open file, path ="" (OS Error: Permission denied, errno = 13)
🌐
Itecnote
itecnote.com › tecnote › android-runtime-getruntime-execsu-java-io-ioexception-permission-denied
Android Runtime.getRuntime().exec(“su”) java.io.IOException: Permission denied – iTecNote
W/System.err(3211): java.io.IOException: Error running exec(). Command: [su] Working Directory: null Environment: null W/System.err(3211): at java.lang.ProcessManager.exec(ProcessManager.java:211) W/System.err(3211): at java.lang.Runtime.exec(Runtime.java:174) W/System.err(3211): at java.lang.Runtime.exec(Runtime.java:247) W/System.err(3211): at java.lang.Runtime.exec(Runtime.java:190) W/System.err(3211): at com.example.executeandroidtest.ShellUtils.execCommand(MainActivity.java:661) W/System.err(3211): at com.example.executeandroidtest.MainActivity$3.run(MainActivity.java:410) W/System.err(3211): at java.lang.Thread.run(Thread.java:818) W/System.err(3211): Caused by: java.io.IOException: Permission denied W/System.err(3211): at java.lang.ProcessManager.exec(Native Method) W/System.err(3211): at java.lang.ProcessManager.exec(ProcessManager.java:209) W/System.err(3211): ...