Commit graph

2654 commits

Author SHA1 Message Date
Josh Gao
6082e7dafb adb: add nonblocking fd Connection.
Implement a nonblocking version of FdConnection. The initial
implementation will be somewhat slower than the blocking one for large
packet sizes, due to an extra copy when coalescing an IOVector into an
apacket, but is still substantially faster for small packets.

Test: adb_benchmark
Change-Id: I4900c9ddf685d3bd557b8cb43958452ecb23db53
2018-06-12 17:04:34 -07:00
Treehugger Robot
ae74e42d25 Merge "Fix exit-time-destructor warning" 2018-06-06 23:28:07 +00:00
Pirama Arumuga Nainar
8b47d316d2 Fix exit-time-destructor warning
By initializing the global handle_list on the heap.

Test: Run Clang-built adb_test.exe under wine
Change-Id: I2326011b7e44c6d0cb4721d4b68fde7188b87c38
2018-06-06 14:41:26 -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
e82401e592 Merge "adb: really fix the mac build." 2018-05-25 05:59:58 +00:00
Josh Gao
6e1246c234 adb: really fix the mac build.
Test: changed `#if !defined(__APPLE__)` to `#if 0` and ran mma
Change-Id: I173cccbfb7bad348ac4796a2d6cebb8490f63479
2018-05-24 22:58:08 -07:00
Treehugger Robot
6c9bb058c5 Merge "Build adbd for recovery" 2018-05-25 05:58:01 +00:00
Josh Gao
99c27d3e99 adb: fix mac build.
Test: none
Change-Id: I93ff87338aa503588e36404f7566651e18f50292
2018-05-24 00:47:05 -07:00
Jiyong Park
a0e75045e6 Build adbd for recovery
adbd (and its dependencies) are marked as recovery_available:true so
that recovery version of the binary is built separately from the one for
system partition. This allows us to stop copying the system version to
the recovery partition and also opens up the way to enable shared
libraries in the recovery partition. Then we can also build adbd as a
dynamic executable.

Bug: 79146551
Test: m -j adbd.recovery
Change-Id: Ib95614c7435f9d0afc02a0c7d5ae1a94e439e32a
2018-05-24 14:11:11 +09:00
Josh Gao
fd3fd937b1 adb: add benchmark script.
Test: ./benchmark_device.py
Change-Id: I9f36cc267b1cbef2d90a30009c87ccc2a8e21795
2018-05-23 11:26:04 -07:00
Josh Gao
7c738cdb53 adb: add IOVector.
An IOVector is a collection of immutable reference counted blocks which
can have its head detached at an arbitrary index. This is extremely
useful for implementing packet-framed protocols like adb on top of a
stream protocol like TCP: a stream reader can read blocks, append them
to the end of the IOVector, and then pull packets off of the front.
This also lends itself naturally towards scatter/gather I/O, which will
enable us to read data from disk and send it across the wire with a
theoretical minimum number of copies in USB, and one extra copy over
TCP.

Since this is basically a generalization of std::deque<Range>, delete
Range and replace its uses with IOVector.

Test: adb_test
Test: wine adb_test.exe
Change-Id: I06561ad0bb25a3a51b378b61d257b5b04b41d9c4
2018-05-23 11:26:04 -07:00
Josh Gao
9da1a9118b Revert "Revert "adb: add support for O_CLOEXEC to unique_fd pipe wrapper.""
Implement pipe2 ourselves on darwin.

This reverts commit f139ba47a1.

Test: none!
Change-Id: I42c2a8d07712fe4ac75b5824f754e79a5b9f5cb4
2018-05-23 11:14:57 -07:00
Josh Gao
a2157a7d92 Merge "Revert "adb: add support for O_CLOEXEC to unique_fd pipe wrapper."" 2018-05-23 16:45:31 +00:00
Josh Gao
f139ba47a1 Revert "adb: add support for O_CLOEXEC to unique_fd pipe wrapper."
This reverts commit 948b3e1068.

Reason for revert: mac doesn't have pipe2

Change-Id: Id6a517bb500cbea602839f06452bc5e6d92289f1
2018-05-23 16:44:53 +00:00
Treehugger Robot
812a6b77c6 Merge "adb: add support for O_CLOEXEC to unique_fd pipe wrapper." 2018-05-23 00:17:32 +00:00
Josh Gao
7a223584c5 Merge changes I465804fd,Ib5a684bb,If5e66570,I8471cc00,I8ba0a70a
* changes:
  adb: convert fdevent over to unique_fd.
  adb: move towards using unique_fd.
  adb: delete FDEVENT_DONTCLOSE.
  adb: remove fdevent_install, fdevent_remove.
  adb: fix uninitialized variable in AsyncServiceRef.
