之前的文章轉帖過網上同行製作的 ADB 協議表格,但內容不夠詳盡,所以這裡筆者基於 Android 4.4.2 的技術文檔重新做一次翻譯。
HOST SERVICES:
主機服務:
host:version
Ask the ADB server for its internal version number. As a special exception, the server will respond with a 4-byte hex string corresponding to its internal version number, without any OKAY or FAIL.
向 ADB 服務器請求其內部版本號。作為協議中的一個例外(請查看 OVERVIEW.txt 了解 ADB 具體協議規則),服務器會返回一個代表其內部版本號的 4 字節十六進制字符串,而不像標準協議那樣返回 OKAY 或 FAIL。
host:kill
Ask the ADB server to quit immediately. This is used when the ADB client detects that an obsolete server is running after an upgrade.
請求 ADB 服務器立刻退出。當 ADB 升級完成後,如果 ADB 客戶端檢測到之前過時的 ADB 服務器還在運行,就會發送這個請求。
host:devices
host:devices-l
Ask to return the list of available Android devices and their state. devices-l includes the device paths in the state. After the OKAY, this is followed by a 4-byte hex len, and a string that will be dumped as-is by the client, then the connection is closed
這兩個服務請求類似,都是請求 ADB 服務器返回一系列有效的安卓設備及其狀態信息,只是 devices-l 會在狀態中包含該設備的更多信息,比如產品型號等。正常返回 OKAY 之後,會緊跟著一個代表數據長度的 4 字節十六進制數,以及對應的輸出內容(就像我們執行 adb devices -l 看到的那樣),然後連接請求關閉。
host:track-devices
This is a variant of host:devices which doesn't close the connection. Instead, a new device list description is sent each time a device is added/removed or the state of a given device changes (hex4 + content). This allows tools like DDMS to track the state of connected devices in real-time without polling the server repeatedly.
這個服務是 host:devices 的一個變種,客戶端與 ADB 服務器的連接會一直保持。當有設備增加/移除或設備狀態改變時,會主動往連接上的客戶端發送新的設備列表信息(4 字節 16 進制長度 + 內容)。這樣就能允許 DDMS 這類工具實時跟蹤所有連接設備的狀態,而不需要每次都去輪詢 ADB 服務器。
host:emulator:<port>
This is a special query that is sent to the ADB server when a new emulator starts up. <port> is a decimal number corresponding to the emulator's ADB control port, i.e. the TCP port that the emulator will forward automatically to the adbd daemon running in the emulator system. This mechanism allows the ADB server to know when new emulator instances start.
這是一個特殊的請求,當一個新的模擬器啟動時會發送到 ADB 服務器。<port> 對應模擬器控制端口的一個十進制數字,例如本機自動轉發到正在運行的模擬器中 adbd 的那個 TCP 轉發端口。這個機制讓 ADB 服務器能清楚知道哪個模擬器被啟動了。
host:transport:<serial-number>
Ask to switch the connection to the device/emulator identified by <serial-number>. After the OKAY response, every client request will be sent directly to the adbd daemon running on the device. (Used to implement the -s option)
請求 ADB 服務器把當前連接切換到 <serial-number> 指定的設備/模擬器。在 OKAY 應答之後,客戶端的所有請求都會重定向到該設備的 adbd 守護進程。(用來實現 ADB 命令行客戶端的 -s 選項)
host:transport-usb
Ask to switch the connection to one device connected through USB to the host machine. This will fail if there are more than one such devices. (Used to implement the -d convenience option)
請求 ADB 服務器把當前連接切換到通過 USB 連接到主機的設備。如果有多於一個設備通過 USB 連接到主機,調用將會失敗。(用來實現 ADB 命令行客戶端的 -d 這個便捷選項)
host:transport-local
Ask to switch the connection to one emulator connected through TCP. This will fail if there is more than one such emulator instance running. (Used to implement the -e convenience option)
請求 ADB 服務器把當前連接切換到一個通過 TCP 協議連接的模擬器。如果有多於一個模擬器在運行,調用將會失敗。(用來實現 -e 這個便捷選項)
host:transport-any
Another host:transport variant. Ask to switch the connection to either the device or emulator connect to/running on the host. Will fail if there is more than one such device/emulator available. (Used when neither -s, -d or -e are provided)
另外一個 host:transport 的變種。請求 ADB 服務器把當前連接切換到已連接主機的設備或正在主機中運行的模擬器。如果有多於一個這類設備存在,調用將會失敗。(在 -s、-d 或 -e 選項都未提供時使用)
host-serial:<serial-number>:<request>
This is a special form of query, where the 'host-serial:<serial-number>:' prefix can be used to indicate that the client is asking the ADB server for information related to a specific device. <request> can be in one of the format described below.
這是一個特殊的請求,前綴 "host-serial:<serial-number>:" 用來指定客戶端請求信息時的目標設備。<request> 可以是以下描述的任一方法。
host-usb:<request>
A variant of host-serial used to target the single USB device connected to the host. This will fail if there is none or more than one.
host-serial 的一個變種,指定的是一個連接上主機的 USB 設備。如果沒有或者有多於一個這種設備,調用將會失敗。
host-local:<request>
A variant of host-serial used to target the single emulator instance running on the host. This will fail if there is none or more than one.
另一個 host-serial 的變種,這次指定的是一個在主機運行的模擬器。如果沒有或者有多於一個這種設備,調用將會失敗。相當於直接執行 "adb get-product" 或 "adb get-serialno" 等。
host:<request>
When asking for information related to a device, 'host:' can also be interpreted as 'any single device or emulator connected to/running on
the host'.
當通過 ADB 服務器向一個相關設備請求信息時,'host:' 在這種情況下也可以指「任意一個連接上主機的設備或正在主機上運行的模擬器」。
<host-prefix>:get-product
XXX
官方就提供了上面的 XXX,沒有更多信息。本人在嘗試 "adb get-product" 時發現並不支持。
<host-prefix>:get-serialno
Returns the serial number of the corresponding device/emulator. Note that emulator serial numbers are of the form "emulator-5554"
返回對應設備/模擬器的序列號。"<host-prefix>:" 指的是上面三種特殊信息請求命令。注意模擬器的序列號格式形如 "emulator-5554",類似於命令行執行 "adb get-serialno"。
<host-prefix>:get-devpath
Returns the device path of the corresponding device/emulator.
返回對應設備/模擬器的設備路徑,這裡的設備路徑指的是 "adb devices -l" 列出的最後一部分,如 "device product:OPPO_12025 model:X909 device:X909"。<host-prefix>: 指的是上面三種特殊信息請求命令,類似於命令行執行 "adb get-devpath"。
<host-prefix>:get-state
Returns the state of a given device as a string.
返回一個代表指定設備狀態的字符串,<host-prefix>: 指的是上面三種特殊信息請求命令,類似於命令行執行 "adb get-state"。
<host-prefix>:forward:<local>;<remote>
Asks the ADB server to forward local connections from <local> to the <remote> address on a given device.There, <host-prefix> can be one of the host-serial/host-usb/host-local/host prefixes as described previously and indicates which device/emulator to target.
請求 ADB 服務器把本地 <local> 指定的連接重定向到指定設備的 <remote> 地址。在這裡,"<host-prefix>" 可以是以上描述的用來指定目標設備/模擬器的 host-serial/host-usb/host-local/host。
the format of <local> is one of:
其中 <local> 的格式可以是以下任一種:
tcp:<port> -> TCP connection on localhost:<port>tcp:<port> -> 本地主機的 <port> 端口的 TCP 連接
local:<path> -> Unix local domain socket on <path>local:<path> -> 基於地址 <path> 的本地主機的 Unix 域套接字連接(UNIX Domain Socket 的地址是一個 socket 類型的文件在文件系統中的路徑) the format of <remote> is one of:
<remote> 的格式如下:
tcp:<port> -> TCP localhost:<port> on devicetcp<port> -> 目標設備的 localhost:<port>
local:<path> -> Unix local domain socket on devicelocal:<path> -> 目標設備的本地 Unix Domain Socket
jdwp:<pid> -> JDWP thread on VM process <pid>jdwp:<pid> -> 目標設備中進程號 <PID> 指定的 JAVA 虛擬機內部的 JDWP 線程
or even any one of the local services described below.
甚至還支持下面描述的任一個本地服務
<host-prefix>:forward:norebind:<local>;<remote>
Same as <host-prefix>:forward:<local>;<remote> except that it will fail it there is already a forward connection from <local>. Used to implement 'adb forward --no-rebind <local> <remote>'
類似 <host-prefix>:forward:<local>;<remote>,有一點區別是如果已經存在 <local> 的一個轉發,調用會失敗。用來實現 "adb forward --no-rebind <local> <remote>"
<host-prefix>:killforward:<local>
Remove any existing forward local connection from <local>. This is used to implement 'adb forward --remove <local>'
移除所有 <local> 指定的本地重定向連接。用來實現 "adb forward --remove <local>" 命令
<host-prefix>:killforward-all
Remove all forward network connections. This is used to implement 'adb forward --remove-all'.
移除所有的重定向連接。用來實現 "adb forward --remove-all" 命令
<host-prefix>:list-forward
List all existing forward connections from this server. This returns something that looks like the following:
列出本機所有存在的轉發連接。返回格式如下:
<hex4>: The length of the payload, as 4 hexadecimal chars.<hex4>: 返回結果長度,由 4 字節 16 進制字符組成
<payload>: A series of lines of the following format:
<serial> " " <local> " " <remote> "\n" :Where <serial> is a device serial number. <local> is the host-specific endpoint (e.g. tcp:9000). <remote> is the device-specific endpoint.
<payload>: 一連串以下格式的行:<serial> " " <local> " " <remote> "\n":<serial> 代表設備序列號,<local> 代表主機端的連接點(比如 tcp:9000),<remote> 代表設備端的連接點。
Used to implement 'adb forward --list'.
這是用來實現 "adb forward --list" 命令的。
LOCAL SERVICES:
本地服務:
All the queries below assumed that you already switched the transport to a real device, or that you have used a query prefix as described above.
下面的所有請求都是建立在「你已經把傳輸切換到一個真實設備上」或「你使用了以上描述的一個 query 前綴」的基礎上。
shell:command arg1 arg2 ...
Run 'command arg1 arg2 ...' in a shell on the device, and return its output and error streams.
在設備的 shell 中運行 'command arg1 arg2 ...',並返回對應的輸出和錯誤流。
Note that arguments must be separated by spaces. If an argument contains a space, it must be quoted with double-quotes. Arguments cannot contain double quotes or things will go very wrong.
注意參數必須用空格隔開。如果一個參數本身包含空格,那麼它必須用雙引號引起來。參數內部不能包含雙引號,否則命令執行結果將無法控制。
Note that this is the non-interactive version of "adb shell"
注意這是 "adb shell" 的一個非交互式版本
shell:
Start an interactive shell session on the device. Redirect stdin/stdout/stderr as appropriate.
開啟設備的一個交互式 shell 會話,並合理地重定向了標準輸入/標準輸出/標準錯誤。
Note that the ADB server uses this to implement "adb shell", but will also cook the input before sending it to the device (see interactive_shell() in commandline.c)
注意 ADB 服務器就是使用這個協議來實現命令行客戶端的 "adb shell" 請求的,當然它會先包裝整理好輸入的信息再發送到目標設備(請查看 commandline.c 的 interactive_shell())。
remount:
Ask adbd to remount the device's filesystem in read-write mode, instead of read-only. This is usually necessary before performing an "adb sync" or "adb push" request.
This request may not succeed on certain builds which do not allow that.
請求 adbd 把設備的只讀文件系統重新掛載成可讀寫模式。這在執行 "adb sync" 或 "adb push" 請求之前通常很有必要。這個請求在一些版本中可能因為不支持而失敗。
dev:<path>
Opens a device file and connects the client directly to it for read/write purposes. Useful for debugging, but may require special privileges and thus may not run on all devices. <path> is a full path from the root of the filesystem.
打開一個設備文件並通過客戶端連接上它進行讀寫操作。通常用於調試,但可能需要特殊權限,因此未必能在所有設備上運行。<path> 指的是從文件系統根開始的全路徑。
tcp:<port>
Tries to connect to tcp port <port> on localhost.
嘗試連接本機的 tcp 端口 <port>。
tcp:<port>:<server-name>
Tries to connect to tcp port <port> on machine <server-name> from the device. This can be useful to debug some networking/proxy issues that can only be revealed on the device itself.
嘗試從設備連接 <server-name> 指定機器的 tcp 端口 <port>。這對調試只能在設備上顯示的網絡/代理問題很有用。
local:<path>
Tries to connect to a Unix domain socket <path> on the device
嘗試連接設備上 <path> 地址指定的 Unix 域套接字。
localreserved:<path>
localabstract:<path>
localfilesystem:<path>
Variants of local:<path> that are used to access other Android socket namespaces.
local:<path> 的幾個變種,用來訪問安卓其他命名空間指定的套接字。
log:<name>
Opens one of the system logs (/dev/log/<name>) and allows the client to read them directly. Used to implement 'adb logcat'. The stream will be read-only for the client.
打開 /dev/log/<name> 指定的一個系統日誌文件,並允許客戶端直接讀取。用來實現 "adb logcat" 命令。日誌流對客戶端是只讀的。
framebuffer:
This service is used to send snapshots of the framebuffer to a client. It requires sufficient privileges but works as follow: After the OKAY, the service sends 16-byte binary structure containing the following fields (little-endian format):
這個服務用來把 framebuffer 的截屏快照發送到客戶端。它需要足夠的權限,工作原理如下:服務在返回 OKAY 之後,會繼續發送一個 16 字節的二進制結構數據到客戶端(小字節序格式),包含以下字段:
depth: uint32_t: framebuffer depthdepth: uint32_t: framebuffer 深度
size: uint32_t: framebuffer size in bytessize: uint32_t: framebuffer 大小(字節)
width: uint32_t: framebuffer width in pixelswidth: uint32_t: framebuffer 寬度(像素)
height: uint32_t: framebuffer height in pixelsheight: uint32_t: framebuffer 高度(像素)
With the current implementation, depth is always 16, and size is always width*height*2
在當前的實現中,深度永遠是 16,大小永遠是寬度 × 高度 × 2。
Then, each time the client wants a snapshot, it should send one byte through the channel, which will trigger the service to send it 'size' bytes of framebuffer data. If the adbd daemon doesn't have sufficient privileges to open the framebuffer device, the connection is simply closed immediately.
每次客戶端想要一個截屏快照時,它會通過 Socket 通道發送一個字節,這會觸發本服務把 framebuffer 數據按 size 指定的字節數發送給客戶端。如果 adbd 守護進程沒有足夠權限打開 framebuffer 設備,那麼連接會立即關閉。
jdwp:<pid>
Connects to the JDWP thread running in the VM of process <pid>.
連接目標設備中由進程號 <PID> 指定的 JAVA 虛擬機進程內部的 JDWP 線程
track-jdwp
This is used to send the list of JDWP pids periodically to the client.
這個服務用來週期性地往客戶端發送有啟用 JDWP 的進程的進程號列表。
The format of the returned data is the following:
返回數據格式如下:
<hex4>: the length of all content as a 4-char hexadecimal string<hex4>: 代表返回數據長度的一個 4 字節 16 進制字符串
<content>: a series of ASCII lines of the following format: <pid> "\n"<content>: 一系列的 ASCII 字符串行,每行的格式如下:<pid> "\n"
This service is used by DDMS to know which debuggable processes are running on the device/emulator.
這個服務被 DDMS 用來知悉有哪些可調試的進程正在真實設備/模擬器上運行。
Note that there is no single-shot service to retrieve the list only once.
注意並不存在另外一個服務來只獲取一次這個列表。
sync:
This starts the file synchronisation service, used to implement "adb push" and "adb pull". Since this service is pretty complex, it will be detailed in a companion document named SYNC.TXT
開啟文件同步服務,用來實現 "adb push" 和 "adb pull" 這兩個命令。由於這個服務相當複雜,更詳細的信息請查看相關的 SYNC.TXT 文檔。
Item
Description
Warning
Author
天地會珠海分舵
轉載請注明出處!
Blog Address
https://blog.csdn.net/zhubaitian