adb概览及协议参考

时间:2022-10-02 08:23:26

原文: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”。 当然还有一些其他的服务了。

命令 解释
host:version  
host:kill 停止server
host:devices  
host:track-devies  
host:emulator:<port>  
host:transport:<serial-number> 连接指定serial-number的设备或者模拟器
host:transport-usb 连接usb上的设备,如果usb上有不止一个设备,会失败。
host:transport-local 通过tcp方式连接模拟器,如果有多个模拟器在运行,会失败。
host:transport-any 连接usb设备或者模拟器都可以,但是如果有超过一个设备或模拟器,会失败。
host-serial:<serial-number>:<request>host-usb:<request>host-local:<request> 向指定的设备发送特定的请求。同样如果存在多个设备的冲突,会失败。
host:<request> 向当前连接的设备发送请求
<host-prefix>:get-serialno 获取设备的serial-number
<host-prefix>:get-state 获取设备状态
<host-prefix>:forward:<local>;<remote>  

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服务器扮演着初始化各种连接以及数据路信使的角色。

命令 解释
shell:command arg1 arg2 ... 在设备上执行命令行操作
shell: 参见commandline.c中的interactive_shell()
remount: 以读/写模式加载设备的文件系统
dev:<path> 为client打开设备上的特定路径,用于读写问题。有可能由于权限问题而失败。
tcp:<port> 尝试从设备连接本主机的某个tcp端口
tcp:<port>:<server-name> 尝试从设备连接特定主机名的某个tcp端口
local:<path> 尝试连接设备上的特定路径,路径是UNIX域名形式
localreserved:<path>localabstract:<path>localfilesystem:<path> 尝试连接设备上的特定路径。
log:<name> 打开设备上的特定日志文件,以便读取日志
framebuffer: 尝试获取framebuffer的快照。即涉笔的屏幕快照
dns:<server-name> 由serer执行来解析特定设备名
recover:<size> 更新设备的恢复镜像
jdwp:<pid> 连接特定VM进程上面的JDWP线程
track-jdwp  
sync: 同步设备和主机上的文件

(注:以上两表整理来自网友 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主机上拔掉的情况)

作者 自主博客 微信服务号及扫描码 CSDN
天地会珠海分舵 http://techgogogo.com 服务号:TechGoGoGo扫描码:adb概览及协议参考 http://blog.csdn.net/zhubaitian

adb概览及协议参考的更多相关文章

  1. adb概览及协议參考

    原文:https://github.com/android/platform_system_core/blob/master/adb/OVERVIEW.TXT) Implementation note ...

  2. dubbo协议参考手册(转)

    原文链接:http://wely.iteye.com/blog/2331332 协议参考手册 (+) (#) 推荐使用Dubbo协议 性能测试报告各协议的性能情况,请参见:性能测试报告 (+) dub ...

  3. Ymodem协议&lpar;参考STM32&rpar;

    相信很多人都希望,不开盖就可以对固件进行升级吧,就像手机那些.下文中的bootload就来实现这样的功能. 前段时间有项目关于Bootload设计.所以就仔细的去了研究了一翻.以前都是用的stm32官 ...

  4. Android KitCat 4&period;4&period;2 ADB 官方所支持的所有Services格式翻译

    在之前的文章中有转帖网上同行制作的ADB协议表格<<adb概览及协议参考>>,但不够详尽,所以这里自己另外基于Android 4.4.2的技术文档重新做一次翻译. HOST S ...

  5. 安卓MonkeyRunner源码分析之与Android设备通讯方式

    如前文<谁动了我的截图?--Monkeyrunner takeSnapshot方法源码跟踪分析>所述,本文主要会尝试描述android的自动化测试框架MonkeyRunner究竟是如何和目 ...

  6. MonkeyRunner源码分析之-谁动了我的截图&quest;

    本文章的目的是通过分析monkeyrunner是如何实现截屏来作为一个例子尝试投石问路为下一篇文章做准备,往下一篇文章本人有意分析下monkeyrunner究竟是如何和目标测试机器通信的,所以最好的办 ...

  7. MonkeyRunner源代码分析Android通信设备

    正如前面<谁动了我的截图?--Monkeyrunner takeSnapshot方法源代码跟踪分析>所述,本文主要会尝试描写叙述android的自己主动化測试框架MonkeyRunner到 ...

  8. 网络编程—网络基础概览、socket,TCP&sol;UDP协议

    网络基础概览 socket概览 socket模块—TCP/UDP的实现 TCP/UDP总结 网络基础概览 osi七层协议各层主要的协议 # 物理层传输电信号1010101010 # 数据链路层,以太网 ...

  9. 协议分析TMP

    最近闲来有事, 分析了一个非常低端(非常低端的意思是说你不应该对她是否能取代你现有的QQ客户端作任何可能的奢望,她只是一个实验性的东西)的手机QQ的协议, 是手机QQ3.0,      所用到的TCP ...

随机推荐

  1. Bigtable 论文 阅读笔记 - 原理部分

    不支持markdown,桑心.更好的阅读体验请看:Github/Bigtable.md Paper: Google Bigtable paper Notes author: Lhfcws Wu Tim ...

  2. Linux 吃掉我的内存

    在Windows下资源管理器查看内存使用的情况,如果使用率达到80%以上,再运行大程序就能感觉到系统不流畅了,因为在内存紧缺的情况下使用交换分区,频繁地从磁盘上换入换出页会极大地影响系统的性能.而当我 ...

  3. C&num;正则表达式编程(四):正则表达式

    正则表达式提供了功能强大.灵活而又高效的方法来处理文本.正则表达式的全面模式匹配表示法使您可以快速分析大量文本以找到特定的字符模式:提取.编辑.替换或删除文本子字符串:或将提取的字符串添加到集合以生成 ...

  4. margin&colon;-75px的理解及妙用——纯CSS制作水平&sol;垂直都居中短边为50px&sol;长边为150px的红色十字架

    有这么一个题目: 使用重构的方式制作出一个如下图的水平.垂直都居中短边为50px,长边为150px的红色十字架. 要求只使用2个div完成 答案: <!DOCTYPE html PUBLIC & ...

  5. log4j是什么

    一.什么是log4jLog4j 是Apache的一个开放源代码项目,通过使用Log4j,我们可以控制日志信息输送的目的地是控制台.文件.GUI组件.甚至是套接口服务器.NT的事 件记录器.UNIX S ...

  6. 将文件从数据库(MySQL)中进行读取

    package com.play; import java.io.FileOutputStream; import java.io.OutputStream; import java.sql.Blob ...

  7. 关于var&lpar;string&rpar;&plus;&plus;的类型自动转换

    展示时间: var miao="50"; var fen="59"; var shi="00"; setInterval(fun, 1000 ...

  8. Android Studio遇到Failed to sync Gradle project错误时的解决办法

    一   报错显示 Gradle sync failed: Unknown host 'd29vzk4ow07wi7.cloudfront.net'. You may need to adjust th ...

  9. Linux文件目录

    简介: Linux 内核最初由芬兰的 Linus Torvalds 开发,后来他组建了团队,Linux 内核由这个团队维护. GNU 组织开发了很多核心软件和基础库,例如 GCC 编译器.C语言标准库 ...

  10. npm版本安装问题

    问题一 描述 运行npm install之后,前端页面console控制台报错,invalid props. 排查 1. 排除了代码问题,完全一样的代码,其他人的运行无误. 2.猜想可能是版本号问题, ...