2018-05-23 00:01:29 +00:00
Josh Gao
948b3e1068 adb: add support for O_CLOEXEC to unique_fd pipe wrapper.
Change-Id: I8fd22fe55db4d3dbcbb7318cf4a364eb07323ed0
2018-05-22 14:55:36 -07:00
Josh Gao
3b37fa256f adb: convert fdevent over to unique_fd.
This adds fdsan deallocation sanitization to all fds monitored by
fdevent, which is most of the ones in adb.

Bug: http://b/79786774
Test: python test_device.py
Change-Id: I465804fdb0fd0ac019445900a30ba3403f5bf711
2018-05-22 14:55:36 -07:00
Josh Gao
ae9c1dc44a adb: move towards using unique_fd.
Bug: http://b/79786774
Test: treehugger
Change-Id: Ib5a684bba88e87e1aad9da452dcdd5edd11f18f4
2018-05-22 14:55:36 -07:00
Josh Gao
e5353021ba adb: delete FDEVENT_DONTCLOSE.
The only existing usage of this doesn't actually need it.

Bug: http://b/79786774
Test: mma
Change-Id: If5e665705393e938cfdbf1526beb5496a8b99a9b
2018-05-22 14:55:36 -07:00
Josh Gao
71f775a944 adb: remove fdevent_install, fdevent_remove.
Remove fdevent_install and fdevent_remove in favor of using
fdevent_create and fdevent_destroy, so that we can put RAII types (i.e.
unique_fd) into fdevent without worrying about -Wexit-time-destructors
or structs that are freed instead of deleted.

Bug: http://b/79786774
Test: python test_device.py
Change-Id: I8471cc00574ed492fe1b196944976cdaae8b7cff
2018-05-22 14:54:49 -07:00
Treehugger Robot
2fa9770c3a Merge changes I4d6da40d,I91c7ced5,I7b9f6d18
* changes:
  adb: Add a test for emulator connection
  adb: Improve test_adb a bit more
  adb: Add a way to reconnect TCP transports
2018-05-21 22:37:21 +00:00
Treehugger Robot
93e4501611 Merge "adb: Retry io in case of interrupt" 2018-05-17 01:17:11 +00:00
Treehugger Robot
adf07c5428 Merge "adb: Move io_setup to usb_handle init" 2018-05-16 23:25:15 +00:00
Luis Hector Chavez
3255974169 adb: Add a test for emulator connection
This should prevent regressions in the future.

Bug: 78991667
Test: python system/core/adb/test_adb.py
Change-Id: I4d6da40da82c6d79797cec82ffaf071d4b56ddc7
2018-05-16 15:20:48 -07:00
Luis Hector Chavez
fbee0a9133 adb: Improve test_adb a bit more
This change:

* uses unittest.main(), which allows for a subset of the tests to be
  selected.
* drops the requirement to have a device already connected since all the
  tests that need a device now spin their own mock device.
* Splits the monolithic test class into more granular classes.
* Makes this file be pylint-compliant.

Bug: None
Test: python system/core/adb/test_adb.py
Test: pylint system/core/adb/test_adb.py
Change-Id: I91c7ced520c3c69f855d639e0dbf7e57bb690e97
2018-05-16 15:20:48 -07:00
Luis Hector Chavez
454bc7c0be adb: Add a way to reconnect TCP transports
This change adds a reconnect handler that tracks all TCP transports that
were connected at some point, but became disconnected. It does so by
attempting to reconnect every 10s for up to a minute.

Bug: 74411879
Test: system/core/adb/test_adb.py
Test: adb connect chromebook:22  # This runs with sslh
Test: CtsBootStatsTestCases
Test: emulator -show-kernel ; adb -s emulator-5554 shell

Change-Id: I7b9f6d181b71ccf5c26ff96c45d36aaf6409b992
2018-05-16 15:20:48 -07:00
Jerry Zhang
d8c1ae910f adb: Move io_setup to usb_handle init
Remove some redundancy by moving io_setup
into aio_block_init. The io_contexts will
now live till the end of the program, similar
to the rest of usb_handle

