Commit graph

2561 commits

Author SHA1 Message Date
Josh Gao
184f480547 adb: don't immediately close a socket when write fails.
When we fail to write to a local socket peer, we might still have data
queued up to send to the other side. Defer closing the socket until
we've failed to both read and write.

Bug: http://b/74616284
Test: python test_device.py
Change-Id: Ifc4b8fe95369b4872e475c2ae4ee611dd2d8b9d7
2018-03-21 15:13:07 -07:00
Josh Gao
1222abc75b adb: make fdevent_run_on_main_thread's fd nonblocking.
If we get a ton of fdevent_run_on_main_thread calls while running one
of the handlers, the socket might become full, which will result in a
deadlock in fdevent_run_on_main_thread when a write to the fd blocks
with the mutex taken. Resolve this by making the fd nonblocking, which
is safe because we always write after appending to the list, and read
before emptying the list, which guarantees that if the byte we write is
consumed, the std::function we appended will be run.

Bug: http://b/74616284
Test: adb_test
Test: python test_device.py
Change-Id: I29319bda2ad7b5a5cdcd91d1d0ddf39f7ab7d115
2018-03-20 13:23:06 -07:00
Josh Gao
7920502065 Merge changes I6a842960,If618c26b
* changes:
  adb: add `adb shell exit 42` stress test.
  adb: improve socket tests.
2018-03-20 07:19:01 +00:00
Josh Gao
4abb5074be adb: skip IPv6 test if IPv6 isn't available.
Bug: http://b/69813298
Test: none
Change-Id: I0793e793bd52c5f1c639faedf09a513df263db78
2018-03-19 18:19:47 -07:00
Josh Gao
c970aefada adb: add adb shell exit 42 stress test.
Add a test to hammer on `adb shell exit $n` for flakiness.

Bug: http://b/74616284
Test: python test_device.py
Change-Id: I6a842960f5b55ff739044698f5c9683992fc42f1
2018-03-19 16:14:53 -07:00
Josh Gao
ecb96ac04d adb: improve socket tests.
Make it so that the socket tests don't leak until your machine blows up
by switching an infinite loop into an assertion failure.

Bug: http://b/74616284
Test: adb_test
Change-Id: If618c26b224b660548454f542cab79bebe46f80e
2018-03-19 16:14:53 -07:00
Treehugger Robot
6156420fb7 Merge changes I99b85f07,If28f6c8d
* changes:
  adb: implement std::make_unique, start using it.
  base: export GetThreadId.
2018-03-19 20:14:33 +00:00
Josh Gao
31b5be69f4 adb: implement std::make_unique, start using it.
Add an implementation of std::make_unique for Windows, where we're
currently stuck with C++11, and switch some uses of new over to it.

Test: treehugger
Change-Id: I99b85f07754adda7c525243480c3e0bce9a25ce7
2018-03-16 15:35:52 -07:00
Josh Gao
5791e21697 base: export GetThreadId.
and stop using the incorrect (on Mac) version in adb..

Test: mma
Change-Id: If28f6c8d73b03db863be13ed88df81422c3aef87
2018-03-16 15:35:52 -07:00
Jerry Zhang
99499f1740 adb: Remove usages of ENDPOINT_ALLOC
All devices that previously used ENDPOINT_ALLOC
are on the new async io routines. None of the devices
using aio_compat have ENDPOINT_ALLOC so remove the
code to stop logging failures.

Fixes: 74213465
Test: adb works
Change-Id: I0c903eb76b006b6bcce48cec24f5353fa47cc128
(cherry picked from commit 9a1be3ad0e)
2018-03-16 15:33:26 -07:00
Josh Gao
32caa9870f Merge "adb: add test for flushing socket data after a write failure." 2018-03-16 22:18:43 +00:00
Josh Gao
df3bae9f06 adb: add test for flushing socket data after a write failure.
Add a currently failing test that's a reduced case of the 'concurrent
adb shell' flakiness reported in b/74616284.

