Android:为什么从PC和USB调试运行adb shell命令不需要权限?



程序运行:getRuntime.exec("screencap", "-p /sdcard/image.png")除了用code=1退出外,什么都不做。

但当USB调试时,在cmd:adb shell screencap -p /sdcard/dddd.png中从pc运行相同的命令可以工作。

从之前的stackoverflow帖子来看,似乎程序运行该命令不起作用,因为该应用程序没有权限,这需要扎根手机才能允许su访问该应用程序。

为什么从电脑运行这些命令不需要特权访问

区别在于adbd(adb守护进程(使用shelluid运行,而在应用程序中运行时,您仍然使用应用程序的uid。所以这是不同的背景。

有一个SELinux规则允许adb调用screencap(在system/sepolicy/private/adbd.te中定义(:

# Perform binder IPC to surfaceflinger (screencap)
# XXX Run screencap in a separate domain?
binder_use(adbd)
binder_call(adbd, surfaceflinger)
binder_call(adbd, gpuservice)
# b/13188914
allow adbd gpu_device:chr_file rw_file_perms;
allow adbd ion_device:chr_file rw_file_perms;
r_dir_file(adbd, system_file)

最新更新