Test: adb works
Bug: 78793464
Change-Id: I910a39d4395645f1ff231f265c285a72893a0ac6
2018-05-16 21:47:11 +00:00
Jerry Zhang
5ba6802e9a adb: Retry io in case of interrupt
io_submit sleeps waiting for the gadget
to be enabled. Currently if that sleep
is interrupted it will shut down adb,
causing it to have to start back up again.

Rather than return EINTR if interrupted,
io_submit actually completes and the EINTR
is found later when looking through events.
Since an io that is interrupted will be
small anyway, add a loop to retry small ios.

Also upgrade aio logs in accordance with
their importance.

Fixes: 75981904
Test: adb works, logs show successful interrupt handling
Change-Id: I35973fce130ee849ce59fef80d15b65afb816ba4
(cherry picked from commit 6e9a327504)
2018-05-16 21:44:46 +00:00
David Anderson
570426aadd adb: warn on remount if undoing deduplication is impossible
A deduplicated filesystem might not have enough free space to undo its
block sharing. In this case "adb remount" should give a more precise
error message.

Bug: 64109868
Test: adb remount on deduplicated filesystem with no free space
Change-Id: I2beb67aa3dfc807cb8493b9c622e7b14174dc9c6
2018-05-16 14:18:59 -07:00
Josh Gao
2744084981 adb: fix uninitialized variable in AsyncServiceRef.
Bug: none
Test: treehugger
Change-Id: I8ba0a70a772f88bfd701730a48d4eb32c6677b9e
2018-05-15 23:43:50 -07:00
Treehugger Robot
da6ab73420 Merge "adb: fix double close in jdwp_service." 2018-05-15 01:52:29 +00:00
Josh Gao
b7a9956cbc adb: fix double close in jdwp_service.
Bug: http://b/78793027
Test: treehugger
Change-Id: Ie66d12e70bdaf09148e3d672e3c7c3da9e8ab2fe
2018-05-14 17:13:47 -07:00
Treehugger Robot
313aa7172f Merge "adb: better error messages on deduplicated filesystems." 2018-05-14 21:10:34 +00:00
David Anderson
a962ec0c73 adb: better error messages on deduplicated filesystems.
If BOARD_EXT4_SHARE_DUP_BLOCKS is true, "adb remount" will error saying
the filesystem is read-only. Instead, it will now list affected
partitions and explain why they can't be remounted.

Bug: 64109868
Test: adb remount with deduplicated system image
Change-Id: Ida737a6be8e9fe9ea26300897d82b1a149e72f6d
2018-05-11 13:20:31 -07:00
Josh Gao
c97cea0d20 Merge "adb: add authorizing, connecting states to transport." 2018-05-09 20:43:31 +00:00
android-build-prod (mdb)
53248e47f4 Merge "Documented adb install --instant" 2018-05-09 18:23:11 +00:00
Felipe Leme
807be77c25 Documented adb install --instant
Test: m -j32 adb && ./out/host/linux-x86/bin/adb help 2>&1 | grep instant
Bug: 79422318

Change-Id: I2830a9e3cf81becac1a6334670d8dc487fe72322
2018-05-09 09:33:38 -07:00
Dan Willemsen
3e41f92cf5 Remove unused tags property from Android.bp files
The tags property is (and has always been) unused by Soong. The property has
been defined as a list of strings, and the `androidmk` converted any
LOCAL_MODULE_TAGS entries over to it, but we've never done anything with it.

In preparation for removing the definition from Soong, I'm removing it from all
Android.bp files in the tree.

Since this has never done anything, this is a no-op, but if you really did want
the Android.mk behavior, the proper way to define a module to be installed in
userdebug / eng builds is to use PRODUCT_PACKAGES_DEBUG or PRODUCT_PACKAGES_ENG
in the appropriate product makefile.

Change-Id: Id519b2c0ec352e45c470a1734dfc633bbe39937e
Exempt-From-Owner-Approval: global no-op build change
Test: remove `tags` from Soong, see errors go away.
2018-05-08 17:15:23 -07:00
Josh Gao
704494b070 adb: add authorizing, connecting states to transport.
Add two states: connecting and authorizing, to disambiguate the offline
and unauthorized states, respectively.

Previously, devices would transition as follows:

  offline -> unauthorized -> offline -> online
  offline -> unauthorized (when actually unauthorized)