Bug: http://b/74616284
Test: changed #if 0 to #if 1, test fails
Change-Id: Id170a185f7c5d2ff44f772f7849a73227f9df441
2018-03-15 15:33:01 -07:00
Bowgo Tsai
8cc9c3835a adb: checks device state when using adb disable-verity for AVB
adb disable-verity will toggle a flag in /vbmeta and introduce AVB
verification error on next boot. If the device is LOCKED, it will make
the device unbootable because verification error isn't allowed when the
device is locked.

Also indicating 'adb root' when failed to get verity state.

Bug: 70969453
Test: adb disable-verity should pop-up warning if the device is locked.

Change-Id: I1ed705e34334ea2231c96b16ddb8d225067af2f0
2018-03-15 18:34:42 +08:00
Josh Gao
6eda1840cb adbd: don't require authentication for userdebug/eng builds.
By default, the build system only sets ro.adb.secure (to 1) when
building user builds.

Bug: http://b/73993211
Bug: http://b/74059119
Test: treehugger
Change-Id: I2a683257c1027394ded90c8d2634def6003e0525
2018-03-06 13:37:45 -08:00
Josh Gao
8db99f810d adbd: make static.
adbd is copied into the recovery image without the accompanying
linker/libraries, so it must be a static executable.

Bug: http://b/74237641
Test: `file $ANDROID_PRODUCT_OUT/system/bin/adbd`
Change-Id: Ie8d0710f6002458519d3eea3d696e9016faafee8
2018-03-06 13:01:34 -08:00
Jerry Zhang
5180d5b4dc Merge "Make libasyncio headers usable from C" 2018-03-06 19:35:21 +00:00
Josh Gao
9ee373ac2c Merge changes from topic "adb_bp"
* changes:
  adb: remove meaningless const.
  adb: convert Connection to a nonblocking interface.
  adb: use soong version stamping.
  adb: switch over to Android.bp.
2018-03-05 23:45:27 +00:00
Josh Gao
ffbd3364a4 adb: remove meaningless const.
Returning a const value is pointless.

Test: mma
Change-Id: Ia578d75345361d53e4a29bb9724bfcc161b8d8be
2018-03-05 13:00:28 -08:00
Josh Gao
0bbf69cbbf adb: convert Connection to a nonblocking interface.
Rename the existing Connection to BlockingConnection, add a nonblocking
Connection, and add an adapter between the two, to enable future work
to reduce the impedance mismatch from implementing a blocking interface
on top of nonblocking primitives.

While we're here, delete A_SYNC, and remove one layer of pipes when
sending a packet (replacing it with a condition variable when using
BlockingConnectionAdapter).

Test: python test_device.py, manually plugging/unplugging devices
Change-Id: Ieac2bf937471d9d494075575f07e53b589aba20a
2018-03-05 13:00:28 -08:00
Josh Gao
c7567fa52e adb: use soong version stamping.
Bug: http://b/71719137
Test: adb version
Change-Id: Ic735814574c83a7c2b8bef213592d494f5ec3860
2018-03-05 13:00:08 -08:00
Jerry Zhang
c3d4e7226a Make libasyncio headers usable from C
This allows us to enable LTP tests
for io_* syscalls.

Bug: 31152298
Test: LTP tests pass
Change-Id: Ic25189d8bf25cdacfa0f144ac57c7b2827adcd9f
2018-03-02 16:28:15 -08:00
George Burgess IV
657db00e3d Add a NOLINT for the memory leak we added
Added by I7255d45335fa009dc9e5de99dff67af52bd70e06

Bug: None
Test: Ran the analyzer. Complaint is gone.
Change-Id: Id9b8debd8b9690210f5a8e19154ee3a5095b8fbd
2018-03-01 18:59:50 +00:00
Josh Gao
2776845aa5 adb: switch over to Android.bp.
Rearrange some files while we're doing this.

