|
Name |
|
Date |
Size |
#Lines |
LOC |
| .. | | - | - |
| apex/ | | 03-May-2024 | - | 194 | 178 |
| client/ | | 03-May-2024 | - | 16,397 | 12,065 |
| coverage/ | | 03-May-2024 | - | 175 | 109 |
| crypto/ | | 03-May-2024 | - | 691 | 425 |
| daemon/ | | 03-May-2024 | - | 6,668 | 4,716 |
| fastdeploy/ | | 03-May-2024 | - | 2,362 | 1,536 |
| fdevent/ | | 03-May-2024 | - | 1,392 | 977 |
| libs/ | | 03-May-2024 | - | 686 | 447 |
| pairing_auth/ | | 03-May-2024 | - | 1,193 | 726 |
| pairing_connection/ | | 03-May-2024 | - | 2,281 | 1,583 |
| proto/ | | 03-May-2024 | - | 271 | 222 |
| sysdeps/ | | 03-May-2024 | - | 924 | 499 |
| tls/ | | 03-May-2024 | - | 1,614 | 1,120 |
| tools/ | | 03-May-2024 | - | 523 | 399 |
| .clang-format | D | 03-May-2024 | 291 | 14 | 13 |
| Android.bp | D | 03-May-2024 | 22.3 KiB | 984 | 875 |
| MODULE_LICENSE_APACHE2 | D | 03-May-2024 | 0 | | |
| NOTICE | D | 03-May-2024 | 10.5 KiB | 192 | 159 |
| OVERVIEW.TXT | D | 03-May-2024 | 5.2 KiB | 136 | 90 |
| OWNERS | D | 03-May-2024 | 123 | 5 | 3 |
| PREUPLOAD.cfg | D | 03-May-2024 | 246 | 9 | 6 |
| README.md | D | 03-May-2024 | 6.5 KiB | 95 | 72 |
| SERVICES.TXT | D | 03-May-2024 | 9.6 KiB | 257 | 193 |
| SOCKET-ACTIVATION.txt | D | 03-May-2024 | 1.4 KiB | 43 | 37 |
| SYNC.TXT | D | 03-May-2024 | 3.4 KiB | 81 | 63 |
| TEST_MAPPING | D | 03-May-2024 | 102 | 8 | 7 |
| adb.bash | D | 03-May-2024 | 12.9 KiB | 500 | 403 |
| adb.cpp | D | 03-May-2024 | 50.6 KiB | 1,428 | 1,068 |
| adb.h | D | 03-May-2024 | 7.5 KiB | 262 | 156 |
| adb_auth.h | D | 03-May-2024 | 1.9 KiB | 71 | 34 |
| adb_integration_test_adb.xml | D | 03-May-2024 | 1.4 KiB | 30 | 14 |
| adb_integration_test_device.xml | D | 03-May-2024 | 1.4 KiB | 30 | 14 |
| adb_io.cpp | D | 03-May-2024 | 5.9 KiB | 190 | 121 |
| adb_io.h | D | 03-May-2024 | 3.1 KiB | 79 | 17 |
| adb_io_test.cpp | D | 03-May-2024 | 4.4 KiB | 157 | 96 |
| adb_listeners.cpp | D | 03-May-2024 | 8.2 KiB | 257 | 189 |
| adb_listeners.h | D | 03-May-2024 | 1.5 KiB | 50 | 23 |
| adb_listeners_test.cpp | D | 03-May-2024 | 5.4 KiB | 167 | 105 |
| adb_mdns.cpp | D | 03-May-2024 | 4.7 KiB | 139 | 90 |
| adb_mdns.h | D | 03-May-2024 | 4.1 KiB | 99 | 47 |
| adb_test.xml | D | 03-May-2024 | 1.7 KiB | 39 | 19 |
| adb_trace.cpp | D | 03-May-2024 | 6.1 KiB | 193 | 132 |
| adb_trace.h | D | 03-May-2024 | 1.6 KiB | 63 | 33 |
| adb_unique_fd.cpp | D | 03-May-2024 | 791 | 29 | 9 |
| adb_unique_fd.h | D | 03-May-2024 | 1.1 KiB | 40 | 16 |
| adb_utils.cpp | D | 03-May-2024 | 10.8 KiB | 381 | 269 |
| adb_utils.h | D | 03-May-2024 | 3.5 KiB | 130 | 82 |
| adb_utils_test.cpp | D | 03-May-2024 | 7.9 KiB | 236 | 172 |
| adb_wifi.h | D | 03-May-2024 | 1 KiB | 39 | 14 |
| benchmark_device.py | D | 03-May-2024 | 4.5 KiB | 157 | 110 |
| bugreport_test.cpp | D | 03-May-2024 | 19.2 KiB | 467 | 332 |
| compression_utils.h | D | 03-May-2024 | 17.1 KiB | 487 | 372 |
| file_sync_protocol.h | D | 03-May-2024 | 3.7 KiB | 145 | 110 |
| mdns_test.cpp | D | 03-May-2024 | 3.6 KiB | 108 | 59 |
| protocol.txt | D | 03-May-2024 | 12 KiB | 300 | 208 |
| security_log_tags.h | D | 03-May-2024 | 1 KiB | 29 | 7 |
| services.cpp | D | 03-May-2024 | 9.4 KiB | 273 | 210 |
| services.h | D | 03-May-2024 | 1.2 KiB | 33 | 10 |
| shell_protocol.h | D | 03-May-2024 | 3.8 KiB | 119 | 38 |
| shell_service_protocol.cpp | D | 03-May-2024 | 1.7 KiB | 63 | 33 |
| shell_service_protocol_test.cpp | D | 03-May-2024 | 5.9 KiB | 199 | 124 |
| socket.h | D | 03-May-2024 | 3.7 KiB | 127 | 45 |
| socket_spec.cpp | D | 03-May-2024 | 15.8 KiB | 468 | 393 |
| socket_spec.h | D | 03-May-2024 | 1.3 KiB | 36 | 12 |
| socket_spec_test.cpp | D | 03-May-2024 | 7.3 KiB | 189 | 149 |
| socket_test.cpp | D | 03-May-2024 | 13.2 KiB | 387 | 268 |
| sockets.cpp | D | 03-May-2024 | 28 KiB | 921 | 653 |
| sockets.dia | D | 03-May-2024 | 2.3 KiB | | |
| sysdeps.h | D | 03-May-2024 | 23.7 KiB | 796 | 530 |
| sysdeps_test.cpp | D | 03-May-2024 | 6.6 KiB | 254 | 192 |
| sysdeps_unix.cpp | D | 03-May-2024 | 3 KiB | 93 | 60 |
| sysdeps_win32.cpp | D | 03-May-2024 | 111.8 KiB | 3,147 | 2,105 |
| sysdeps_win32_test.cpp | D | 03-May-2024 | 7.1 KiB | 171 | 100 |
| test_adb.py | D | 03-May-2024 | 33.4 KiB | 813 | 576 |
| test_device.py | D | 03-May-2024 | 69.1 KiB | 1,787 | 1,302 |
| trace.sh | D | 03-May-2024 | 651 | 18 | 15 |
| transfer_id.h | D | 03-May-2024 | 2.1 KiB | 74 | 44 |
| transport.cpp | D | 03-May-2024 | 47.5 KiB | 1,568 | 1,216 |
| transport.h | D | 03-May-2024 | 16.3 KiB | 498 | 280 |
| transport_benchmark.cpp | D | 03-May-2024 | 6.8 KiB | 195 | 140 |
| transport_fd.cpp | D | 03-May-2024 | 7.8 KiB | 242 | 183 |
| transport_test.cpp | D | 03-May-2024 | 5.7 KiB | 188 | 128 |
| types.cpp | D | 03-May-2024 | 6.5 KiB | 205 | 164 |
| types.h | D | 03-May-2024 | 9.7 KiB | 359 | 248 |
| types_test.cpp | D | 03-May-2024 | 3.8 KiB | 137 | 91 |
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 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.
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 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.
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. 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).
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 [services.cpp](services.cpp). The JDWP extension implemented by Dalvik/ART are documented in:
93- platform/dalvik/+/master/docs/debugmon.html
94- platform/dalvik/+/master/docs/debugger.html
95