[ADB]ADB(Android Debug Bridge)简介及基础(不包含命令)
"Android Debug Bridge (adb) is a versatile command line tool that lets you communicate with an emulator instance or connected Android-powered device."
ADB作为一个多功能命令行工具,为你与模拟器或者连接到电脑的安卓设备的通讯提供了可能。
"It is a client-server program that includes three components:
- A client, which runs on your development machine. You can invoke a client from a shell by issuing an adb command. Other Android tools such as the ADT plugin and DDMS also create adb clients.
- A server, which runs as a background process on your development machine. The server manages communication between the client and the adb daemon running on an emulator or device.
- A daemon, which runs as a background process on each emulator or device instance.
You can find the
adb
tool in<sdk>/platform-tools/
."
ADB是一个CS架构的程序,它包含三个部件:
- 客户端,运行在你的开发机器上。通过发送adb命令,你可以从shell引用一个客户端。其他诸如ADT插件、DDMS也都会创建adb客户端
- 服务器,该进程运行在开发机器的后台。服务器对客户端和adb后台驻留程序(adb daemon,在模拟器或设备上运行)之间的通讯进行管理
- daemon,在每个模拟器或设备实例后台运行的进程
adb 工具可以在<sdk>/platform-tools/中找到
"When you start an adb client, the client first checks whether there is an adb server process already running. If there isn‘t, it starts the server process. When the server starts, it binds to local TCP port 5037 and listens for commands sent from adb clients—all adb clients use port 5037 to communicate with the adb server.
The server then sets up connections to all running emulator/device instances. It locates emulator/device instances by scanning odd-numbered ports in the range 5555 to 5585, the range used by emulators/devices. Where the server finds an adb daemon, it sets up a connection to that port. Note that each emulator/device instance acquires a pair of sequential ports — an even-numbered port for console connections and an odd-numbered port for adb connections. For example:
Emulator 1, console: 5554
Emulator 1, adb: 5555
Emulator 2, console: 5556
Emulator 2, adb: 5557
and so on...As shown, the emulator instance connected to adb on port 5555 is the same as the instance whose console listens on port 5554.
Once the server has set up connections to all emulator instances, you can use adb commands to access those instances. Because the server manages connections to emulator/device instances and handles commands from multiple adb clients, you can control any emulator/device instance from any client (or from a script).
Note: When you connect a device running Android 4.2.2 or higher to your computer, the system shows a dialog asking whether to accept an RSA key that allows debugging through this computer. This security mechanism protects user devices because it ensures that USB debugging and other adb commands cannot be executed unless you‘re able to unlock the device and acknowledge the dialog. This requires that you have adb version 1.0.31 (available with SDK Platform-tools r16.0.1 and higher) in order to debug on a device running Android 4.2.2 or higher."
启动adb客户端后,客户端首先检查adb服务器是否在运行。如果没有,它会启动服务器进程。服务器启动后,其将会绑定本地TCP的5037端口,来监听来自adb客户端的命令。所有的adb客户端都使用5037端口来与adb服务器通信。
然后,服务器与所有正在运行的emulator/device实例建立连接。服务器通过扫描从5555到5585的奇数端口号来定位emulator/device(因此每台机器最多同时连接16台设备)。当服务器找到adb后台驻留程序的端口后,其通过那个端口进行连接。每个emulator/device实例都需要一对连续的端口号——一个控制台连接的偶数端口,和一个adb连接的奇数端口。例如:
模拟器1,控制台:5554
模拟器1,adb:5555
模拟器2,控制台:5556
模拟器2,adb:5557
……
如上所示,通过5555连接到adb的模拟器实例和监听5554端口控制台连接的实例是相同的。
一旦服务器与所有的模拟器实例建立了连接,你就能通过adb命令来访问哪些实例。因为服务器对所有连接到它的实例进行管理而且处理多个adb客户端发送来的命令,所以你可以通过任意的客户端或者脚本来操控任意一个emulator/device实例。
注意:当你连接到电脑的设备Android版本是或者高于4.2.2时,系统会询问是否允许在这台电脑上调试程序,具体是RSA key。增加了些安全性。
p.s.以上内容引用部分来自Google Android
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。