Bug: http://b/71721338
Test: manually ran adb on windows
Change-Id: Ie47bda82279e4b9521505ad0353bf9ef649fc7d7
2018-02-28 15:29:50 -08:00
Josh Gao
e2176118f4 adb: add a way to make the server intentionally leak.
Add a way to test LeakSanitizer with the server by adding an
environment variable that intentionally leaks.

Test: ASAN_OPTIONS=detect_leaks=1:leak_check_at_exit=1 ADB_LEAK=1 adb server nodaemon
Change-Id: I7255d45335fa009dc9e5de99dff67af52bd70e06
2018-02-28 14:16:14 -08:00
Treehugger Robot
d24c8484c8 Merge "Change the remount command to be more container-friendly" 2018-02-28 16:48:37 +00:00
Josh Gao
e39ccd3cbd adb: allow reentrant calls to fdevent_run_on_main_thread.
Previously, reentrant calls to fdevent_run_on_main_thread would
deadlock.

Test: adb_test on host
Change-Id: I0783be0558dcaf61ddbe76d13ac6917fc2de0be0
2018-02-27 14:50:07 -08:00
Josh Gao
d51c6df1ef adb: stop using quick_exit.
We don't actually need to use quick_exit to avoid calling static
destructors, since we have -Wexit-time-destructors to guarantee we
don't actually have any, and this precludes the use of asan's exit time
leak checking, so switch back to atexit/exit.

Test: ASAN_OPTIONS=detect_leaks=1:leak_check_at_exit=1 adb server nodaemon with a manually inserted leak
Change-Id: Id8178913f64cb02c820c5073351369a9e4d8c74d
2018-02-27 14:50:07 -08:00
Luis Hector Chavez
0db4b7a95b Change the remount command to be more container-friendly
Passing in MS_REMOUNT | MS_BIND tells the kernel to only remove the
MS_RDONLY flag and keep all the other flags the same. This is also the
only kind of remount that is allowed in Linux containers (to be more
precise, within user namespaces).

This change also attempts to always run the remount command when dealing
with /, since containers will almost always run a loop device, and since
the number of the device changes, it is not convenient to put it in the
fstab. Plus, the container won't have permission to modify it, but might
be able to perform the remount.

Bug: 72178046
Test: `adb remount` works in both sailfish and Chrome OS
Change-Id: I9e8ec8afcd57f67875a312824667768b3aa89faa
2018-02-27 14:37:26 -08:00
Josh Gao
f571fcbe87 adb: switch apacket over to a std::string payload.
Test: python test_device.py with walleye/x86_64 emulator
Change-Id: I0a18941af1cb2279e5019a24ace25741def1202f
2018-02-21 14:30:17 -08:00
Treehugger Robot
0609e8d231 Merge "bpfmt." 2018-02-20 02:02:59 +00: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
Elliott Hughes
dc699a269f bpfmt.
Bug: N/A
Test: builds
Change-Id: I89ad00e1c4c7e0767bc80a7ac7935a4d55e090ac
2018-02-16 17:58:14 -08:00
Treehugger Robot
d31df3a1be Merge "adbd: receive jdwp pids from art as raw integers." 2018-02-13 23:34:49 +00:00
Josh Gao
1b58bbf2ef adb: fix build breakage.
Test: mma
Change-Id: Id8e7ffd2212449bbac5b64b50e7b3aef7e97d649
2018-02-12 18:03:49 -08:00
Josh Gao
e0361d1e90 adb: use delete on objects with destructors.
asocket has a destructor now, so we have to delete it, or leak the
data pointed to by its std::string.

Bug: http://b/73257049
Test: manual testing with asan
Change-Id: Ia88199292cc74e10032a9a16226d3afc61c3e0be
2018-02-12 17:31:39 -08:00
Josh Gao
86f39b4078 adbd: receive jdwp pids from art as raw integers.
Don't go through a pointless conversion to hex that reduces our maximum
pid to 64k.

