就 Linux 而言,system 用户只是普通用户(UID 1000)。然而,Android 服务赋予它特殊权限,您几乎可以访问任何东西。大多数服务在某处都有这样的代码:
private static final void enforceSystemOrRoot(String message) {
final int uid = Binder.getCallingUid();
if (uid != Process.SYSTEM_UID && uid != 0) {
throw new SecurityException(message);
}
}
这样做是拒绝非 root 或system 的任何人访问。 shell 用户(UID 2000)(您在执行 adb shell 时得到的)是另一个具有很大权力的用户(许多组的成员)。参照。
system:
$ su 1000
$ id
uid=1000(system) gid=1000(system)
groups=1003(graphics),1004(input),1007(log),1009(mount),
1011(adb),1015(sdcard_rw),1028(sdcard_r),3001(net_bt_admin),
3002(net_bt),3003(inet),3006(net_bw_stats)
shell:
$ adb shell
shell@android:/ $ id
uid=2000(shell) gid=2000(shell)
groups=1003(graphics),1004(input),1007(log),1009(mount),
1011(adb),1015(sdcard_rw),1028(sdcard_r),3001(net_bt_admin),
3002(net_bt),3003(inet),3006(net_bw_stats)
Android 为每个应用程序使用单独的用户,系统服务也有其专用用户(media、radio、wifi 等)。很少有东西以 root 身份运行(主要是本机守护进程)。