Commit graph

2577 commits

Author SHA1 Message Date
Josh Gao
09b309807f Merge "adb: fix double close in jdwp_service." into pi-dev 2018-05-15 04:50:43 +00:00
Josh Gao
d88f3b6964 adb: fix double close in jdwp_service.
Bug: http://b/78793027
Test: treehugger
Change-Id: Ie66d12e70bdaf09148e3d672e3c7c3da9e8ab2fe
(cherry picked from commit b7a9956cbc)
2018-05-14 17:36:45 -07:00
Felipe Leme
95c5b7f358 Documented adb install --instant
Test: m -j32 adb && ./out/host/linux-x86/bin/adb help 2>&1 | grep instant
Bug: 79422318

Change-Id: I2830a9e3cf81becac1a6334670d8dc487fe72322
    (cherry picked from commit 807be77c25)
2018-05-09 09:42:55 -07:00
Josh Gao
05e5bc1b17 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
(cherry picked from commit 78f133d7d4)
2018-04-19 13:29:59 -07:00
Josh Gao
a98aab2a72 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
(cherry picked from commit 44899eeb53)
2018-04-13 17:47:42 -07:00
Josh Gao
217b8fcf86 adbd: increase oom_score_adj for adb shell
Previously, processes started via `adb shell` have an oom_score_adj of
-1000, making them invisible to the oom killer. This makes running a
process that consumes all memory (e.g. by leaking in a loop) lead to
the entire rest of the system (including adbd, because of bad
heuristics in the kernel) being oom killed before getting to it.

Bug: http://b/63143027
Test: `adb shell cat /proc/self/oom_score_adj` with adb root
Change-Id: I59111134e36dc271adf4c1dd4bd4400d4fe6aee0
(cherry picked from commit 2de2ade387)
2018-04-13 15:47:53 -07:00
Josh Gao
2e05dfa2f2 adb: properly calculate packet size on Mac.
OS X reports maxPacketSize as wMaxPacketSize * (bMaxBurst + 1) in the
deprecated GetPipeProperties function. Use the also-deprecated
GetPipePropetiesV2 API to get bMaxBurst and figure out what
wMaxPacketSize is. (This file is going to go away eventually, so don't
bother with switching to the recommended GetPipePropertiesV3, since
it would be a substantially larger charge.)

libusb is unaffected.

Bug: http://b/77733422
Test: python test_device.py
Change-Id: I66517d699a4f39b93ba5eb7882bd8ee6c70f3672
(cherry picked from commit 2ea46521f3)
2018-04-11 11:44:26 -07:00
Elliott Hughes
6d2f2135ee Merge "Support /odm and /product in "adb remount" and "adb sync"." into pi-dev 2018-04-09 15:41:00 +00:00
Luis Hector Chavez
2685c77c34 adb: Correctly drop caps when ambient capabilities are used
This change splits the capability-dropping step of adbd into two. This
is more robust when ambient capabilities are being used, since minijail
cannot currently handle that case.

Bug: 77146512
Test: grep Cap /proc/`pidof adbd`/status
      CapInh: 0000000000000000
      CapPrm: 0000000000000000
      CapEff: 0000000000000000
      CapBnd: 00000000000000c0
      CapAmb: 0000000000000000

Change-Id: I0476a8d80f7a2497600196932542045f3bc87537
Merged-In: I0476a8d80f7a2497600196932542045f3bc87537
(cherry picked from commit daacf4f6f3)
2018-04-06 06:40:14 -07:00
Elliott Hughes
792581f183 Support /odm and /product in "adb remount" and "adb sync".
Bug: http://b/77587036
Test: `adb remount` and `adb sync` still work on hikey

(cherry picked from commit 57e97cb7aa)

