1```
2This file tries to document all requests a client can make
3to the ADB server of an adbd daemon. See the OVERVIEW.TXT document
4to understand what's going on here.
5
6HOST SERVICES:
7
8host:version
9    Ask the ADB server for its internal version number.
10
11host:kill
12    Ask the ADB server to quit immediately. This is used when the
13    ADB client detects that an obsolete server is running after an
14    upgrade.
15
16host:devices
17host:devices-l
18    Ask to return the list of available Android devices and their
19    state. devices-l includes the device paths in the state.
20    After the OKAY, this is followed by a 4-byte hex len,
21    and a string that will be dumped as-is by the client, then
22    the connection is closed
23
24host:track-devices
25host:track-devices-proto-binary
26host:track-devices-proto-text
27    These are variants of host:devices which doesn't close the
28    connection. Instead, a new device list description is sent
29    each time a device is added/removed or the state of a given
30    device changes.
31    Variant [-proto-binary] is binary protobuf format.
32    Variant [-proto-text] is text protobuf format.
33
34host:emulator:<port>
35    This is a special query that is sent to the ADB server when a
36    new emulator starts up. <port> is a decimal number corresponding
37    to the emulator's ADB control port, i.e. the TCP port that the
38    emulator will forward automatically to the adbd daemon running
39    in the emulator system.
40
41    This mechanism allows the ADB server to know when new emulator
42    instances start.
43
44host:transport:<serial-number>
45    Ask to switch the connection to the device/emulator identified by
46    <serial-number>. After the OKAY response, every client request will
47    be sent directly to the adbd daemon running on the device.
48    (Used to implement the -s option)
49
50host:transport-usb
51    Ask to switch the connection to one device connected through USB
52    to the host machine. This will fail if there are more than one such
53    devices. (Used to implement the -d convenience option)
54
55host:transport-local
56    Ask to switch the connection to one emulator connected through TCP.
57    This will fail if there is more than one such emulator instance
58    running. (Used to implement the -e convenience option)
59
60host:transport-any
61    Another host:transport variant. Ask to switch the connection to
62    either the device or emulator connect to/running on the host.
63    Will fail if there is more than one such device/emulator available.
64    (Used when neither -s, -d or -e are provided)
65
66host-serial:<serial-number>:<request>
67    This is a special form of query, where the 'host-serial:<serial-number>:'
68    prefix can be used to indicate that the client is asking the ADB server
69    for information related to a specific device. <request> can be in one
70    of the format described below.
71
72host-usb:<request>
73    A variant of host-serial used to target the single USB device connected
74    to the host. This will fail if there is none or more than one.
75
76host-local:<request>
77    A variant of host-serial used to target the single emulator instance
78    running on the host. This will fail if there is none or more than one.
79
80host:<request>
81    When asking for information related to a device, 'host:' can also be
82    interpreted as 'any single device or emulator connected to/running on
83    the host'.
84
85host:server-status
86    Return adb server status (version, build, usb backend, mdns backend, ...).
87    See adb_host.proto AdbServerStatus for more details.
88
89<host-prefix>:get-serialno
90    Returns the serial number of the corresponding device/emulator.
91    Note that emulator serial numbers are of the form "emulator-5554"
92
93<host-prefix>:get-devpath
94    Returns the device path of the corresponding device/emulator.
95
96<host-prefix>:get-state
97    Returns the state of a given device as a string.
98
99<host-prefix>:forward:<local>;<remote>
100    Asks the ADB server to forward local connections from <local>
101    to the <remote> address on a given device.
102
103    There, <host-prefix> can be one of the
104    host-serial/host-usb/host-local/host prefixes as described previously
105    and indicates which device/emulator to target.
106
107    the format of <local> is one of:
108
109        tcp:<port>      -> TCP connection on localhost:<port>
110        local:<path>    -> Unix local domain socket on <path>
111
112    the format of <remote> is one of:
113
114        tcp:<port>      -> TCP localhost:<port> on device
115        local:<path>    -> Unix local domain socket on device
116        jdwp:<pid>      -> JDWP thread on VM process <pid>
117        vsock:<CID>:<port> -> vsock on the given CID and port
118
119    or even any one of the local services described below.
120
121<host-prefix>:forward:norebind:<local>;<remote>
122    Same as <host-prefix>:forward:<local>;<remote> except that it will
123    fail it there is already a forward connection from <local>.
124
125    Used to implement 'adb forward --no-rebind <local> <remote>'
126
127<host-prefix>:killforward:<local>
128    Remove any existing forward local connection from <local>.
129    This is used to implement 'adb forward --remove <local>'
130
131<host-prefix>:killforward-all
132    Remove all forward network connections.
133    This is used to implement 'adb forward --remove-all'.
134
135<host-prefix>:list-forward
136    List all existing forward connections from this server.
137    This returns something that looks like the following:
138
139       <hex4>: The length of the payload, as 4 hexadecimal chars.
140       <payload>: A series of lines of the following format:
141
142         <serial> " " <local> " " <remote> "\n"
143
144    Where <serial> is a device serial number.
145          <local>  is the host-specific endpoint (e.g. tcp:9000).
146          <remote> is the device-specific endpoint.
147
148    Used to implement 'adb forward --list'.
149
150LOCAL SERVICES:
151
152All the queries below assumed that you already switched the transport
153to a real device, or that you have used a query prefix as described
154above.
155
156shell:command arg1 arg2 ...
157    Run 'command arg1 arg2 ...' in a shell on the device, and return
158    its output and error streams. Note that arguments must be separated
159    by spaces. If an argument contains a space, it must be quoted with
160    double-quotes. Arguments cannot contain double quotes or things
161    will go very wrong.
162
163    Note that this is the non-interactive version of "adb shell"
164
165shell:
166    Start an interactive shell session on the device. Redirect
167    stdin/stdout/stderr as appropriate. Note that the ADB server uses
168    this to implement "adb shell", but will also cook the input before
169    sending it to the device (see interactive_shell() in commandline.c)
170
171shell,v2: (API>=24)
172    Variant of shell service which uses "shell protocol" in order to
173    differentiate stdin, stderr, and also retrieve exit code.
174
175exec:
176    Variant of shell which uses a raw PTY in order to not mangle output.
177
178abb: (API>=30)
179    Direct connection to Binder on device. This service does not use space
180    for parameter separator but "\u0000". Example:
181    abb:package0install-create
182
183abb_exec: (API>=30)
184    Variant of abb. Use a raw PTY in order to not mangle output. Example:
185    abb_exec:package0install-write
186
187remount:
188    Ask adbd to remount the device's filesystem in read-write mode,
189    instead of read-only. This is usually necessary before performing
190    an "adb sync" or "adb push" request.
191
192    This request may not succeed on certain builds which do not allow
193    that.
194
195dev:<path>
196    Opens a device file and connects the client directly to it for
197    read/write purposes. Useful for debugging, but may require special
198    privileges and thus may not run on all devices. <path> is a full
199    path from the root of the filesystem. Besides debugging this is
200    useful for allowing test automation running on host (not Android
201    device) to directly interact with the device file when a
202    non-trivial protocol is needed and adb shell is not suitable. Use
203    cases: factory tests for device peripherals, emulated peripheral
204    control (cuttlefish) for test automation.
205
206dev-raw:<path>
207    Similar with dev:<path>, the only difference being that the device
208    is opened in raw tty mode. Useful when default tty settings
209    interferes with protocol that is used to control the device.
210
211tcp:<port>
212    Tries to connect to tcp port <port> on localhost.
213
214tcp:<port>:<server-name>
215    Tries to connect to tcp port <port> on machine <server-name> from
216    the device. This can be useful to debug some networking/proxy
217    issues that can only be revealed on the device itself.
218
219local:<path>
220    Tries to connect to a Unix domain socket <path> on the device
221
222localreserved:<path>
223localabstract:<path>
224localfilesystem:<path>
225    Variants of local:<path> that are used to access other Android
226    socket namespaces.
227
228framebuffer:
229    This service is used to send snapshots of the framebuffer to a client.
230    It requires sufficient privileges but works as follow:
231
232      After the OKAY, the service sends 16-byte binary structure
233      containing the following fields (little-endian format):
234
235            depth:   uint32_t:    framebuffer depth
236            size:    uint32_t:    framebuffer size in bytes
237            width:   uint32_t:    framebuffer width in pixels
238            height:  uint32_t:    framebuffer height in pixels
239
240      With the current implementation, depth is always 16, and
241      size is always width*height*2
242
243      Then, each time the client wants a snapshot, it should send
244      one byte through the channel, which will trigger the service
245      to send it 'size' bytes of framebuffer data.
246
247      If the adbd daemon doesn't have sufficient privileges to open
248      the framebuffer device, the connection is simply closed immediately.
249
250jdwp:<pid>
251    Connects to the JDWP thread running in the VM of process <pid>.
252
253track-jdwp
254    This is used to send the list of JDWP pids periodically to the client.
255    The format of the returned data is the following:
256
257        <hex4>:    the length of all content as a 4-char hexadecimal string
258        <content>: a series of ASCII lines of the following format:
259                        <pid> "\n"
260
261    This service is used by DDMS to know which debuggable processes are running
262    on the device/emulator.
263
264    Note that there is no single-shot service to retrieve the list only once.
265
266track-app:
267    Improved version of "track-jdwp" service which also mentions whether the
268    app is profileable and its architecture. Each time the list changes,
269    a new messeage is sent (this service never stops).
270
271    Each message features a hex4 length prefix followed by a
272    binary protocol buffer. e.g.:
273
274    process {
275      pid: 18595
276      debuggable: true
277      architecture: "arm64"
278    }
279    process {
280      pid: 18407
281      debuggable: true
282      profileable: true
283      architecture: "arm64"
284    }
285
286    Note: Generate a parser from [app_processes.proto].
287
288sync:
289    This starts the file synchronization service, used to implement "adb push"
290    and "adb pull". Since this service is pretty complex, it will be detailed
291    in a companion document named SYNC.TXT
292
293reverse:<forward-command>
294    This implements the 'adb reverse' feature, i.e. the ability to reverse
295    socket connections from a device to the host. <forward-command> is one
296    of the forwarding commands that are described above, as in:
297
298      list-forward
299      forward:<local>;<remote>
300      forward:norebind:<local>;<remote>
301      killforward-all
302      killforward:<local>
303
304    Note that in this case, <local> corresponds to the socket on the device
305    and <remote> corresponds to the socket on the host.
306
307    The output of reverse:list-forward is the same as host:list-forward
308    except that <serial> will be just 'host'.
309```