platform_system_core/adb
2020-10-16 23:16:43 +00:00
..
apex Make change and version bump to r_aml_300900700 for mainline module file: adb/apex/apex_manifest.json 2020-07-09 03:15:03 +00:00
client Merge "adb: fix timeout-related test flakiness." am: fe1eba0056 am: 51d8abc846 am: b9fd9097cc am: 966c3febea 2020-10-16 23:16:43 +00:00
coverage Merge changes Id8d9fa6c,I47d3ad50,I7cebbf75,Id10e320a 2020-05-12 05:32:48 +00:00
crypto [adb] Correctly read host/user name on Windows. 2020-08-03 18:55:17 -07:00
daemon adbd: Fix check against valid payload size 2020-09-18 19:26:45 +00:00
fastdeploy Remove unneeded optimize_for lite 2020-05-01 16:11:22 +02:00
fdevent Update language to comply with Android's inclusive language guidance 2020-07-31 16:36:06 -06:00
libs adb: mark kMaxProcessNameLength as constexpr. 2020-04-27 14:38:28 -07:00
pairing_auth Fix pairing aes_128_gcm key initialization. 2020-03-26 02:17:34 +00:00
pairing_connection Remove host_supported from libadb_pairing_server. 2020-04-15 06:53:38 +00:00
proto Statically link libadbd into minadbd. 2020-03-31 19:16:08 -07:00
sysdeps [adb] Correctly read host/user name on Windows. 2020-08-03 18:55:17 -07:00
tls Statically link libadbd into minadbd. 2020-03-31 19:16:08 -07:00
tools check_ms_os_desc: fix buffer overflow. 2020-06-03 15:32:06 -07:00
.clang-format
adb.bash Adb and fastboot completion supports zsh users. 2018-07-17 14:19:35 +08:00
adb.cpp adbd: avoid compiling more code in the daemon. 2020-04-27 14:38:28 -07:00
adb.h adb: add option to disable kill-server. 2020-04-06 14:33:14 -07:00
adb_auth.h [adbwifi] Add A_STLS command. 2020-02-21 21:07:13 +00:00
adb_integration_test_adb.xml Add adb integration test to general-tests 2018-08-08 12:08:50 -07:00
adb_integration_test_device.xml Add adb_integration_test_device to general-tests 2018-10-12 13:48:14 -07:00
adb_io.cpp Revert "Revert "Add a way to turn off unique_fd's operator int."" 2019-05-06 16:18:02 -07:00
adb_io.h Revert "Revert "Add a way to turn off unique_fd's operator int."" 2019-05-06 16:18:02 -07:00
adb_io_test.cpp switch to using android-base/file.h instead of android-base/test_utils.h 2018-11-14 09:35:34 -08:00
adb_listeners.cpp adbd: avoid compiling more code in the daemon. 2020-04-27 14:38:28 -07:00
adb_listeners.h adbd: avoid compiling more code in the daemon. 2020-04-27 14:38:28 -07:00
adb_listeners_test.cpp adb: move fdevent to its own folder. 2019-07-08 14:37:27 -07:00
adb_mdns.h adb: change mdns tls service names (RFC 6763). 2020-04-20 21:03:15 +00:00
adb_test.xml Add test config for adbd_test and apply MainlineTestModuleController to it 2020-05-08 16:47:07 -07:00
adb_trace.cpp adbd: respect ADB_TRACE on host adbd. 2020-04-27 14:38:28 -07:00
adb_trace.h adbd: remove static dependency on libcutils. 2020-02-24 17:58:06 -08:00
adb_unique_fd.cpp adb: actually enable fdsan. 2018-08-06 18:50:10 -07:00
adb_unique_fd.h Revert "Revert "Add a way to turn off unique_fd's operator int."" 2019-05-06 16:18:02 -07:00
adb_utils.cpp Allow overriding the log path. 2019-07-30 12:26:31 -07:00
adb_utils.h Update language to comply with Android's inclusive language guidance 2020-07-31 16:36:06 -06:00
adb_utils_test.cpp Revert "Revert "Add a way to turn off unique_fd's operator int."" 2019-05-06 16:18:02 -07:00
adb_wifi.h 'adb pair' by mdns instance name. 2020-05-18 14:23:01 -07:00
Android.bp Turn off -Wnon-virtual-dtor explicitly 2020-09-25 11:56:04 +09:00
benchmark_device.py adb: add benchmarks for sink/source. 2019-02-28 15:53:48 -08:00
bugreport_test.cpp adb: Avoid extra std::string copies 2019-03-26 12:00:19 -07:00
compression_utils.h adb: implement zstd compression for file sync. 2020-05-28 13:00:01 -07:00
file_sync_protocol.h adb: implement zstd compression for file sync. 2020-05-28 13:00:01 -07:00
mdns_test.cpp adb: change mdns tls service names (RFC 6763). 2020-04-20 21:03:15 +00:00
MODULE_LICENSE_APACHE2
NOTICE Revert "Revert "Revert "adb: append the libwinpthread COPYING to adb's NOTICE.""" 2018-11-29 23:14:02 +00:00
OVERVIEW.TXT adb: fix obsolete documentation. 2018-06-22 13:12:19 -07:00
OWNERS Add OWNERS. 2017-12-07 13:30:03 -08:00
protocol.txt [adbwifi] Add A_STLS command. 2020-02-21 21:07:13 +00:00
README.md ADB internals documentation 2020-09-15 22:50:59 -07:00
security_log_tags.h
services.cpp adb: allow wait-for-disconnect to match offline for TCP devices. 2020-04-21 17:57:15 -07:00
services.h Support adb rescue wipe command 2019-04-29 15:21:50 -07:00
SERVICES.TXT adb: fix obsolete documentation. 2018-06-22 13:12:19 -07:00
shell_protocol.h Revert "Revert "Add a way to turn off unique_fd's operator int."" 2019-05-06 16:18:02 -07:00
shell_service_protocol.cpp Revert "Revert "Add a way to turn off unique_fd's operator int."" 2019-05-06 16:18:02 -07:00
shell_service_protocol_test.cpp adb: split shell_service.h into client/daemon/protocol parts. 2018-07-25 18:08:44 -07:00
SOCKET-ACTIVATION.txt Revert "Revert "Support socket activation of adb server"" 2019-12-11 08:20:20 +00:00
socket.h adbd: avoid compiling more code in the daemon. 2020-04-27 14:38:28 -07:00
socket_spec.cpp Merge changes from topic "adb-mdns" 2020-05-19 00:30:06 +00:00
socket_spec.h Enable "localfilesystem" UNIX domain socket for ADB. 2019-12-04 10:05:05 +09:00
socket_spec_test.cpp Add a few more trivial socket_spec.h tests. 2020-05-12 16:38:11 -07:00
socket_test.cpp adb: move fdevent to its own folder. 2019-07-08 14:37:27 -07:00
sockets.cpp Update language to comply with Android's inclusive language guidance 2020-07-31 16:36:06 -06:00
sockets.dia
SYNC.TXT Fix typos in ADB documentation 2017-11-30 10:57:51 -08:00
sysdeps.h Add missing static for macOS inline. 2020-04-13 17:17:31 -07:00
sysdeps_test.cpp adb: win32: silence wine test failure. 2019-07-16 15:22:51 -07:00
sysdeps_unix.cpp Incremental installations in adb, client/host side. 2020-02-19 08:01:06 -08:00
sysdeps_win32.cpp [adb] Correctly read host/user name on Windows. 2020-08-03 18:55:17 -07:00
sysdeps_win32_test.cpp switch to using android-base/file.h instead of android-base/test_utils.h 2018-11-14 09:35:34 -08:00
test_adb.py [adb] Fix crash in mdns service removal. 2020-07-01 15:06:33 -07:00
test_device.py adb: fix push --sync with multiple inputs. 2020-09-08 18:07:47 -07:00
trace.sh
transport.cpp adb: fix timeout-related test flakiness. 2020-10-15 18:46:45 -07:00
transport.h Merge "adbd: check auth id." into rvc-dev am: d389d983bc 2020-06-25 23:10:12 +00:00
transport_benchmark.cpp Revert "adb: make benchmarks build on the host." 2018-11-13 11:28:29 -08:00
transport_fd.cpp [adbwifi] Add A_STLS command. 2020-02-21 21:07:13 +00:00
transport_test.cpp adbd: avoid compiling more code in the daemon. 2020-04-27 14:38:28 -07:00
types.cpp adb: fix front_size, front_data. 2020-04-02 17:11:07 -07:00
types.h adb: fix front_size, front_data. 2020-04-02 17:11:07 -07:00
types_test.cpp adb: fix front_size, front_data. 2020-04-02 17:11:07 -07:00

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