• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

apex/15-Dec-2024-178162

client/15-Dec-2024-16,80212,377

coverage/14-Jan-2024-192120

crypto/14-Jan-2024-697430

daemon/15-Dec-2024-6,7414,731

docs/user/14-Jan-2024-480312

fastdeploy/15-Dec-2024-2,3881,546

fdevent/15-Dec-2024-1,4891,036

libs/14-Jan-2024-1,113750

pairing_auth/14-Jan-2024-1,201732

pairing_connection/14-Jan-2024-2,2721,575

proto/15-Dec-2024-385319

sysdeps/15-Dec-2024-878465

test_device_apks/15-Dec-2024-194125

test_utils/14-Jan-2024-15982

tls/14-Jan-2024-1,6211,126

tools/14-Jan-2024-523399

.clang-formatD14-Jan-2024291 1413

Android.bpD15-Dec-202423.8 KiB1,041928

MODULE_LICENSE_APACHE2D14-Jan-20240

NOTICED14-Jan-202410.5 KiB192159

OVERVIEW.TXTD14-Jan-20245.2 KiB13690

OWNERSD15-Dec-2024149 64

PREUPLOAD.cfgD14-Jan-2024246 96

README.mdD15-Dec-20247.1 KiB10982

SERVICES.TXTD15-Dec-202411.2 KiB304232

SOCKET-ACTIVATION.txtD14-Jan-20241.4 KiB4337

SYNC.TXTD14-Jan-20243.5 KiB8163

TEST_MAPPINGD15-Dec-20241,003 6463

adb.bashD14-Jan-202413.5 KiB520421

adb.cppD15-Dec-202456.7 KiB1,6021,208

adb.hD15-Dec-20248.3 KiB266155

adb_auth.hD14-Jan-20242 KiB7235

adb_integration_test_adb.xmlD14-Jan-20241.4 KiB3014

adb_integration_test_device.xmlD14-Jan-20241.4 KiB3014

adb_io.cppD14-Jan-20245.9 KiB190121

adb_io.hD14-Jan-20243.1 KiB7917

adb_io_test.cppD15-Dec-20244.5 KiB160100

adb_listeners.cppD15-Dec-20248.3 KiB259190

adb_listeners.hD15-Dec-20241.6 KiB5224

adb_listeners_test.cppD14-Jan-20245.4 KiB167105

adb_mdns.cppD15-Dec-20244.7 KiB14091

adb_mdns.hD15-Dec-20244.1 KiB10048

adb_trace.cppD15-Dec-20246.1 KiB193132

adb_trace.hD14-Jan-20241.6 KiB6333

adb_unique_fd.cppD14-Jan-2024791 299

adb_unique_fd.hD14-Jan-20241.1 KiB4016

adb_utils.cppD14-Jan-202410.8 KiB381269

adb_utils.hD14-Jan-20243.5 KiB13082

adb_utils_test.cppD15-Dec-20247.9 KiB237173

adb_wifi.hD15-Dec-20241 KiB3813

adbd_test.mapD15-Dec-20241.1 KiB2725

adbd_test.xmlD14-Jan-20241.7 KiB3919

benchmark_device.pyD15-Dec-20244.8 KiB163114

bugreport_test.cppD14-Jan-202419.2 KiB467332

compression_utils.hD14-Jan-202417.1 KiB487372

file_sync_protocol.hD14-Jan-20243.7 KiB147111

mdns_test.cppD14-Jan-20243.6 KiB10859

protocol.txtD14-Jan-202412 KiB300208

run-device-tests.shD15-Dec-2024191 53

security_log_tags.hD14-Jan-20241 KiB297

services.cppD15-Dec-202410.1 KiB285215

services.hD15-Dec-20241.2 KiB3511

shell_protocol.hD14-Jan-20243.8 KiB11938

shell_service_protocol.cppD14-Jan-20241.7 KiB6333

shell_service_protocol_test.cppD14-Jan-20245.9 KiB199124

socket.hD14-Jan-20246.5 KiB16648

socket_spec.cppD15-Dec-202416.1 KiB477400

socket_spec.hD15-Dec-20241.3 KiB3813

socket_spec_test.cppD15-Dec-202411.1 KiB268209

socket_test.cppD14-Jan-202413.1 KiB393269

sockets.cppD15-Dec-202430.5 KiB992708

sockets.diaD14-Jan-20242.3 KiB

sysdeps.hD15-Dec-202423.8 KiB798532

sysdeps_test.cppD15-Dec-20247 KiB263196

sysdeps_unix.cppD14-Jan-20243.6 KiB11067

sysdeps_win32.cppD15-Dec-2024113.2 KiB3,1732,117

sysdeps_win32_test.cppD14-Jan-20247.1 KiB171100

test_adb.pyD14-Jan-202433.4 KiB813576

test_device.pyD15-Dec-202474.9 KiB1,8881,385

trace.shD14-Jan-2024651 1815

transfer_id.hD14-Jan-20242.1 KiB7444

transport.cppD15-Dec-202453.2 KiB1,7241,336

transport.hD15-Dec-202417.6 KiB539300

transport_benchmark.cppD14-Jan-20246.8 KiB195140

