Commit graph

78 commits

Author SHA1 Message Date
Josh Gao
d19b77ac12 adb: finish switching service creation to string_view.
Test: test_adb.py
Test: test_device.py
Test: $ANDROID_HOST_OUT/nativetest64/adb_test/adb_test
Test: adb shell /data/nativetest64/adbd_test/adbd_test
Change-Id: If4ea92aee1c0264d946de72483f8d715d96fcfd8
2018-12-21 11:53:27 -08:00
Josh Gao
997cfac89f adb: split daemon services out of service_to_fd.
Let minadbd override daemon services by pulling out the daemon services
into a separate translation unit, that isn't compiled into libadbd.

Bug: http://b/111831478
Test: mma
Change-Id: Iecfebea371e03864108eca9a4d2e9cfd5db34749
2018-07-25 18:49:37 -07:00
Josh Gao
73a5ee4df5 adb: use adb's unique_fd instead of android::base.
Replace all usages of android::base::unique_fd with the unique_fd from
adb_unique_fd.h, which calls adb_close instead of close on Windows.

Most of these changes are no-ops, except for the ones to
create_service_thread, which was probably pretty broken on Windows.

Test: python test_device.py
Test: adb_test
Test: wine adb_test.exe
Change-Id: Ia4d03f9e2e7ddc88c97dc64172d721f93f3bf853
2018-07-25 18:08:45 -07:00
Josh Gao
2deb787ee2 adb: move remount_service.h into daemon.
Test: treehugger
Change-Id: I1a895d52da2c2ef281d562be778cfe0a01854a4f
2018-07-25 18:08:45 -07:00
Josh Gao
86acb863ff adb: split shell_service.h into client/daemon/protocol parts.
Test: treehugger
Change-Id: I67042f6b29a8a07619b8d56e7376d49b956a840c
2018-07-25 18:08:44 -07:00
Josh Gao
edec033b26 adb: split file_sync_service.h into client and daemon parts.
Test: treehugger
Change-Id: I648c7001903a91448c69986e08a6cd2dd76ed793
2018-07-25 18:08:32 -07:00
Luis Hector Chavez
095792c300 adb: Modernize the service creation
This change removes the void* argument passing and instead uses C++11
features to avoid having to handle memory manually.

Bug: None
Test: python ./system/core/adb/test_device.py

Change-Id: I6380245b2ca583591810e3e363c67c993a107621
2018-07-18 20:38:10 -07:00
Yi Kong
aed415cc47 [adb] Modernize codebase by replacing NULL with nullptr
Fixes -Wzero-as-null-pointer-constant warning.

Test: m
Bug: 68236239
Change-Id: Ia8c4deacafed2f3b7dbc3d4c3c77c6c632e3de81
2018-07-13 18:21:00 -07:00
Josh Gao
04b9ca8c31 Revert "adb: detect some spin loops and abort."
This seems to be falsely triggering.

This reverts commit 3bbc8164b1.

Test: none
2018-06-22 13:07:22 -07:00
Josh Gao
3bbc8164b1 adb: detect some spin loops and abort.
Track pending fdevents, and abort if we see an fdevent ready for
read/write for 5 minutes continuously.

Also, add a service that intentionally starts spinning, to test this.

Test: manually changed timeout to a minute, `adb raw spin`
Change-Id: Ibfa5e7e654996587f745887cb04987b982d79bed
2018-06-18 17:46:34 -07:00
David Anderson
07445f4a71 adb: add remount -R for deduplicated ext4
When using "adb remount" on a deduplicated filesystem, the current
response is a warning that the remount will not work. This patch
allows the user to specify an -R option. This option will reboot to recovery,
run e2fsck to undo deduplication, and then reboot the device where "adb
remount" will then succeed.

In addition, if verity needs to be disabled to remount, it will be disabled in
the same reboot cycle to minimize reboots.

Bug: 64109868
Test: adb remount -R on a deduplicated filesystem
Change-Id: I812407499b2df6f4d2509e8d51878117108a6849
2018-05-31 15:38:25 -07:00
Josh Gao
44899eeb53 adb: fix adb reverse when adbd has multiple transports.
Plumb the transport that we received the adb reverse request on through
to reverse_service, instead of trying to get a unique transport on
devices that have multiple active transports (e.g. a device with USB
(even unplugged) connected via TCP).

Bug: http://b/37066218
Bug: http://b/71898863
Test: `echo foo | nc -l 12345 & adb reverse tcp:12345 tcp:12345; adb shell nc localhost 12345` on a device connected via TCP
Change-Id: Iae199ae787f2e344126bbcacca8544cfc9844a4c
2018-04-13 14:25:28 -07:00
George Burgess IV
cb2449f851 Fix a memory leak
If create_service_thread fails, we'll leak `arg`.