With this patch:

  connecting -> authorizing -> online
  connecting -> authorizing -> unauthorized (when actually unauthorized)

This allows test automation and the like to distinguish between offline
devices, unauthorized devices, and working devices without having to
do retry loops with arbitrary sleeps on their end.

Bug: http://b/79257434
Test: adb_test
Test: adbd_test
Test: manually plugging in a device with `while true; do adb shell echo foo; done`
Change-Id: I036d9b593b51a27a59ac3fc57da966fd52658567
2018-05-04 18:05:18 -07:00
Luis Hector Chavez
c587f02cc6 adb: Avoid waiting for emulator connections
This change exempts the emulator connections from
WaitableConnection.WaitForConnection(). This is because emulator
connections are a) more reliable and b) handled a bit differently than
normal TCP connections.

Bug: 78991667
Test: emulator -showkernel ; adb shell
Change-Id: I552946198889a82d6c265f45e8c3b38f6ac9d045
2018-05-01 17:12:16 -07:00
Elliott Hughes
4e6f3d9603 Merge "Add test_suites lines." 2018-04-28 16:02:40 +00:00
Elliott Hughes
40fdf3f4ab Add test_suites lines.
Bug: N/A
Test: builds
Change-Id: Ic5e2b9206bcfcb53c774989013b5db6aab462e42
2018-04-27 16:12:06 -07:00
Luis Hector Chavez
9a388d5387 adb: Make the Connection object a std::shared_ptr
This change is in preparation to allow the TCP-based transports to be
able to reconnect. This is needed because multiple threads can access
the Connection object. It used to be safe to do because one instance of
atransport would have the same Connection instance throughout its
lifetime, but now it is possible to replace the Connection instance,
which could cause threads that were attempting to Write to an
atransport* to use-after-free the Connection instance.

Bug: 74411879
Test: system/core/adb/test_adb.py
Change-Id: I4f092be11b2095088a9a9de2c0386086814d37ce
2018-04-26 13:53:35 -07:00
Luis Hector Chavez
56fe753070 adb: Add a way to distinguish between connection failures and successes
This change adds a callback that is invoked exactly once, either when
the connection is fully established (i.e. CNXN packets have been sent
and received) or the atransport object is deleted before that (because
the connection failed).

This helps in distinguishing between successful and failing connections
for TCP. Especially when there is some kind of port
forwarding/multiplexing in between (like an SSH tunnel or SSLH proxy).

Bug: 74411879
Test: adb connect chromebook:22 (which runs an sslh tunnel to adbd).
      either succeeds or fails, but not fake-succeeds.

Change-Id: I7e826c6f5d4c30338a03b2d376a857ac5d05672a
2018-04-26 13:53:35 -07:00
Treehugger Robot
c4ad6b6adc Merge changes I722d2c41,Ic216ddef
* changes:
  Improve test_adb.py
  adb: Distinguish betwen already-connected and connection failure
2018-04-20 02:13:09 +00:00
Treehugger Robot
224d965be0 Merge "adb: don't error in handle_host_request if we can't acquire a transport." 2018-04-19 21:40:57 +00:00
Josh Gao
78f133d7d4 adb: don't error in handle_host_request if we can't acquire a transport.
Host services are attempted after handle_host_request, which means that
failing to find a transport to give to handle_forward_request shouldn't
send an error over to the other end.

Bug: http://b/78294734
Test: `adb track-devices` with multiple devices connected
Change-Id: I46c89cc1894b51d48fea7d4e629b1d57f73e3fd6
2018-04-19 13:09:18 -07:00
Luis Hector Chavez
8b67c52099 Improve test_adb.py
This change uses a context manager to create the fake ADB servers (and
cleanly tear them down.

Bug: 74411879
Test: python system/core/adb/test_adb.py

Change-Id: I722d2c4135259b1b0ef00a1510aa8402e87ecf72
2018-04-17 21:49:43 -07:00
Luis Hector Chavez
5d39585255 adb: Distinguish betwen already-connected and connection failure
This change returns a different value (-EALREADY) when a connection has
already been established, as opposed to a real connection failure (which
still returns -1).

Bug: 74411879
Test: Opened a socket, tried to adb connect to it,
      got "failed to connect to localhost:1337"

Change-Id: Ic216ddef7f28eb43ca750f9e51d068c077d54b07
2018-04-17 14:36:33 -07:00