Bug: http://b/17661822
Test: `adb jdwp`
Change-Id: Idd572eac827f3ed3825ac2cf55fc4db109e70854
2018-02-12 15:07:28 -08:00
Josh Gao
9bf624cd3a Merge "adb: switch asocket::enqueue to std::string." 2018-02-08 01:06:22 +00:00
Josh Gao
f99711fe87 Merge changes I86bcfaaa,I24d7f5d0
* changes:
  adb: restore packet data length checks.
  adb: switch asocket's intrusive linked list to vectors.
2018-02-08 00:34:40 +00:00
Josh Gao
95c4497bd4 adb: don't spew to logcat when tracing is enabled.
When persist.adb.trace_mask is used to enable verbose logging, avoid
exponential logging when a user runs `adb logcat`. As a side-effect,
set the minimum logging level to include everything when ADB_TRACE is
used on the client (which is something we want anyway).

Bug: http://b/72971016
Test: `adb shell 'setprop persist.adb.trace_mask; killall adbd'; adb logcat`
Change-Id: Id4bca1f3933a920345499dbeaeb103c8a2e220cd
2018-02-06 15:55:06 -08:00
Josh Gao
27cb7dca77 adb: switch asocket::enqueue to std::string.
Switch asocket over to taking a std::string instead of apacket* for
data. This allows us to remove asocket specific fields from apacket*.

Test: python test_device.py with x86_64 emulator, walleye
Test: adb_test on host
Change-Id: I9d157ff331a75ba49a54fdd4194e3f6cdff722f4
2018-02-06 12:59:06 -08:00
Josh Gao
5caaebdc3d adb: restore packet data length checks.
These checks were moved to after the read of the payload, which is too
late. Add a check before each read to avoid a heap buffer overflow.

Test: python test_device.py with x86_64 emulator, walleye
Change-Id: I86bcfaaa9004951cc52ad89af74680cf748e717d
2018-02-06 12:59:06 -08:00
Josh Gao
5e5076404a adb: switch asocket's intrusive linked list to vectors.
Test: python test_device.py
Change-Id: I24d7f5d0401de77d80c7a2dd5a7dcb551943342d
2018-02-06 12:59:06 -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
fb413a2304 adb: fix a leak.
Test: none
Change-Id: I469bd93180cd2a8b6408f73e8c8f164f72b3345c
2018-01-30 13:32:38 -08:00
Treehugger Robot
ef213b6d5b Merge "adb/fastboot: switch over to shared AdbWinApi." 2018-01-09 19:49:23 +00:00
Josh Gao
b0449da977 adb/fastboot: switch over to shared AdbWinApi.
Bug: http://b/71721338
Test: manually ran adb/fastboot on windows
Change-Id: I9fee6ea4c0e07cbeb69a48e456161832a5994e7b
2018-01-08 16:45:30 -08:00
Elliott Hughes
18cdd3502a Merge "Sort devices list before output." 2018-01-08 22:11:23 +00:00
Mike Frysinger
50ecaca744 adb: add missing condition_variable include
Test: build still works
Change-Id: I0e77336bab2a4a54cb2e77143162627d47aac0b1
2018-01-02 02:25:02 -05:00
Elliott Hughes
579e682628 Add std::string StartsWith*/EndsWith* overloads.
We should have done this from the beginning. Thanks to Windows, we're not
going to be able to switch libbase over to std::string_view any time soon.

Bug: N/A
Test: ran tests
Change-Id: Iff2f56986e39de53f3ac484415378af17dacf26b
2017-12-20 09:42:22 -08:00
Artem Iglikov
04398a9b23 Sort devices list before output.
Makes copy of the transport list and sorts it by type and serial before
printing.

Bug: 70748433
Test: adb devices displays all connected devices
Change-Id: I917728a102972f2f38f2e370a0c6011c1eb883c7
2017-12-19 09:22:53 +00:00