【问题标题】:Android: why does running adb shell commands from pc and USB debugging doesn't required permission?Android:为什么从 pc 和 USB 调试运行 adb shell 命令不需要权限?
【发布时间】:2021-02-26 18:58:06
【问题描述】:

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

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

从以前的stackoverflow帖子来看,似乎以程序方式运行该命令不起作用,因为该应用没有权限,这需要root手机才能授予su访问该应用的权限。

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

【问题讨论】:

    标签: android adb privileges usb-debugging superuser


    【解决方案1】:

    不同之处在于adbd(adb 守护程序)使用shell uid 运行,而从应用程序执行此操作时您仍然使用应用程序的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)
    

    【讨论】:

    • 和su UID一样的权限?
    • 没有。要从 adb 获得相同的 root 权限,您需要运行 adb root(在 OS 的生产版本中不启用)
    • @EEAH 对 AOSP 代码进行了更多研究,并更新了我的答案以添加更多细节:)
    • 谢谢。是否可以通过使用 shell uid 来授予应用程序权限?如果不是,(如果必须由 su UID 授予权限)是否可以像这个问题一样分 3 个步骤执行此操作:stackoverflow.com/q/64843656/13695921
    • 您可以使用媒体投影API。这是一个图书馆github.com/bolteu/screenshotty
    猜你喜欢
    • 2022-07-12
    • 2012-05-03
    • 1970-01-01
    • 2013-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-17
    • 2012-01-06
    相关资源
    最近更新 更多