This fixes a static analyzer complaint:
system/core/adb/services.cpp:298:13: warning: Potential leak of memory
pointed to by 'arg'

Bug: None
Test: Reran the static analyzer. No more complaints about this leak.
Change-Id: I5aec7fd78f2cc775b650501b02bdf0039d1647ca
2018-02-19 01:05:56 -08:00
Josh Gao
b800d88b34 adb: extract atransport's connection interface.
As step one of refactoring atransport to separate out protocol handling
from its underlying connection, extract atransport's existing
hand-rolled connection vtable out to its own abstract interface.

This should not change behavior except in one case: emulators are
now treated as TCP devices for the purposes of `adb disconnect`.

Test: python test_device.py, with walleye over USB + TCP
Test: manually connecting and disconnecting devices/emulators
Change-Id: I877b8027e567cc6a7461749432b49f6cb2c2f0d7
2018-01-30 15:22:41 -08:00
Josh Gao
bcadc77550 adbd: improve thread names.
Name each service thread specifically to improve debuggability.

Bug: http://b/65648324
Test: adb shell debuggerd -b `adb shell pidof adbd` during a sync
Change-Id: I644e25fc2f14a26eafd19f596e4e8f3c2bb79967
2017-09-28 16:45:24 -07:00
Mark Salyzyn
277eca138b adb: reboot: last boot command default
For reboot [reboot_arg] requests via either reboot or adb reboot,
if reboot_arg is empty then report "shell" or "adb" respectively.

Test: boot_reason_test.sh shell_reboot adb_reboot
Bug: 63736262
Change-Id: Ie613d9e62db6a705885e4e7520aede27af3aa1b9
2017-09-12 12:24:02 -07:00
Josh Gao
b0c1802615 adb: add track-devices-l service.
Add a way to get the full `devices -l` output on a continuous basis.

Test: manual
Change-Id: I2270cc0a0d7e1384ce19631724ddf2462d963ade
2017-08-21 14:15:07 -07:00
Josh Gao
b122b17555 adb: allow selection of a specific transport.
Extend device selection to allow selecting a specific transport via
monotonically increasing identifier (visible in devices -l).

This is useful when using multiple devices (like hikey960...) that
have identical bogus serial numbers like 0123456789ABCDEF.

Bug: http://b/37043226
Test: adb -t {1, 2, 9999999} {get-serialno, shell, features}
Change-Id: I55e5dc5a406a4eeee0012e39b52e8cd232e608a6
2017-08-21 14:15:06 -07:00
Ting-Yuan Huang
f26cf6d520 Fix a potential memory leak
Test: Built without seeing the warnings
Change-Id: I934509c78482af9ef7dc447c807f6450484b4b38
2017-08-15 16:48:24 -07:00
Treehugger Robot
2e821078e4 Merge "adb: fix two device offline problems." 2017-04-20 19:45:18 +00:00
Yabin Cui
b5e11415d9 adb: fix two device offline problems.
When device goes offline, user usually has to manually replug the
usb device. This patch tries to solve two offline situations, all
because when adb on host is killed, the adbd on device is not notified.

1. When adb server is killed while pushing a large file to device,
the device is still reading the unfinished large message. So the
device thinks of the CNXN message as part of the previous unfinished
message, so it doesn't reply and the device is in offline state.

The solution is to add a write_msg_lock in atransport struct. And it
kicks the transport only after sending a whole message. By kicking
all transports before exit, we ensure that we don't write part of
a message to any device. So next time we start adb server, the device
should be waiting for a new message.

2. When adb server is killed while pulling a large file from device,
the device is still trying to send the unfinished large message. So
adb on host usually reads data with EOVERFLOW error. This is because
adb on host is reading less than one packet sent from device.

The solution is to use buffered read on host. The max packet size
of bulk transactions in USB 3.0 is 1024 bytes. By preparing an at least
1024 bytes buffer when reading, EOVERFLOW no longer occurs. And teach
adb host to ignore wrong messages.

To be safe, this patch doesn't change any logic on device.

Bug: http://b/32952319
Test: run python -m unittest -q test_device.DeviceOfflineTest
Test: on linux/mac/windows with bullhead, ryu.
Change-Id: Ib149d30028a62a6f03857b8a95ab5a1d6e9b9c4e
2017-04-20 10:14:59 -07:00
Steven Moreland
d73be1b96b libcutils: compile with BOARD_VNDK_VERSION current
- moved __android_log_is_debuggable to a new public header
    (log_properties.h)
