ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
原文: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:&lt;port&gt;</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:&lt;serial-number&gt;</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:&lt;serial-number&gt;:&lt;request&gt;</span></p><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">host-usb:&lt;request&gt;</span></p><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">host-local:&lt;request&gt;</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:&lt;request&gt;</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">&lt;host-prefix&gt;: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">&lt;host-prefix&gt;: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">&lt;host-prefix&gt;:forward:&lt;local&gt;;&lt;remote&gt;</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:&lt;path&gt;</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:&lt;port&gt;</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:&lt;port&gt;:&lt;server-name&gt;</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:&lt;path&gt;</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:&lt;path&gt;</span></p><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">localabstract:&lt;path&gt;</span></p><p style="margin:10px auto; font-size:13px; line-height:1.5"><span style="color:#3366ff">localfilesystem:&lt;path&gt;</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:&lt;name&gt;</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:&lt;server-name&gt;</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:&lt;size&gt;</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:&lt;pid&gt;</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',΢ÈíÑźÚ,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>