原文:https://github.com/android/platform_system_core/blob/master/adb/OVERVIEW.TXT)
*Implementation notes regarding ADB.*
ADB實現注解
## 1. General Overview:
1概要
*The Android Debug Bridge (ADB) is used to:*
ADB在以下情況下使用:
- *keep track of all Android devices and emulators instances connected to or running on a given host developer machine*
- 對所有連接到開發機器上的android真機和模擬器進行跟蹤管理
- *implement various control commands (e.g. "adb shell", "adb pull", etc..)?for the benefit of clients (command-line users, or helper programs like DDMS). These commands are what is called a 'service' in ADB.*
- 實現了大量的控制命令(比如: "adb shell", "adb pull",等等)來方便用戶使用(包括命令行用戶和助手類程序如ddms),這些命令往往被我們叫做adb中的一個‘服務’。
*As a whole, everything works through the following components:*
總而言之,所有的事情都是圍繞著以下這幾個模塊進行的:
### 1.1 The ADB server
1.1 ADB服務器
*This is a background process that runs on the host machine. Its purpose?if to sense the USB ports to know when devices are attached/removed,as well as when emulator instances start/stop.*
這是在**主機設備(PC/開發機器)上運行的**一個后臺進程。它的目的是嗅探何時有設備在主機的usb口上掛載/移除,以及模擬器何時開啟/關閉。
*It thus maintains a list of "connected devices" and assigns a 'state'?to each one of them: OFFLINE, BOOTLOADER, RECOVERY or ONLINE (more on?this below).*
因此它會維護著一個"已連接設備"列表,并且為每個設備指定一個‘狀態’:OFFLINE, BOOTLOADER, RECOVERY 或 ONLINE (下文會詳述)。
*The ADB server is really one giant multiplexing loop whose purpose is?to orchestrate the exchange of data (packets, really) between clients,?services and devices.*
ADB服務器確實可以稱為是一個強大的多路路由,它的目的就是去協調組織客戶端,各種服務和設備之間的數據交換(數據包,真實數據)。
### 1.2 The ADB daemon (adbd)
1.2 ADB守護進程(adbd)
*The 'adbd' program runs as a background process within an Android device?or emulated system. Its purpose is to connect to the ADB server?(through USB for devices, through TCP for emulators) and provide a?few services for clients that run on the host.*
adbd是一個在android真實機器或者模擬器上運行的后臺伺服程序。它的目的是為了連接pc端的adb服務器(真實機器用usb,模擬器用tcp協議(譯者注:其實真實機器也可以用tcp來連接,這篇文章沒有及時更新過來))并且為在主機pc上運行的adb客戶端應用提供一些服務。
*The ADB server considers that a device is ONLINE when it has successfully?connected to the adbd program within it. Otherwise, the device is OFFLINE,?meaning that the ADB server detected a new device/emulator, but could not?connect to the adbd daemon.*
當adb服務器成功連接上android機器上的adbd伺服程序的時候就會認為該設備已經online,否者就會認為該設備是offline,指的是adb服務器有檢測到一個新的設備連接上來,但是卻沒有成功連接上該設備的的adbd。
*the BOOTLOADER and RECOVERY states correspond to alternate states of?devices when they are in the bootloader or recovery mode.*
BOOTLOADER和RECOVERY著兩個狀態分別代表android設備處于bootloader或者recovery模式下的對應的可選狀態。
### 1.3. The ADB command-line client
1.3 ADB命令行客戶端
*The 'adb' command-line program is used to run adb commands from a shell?or a script. It first tries to locate the ADB server on the host machine,?and will start one automatically if none is found.*
adb命令行客戶端是給shell或者腳本調用來跑各種adb命令的。它首先會嘗試找到主機pc上運行的adb服務器,如果沒有找到的話就會自動啟動一個adb服務器。
*then, the client sends its service requests to the ADB server. It doesn't?need to know.*
然后該adb命令行客戶端會往adb服務器發送服務請求,而這些對于adb服務器來說是無需知道的。
*Currently, a single 'adb' binary is used for both the server and client.?this makes distribution and starting the server easier.*
就當前來說,adb服務器和adb客戶端使用的其實是同一個二進制文件,這樣使得發布和啟動服務器會更方便。
### *1.4. Services*
1.4. 服務
*There are essentially two kinds of services that a client can talk to.*
本質上一個adb命令行客戶端會和兩類服務進行通信。
*Host Services:?these services run within the ADB Server and thus do not need to?communicate with a device at all. A typical example is "adb devices"?which is used to return the list of currently known devices and their?state. They are a few couple other services though.*
主機服務:這些服務是在adb服務器自身內部運行的所以根本不需要和任何的android設備進行交互。一個典型的命令就是列出當前連接的所有android設備和狀態的命令“adb devices”。 當然還有一些其他的服務了。
<table border="1" cellspacing="0" cellpadding="0" style="border:1px solid silver; border-collapse:collapse; font-family:Verdana,Geneva,Arial,Helvetica,sans-serif"><tbody><tr><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="line-height:1.5; font-family:宋體"><span style="color:#3366ff">命令</span></span></p></td><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="line-height:1.5; font-family:宋體"><span style="color:#3366ff">解釋</span></span></p></td></tr><tr><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">host:version</span></p></td><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">?</span></p></td></tr><tr><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">host:kill</span></p></td><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff"><span style="line-height:1.5; font-family:宋體">停止</span>server</span></p></td></tr><tr><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">host:devices</span></p></td><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">?</span></p></td></tr><tr><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">host:track-devies</span></p></td><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">?</span></p></td></tr><tr><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">host:emulator:<port></span></p></td><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">?</span></p></td></tr><tr><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">host:transport:<serial-number></span></p></td><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff"><span style="line-height:1.5; font-family:宋體">連接指定</span>serial-number<span style="line-height:1.5; font-family:宋體">的設備或者模擬器</span></span></p></td></tr><tr><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">host:transport-usb</span></p></td><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff"><span style="line-height:1.5; font-family:宋體">連接</span>usb<span style="line-height:1.5; font-family:宋體">上的設備,如果</span>usb<span style="line-height:1.5; font-family:宋體">上有不止一個設備,會失敗。</span></span></p></td></tr><tr><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">host:transport-local</span></p></td><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff"><span style="line-height:1.5; font-family:宋體">通過</span>tcp<span style="line-height:1.5; font-family:宋體">方式連接模擬器,如果有多個模擬器在運行,會失敗。</span></span></p></td></tr><tr><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">host:transport-any</span></p></td><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff"><span style="line-height:1.5; font-family:宋體">連接</span>usb<span style="line-height:1.5; font-family:宋體">設備或者模擬器都可以,但是如果有超過一個設備或模擬器,會失敗。</span></span></p></td></tr><tr><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">host-serial:<serial-number>:<request></span></p><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">host-usb:<request></span></p><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">host-local:<request></span></p></td><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="line-height:1.5; font-family:宋體"><span style="color:#3366ff">向指定的設備發送特定的請求。同樣如果存在多個設備的沖突,會失敗。</span></span></p></td></tr><tr><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">host:<request></span></p></td><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="line-height:1.5; font-family:宋體"><span style="color:#3366ff">向當前連接的設備發送請求</span></span></p></td></tr><tr><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff"><host-prefix>:get-serialno</span></p></td><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff"><span style="line-height:1.5; font-family:宋體">獲取設備的</span>serial-number</span></p></td></tr><tr><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff"><host-prefix>:get-state</span></p></td><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="line-height:1.5; font-family:宋體"><span style="color:#3366ff">獲取設備狀態</span></span></p></td></tr><tr><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff"><host-prefix>:forward:<local>;<remote></span></p></td><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">?</span></p><div><br/></div></td></tr></tbody></table>
*Local Services:?these services either run within the adbd daemon, or are started by?it on the device. The ADB server is used to multiplex streams?between the client and the service running in adbd. In this case?its role is to initiate the connection, then of being a pass-through?for the data.*
本地服務:這類服務是在adbd這個守護進程自身內部運行的,或者是由它啟動運行的。adb服務器會在客戶端和這些adbd中運行的服務之間進行數據路由。在這種情況下adb服務器扮演著初始化各種連接以及數據路信使的角色。
<table border="1" cellspacing="0" cellpadding="0" style="border:1px solid silver; border-collapse:collapse; font-family:Verdana,Geneva,Arial,Helvetica,sans-serif"><tbody><tr><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">命令</span></p></td><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">解釋</span></p></td></tr><tr><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">shell:command arg1 arg2 ...</span></p></td><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">在設備上執行命令行操作</span></p></td></tr><tr><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">shell:</span></p></td><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">參見commandline.c中的interactive_shell()</span></p></td></tr><tr><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">remount:</span></p></td><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">以讀/寫模式加載設備的文件系統</span></p></td></tr><tr><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">dev:<path></span></p></td><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">為client打開設備上的特定路徑,用于讀寫問題。有可能由于權限問題而失敗。</span></p></td></tr><tr><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">tcp:<port></span></p></td><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">嘗試從設備連接本主機的某個tcp端口</span></p></td></tr><tr><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">tcp:<port>:<server-name></span></p></td><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">嘗試從設備連接特定主機名的某個tcp端口</span></p></td></tr><tr><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">local:<path></span></p></td><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">嘗試連接設備上的特定路徑,路徑是UNIX域名形式</span></p></td></tr><tr><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">localreserved:<path></span></p><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">localabstract:<path></span></p><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">localfilesystem:<path></span></p></td><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">嘗試連接設備上的特定路徑。</span></p></td></tr><tr><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">log:<name></span></p></td><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">打開設備上的特定日志文件,以便讀取日志</span></p></td></tr><tr><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">framebuffer:</span></p></td><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">嘗試獲取framebuffer的快照。即涉筆的屏幕快照</span></p></td></tr><tr><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">dns:<server-name></span></p></td><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">由serer執行來解析特定設備名</span></p></td></tr><tr><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">recover:<size></span></p></td><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">更新設備的恢復鏡像</span></p></td></tr><tr><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">jdwp:<pid></span></p></td><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">連接特定VM進程上面的JDWP線程</span></p></td></tr><tr><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">track-jdwp</span></p></td><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">?</span></p></td></tr><tr><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">sync:</span></p></td><td width="284" valign="top" style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; border:1px solid silver; border-collapse:collapse; padding:3px"><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">同步設備和主機上的文件</span></p></td></tr></tbody></table>
(注:以上兩表整理來自網友 arm-linux:http://www.cnblogs.com/armlinux/archive/2011/02/16/2396845.html)
## 2 Protocol details:
2 協議細節
### 2.1 Client <-> Server protocol:
2.1 客戶端<--->服務器端
*This details the protocol used between ADB clients and the ADB?server itself. The ADB server listens on TCP:localhost:5037.*
以下細節描述的是主機pc中adb客戶端和adb服務器端通信用到的協議。adb服務器端會監聽TCP:localhost:5037
*A client sends a request using the following format:*
客戶端使用以下的協議格式發送請求:
- *1. A 4-byte hexadecimal string giving the length of the payload*
- 1. 前面是一個4字節的十六進制用來指定請求命令的長度
- *2. Followed by the payload itself.*
- 2. 緊跟著請求命令自身的內容
*For example, to query the ADB server for its internal version number,?the client will do the following:*
比如,為了得到adb服務器的內部版本號,客戶端會做以下動作:
- *1. Connect to tcp:localhost:5037*
- 1. 連接到 tcp:localhost:5037
- *2. Send the string "000Chost:version" to the corresponding socket*
- 2. 發送字串"000Chost:version"到對應套接字(譯者注:十六進制000C就是十進制12,"host:version"剛好12個字節)
*The 'host:' prefix is used to indicate that the request is addressed?to the server itself (we will talk about other kinds of requests later).?The content length is encoded in ASCII for easier debugging.*
'host'這個前綴是用來指定這個請求是發送給服務器自身的(我們晚點會談下其他的請求類型),為了方便調試,請求內容長度是用ASCII編碼的。
*The server should answer a request with one of the following:*
服務器端將會用以下的一種方式進行應答:
- *1. For success, the 4-byte "OKAY" string*
- 1. 成功:應答一個4字節的"OKAY"字串
- *2. For failure, the 4-byte "FAIL" string, followed by a 4-byte hex length, followed by a string giving the reason for failure.*
- 2.失敗:應答一個4字節的"FAIL"字串,緊跟著一個4字節十六進制描述錯誤描述內容長度,然后是描述錯誤的內容字串。
- *3. As a special exception, for 'host:version', a 4-byte hex string corresponding to the server's internal version number*
- 3. 例外:'host:version'的返回將會是一個4字節字串代表著服務器的內部版本號。
*Note that the connection is still alive after an OKAY, which allows the?client to make other requests. But in certain cases, an OKAY will even?change the state of the connection.*
注意客戶端和服務器端的連接在接收到OKAY的應答后將會繼續保持,以便客戶端繼續其他請求。但在一些特定的情況下,OKAY應答會改變連接的狀態。
*For example, the case of the 'host:transport:<serialnumber>' request,?where '<serialnumber>' is used to identify a given device/emulator; after?the "OKAY" answer, all further requests made by the client will go?directly to the corresponding adbd daemon.*
比如,以命令'host:transport:<serialnumber>‘請求為例(其中 '<serialnumber>'用來指定一個指定的設備/模擬器),收到'OKAY'應答后,客戶端往后的所有請求都將會直接發送到對應的設備/模擬器的adbd守護進程。
*The file SERVICES.TXT lists all services currently implemented by ADB.*
文件SERVICES.TXT列出了adb當前已經實現的所有服務(譯者注:大家請自行google)。
### *2.2. Transports:*
*An ADB transport models a connection between the ADB server and one device?or emulator. There are currently two kinds of transports:*
adb傳輸指的是adb服務器和一個設備/模擬器之間的連接模型。當前有以下兩種傳輸模型:
- *USB transports, for physical devices through USB*
- USB傳輸:真實機器通過usb連接的情況下
- *Local transports, for emulators running on the host, connected to?the server through TCP*
- 本地傳輸:本機上的模擬器通過tcp連接到adb服務器的情況下
*In theory, it should be possible to write a local transport that proxies?a connection between an ADB server and a device/emulator connected to/?running on another machine. This hasn't been done yet though.*
理論上說,我們可以編寫一個本地運行的傳輸代理來處理adb服務器和連接/運行在其他主機pc上的設備/模擬器的連接,但這個還沒有實現。
*Each transport can carry one or more multiplexed streams between clients?and the device/emulator they point to. The ADB server must handle?unexpected transport disconnections (e.g. when a device is physically?unplugged) properly.*
每一種傳輸方式都可以承載多路客戶端和其指定的設備/模擬器之間的數據流傳輸。adb服務器必須合理的處理傳輸斷開等異常(比如:當一個設備從pc主機上拔掉的情況)
<table cellspacing="0" cellpadding="0" width="539" class=" " style="margin:0px 0px 10px; padding:0px; border-collapse:collapse; width:668px; max-width:100%; word-wrap:break-word!important"><tbody style="margin:0px; padding:0px; max-width:100%; word-wrap:break-word!important"><tr style="margin:0px; padding:0px; max-width:100%; word-wrap:break-word!important"><td valign="top" width="112" height="39" style="border-style:solid; border-color:rgb(0,0,0); margin:0px; padding:4px; word-break:break-all; max-width:100%; word-wrap:break-word!important">?</td></tr><tr style="margin:0px; padding:0px; max-width:100%; word-wrap:break-word!important"><td valign="top" width="111" height="13" style="border-style:solid; border-color:rgb(0,0,0); margin:0px; padding:4px; word-break:break-all; max-width:100%; word-wrap:break-word!important; background-color:rgb(190,192,191)"><p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; max-width:100%; clear:both; min-height:1em; white-space:pre-wrap; word-wrap:break-word!important"><span style="margin:0px; padding:0px; max-width:100%; word-wrap:break-word!important">作者</span></p></td><td valign="top" width="112" height="13" style="border-style:solid; border-color:rgb(0,0,0); margin:0px; padding:4px; word-break:break-all; max-width:100%; word-wrap:break-word!important; background-color:rgb(190,192,191)"><p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; max-width:100%; clear:both; min-height:1em; white-space:pre-wrap; word-wrap:break-word!important"><span style="margin:0px; padding:0px; max-width:100%; word-wrap:break-word!important">自主博客</span></p></td><td valign="top" width="111" height="13" style="border-style:solid; border-color:rgb(0,0,0); margin:0px; padding:4px; word-break:break-all; max-width:100%; word-wrap:break-word!important; background-color:rgb(190,192,191)"><p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; max-width:100%; clear:both; min-height:1em; white-space:pre-wrap; word-wrap:break-word!important"><span style="margin:0px; padding:0px; max-width:100%; word-wrap:break-word!important">微信</span></p></td><td valign="top" width="112" height="13" style="border-style:solid; border-color:rgb(0,0,0); margin:0px; padding:4px; word-break:break-all; max-width:100%; word-wrap:break-word!important; background-color:rgb(190,192,191)"><p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; max-width:100%; clear:both; min-height:1em; white-space:pre-wrap; word-wrap:break-word!important"><span style="margin:0px; padding:0px; max-width:100%; font-family:Helvetica; letter-spacing:0px; word-wrap:break-word!important">CSDN</span></p></td></tr><tr style="margin:0px; padding:0px; max-width:100%; word-wrap:break-word!important"><td valign="top" width="111" height="39" style="border-style:solid; border-color:rgb(0,0,0); margin:0px; padding:4px; word-break:break-all; max-width:100%; word-wrap:break-word!important; background-color:rgb(227,228,228)"><p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; max-width:100%; clear:both; min-height:1em; white-space:pre-wrap; word-wrap:break-word!important"><span style="margin:0px; padding:0px; max-width:100%; word-wrap:break-word!important">天地會珠海分舵</span></p></td><td valign="top" width="112" height="39" style="border-style:solid; border-color:rgb(0,0,0); margin:0px; padding:4px; word-break:break-all; max-width:100%; word-wrap:break-word!important"><p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; max-width:100%; clear:both; min-height:1em; white-space:pre-wrap; word-wrap:break-word!important"><span style="margin:0px; padding:0px; max-width:100%; font-size:11px; font-family:Helvetica; letter-spacing:0px; word-wrap:break-word!important"><a target="_blank" href="http://techgogogo.com/">http://techgogogo.com</a></span><span style="margin:0px; padding:0px; max-width:100%; font-family:Helvetica; font-size:11px; letter-spacing:0px; word-wrap:break-word!important"/></p><p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; max-width:100%; clear:both; min-height:14px; white-space:pre-wrap; font-family:Helvetica; word-wrap:break-word!important"><br style="margin:0px; padding:0px; max-width:100%; word-wrap:break-word!important"/></p></td><td valign="top" width="111" height="39" style="border-style:solid; border-color:rgb(0,0,0); margin:0px; padding:4px; word-break:break-all; max-width:100%; word-wrap:break-word!important"><p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; max-width:100%; clear:both; min-height:1em; white-space:pre-wrap; word-wrap:break-word!important"><span style="margin:0px; padding:0px; max-width:100%; word-wrap:break-word!important">服務號</span><span style="margin:0px; padding:0px; max-width:100%; font-size:10px; font-family:Helvetica; letter-spacing:0px; word-wrap:break-word!important">:TechGoGoGo</span></p><p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; max-width:100%; clear:both; min-height:1em; white-space:pre-wrap; word-wrap:break-word!important"><span style="margin:0px; padding:0px; max-width:100%; word-wrap:break-word!important">掃描碼</span><span style="margin:0px; padding:0px; max-width:100%; font-size:10px; font-family:Helvetica; letter-spacing:0px; word-wrap:break-word!important">:</span></p><p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; max-width:100%; clear:both; min-height:14px; white-space:pre-wrap; font-family:Helvetica; word-wrap:break-word!important"><img src="image/47cf4f9ec59b0ef1f807a6c33ab5ce5f.jpg" alt="" style="max-width:100%; margin:0px; padding:0px; height:auto!important; word-wrap:break-word!important; width:auto!important; visibility:visible!important"/></p></td><td valign="top" width="112" height="39" style="border-style:solid; border-color:rgb(0,0,0); margin:0px; padding:4px; word-break:break-all; max-width:100%; word-wrap:break-word!important"><p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; max-width:100%; clear:both; min-height:1em; white-space:pre-wrap; color:rgb(62,62,62); font-family:'Helvetica Neue',Helvetica,'Hiragino Sans GB','Microsoft YaHei',?¢èí??oú,Arial,sans-serif; font-size:18px; line-height:28.7999992370605px; word-wrap:break-word!important"><span style="margin:0px; padding:0px; max-width:100%; color:rgb(0,0,0); font-size:11px; font-family:Helvetica; letter-spacing:0px; word-wrap:break-word!important"><a target="_blank" href="http://blog.csdn.net/zhubaitian">http://blog.csdn.net/zhubaitian</a></span><span style="margin:0px; padding:0px; max-width:100%; color:rgb(0,0,0); font-family:Helvetica; font-size:11px; letter-spacing:0px; line-height:28.7999992370605px; word-wrap:break-word!important"/></p><div><span style="margin:0px; padding:0px; max-width:100%; color:rgb(0,0,0); font-family:Helvetica; font-size:11px; letter-spacing:0px; line-height:28.7999992370605px; word-wrap:break-word!important"><br/></span></div></td></tr></tbody></table>
- 前言
- MonkeyRunner創建一個Note的實例
- MonkeyRunner在Windows下的Eclipse開發環境搭建步驟(兼解決網上Jython配置出錯的問題)
- MonkenRunner通過HierarchyViewer定位控件的方法和建議(Appium/UIAutomator/Robotium姊妹篇)
- MonkeyDevcie API 實踐全記錄
- MonkeyImage API 實踐全記錄
- EasyMonkeyDevice vs MonkeyDevice&amp;HierarchyViewer API Mapping Matrix
- adb概覽及協議參考
- MonkeyRunner源碼分析之-誰動了我的截圖?
- MonkeyRunner源碼分析之與Android設備通訊方式
- MonkeyRunner源碼分析之啟動
- Monkey源碼分析之運行流程
- Monkey源碼分析之事件源
- Monkey源碼分析番外篇之WindowManager注入事件如何跳出進程間安全限制
- Monkey源碼分析番外篇之Android注入事件的三種方法比較
- Monkey源碼分析之事件注入
- monkey源碼分析之事件注入方法變化
- MonkeyRunner源碼分析之工作原理圖
- Android自動化測試框架新書:&lt;&lt;MonnkeyRunner實現原理剖析&gt;&gt;交流