- vendor version of sched_policy uses ALOG* instead SLOG*

Test: (sanity) liblog-unit-tests
Test: (sanity) libcutils_test (noting b/b/32972117, two tests continue
  to fail)
Test: system/core as a whole makes with BOARD_VNDK_VERSION := current
  now with no problems.
Test: boots/works on internal marlin
Bug: 33241851

(cherry picked from commit 1f83aa424f)

Merged-In: I5bc1f348dc0f0c8814bec5b5c3d2c52c825ab640
Change-Id: I5bc1f348dc0f0c8814bec5b5c3d2c52c825ab640
2017-04-17 14:44:17 -07:00
Josh Gao
e1dacfc1b6 adb: kill adb_thread_{create, join, detach, exit}.
We have std::thread now, so we can delete this cruft.

Test: python test_device.py
Test: adb_test
Test: wine adb_test.exe
Test: /data/nativetest/adbd_test/adbd_test
Change-Id: Ie1c1792547b20dec45e2a62ce6515fcb981c3ef8
2017-04-12 17:12:32 -07:00
Casey Dahlin
13a269ea24 Add mDNS device discovery for adb client
Test: Was able to discover a raspberry pi.
Bug: 28074466
(cherry picked from e292cd16760321fccc99c8c261cb92fa4b6462ab)

Change-Id: Id9571576457a4a0a078e48a274a4e8eac78bfe2b
2017-03-07 14:45:51 -08:00
Jerry Zhang
2f8c60b1cc adb: Set max socket sizes to larger values.
This improves performance of push/pull.

Test: adb push/pull multi GB files.
Bug: 31722483
Change-Id: Ia01574c3db6a740d7a7e64ba1f5bc1fc279fb3f6
2017-02-13 18:19:36 -08:00
Tao Bao
40e0ec918e adb: Fix the 'adb reboot sideload' for A/B devices.
We used to write the command file (/cache/recovery/command) to trigger
the sideload mode. A/B devices don't support that (may not have /cache
paritition). This CL switches to using libbootloader_message which
writes the command to BCB (bootloader control block) instead.

Test: "adb root && adb reboot sideload" reboots sailfish into recovery
      sideload mode.

Change-Id: I158fd7cbcfa9a5d0609f1f684a2d03675217628f
2017-01-05 18:01:01 -08:00
Mark Salyzyn
97787a00e6 adb: use __android_log_is_debuggable()
Test: compile and months of adb functionality use
Bug: 27566046
Bug: 31456426
Change-Id: I6568eea0eda8dc67dec2ba34cd4c3f56fb0ff0e9
2016-10-14 11:12:24 -07:00
Elliott Hughes
ffdec18017 Switch adb to <android-base/properties.h>.
Bug: http://b/23102347
Test: manual
Change-Id: Iffa66258c01f84f41b9af99ab5e768a0a2669106
2016-09-26 13:14:14 -07:00
Josh Gao
cfb21412e5 adb: factor out socket specification.
Move the logic for string socket specification out to separate
functions to facilitate using arbitrary sockets for the adb command
socket.

Bug: http://b/30445394
Change-Id: Icd8fdb853272edc029fb3a0f5b18e941dc8ef52c
Test: adb_test, adbd_test, test_device.py
2016-08-25 17:12:26 -07:00
Yabin Cui
643bc369ef Merge "adb: add reconnect command." 2016-04-16 01:50:54 +00:00
Josh Gao
86441c31fe adb: add support for 'wait-for-any'.
Allow waiting for a device in any state.

Bug: http://b/28168212
Change-Id: I1876ecd70089ca88f2da5de4182e13724ec50501
2016-04-13 12:28:04 -07:00
Yabin Cui
1f4ec19e49 adb: add reconnect command.
Add reconnect command for debugging. `reconnect` kicks a transport
from the host side, `reconnect device` kicks a transport from
the device side. They can be used to produce transport errors.

Bug: 25935458

Change-Id: I47daa338796b561941e7aba44a51a6dd117d1e98
2016-04-05 15:21:36 -07:00
David Pursell
bfd9503d1d adb: use TCP keepalive.
Currently adb only realizes a TCP transport has gone away when it tries
to send a packet, which caused problems in particular for `adb reboot`
since no packets are sent, leading to the client hanging until Ctrl+C.

This CL turns on TCP keepalive packets to send 1 packet every second,
allowing up to 10 failures before disconnecting. Using built-in TCP
functionality turns out to be much cleaner in this case than trying to
implement our own keepalive packets at the application layer, and
should be more lightweight since it's all done in the TCP stack.