Change-Id: Ie49d703dac04e2fb8eda420b9253b8d45b6e1479
2018-04-05 19:45:27 -07:00
Josh Gao
83ebd8da84 adb: fix windows test build.
The switch over to soong unintentionally turned off building the
Windows tests (and there's a bug preventing them from being turned on).
Preemptively fix the build breakages that'll happen when we turn them
back on.

Bug: http://b/74616284
Test: mma with Android.bp 's/cc_test_host/cc_binary_host' hacks
Change-Id: I6582cfc61b96052537d50d8ba90533dbb66e3e1d
(cherry picked from commit 2e1e789e2a)
2018-03-28 23:36:38 -07:00
Josh Gao
abb634308f adb: bump the local socket backlog to the maximum.
The listen backlog seems to be more meaningful on Darwin than on Linux,
resulting in connections failing with ECONNRESET. Bump it up to the
maximum supported value to make this less likely. 128 pending
connections ought to be enough for anybody.

Bug: http://b/74616284
Test: python test_device.py
Change-Id: I5fe0205924188cf18ca1fc1204f923ab5523eeb2
(cherry picked from commit bf243a6128)
2018-03-28 23:36:34 -07:00
Josh Gao
cc9414eda4 adb: delete vestigial SHELL_EXIT_NOTIFY_FD.
There exists no path through which a value other than -1 can be written
to the SHELL_EXIT_NOTIFY_FD.

Bug: http://b/74616284
Test: adb_test
Test: adbd_test
Test: python test_device.py
Change-Id: I0630c302ba06bc76917f0445aea75d2dbe1dc865
(cherry picked from commit dcc055af64)
2018-03-28 23:36:32 -07:00
Josh Gao
7c87b0739a 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
(cherry picked from commit 184f480547)
2018-03-28 23:36:28 -07:00
Josh Gao
3b0146cc37 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
(cherry picked from commit 1222abc75b)
2018-03-28 23:36:24 -07:00
Josh Gao
9edb94fb6b adb: skip IPv6 test if IPv6 isn't available.
Bug: http://b/69813298
Test: none
Change-Id: I0793e793bd52c5f1c639faedf09a513df263db78
(cherry picked from commit 4abb5074be)
2018-03-28 23:36:20 -07:00
Josh Gao
fd6ffb8ad5 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
(cherry picked from commit c970aefada)
2018-03-28 23:36:17 -07:00
Josh Gao
e523e4e54b 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
(cherry picked from commit ecb96ac04d)
2018-03-28 23:36:14 -07:00
Josh Gao
28589bbe18 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.

Bug: http://b/74616284
Test: treehugger
Change-Id: I99b85f07754adda7c525243480c3e0bce9a25ce7
(cherry picked from commit 31b5be69f4)
2018-03-28 23:36:12 -07:00
Josh Gao
1430d39be6 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
(cherry picked from commit df3bae9f06)
2018-03-28 23:36:09 -07:00
Jerry Zhang
6e9a327504 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
2018-03-23 00:11:05 +00:00
Bowgo Tsai
45a00fdcce 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
Merged-In: I1ed705e34334ea2231c96b16ddb8d225067af2f0
(cherry picked from commit 8cc9c3835a)
2018-03-16 15:06:23 +08:00
Jerry Zhang
9a1be3ad0e 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
2018-03-14 22:11:59 +00:00
George Burgess IV
a712e2164a Merge "Add a NOLINT for the memory leak we added" am: 10f62351eb am: 4e3ae2cbfa
am: ad4025b35b

Change-Id: I1d4831bc70b8874e66583f4a130b3a711c24b019
2018-03-01 22:19:41 +00: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
0e459e1d47 Merge "adb: add a way to make the server intentionally leak." am: 1ac7150590 am: 9ba182e3bb
am: 399c3591f2

Change-Id: Ifa340ad4f3ce53786391722a7d4f8b97816dfd20
2018-02-28 23:16:34 +00: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
Luis Hector Chavez
b14ce54176 Merge "Change the remount command to be more container-friendly" am: d24c8484c8 am: 677288c80a
am: d12cf88945

Change-Id: Ie9986fe8723ed34ecc787deb72bd75c89f1e8554
2018-02-28 17:12:31 +00:00
Treehugger Robot
d24c8484c8 Merge "Change the remount command to be more container-friendly" 2018-02-28 16:48:37 +00:00
Josh Gao
a085c9f826 Merge changes I0783be05,Id8178913 am: 09d5e258ef am: 2c1b3e9761
am: d8b711e16b

Change-Id: Ifa679ee1857fddf693f9e9b994bb4d9dff3f6c8a
2018-02-28 02:07:21 +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
0a3726a113 Merge "adb: switch apacket over to a std::string payload." am: 581a4ceb00 am: 4d74066425
am: ea9359a957

Change-Id: Ib9b1f7c9c3e59e3cfd3ea492360703d2b7a68119
2018-02-24 01:10:36 +00: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
Elliott Hughes
4c33b88c4b Merge "bpfmt." am: 0609e8d231 am: b57755c429
am: a91867a788

Change-Id: Ieb0985434e2464e47b3adb93fb27fe5042e91657
2018-02-20 02:24:45 +00:00
Treehugger Robot
0609e8d231 Merge "bpfmt." 2018-02-20 02:02:59 +00:00
George Burgess IV
54abd1d82f Merge "Fix a memory leak" am: cb1b68f9b3 am: 894337ee0b
am: 2a7d34014a

Change-Id: I2b763775555659f77e969f1d4d5bc73363afc53b
2018-02-19 11:02:02 +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
Josh Gao
d8e298a3ac Merge "adbd: receive jdwp pids from art as raw integers." am: d31df3a1be am: f6a2296aff
am: 33bedcde5b

Change-Id: I8317d035fe4d65e06bcd849b64654419c051c021
2018-02-14 00:06:17 +00:00
Treehugger Robot
d31df3a1be Merge "adbd: receive jdwp pids from art as raw integers." 2018-02-13 23:34:49 +00:00
Josh Gao
483046d952 Merge "adb: fix build breakage." am: 14d7cdce51 am: a4c4ef463b
am: 07de47eeb3

Change-Id: I935612655924b3263883e0f4bfdba2bdbd9d5386
2018-02-13 08:50:37 +00:00
Josh Gao
69b86a24a4 Merge "adb: use delete on objects with destructors." am: e504360f3d am: 854879ecdc
am: 84cd5de121

Change-Id: I33b77e3daef7e7778cce6b05a36b9710f6209af5
2018-02-13 08:44:58 +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
8d220bb0cd Merge "adb: switch asocket::enqueue to std::string." am: 9bf624cd3a am: e523a6c94f
am: 16bbf3b4cd

Change-Id: Ie46218fe0fff30999f1ca40c509bb7e27fe2cb42
2018-02-08 05:37:19 +00:00
Josh Gao
e75f43461d Merge changes I86bcfaaa,I24d7f5d0 am: f99711fe87 am: 157c2fa504
am: d3f70d4a83

Change-Id: Iafc3ec17d90251d1f120c34f27f5c17041f6f882
2018-02-08 05:10:22 +00:00
Josh Gao
9bf624cd3a Merge "adb: switch asocket::enqueue to std::string." 2018-02-08 01:06:22 +00:00