【Android7.1.2源码解析系列】Android ADB概览 ---system/core/adb/OVERVIEW.txt

2023-05-16

ADB实施笔记


I. 总体概览:


安卓调试桥(ADB)被用来:


- 保持一条指向于所有安卓设备以及连接向或者运行于所给的开发主机的仿真机。


- 实现多个适用于客户端(命令行用户或者像DDMS那样的帮助程序)的控制命令(比如说"adb shell"、"adb pull"等等)。这些命令在ADB当中被称作"服务"。


总的来说,所有的东西都运行在下面的组件当中:


  1、ADB服务端

这是一个运行在主机上的后台进程。它的目的是通过USB端口感知设备连接和移除的时间,同样也包括仿真机的开始与关闭。


因此它保持了一个"已连接设备"的列表并为它们分别分配了一个"状态":离线(OFFLINE)、开机加载状态(BOOTLOADER)、恢复状态(RECOVERY)或者在线(ONLINE)。(更多的在下面)。


ADB服务端是一个很巨大的循环系统,目的在于处理客户端、服务端以及设备之间的数据(包)交换。


  2、ADB守护进程(adbd)


"adbd"程序作为一个后台进程运行在一个安卓设备或者模拟器上。它的作用是连接上ADB服务器(真机通过USB连接,仿真机通过TCP连接)并且为运行在主机上的客户端提供一些服务。


ADB服务端在一台设备成功地连接上它的adbd程序的时候认为它是在线(ONLINE)状态。否则,设备为离线(OFFLINE),这意味着ADB服务端检测到了一个新的设备或仿真机,但是不能连接到adbd守护进程。


开机加载状态(BOOTLOADER)和恢复状态(RECOVERY)对应着系统的bootloader模式和recovery模式。---刷机时候的一些模式,通常长按音量下+关机键可以跳转。


  3、ADB命令行客户端


"adb"命令行程序被用来在壳程序(控制台、shell)或者脚本上运行adb命令。它最开始会尝试定位主机上的ADB服务端,如果没有找到则会自动开启一个。


然后,客户端发送它的服务请求到ADB服务端。它不需要知道。


现在,一个简单的"adb"二进制程序被同时用于服务端和客户端。这使得分配和打开服务更加的简单。


  4、服务


一个客户端可以和两种必要的服务进行交流:


主机服务:
 这些服务运行在ADB服务端,因此它们完全不需要和一台设备交流。一个典型的例子就是"adb devices"命令,这个命令的作用是返回当前已知设备以及它们的状态的列表。它们是一些其他的服务。


本地服务:
 这些服务运行在adbd守护进程上或者在设备上被它打开。ADB服务端被用来梳理客户端和运行在adbd的服务。此时它的作用是初始化连接,然后作为数据传输的通道。


II.协议细节:
  
  1、客户端<->服务端协议:

此处描述了ADB客户端以及ADB服务端进行通讯的协议细节。ADB服务端接收端口为TCP:localhost:5037。


客户端通过如下的格式发送请求:


1、一个四字节的十六位字符串描述内容长度
2、接下来是内容


比如说,想要查询ADB服务端的内部版本号,客户端会像下面这么做:


1、连接到tcp:localhost:5037
2、发送字符串"000Chost:version"到适合的接口


主机端:前缀被用来确认这个请求已经被指向了服务端本身(我们会在接下来讨论其他种类的请求)。为了调试方便,内容的长度通过ACSLL编码。


服务端应该通过以下的其中一种回应请求:


1、成功,返回四字节的字符串"OKAY"


2、失败,首先是一个四字节的字符串"FAIL",然后是一个四字节的十六位数字(描述长度),然后是失败的原因


3、作为一个特殊的异常,对于"host:version",一个四字节的十六位字符串,对应着服务端的内部版本号


记住在"OKAY"回复之后连接依然是活动的,这允许客户端发送其他请求。但是在明确的条件下,一个"OKAY"回复甚至会改变连接的状态。


比如说,"host:transport:<serialnumber>"请求,"<serialnumber>"被用来指明一个给定的设备或仿真机;在"OKAY"返回之后,之后所有的由客户端产生的请求都回直接发送到对应的adbd守护进程。


文件SERVICES.TXT列举了所有当前被ADB实现的服务。


  2、传输:


一个ADB传输构成了一个ADB服务端到一个设备或者仿真机的连接。现在有两种类型的传输:


- USB传输,通过USB连接物理设备


- 本地传输,为了主机上运行的仿真机,通过TCP连接到服务端


理论上,应该可以写一个本地的传输来同时代理从ADB服务端或仿真机到另一台机器上的连接。不过现在这个还没有做。


每一个传输都可以携带一个或者更多的介于客户端和设备或者仿真机的流。ADB服务端必须正确地处理未预期的传输断线(比如说,当一个设备被物理性的拔出的时候)。