Bug: http://b/23093474

Change-Id: Ifb41cbb85b9752a9f394e1eed3c6ac4da47a4e4d
2016-02-23 09:11:18 -08:00
Josh Gao
09855472f4 adb: detect when the client disconnects in wait-for-device.
Avoid leaking a thread and its associated resources when a user cancels
wait-for-device.

Bug: http://b/26966721
Bug: https://code.google.com/p/android/issues/detail?id=199088
Change-Id: Idac80a24e9739ddd24e500fe14826a78f350c018
2016-02-19 14:35:48 -08:00
Josh Gao
b5fea14e13 adb: make adb_thread_func_t return void, add adb_thread_exit.
Windows restricts the return value of threads to 32-bits, even on 64-bit
platforms. Since we don't actually return meaningful values from thread,
resolve this inconsistency with POSIX by making adb's thread abstraction
only take void functions.

Change-Id: I5c23b4432314f13bf16d606fd5e6b6b7b6ef98b5
2016-02-12 15:23:54 -08:00
David Pursell
706955ff0d base: add network address parsing function from adb.
This CL moves the network address parsing function from adb to libbase
so that it can be used by fastboot as well as adb.

libbase seemed like the right choice because:
  1. It already has some parsing functions (parseint)
  2. The net address parsing function uses the libbase string
     functions so we have a libbase dependency anyway.

The parsing function has been modified slightly to make the canonical
address optional, and debug logging on success has been removed.

For adb the only functional difference is that parsing a network
address will no longer print the result to the debug log, which seemed
unnecessary.

Bug: http://b/26236380
Change-Id: Ife6df02937225fc66de87884d3572d79c092c522
2016-01-21 20:03:33 -08:00
Leo Sartre
94e0776eb8 WA: Fix adb wait-for-device command
Without -s argument, adb wait-for-device will make a call to
acquire_one_transport() with sinfo->serial.c_str() == "".
Waiting for acquire_one_transport() to be reworked to use std::string
rather than const char * for serial, work around this by passing NULL
when sinfo->serial is not initialized in host_service_to_socket().

Change-Id: Ifef53e0e82850364f5029ee36560376f2a4a5104
Signed-off-by: Leo Sartre <leox.sartre@intel.com>
2016-01-05 12:13:24 +01:00
Leo Sartre
1fbc9dbd0f adb host: add device state in "adb wait-for-*"
The current implementation of the host commands "adb wait-for-*" allows
to specify only the transport layer (local, usb or any).
This patch allows the specification of the expected device state
(bootloader, recovery, device or sideload), this is usefull for
scripting purposes.

Use case:
$ adb reboot sideload-auto-reboot
$ adb wait-for-usb-sideload && adb sideload package.zip

Change-Id: I276a6be4d82f8b7901f74e1e5395b86d16548e8f
Signed-off-by: Leo Sartre <leox.sartre@intel.com>
2015-12-16 18:11:18 -08:00
Elliott Hughes
4f71319df0 Track rename of base/ to android-base/.
Change-Id: Idf9444fece4aa89c93e15640de59a91f6e758ccf
2015-12-04 22:00:26 -08:00
Elliott Hughes
18ddf5c6a2 Pass $TERM to the device.
Unfortunately, this isn't backwards-compatible with the current shell
protocol because we made unknown shell: arguments errors. We could try
to commit the change to make them just warnings first, but how would
we know when everyone was running adbd with that change? Bumping the
protocol version doesn't help because that only affects the code running
on the host. And although we could add another feature to the reported
features, since shell_v2 is still in development, that doesn't seem
worthwhile.

Bug: http://b/25601436
Change-Id: I12b81aa656cd25b91d14ef691dcbd2b7dab49535
2015-11-16 10:55:34 -08:00
Yabin Cui
fbfa84045d adb: run reverse_service() in main thread.
reverse_service() calls handle_forward_request(), which calls
functions in fdevent.cpp. fdevent functions is only supposed
to be called in the main thread.
Add check in fdevent.cpp to make sure all operations come from
main thread.

Bug: 25355808
Change-Id: Iceb9273f3056acc0713eaafe086ac950ca80ff4f
2015-11-02 10:39:09 -08:00
Elliott Hughes
8d28e191c5 Fix adb -d/-e error reporting.
If -d/-e fail, get-serialno and friends will now report an error
and return a failure status code on exit.

Also fix the behavior of -d/-e with $ANDROID_SERIAL --- -d/-e
should override $ANDROID_SERIAL, not the other way round.

