1
0
Fork 0
hmz007 6d24f2138b Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
..
apex Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
client Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
coverage Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
crypto Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
daemon Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
fastdeploy Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
fdevent Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
libs Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
pairing_auth Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
pairing_connection Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
proto Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
sysdeps Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
tls Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
tools Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
.clang-format Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
Android.bp Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
MODULE_LICENSE_APACHE2 Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
NOTICE Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
OVERVIEW.TXT Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
OWNERS Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
PREUPLOAD.cfg Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
README.md Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
SERVICES.TXT Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
SOCKET-ACTIVATION.txt Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
SYNC.TXT Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
TEST_MAPPING Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
adb.bash Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
adb.cpp Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
adb.h Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
adb_auth.h Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
adb_integration_test_adb.xml Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
adb_integration_test_device.xml Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
adb_io.cpp Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
adb_io.h Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
adb_io_test.cpp Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
adb_listeners.cpp Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
adb_listeners.h Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
adb_listeners_test.cpp Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
adb_mdns.cpp Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
adb_mdns.h Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
adb_test.xml Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
adb_trace.cpp Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
adb_trace.h Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
adb_unique_fd.cpp Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
adb_unique_fd.h Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
adb_utils.cpp Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
adb_utils.h Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
adb_utils_test.cpp Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
adb_wifi.h Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
benchmark_device.py Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
bugreport_test.cpp Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
compression_utils.h Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
file_sync_protocol.h Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
mdns_test.cpp Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
protocol.txt Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
security_log_tags.h Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
services.cpp Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
services.h Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
shell_protocol.h Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
shell_service_protocol.cpp Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
shell_service_protocol_test.cpp Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
socket.h Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
socket_spec.cpp Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
socket_spec.h Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
socket_spec_test.cpp Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
socket_test.cpp Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
sockets.cpp Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
sockets.dia Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
sysdeps.h Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
sysdeps_test.cpp Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
sysdeps_unix.cpp Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
sysdeps_win32.cpp Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
sysdeps_win32_test.cpp Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
test_adb.py Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
test_device.py Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
trace.sh Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
transfer_id.h Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
transport.cpp Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
transport.h Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
transport_benchmark.cpp Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
transport_fd.cpp Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
transport_test.cpp Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
types.cpp Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
types.h Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago
types_test.cpp Rockchip Anroid12_SDK 20220721-rkr10 (e1522e56) 3 years ago

README.md

ADB Internals

If you are new to adb source code, you should start by reading OVERVIEW.TXT which describes the three components of adb pipeline.

This document is here to boost what can be achieved within a "window of naive interest". You will not find function or class documentation here but rather the "big picture" which should allow you to build a mental map to help navigate the code.

Three components of adb pipeline

As outlined in the overview, this codebase generates three components (Client, Server (a.k.a Host), and Daemon (a.k.a adbd)). The central part is the Server which runs on the Host computer. On one side the Server exposes a "Smart Socket" to Clients such as adb or DDMLIB. On the other side, the Server continuously monitors for connecting Daemons (as USB devices or TCP emulator). Communication with a device is done with a Transport.

+----------+              +------------------------+
|   ADB    +----------+   |      ADB SERVER        |                   +----------+
|  CLIENT  |          |   |                        |              (USB)|   ADBD   |
+----------+          |   |                     Transport+-------------+ (DEVICE) |
                      |   |                        |                   +----------+
+-----------          |   |                        |
|   ADB    |          v   +                        |                   +----------+
|  CLIENT  +--------->SmartSocket                  |              (USB)|   ADBD   |
+----------+          ^   | (TCP/IP)            Transport+-------------+ (DEVICE) |
                      |   |                        |                   +----------+
+----------+          |   |                        |
|  DDMLIB  |          |   |                     Transport+--+          +----------+
|  CLIENT  +----------+   |                        |        |  (TCP/IP)|   ADBD   |
+----------+              +------------------------+        +----------|(EMULATOR)|
                                                                       +----------+

