如何使用ROOT权限从Android应用启动进程?
错误日志(使用Runtime.getRuntime().exec(commandArray);
时 IOException ):
Caused by: java.io.IOException: Error running exec(). Command: [su -c, /data/data/%my_app_package%/%app% %params%] Working Directory: null Environment: null
08-22 11:02:17.515: WARN/System.err(19804): at java.lang.ProcessManager.exec(ProcessManager.java:211)
08-22 11:02:17.515: WARN/System.err(19804): at java.lang.Runtime.exec(Runtime.java:168)
08-22 11:02:17.515: WARN/System.err(19804): at java.lang.Runtime.exec(Runtime.java:123)
08-22 11:02:17.515: WARN/System.err(19804): ... 5 more
08-22 11:02:17.515: WARN/System.err(19804): Caused by: java.io.IOException: Permission denied
08-22 11:02:17.515: WARN/System.err(19804): at java.lang.ProcessManager.exec(Native Method)
08-22 11:02:17.515: WARN/System.err(19804): at java.lang.ProcessManager.exec(ProcessManager.java:209)
08-22 11:02:17.515: WARN/System.err(19804): ... 8 more
使用ProcessBuilder
启动时输出类似的错误:
08-22 11:19:34.052: WARN/System.err(22054): Caused by: java.io.IOException: Error running exec(). Command: [su -c, /data/data/%app_package%/%app% %parameters%] Working Directory: null Environment: [ANDROID_SOCKET_zygote=9, ANDROID_BOOTLOGO=1, EXTERNAL_STORAGE=/storage/sdcard0, ANDROID_ASSETS=/system/app, PATH=/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin, ASEC_MOUNTPOINT=/mnt/asec, LOOP_MOUNTPOINT=/mnt/obb, BOOTCLASSPATH=/system/framework/core.jar:/system/framework/core-junit.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/framework_ext.jar:/system/framework/android.policy.jar:/system/framework/services.jar:/system/framework/apache-xml.jar, ANDROID_DATA=/data, LD_LIBRARY_PATH=/vendor/lib:/system/lib, ANDROID_ROOT=/system, ANDROID_PROPERTY_WORKSPACE=8,65536]
08-22 11:19:34.052: WARN/System.err(22054): at java.lang.ProcessManager.exec(ProcessManager.java:211)
08-22 11:19:34.052: WARN/System.err(22054): at java.lang.ProcessBuilder.start(ProcessBuilder.java:195)
08-22 11:19:34.052: WARN/System.err(22054): ... 5 more
08-22 11:19:34.052: WARN/System.err(22054): Caused by: java.io.IOException: Permission denied
我绝对相信该设备已植根,而且工作正常。有时我被要求授予应用程序root权限。在这种情况下,我不会被问到,只是得到错误。
如何在运行时询问应用程序的root权限?它是否为所有已启动的进程授予root权限?
答案 0 :(得分:2)
如何为ProcessBuilder
:
不工作代码:
commandLine.add("su -c"); commandLine.add("app"); commandLine.add("params")
commandLine.add("sudo"); commandLine.add("app"); commandLine.add("params")
工作代码:
commandDownloader.add("su"); commandDownloader.add("-c"); commandLine.add("app");
对于工作代码我被Android操作系统要求许可(在我的情况下MIUI更详细)