I'm deleting my own comment here about always returning "unknown"
for scripts. I can't find any evidence that there are scripts
relying on that, so I think my comment meant "I fear that there
are scripts doing so".

Bug: http://b/24403699
Change-Id: Ie13a751f1137abcfe0cc6c46a0630ba5e02db676
2015-10-07 15:35:18 -07:00
David Pursell
70ef7b40f9 adb: put legacy shell: service back in.
ddmlib does not use the ADB client, but instead connects directly to
the adb server. This breaks some of the assumptions I previously made
when enabling the shell protocol.

To fix this, the adb server now defaults to no protocol for the
standalone command, and the shell protocol must be explicitly requested
by the client. For example:
  shell:echo foo     -- no shell protocol
  shell,v2:echo foo  -- shell protocol

As long as I was touching the shell service arguments I also changed
them to no longer duplicate the command-line arguments. This allows
more flexibility to change the adb client CLI if necessary and makes
the code more readable.

Bug: http://b/24148636
Change-Id: I28d5ae578cf18cbe79347dc89cea1750ff4571a8
2015-09-30 15:40:09 -07:00
Yabin Cui
aed3c61c44 Adb: use VLOG() to replace D() for verbose logging.
As there are too many D(), we can keep both VLOG() and D() now, and get
rid of D() gradually.

Change-Id: I2f1cb70bcab3e82c99fed939341d03f6b2216076
2015-09-23 12:53:38 -07:00
David Pursell
4e2fd36bc8 adb: add -Tt options to adb shell.
Adds -T (no PTY) and -t (force PTY) options to `adb shell` to mimic
ssh options. Small cleanup to send an entire FeatureSet to the adb
client at once to avoid multiple round-trips when querying multiple
features.

Known issue: humans using `adb shell -T` to start a non-PTY interactive
session may experience problems since neither side will have PTY
features like echoing or newline translation. This is probably OK for
now as the -Tt options are primarily useful for scripting.

Bug: http://b/23825231
Change-Id: I4d0df300db0abd1f7410bab59dd4d5b991babda7
2015-09-22 12:50:11 -07:00
David Pursell
0955c66b22 adb: implement shell protocol.
Adds functionality for handling stdin/stdout/stderr streams and exit
codes using the shell protocol.

This CL just contains implementation for adbd which will not yet be
enabled. Once we have the ability to query transport features from the
adb client, another CL will add the implementation for the client side
and update the feature list to turn this on.

Note: this CL must be submitted together with a minadbd CL to update
the service_to_fd() function signature.

Bug: http://b/23030641

Change-Id: Ibed55e9c1946d8a35190696163ff63e8fb880238
2015-09-11 11:27:50 -07:00
David Pursell
80f67029e0 adb: move shell service to a separate file.
Upcoming changes to the shell will require significant additions to
the subprocess code, and it will be cleaner if it's in a separate file.

The only functional change here is a new debug tag specifically for
the shell service. Everything else has been copied exactly as-is in
order to make it easier to determine what's changing in upcoming CLs.

Change-Id: I13bd4294059051ee10e0d0c6a06affd8eca62967
2015-09-04 08:52:35 -07:00
Yabin Cui
7a3f8d6691 adb: clean up debug tracing a little.
Always use LOG() for debug tracing.
Remove useless D_lock. I believe it is useless to lock just before and after fprintf.

I verified the log output both on host and on device. The output looks fine to me.

Change-Id: I96ccfe408ff56864361551afe9ad464d197ae104
2015-09-02 20:21:00 -07:00
Siva Velusamy
49ee7cf9a1 adb: set thread names (linux & mac)
Bug: 23423333
Change-Id: I0069f32ddbae2a10fb130064f721facf45b2cc09
2015-08-31 07:52:52 -07:00
Elliott Hughes
aa24549190 adb sync cleanup.
We can double the speed of "adb sync" (on N9) if we increase SYNC_DATA_MAX
from 64KiB to 256KiB. This change doesn't do that, because I still haven't
managed to plumb through the information about whether we're a new adb/adbd
to file_sync_client.cpp and file_sync_service.cpp. But this is already a big
change with a lot of cleanup, so let's do the cleanup and worry about the
intended change another day...

This change does improve performance somewhat by halving the number of
lstat(2) calls made on the client side, and ensuring that most packets are
sent with a single write. This has the pleasing result of making the null
sync on an AOSP N9 go from just over 300ms to around 100ms, which means it
now seems instantaneous (https://en.wikipedia.org/wiki/Mental_chronometry).

Change-Id: If9f6d4c1f93ec752b95f71211bbbb1c513045166
2015-08-24 11:15:01 -07:00