The Client and the Server are contained in the same executable and both run on the Host machine. Code sections specific to the Host is enclosed within ADB_HOST guard. adbd runs on the Android Device. Daemon specific code is enclosed in !ADB_HOST but also sometimes with-in __ANDROID__ guard.

"SMART SOCKET" and TRANSPORT

A smart socket is a simple TCP socket with a smart protocol built on top of it. This is what Clients connect onto from the Host side. The Client must always initiate communication via a human readable request but the response format varies. The smart protocol is documented in SERVICES.TXT.

On the other side, the Server communicate with a device via a Transport. adb initially targeted devices connecting over USB, which is restricted to a fixed number of data streams. Therefore, adb multiplexes multiple byte streams over a single pipe via Transport. When devices connecting over other mechanisms (e.g. emulators over TCP) were introduced, the existing transport protocol was maintained.

THREADING MODEL and FDEVENT system

At the heart of both the Server and Daemon is a main thread running an fdevent loop, which is an platform-independent abstraction over poll/epoll/WSAPoll monitoring file descriptors events. Requests and services are usually server from the main thread but some service requests result in new threads being spawned.

To allow for operations to run on the Main thread, fdevent features a RunQueue combined with an interrupt fd to force polling to return.

+------------+    +-------------------------^
|  RUNQUEUE  |    |                         |
+------------+    |  POLLING (Main thread)  |
| Function<> |    |                         |
+------------+    |                         |
| Function<> |    ^-^-------^-------^------^^
+------------+      |       |       |       |
|    ...     |      |       |       |       |
+------------+      |       |       |       |
|            |      |       |       |       |
|============|      |       |       |       |
|Interrupt fd+------+  +----+  +----+  +----+
+------------+         fd      Socket  Pipe

ASOCKET, APACKET, and AMESSAGE

The asocket, apacket, and amessage constructs exist only to wrap data while it transits on a Transport. An asocket handles a stream of apackets. An apacket consists in a amessage header featuring a command (A_SYNC, A_OPEN, A_CLSE, A_WRTE, A_OKAY, ...) followed by a payload (find more documentation in protocol.txt. There is no A_READ command because an asocket is unidirectional. To model a bi-directional stream, asocket have a peer which go in the opposite direction.

An asocket features a buffer where the elemental unit is an apacket. Is traffic is inbound, the buffer stores apacket until they are consumed. If the traffic is oubound, the buffer store apackets until they are sent down the wire (with A_WRTE commands).

+---------------------ASocket------------------------+
 |                                                   |
 | +----------------APacket Queue------------------+ |
 | |                                               | |
 | |            APacket     APacket     APacket    | |
 | |          +--------+  +--------+  +--------+   | |
 | |          |AMessage|  |AMessage|  |AMessage|   | |
 | |          +--------+  +--------+  +--------+   | |
 | |          |        |  |        |  |        |   | |
 | |  .....   |        |  |        |  |        |   | |
 | |          |  Data  |  |  Data  |  |  Data  |   | |
 | |          |        |  |        |  |        |   | |
 | |          |        |  |        |  |        |   | |
 | |          +--------+  +--------+  +--------+   | |
 | |                                               | |
 | +-----------------------------------------------+ |
 +---------------------------------------------------+

This system allows to multiplex data streams on an unique byte stream. Without entering too much into details, the amessage fields arg1 and arg2 are used alike in the TCP protocol where local and remote ports identify an unique stream. Note that unlike TCP which feature an "unacknowledged-send window", an apacket is sent only after the previous one has been confirmed to be received.

The two types of asocket (Remote and Local) differentiate between outbound and inbound traffic.

adbd <-> APPPLICATION communication

This pipeline is detailed in services.cpp. The JDWP extension implemented by Dalvik/ART are documented in:

  • platform/dalvik/+/master/docs/debugmon.html
  • platform/dalvik/+/master/docs/debugger.html