原文:


Implementation notes regarding ADB.


I. General Overview:


The Android Debug Bridge (ADB) is used to:


- keep track of all Android devices and emulators instances
  connected to or running on a given host developer machine


- 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.


As a whole, everything works through the following components:


  1. The ADB server


    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.


    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).


    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.




  2. The ADB daemon (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.


    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.


    the BOOTLOADER and RECOVERY states correspond to alternate states of
    devices when they are in the bootloader or recovery mode.


  3. The ADB command-line client


    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.


    then, the client sends its service requests to the ADB server. It doesn't
    need to know..


    Currently, a single 'adb' binary is used for both the server and client.
    this makes distribution and starting the server easier.




  4. Services


    There are essentially two kinds of services that a client can talk to.


    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.


    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.




II. Protocol details:


  1. Client <-> Server protocol:


    This details the protocol used between ADB clients and the ADB
    server itself. The ADB server listens on TCP:localhost:5037.


    A client sends a request using the following format:


        1. A 4-byte hexadecimal string giving the length of the payload
        2. Followed by the payload itself.


    For example, to query the ADB server for its internal version number,
    the client will do the following:


        1. Connect to tcp:localhost:5037
        2. Send the string "000Chost:version" to the corresponding socket


    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.


    The server should answer a request with one of the following:


        1. For success, the 4-byte "OKAY" string


        2. For failure, the 4-byte "FAIL" string, followed by a
           4-byte hex length, followed by a string giving the reason
           for failure.


        3. As a special exception, for 'host:version', a 4-byte
           hex string corresponding to the server's internal version number


    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. 


    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.


    The file SERVICES.TXT lists all services currently implemented by ADB.




  2. Transports:


    An ADB transport models a connection between the ADB server and one device
    or emulator. There are currently two kinds of transports:


       - USB transports, for physical devices through USB


       - Local transports, for emulators running on the host, connected to
         the server through TCP


    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.


    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.



  
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

【Android7.1.2源码解析系列】Android ADB概览 ---system/core/adb/OVERVIEW.txt 的相关文章

  • Kapt 未在即时应用程序功能模块中生成类

    我在我的 Android 应用程序中使用 dagger2 即使没有错误 它也不会生成匕首组件类 我已经在设置中启用了注释处理器并重新启动了我的 android studio 但这对我来说不起作用 我也读过这个帖子Dagger2 不生成 Da
  • startActivity overridePendingTransition 只显示进入动画

    基本上 我遇到的问题是只显示输入幻灯片动画 调用 Activity 不会产生动画 startActivity intent overridePendingTransition R anim right in partly R anim le
  • 如何从一个活动中完成一系列开放的子活动?

    我正在尝试为我的应用程序制作一个退出按钮 无论如何 我能够跟踪我的应用程序中的所有活动实例 然后完成它们 但在某些情况下 仍有一些活动仍然存在 不知道怎么办 有没有什么方法可以杀死android中的特定应用程序 或者我可以通过任何其他方式退
  • 编译后从字节代码中删除注释

    我们正在使用一个包含使用 JAXB 注释进行注释的 bean 的库 我们使用这些类的方式完全不依赖于 JAXB 换句话说 我们不需要 JAXB 也不依赖注释 但是 由于注释存在 它们最终会被处理注释的其他类引用 这要求我将 JAXB 捆绑到
  • 如何将 Android Instrumentation 测试推送到模拟器/设备?

    我正在尝试使用 Ubuntu 9 04 中的命令行 shell 在 Android 模拟器上运行 Webkit 布局测试 adb s emulator 5554 shell am instrument w com android dumpr
  • FLAG_ACTIVITY_REORDER_TO_FRONT 被忽略

    我有一个包含项目列表的 FragmentActivity 当应用程序处于后台时 可以推送该项目列表 发生这种情况时 我想创建一个状态栏通知并提醒用户更新 当用户单击通知时 活动应重新排序到前面并显示在屏幕上 同时在列表底部显示新项目 所以我
  • Android 中有没有办法获取 SD 卡大小?

    欢迎大家 我已经在 Stackoverflow 和 google 上尝试过与此相关的每个问题 但没有一个有效 我已经尝试过类似下一个链接的操作 但它返回的内容与内部存储相同 如何获取外部存储 SD 卡的大小 带安装的 SD 卡 https
  • 多语言 Android 应用程序:在电子邮件和密码字段中显示英文键盘

    我们正在开发一款多语言 Android 应用程序 针对英语和阿拉伯语 面临的问题是在登录和注册屏幕中 我们希望仅以英文文本输入用户名和密码字段 从而显示英文键盘 无论设备区域设置语言如何 已尝试在 edittext 中设置 inputtyp
  • 在 Android 中始终以横向模式打开相机

    在我的 Android 应用程序中 单击按钮后我希望相机以横向模式打开 即使我将手机旋转为纵向模式 相机也应始终处于横向模式或纵向模式 使用此代码在横向模式下打开相机 Intent cameraIntent new Intent Media
  • 无法在云控制台中启用 Maps SDK for Android

    我在云控制台中启用适用于 Android 的 Maps SDK 时遇到此问题 https console cloud google com https console cloud google com 它会抛出以下错误 附截图 我收到错误消
  • 更改 Android 中的媒体音量?

    我可以更改媒体音量吗 如何 到目前为止我用过这个 setVolumeControlStream AudioManager STREAM MUSIC 但有一个搜索栏并且想要更改媒体音量 而不是铃声音量 那么有人可以告诉我如何更改媒体音量onC
  • 使用 UPI url 调用 PSP 应用程序

    我正在尝试创建一个商家应用程序 它将根据 NPCI 的指南生成一个 url 此 url 将作为意图共享 并且 PSP 应用程序 任何注册的银行应用程序 应该能够侦听该 url 并被调用 我已经形成了这样的网址 upi pay pa icic
  • 有没有办法在多个嵌套的 RecyclerView 之间共享同一个 LayoutManager

    我正在开发一个显示游戏列表的应用程序 在每个游戏的 itemView 内 我还有一个要显示的视频列表 预览和结构如下 我部署了一个RecyclerView作为窗口根视图 然后对于视频 我使用网格样式的RecyclerView来显示 所以这里
  • 无法登录 Google Play 游戏服务

    我在开发者控制台上使用包名称和正确的签名证书设置了我的游戏 并为其创建了排行榜 但没有创建任何成就 然后 我从以下位置下载了示例 Type A Number Challenge 和 BaseGameUtils https developer
  • 在片段之间切换时底部导航栏会向下推

    在我的活动中 我有一个底部导航栏和框架布局来显示片段 一切正常 但问题是当我开始按顺序从 1 4 移动时 底部导航栏保持在其位置 但当我突然从 4 跳到2 然后底部导航栏就会超出屏幕 当再次单击同一项目时 它就会回到正常位置 该视频将清楚地
  • 如何从灰度字节缓冲区图像创建位图?

    我正在尝试使用新的 Android 人脸检测移动视觉 API 来处理帧图像 所以我创建了自定义检测器来获取帧并尝试调用 getBitmap 方法 但它为空 所以我访问了帧的灰度数据 有没有办法从它或类似的图像持有者类创建位图 public
  • 在android中使用BaseActivity的不同活动中的通用标头

    我想编写一次代码并在不同的活动中使用 我创建了一个Base Activity class为了那个原因 此外 不同活动中所有布局的标题都是相同的 我在以下人员的帮助下做到了这一点
  • Android Jasper 报告

    Jasper Reporting 可以集成到 Android 应用程序中吗 我正在尝试从 jrxml 文件生成 PDF CSV 文本和 XLS 报告 但是 我没有看到 Android SDK 支持 net sf jasperreports
  • 如何检查设备上是否安装了文本转语音 (TTS) 的特定语言数据?

    我正在创建一个使用文本转语音的应用程序 我希望用户能够离线使用它 因此我检查设备上是否安装了 TTS 数据 以下是执行此操作的代码 Check tts data is installed Intent checkTTSIntent new
  • Android Espresso - 如果未选中,请单击复选框

    I have onView withId R id check box perform click 但我只想在尚未选中该复选框时执行此操作 我怎样才能在浓缩咖啡中做到这一点 我还想根据其之前的状态来切换复选框 开关 起初 我尝试用此方法打开

随机推荐

  • 连接服务器VNC

    1 xff0c 启动vnc vncserver 2 xff0c 提示输入密码 3 xff0c Would you like to enter a view only password y n 选择n 4 xff0c 会生成一个端口号 5 更
  • Android基础知识(七):Activity互调之间的生命周期变化与onNewIntent()触发机制

    Android基础知识 xff08 七 xff09 xff1a Activity互调之间的生命周期变化与onNewIntent 触发机制 一 Activity切换的生命周期 前面Android基础知识 xff08 五 xff09 xff1a
  • 二叉树节点和度的关系及特点

    写在前边的话 xff1a 你的支持是我写作的动力 xff0c 有帮助到你的话麻烦点赞 加收藏 呦 感激不尽 xff01 如有错误也请留言指正 目录 一 完全二叉树 节点总数的特点 二 二叉树 度的特点 1 n0与n2的关系 2 节点总数和度
  • 平衡二叉树的最大深度和最少节点数

    写在前边的话 xff1a 你的支持是我写作的动力 xff0c 有帮助到你的话麻烦点赞加收藏呦 感激不尽 xff01 如有错误也请留言指正 考研数据结构练习 xff0c 欢迎订阅我的专辑 考研数据结构题型分类讲解练习 目录 一 知识点 二 例
  • dataturks解析

    34 34 34 根据大json写小json 34 34 34 with open 39 pay json 39 as f datas 61 f readlines for data in datas data 61 data strip
  • STM32串口之环形队列接收数据

    原文链接 xff1a STM32串口之环形队列接收数据 码代码的应该学数据结构都学过队列 环形队列是队列的一种特殊形式 xff0c 应用挺广泛的 因为有太多文章关于这方面的内容 xff0c 理论知识可以看别人的 xff0c 下面写得挺好的
  • Linux使用ssh远程登陆

    什么是SSH xff1f 简单说 xff0c SSH是一种网络协议 xff0c 用于计算机之间的加密登录 如果一个用户从本地计算机 xff0c 使用SSH协议登录另一台远程计算机 xff0c 我们就可以认为 xff0c 这种登录是安全的 x
  • 使用Vscode 编译 开发 调试 STM32单片机 VScode+openocd+STM32CubeMX+GDB

    Vscode 编译 开发 调试 STM32单片机 为什么记录这篇文章环境准备软件及工具下载软件安装 VScode功能搭建使用STM32CubeMX生成带有makefile的工程配置VScode工程 使用vscode 开发 xff0c 编译
  • 出错信息“module or group tools is not avaliable”

    出错信息 module or group tools is not avaliable 使用yum安装软件时 xff0c 有时会出现这个问题 xff0c 可能是需要安装的软件来自第三方 解决办法 yum install epel relea
  • ubuntu 自动登录/图形界面启动流程

    ubuntu 自动登录 图形界面启动流程 启动流程配置greeter和desktop自动登录配置自动登录后进入的desktop总结 这两天在Jetson nano 上想做一个跳过用户界面直接自动登录到桌面的功能 本来很简单的在System
  • Ubuntu update-alternatives 安装/管理多版本 Python3及PIP3

    Ubuntu update alternatives 安装 管理多版本 Python3及PIP3 前言安装python安装对应版本pipupdate alternatives 切换python3 环境 前言 在ubuntu系统上 xff0c
  • 实用的Visual Studio Code插件

    1 vscode color highlight 颜色代码高亮插件 xff08 sublime text也有 xff09 2 vscode Open in Browser 右键在浏览器打开 xff08 sublime text也有 xff0
  • LWIP 双IP实现

    LwIP是Light Weight 轻型 IP协议 xff0c 有无操作系统的支持都可以运行 LwIP实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用 xff0c 它只需十几KB的RAM和40K左右的ROM就可以运行 xff
  • Seata解析-seata部署启动初体验

    本文基于seata 1 3 0版本 seata是由阿里巴巴开源的分布式事务框架 xff0c 用于在分布式环境中保持事务一致性 它提供了四种事务模式 xff1a AT TCC SAGA 和 XA 事务模式 xff0c 默认是AT模式 Seat
  • 功能案例----java实现语音播报功能

    功能案例 java实现语音播报功能 根据自己最近的写的项目 xff0c 总结整理了关于java语音播报功能的方法 xff0c 可分为两种形式 一种是通过自己写出一个语音播报方法的工具类 xff0c 然后从前端获取文本数据 xff0c 最后跳
  • spring mvc拦截器 需求:在controller层的方法上,使用自定义注解的方式 不拦截指定请求

    原来是在controller类上实现此需求 缺点 xff1a 只能是整个controller类下的方法全部放开拦截 xff0c 不能放开其中某个方法 xff0c 颗粒度太高 现实现在方法上增加注解 xff0c 更加细颗粒度 1 首先是自定义
  • 生产者消费者代码实现(JAVA)

    代码 import lombok extern slf4j Slf4j import java util LinkedList final class Message 单条消息 private int id private String m
  • 手误删除服务器tomcat下的bin目录,./start.sh无效

    关于LINUX权限 bash startup sh Permission denied 在执行 startup sh 或者 shutdown sh的时候 xff0c 爆出了Permission denied xff0c 其实很简单 xff0
  • C++ 进程间通信

    一 xff0c C 43 43 常用进程间通信 管道 Pipe xff1a 管道可用于具有亲缘关系进程间的通信 xff0c 允许一个进程和另一个与它有共同祖先的进程之间进行通信 命名管道 named pipe xff1a 命名管道克服了管道
  • 【Android7.1.2源码解析系列】Android ADB概览 ---system/core/adb/OVERVIEW.txt

    ADB实施笔记 I 总体概览 xff1a 安卓调试桥 ADB 被用来 xff1a 保持一条指向于所有安卓设备以及连接向或者运行于所给的开发主机的仿真机 实现多个适用于客户端 命令行用户或者像DDMS那样的帮助程序 的控制命令 比如说 34