首先:请注意,您只能使用 su 执行 shell 命令(= 您只能以 root 身份使用 shell 命令,而不是 java 代码)。
第二:不确定这是否适用于所有 su 应用程序,但这是su
我手机上的帮助信息:
Usage: su [options] [--] [-] [LOGIN] [--] [args...]
Options:
--daemon start the su daemon agent
-c, --command COMMAND pass COMMAND to the invoked shell
-h, --help display this help message and exit
-, -l, --login pretend the shell to be a login shell
-m, -p,
--preserve-environment do not change environment variables
-s, --shell SHELL use SHELL instead of the default /system/bin/sh
-u display the multiuser mode and exit
-v, --version display version number and exit
-V display version code and exit,
this is used almost exclusively by Superuser.apk
这意味着:您必须运行su -c something
(或su -c something - root
, 但root
无论如何都是默认设置)。基本上这在大多数 Linux 系统上等于 su,除了守护进程,因为在常规 Linux 系统上没有守护进程和 su 调用。
如果其他 su 命令的行为不同(这是可能的),打开一个流到 shell,执行su
,评估它的返回代码,然后继续执行其他命令,最后执行会更安全exit
。