transport_fd.cppD14-Jan-20247.8 KiB242183

transport_test.cppD14-Jan-20246.4 KiB201140

types.cppD14-Jan-20246.5 KiB205164

types.hD15-Dec-20249.9 KiB362251

types_test.cppD15-Dec-20245.7 KiB219151

README.md

1# ADB Internals
2
3If you are new to adb source code, you should start by reading [OVERVIEW.TXT](OVERVIEW.TXT) which describes the three components of adb pipeline.
4
5This 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.
6
7## Three components of adb pipeline
8
9As 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.
10
11```
12+----------+              +------------------------+
13|   ADB    +----------+   |      ADB SERVER        |                   +----------+
14|  CLIENT  |          |   |                        |              (USB)|   ADBD   |
15+----------+          |   |                     Transport+-------------+ (DEVICE) |
16                      |   |                        |                   +----------+
17+-----------          |   |                        |
18|   ADB    |          v   +                        |                   +----------+
19|  CLIENT  +--------->SmartSocket                  |              (USB)|   ADBD   |
20+----------+          ^   | (TCP/IP)            Transport+-------------+ (DEVICE) |
21                      |   |                        |                   +----------+
22+----------+          |   |                        |
23|  DDMLIB  |          |   |                     Transport+--+          +----------+
24|  CLIENT  +----------+   |                        |        |  (TCP/IP)|   ADBD   |
25+----------+              +------------------------+        +----------|(EMULATOR)|
26                                                                       +----------+
27```
28
29The 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.
30
31
32## "SMART SOCKET" and TRANSPORT
33
34A 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](SERVICES.TXT).
35
36On the other side, the Server communicates 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.
37
38## THREADING MODEL and FDEVENT system
39
40At the heart of both the Server and Daemon is a main thread running an fdevent loop, which is a platform-independent abstraction over poll/epoll/WSAPoll monitoring file descriptors events. Requests and services are usually served from the main thread but some service requests result in new threads being spawned.
41
42To allow for operations to run on the Main thread, fdevent features a RunQueue combined with an interrupt fd to force polling to return.
43
44```
45+------------+    +-------------------------^
46|  RUNQUEUE  |    |                         |
47+------------+    |  POLLING (Main thread)  |
48| Function<> |    |                         |
49+------------+    |                         |
50| Function<> |    ^-^-------^-------^------^^
51+------------+      |       |       |       |
52|    ...     |      |       |       |       |
53+------------+      |       |       |       |
54|            |      |       |       |       |
55|============|      |       |       |       |
56|Interrupt fd+------+  +----+  +----+  +----+
57+------------+         fd      Socket  Pipe
58```
59
60## ASOCKET, APACKET, and AMESSAGE
61
62The 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](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.
63
64An asocket features a buffer where the elemental unit is an apacket. If traffic is inbound, the buffer stores the apacket until it is consumed. If the traffic is oubound, the buffer stores apackets until they are sent down the wire (with `A_WRTE` commands).
65
66```
67+---------------------ASocket------------------------+
68 |                                                   |
69 | +----------------APacket Queue------------------+ |
70 | |                                               | |
71 | |            APacket     APacket     APacket    | |
72 | |          +--------+  +--------+  +--------+   | |
73 | |          |AMessage|  |AMessage|  |AMessage|   | |
74 | |          +--------+  +--------+  +--------+   | |
75 | |          |        |  |        |  |        |   | |
76 | |  .....   |        |  |        |  |        |   | |
77 | |          |  Data  |  |  Data  |  |  Data  |   | |
78 | |          |        |  |        |  |        |   | |
79 | |          |        |  |        |  |        |   | |
80 | |          +--------+  +--------+  +--------+   | |
81 | |                                               | |
82 | +-----------------------------------------------+ |
83 +---------------------------------------------------+
84```
85
86This 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.
87
88The two types of asocket (Remote and Local) differentiate between outbound and inbound traffic.
89
90## adbd <-> APPPLICATION communication
91
92This pipeline is detailed in [daemon/jdwp_service.cpp](daemon/jdwp_service.cpp) with ASCII drawings! The JDWP extension implemented by Dalvik/ART are documented in:
93- platform/dalvik/+/main/docs/debugmon.html
94- platform/dalvik/+/main/docs/debugger.html
95
96### Sync protocol
97
98To transfer files and directories, ADB places a smart-socket in SYNC mode and then issues SYNC commands. The SYNC protocol is documented in [SYNC.TXT](SYNC.TXT).
99
100### Benchmark sample run for Pixel 8,USB
101
102```
103$ ./benchmark_device.py
104sink 100MiB: 10 runs: median 27.00 MiB/s, mean 26.39 MiB/s, stddev: 1.11 MiB/s
105source 100MiB: 10 runs: median 36.97 MiB/s, mean 37.05 MiB/s, stddev: 0.46 MiB/s
106push 100MiB: 10 runs: median 331.96 MiB/s, mean 329.81 MiB/s, stddev: 14.67 MiB/s
107pull 100MiB: 10 runs: median 34.55 MiB/s, mean 33.57 MiB/s, stddev: 2.54 MiB/s
108```
109