簡體   English   中英

Android:為什么從pc運行adb shell命令和USB調試不需要權限?

[英]Android: why does running adb shell commands from pc and USB debugging doesn't required permission?

以編程方式運行: getRuntime.exec("screencap", "-p /sdcard/image.png")除了以code=1退出之外不執行任何操作。

但是當 USB 調試時,從 cmd 中的 pc 運行相同的命令: adb shell screencap -p /sdcard/dddd.png有效。

從以前的 stackoverflow 帖子來看,似乎以編程方式運行該命令不起作用,因為該應用程序沒有權限,這需要對手機進行 root 才能授予 su 訪問該應用程序的權限。

為什么從 pc 上運行這些命令不需要特權訪問?

不同之處在於adbd (adb 守護進程)使用shell uid 運行,而從應用程序執行此操作時,您仍然使用應用程序的 uid。 所以是不同的語境。

有一個 SELinux 規則允許 adb 調用屏幕截圖(在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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM