Commit graph

268 commits

Author SHA1 Message Date
Josh Gao
3828ebcdd8 adb: report error in copy_to_file.
Previously, if we failed to read a file after successfully opening it,
(e.g. because it's a directory), we would return prematurely without
notifying our caller, which would then wait forever for a response that
isn't coming.

Switch all of the adb install callsites over to checking the result,
but leave the other callsites ignoring the result, because they're
either deprecated, or don't care.

Bug: http://b/145621968
Test: mkdir foo.apk; adb install foo.apk
Change-Id: Ia82f8280b144f7881e067a10cd17f9a89019cf3f
2020-02-04 13:47:57 -08:00
Elliott Hughes
00ff8d7021 adb: make the push summary fit in 80 columns.
Elide $ANDROID_PRODUCT_OUT for a large saving:

  /data/: 2 files pushed. 734 files skipped. 6.5 MB/s (830776 bytes in 0.122s)
  /product/: 0 files pushed. 357 files skipped.
  /system/: 7 files pushed. 2638 files s...d. 16.3 MB/s (3785511 bytes in 0.221s)
  /system_ext/: 1 file pushed. 90 files ...d. 13.2 MB/s (1152016 bytes in 0.084s)
  /vendor/: 0 files pushed. 200 files skipped.

And drop the repeated "files" when talking about how many were skipped
for a small saving:

  /data/: 2 files pushed, 734 skipped. 6.4 MB/s (830776 bytes in 0.124s)
  /product/: 0 files pushed, 357 skipped.
  /system/: 7 files pushed, 2638 skipped. 13.8 MB/s (3785511 bytes in 0.262s)
  /system_ext/: 1 file pushed, 90 skipped. 12.2 MB/s (1152016 bytes in 0.090s)
  /vendor/: 0 files pushed, 200 skipped.

Bug: http://b/131717844
Test: adb sync
Change-Id: I9d24df49498211bc2b8dcebcc6d8bd557da214c1
2020-01-27 10:05:36 -08:00
Junyong Sun
1ffccf5c8b adb: windows: fix adb execute root cmd with no tips
fwrite can cross windows platform to show log on terminal,
so we use it instead of WriteFdExactly.

Change-Id: I252c15a0bc72e1dbd98b7b5ec8000ecdcde16416
Signed-off-by: Junyong Sun <sunjy516@gmail.com>
2020-01-17 09:39:21 +08:00
Treehugger Robot
f5a329f1a4 Merge "adb: fix adb connect help typo." 2020-01-09 04:34:27 +00:00
Josh Gao
9e75634082 adb: avoid consuming input in adb remount.
Bug: https://issuetracker.google.com/146163747
Test: dd if=/dev/zero bs=1024 count=1 | (adb remount; wc)
Change-Id: I700090cd0bbae2d76569008f3c1a116336951c0a
2020-01-08 12:43:34 -08:00
Elliott Hughes
65474fd78c adb: fix adb connect help typo.
Bug: http://b/130380645
Test: adb connect
Change-Id: I04205ff0120bcfd865dc5fa95846694d0ff6de80
2020-01-08 10:02:43 -08:00
Treehugger Robot
90e9217aca Merge "Enable "localfilesystem" UNIX domain socket for ADB." 2019-12-18 05:34:30 +00:00
Elliott Hughes
dfe6c84709 adb: improve help for -t/-tt.
Test: adb help
Change-Id: Ic75bf184dfc51e57b422666d85e3b7a5139b3853
2019-12-13 16:43:10 -08:00
Josh Gao
f4ddee0f32 Merge changes I6ff85723,Ia7d743d5
* changes:
  adb: add ls_v2.
  adb: rename syncmsg::*::time to mtime.
2019-12-12 01:39:20 +00:00
Daniel Colascione
3ec7be7a84 Revert "Revert "Support socket activation of adb server""
Test: actually build both device and client adb this time

This reverts commit c77904e3c5.

Change-Id: I8c2b8f24884ff36ff2460dab2500bad777100dfd
2019-12-11 08:20:20 +00:00
Jason Jeremy Iman
8bde191202 Enable "localfilesystem" UNIX domain socket for ADB.
This patch introduce "service.adb.listen_addrs", a new
string type property, while keeping the old properties.
The new property added in this patch is used to listen
on UNIX domain socket "localfilesystem".

"service.adb.listen_addrs" can be used to listen on
multiple addresses, such as tcp:5555 and tcp:5556.
It is separated by ',' (comma) character.

In the process of introducing the new socket type, the
method tcp_connect is removed and combined into
socket_spec_connect.

Without specifying using the new property, adb will
try to listen on both tcp and vsock (following the
previous implementation).

Some examples of the new property value are:
  - "tcp:5555"
  - "vsock:5555"
  - "localfilesystem:/tmp/test"
  - "tcp:5555,vsock:5555"

Bug: 133378083
Test: On master-arc-dev:
        adb root;
        setprop service.adb.listen_addrs localfilesystem:
	    <path_to_socket>;
        adb connect localfilesystem:<path_to_socket>;
        adb -s localfilesystem:<path_to_socket> shell;
	    inside Chrome OS.
Test: On aosp_bluefin:
        setprop service.adb.listen_addr tcp:5555;
        adb connect <IP>:5555; adb shell;
Test: On aosp_bluefin:
        setprop service.adb.tcp.port 5555;
        adb connect <IP>:5555; adb shell;
Test: On aosp_bluefin:
        setprop service.adb.listen_addrs tcp:5555,tcp:6666;
        adb connect <IP>:5555; adb shell;
        adb connect <IP>:6666; adb shell;
Test: On aosp_bluefin:
        ./adb_test;
Test: On cuttlefish:
        launch_cvd;
        adb -s 127.0.0.1:6520 shell;
Test: Ran host tests:
        ./adb_test;
        ./adb_integration_test_adb;
        ./adb_integration_test_device;

Change-Id: I8289bf0ab3305cf23ce5695ffba46845d58ef6bb
2019-12-04 10:05:05 +09:00
Raman Tenneti
5fff3877a1 Merge "Revert "Delay initial accept() until server initialized"" 2019-11-12 18:58:32 +00:00
Raman Tenneti
b71b5af783 Revert "Delay initial accept() until server initialized"
This reverts commit 4ad4a11aa8.

Reason for revert: BUG: 144355953

Change-Id: Icb3d87e1f697ff60fc1262798cb19be8705e3740
2019-11-12 18:57:51 +00:00
Raman Tenneti
6657c5d71f Merge "Revert "Support socket activation of adb server"" 2019-11-12 18:56:27 +00:00
Raman Tenneti
c77904e3c5 Revert "Support socket activation of adb server"
This reverts commit 4456b5fc15.

Reason for revert: Device boot failure BUG: 144355953

Change-Id: I539400fa2422bd4d6e396634c629a928cd2ac398
2019-11-12 18:55:29 +00:00
Treehugger Robot
d9381651ee Merge "Delay initial accept() until server initialized" 2019-11-12 03:45:51 +00:00
Daniel Colascione
d7052824d4 Merge "Support socket activation of adb server" 2019-11-12 02:27:02 +00:00
Elliott Hughes
ef6d913027 Merge "fastdeploy: fix tests." 2019-11-08 21:11:45 +00:00
Elliott Hughes
74f0fc6b18 fastdeploy: fix tests.
Actually log results of adb commands, so we can see why this fails.

Fix the asan-detected use of a value from a reused part of the stack.

Test: atest FastDeployTest on Linux (with an asan adb)
Change-Id: I4d2bbae62a301e16065d604a2c9918077489cafb
2019-11-08 15:39:50 +00:00
Daniel Colascione
4ad4a11aa8 Delay initial accept() until server initialized
When the adb client starts the adb server, it waits until the server
reports that it's fully-initialized (via reply-fd) before executing
its adb client operation. This wait prevent that adb client from
talking to the server while it's initializing and becoming confused.
But if a *different* adb client connects to the server while it's
initializing, *that* client can temporarily observe unexpected state
while the server initializes itself. For example, such a client can
observe a device that's alive and connected as being offline while the
server connects to it.

The new socket activation support makes this race more apparent, since
in the socket activation configuration, there's no initial adb client
waiting for the server's all-clear indication and so even the first
client observes the partially-initialized server state.

This CL prevents the server accepting *any* client connection until
the server has fully initialized itself, preventing all clients, not
just the initial client, from observing a
partially-initialized server.

Test: test_adb.py; test_adb gtest binary
Test: [with socket activation] adb kill-server; adb devices
Change-Id: I5d399ee62436eee63340b6b8b0f64131ad17ac65
2019-11-07 20:58:28 -08:00
Daniel Colascione
4456b5fc15 Support socket activation of adb server
Socket activation allows adb to be run as a system daemon that starts
only as needed and supports race-free transparent restarts of the adb
server after a client issues an "adb kill-server" command.

Test: see SOCKET-ACTIVATION.txt
Change-Id: Ieabf08710ce4365e5513102f3aa578560aa7355e
2019-11-07 20:28:06 -08:00
Daniel Colascione
3aef5c82f7 Properly finish daemon init when initial USB scan complete
Call adb_notify_device_scan_complete when we finish enumerating USB
devices. The original intent of the code appears to have been to have
adb_wait_for_device_initialization return as soon as we've finished
looking around at the system USB environment on daemon startup, but at
some point, we forgot to actually notify the init thread that we
finished scanning all the USB devices, forcing the wait on init_cv to
time out after three seconds on every daemon initialization.

After this change, the daemon starts in a few milliseconds on my Linux
machine

Test: killall adb && sleep 1 && time adb server && adb shell ls
Change-Id: I0bc1da7a597d2077dd2b591560d03798b05905b7
2019-11-04 11:43:20 -08:00
Elliott Hughes
7fb1407125 adb: log more detail on failure to read keys.
Before we just got "Failed to read key". After:

  adb E 10-07 08:20:14 258249 258249 auth.cpp:176] Failed to read key \
    from '/usr/local/google/home/enh/.android/adbkey'
  94390117965240:error:0900006e:PEM routines:OPENSSL_internal:NO_START_LINE:\
    external/boringssl/src/crypto/pem/pem_lib.c:622:Expecting: ANY PRIVATE KEY

Also fix the misleading "Failed to generate" message from adb_auth_init.

Bug: http://b/141715453
Test: manually corrupted key; see above
Change-Id: I6732ee6b683c8548d596d7c22eeddab8ce9a3cea
2019-10-07 08:25:42 -07:00
Alex Buynytskyy
665f3ff5a7 FastDeploy refactor: 2+GB APK support, optimizations, tests.
- removed 2GB apk size cap,
- removed zip archive parsing on device (1.1M->236K agent size reduction),
- optimized matching entries search,
- added more robust matching entries search based on hash of CDr entry,
- reduced patch size by reusing Local File Header of matched entries,
- removed extra manifest parsing and extra agent calls,
- added device-side tests for agent,
- fix for Windows patch creation.

Test: atest adb_test fastdeploy_test FastDeployTests

Total time for 0-size patch reduction for 1.7G apk: 1m1.778s->0m36.234s.

Change-Id: I66d2cef1adf5b2be3325e355a7e72e9c99992369
2019-10-02 13:25:03 -07:00
Josh Gao
3a22e8cf73 Merge "adb: fragment host linux USB writes when needed." 2019-09-25 21:20:54 +00:00
Treehugger Robot
070c030289 Merge "adb: fix infinite loop when attempting to push to //foo." 2019-09-25 19:59:51 +00:00
Josh Gao
76b64ba826 adb: fix infinite loop when attempting to push to //foo.
dirname (on glibc, at least) preserves multiple leading slashes, and we
were looping until path != "/", which would lead to an infinite loop
when attempting to push to a path like //data/local/tmp.

Bug: http://b/141311284
Test: python -m unittest test_device.FileOperationsTest.test_push_multiple_slash_root
Change-Id: I182b3e89ef52579c716fdb525e9215f1fe822477
2019-09-26 01:56:58 +08:00
Mark Salyzyn
6f908cefe7 adb: fix adb remount -R
A regression from commit 8c2198c809
("adb: use shell for remount to forward return codes.") where the
optional argv[1] got missed for the remount command.  This change
hands off _all_ the arguments if to a shell and activates some of
the extra features in the remount command.

$ adb remount --help
remount [-h] [-R] [-T fstab_file] [partition]...
	-h --help	this help
	-R --reboot	disable verity & reboot to facilitate remount
	-T --fstab	custom fstab file location
	partition	specific partition(s) (empty does all)

Remount specified partition(s) read-write, by name or mount point.
-R notwithstanding, verity must be disabled on partition(s).
$

SideEffects: adb remount [-h] [-R] [-T fstab_file] [partition]...
Test: adb-remount-test.sh
Bug: 138577868
Bug: 139283818
Bug: 139226412
Change-Id: I8223d4000ab20857e9b634e4d4a326eed530d7be
2019-09-18 09:40:50 -07:00
Josh Gao
1025b228ba adb: fragment host linux USB writes when needed.
We've seen USB writes failing due to inability to allocate contiguous
chunks of memory in the kernel on devices, but it looks like the same
problem can occur on the host, as well. It's a mild performance
regression (90->80 MB/s on a blueline) to split the writes always, so
attempt the full write first, and fall back to splitting it up if that
fails with ENOMEM. Once we switch over the the asynchronous transport
API, we'll be able to submit multiple writes cheaply, like on devices,
so we won't need to retry at that point.

Bug: http://b/140985544
Test: test_device.py
Change-Id: I1517c348375b829dfff6796c4e9d394802b02d5b
2019-09-17 14:48:16 +08:00
Alex Buynytskyy
7ea92d8232 Using the correct feature name for abb_exec.
Test: atest adb_test
Test: atest fastdeploy_test

Change-Id: Ib917ed8293d0f51339cade032c768a4058ba578e
2019-09-16 10:36:52 -07:00
Josh Gao
8c2198c809 adb: use shell for remount to forward return codes.
Bug: http://b/25842395
Test: manual
Change-Id: I719c86bdf573db14ca2a0bdf608065ad63f573c1
2019-08-12 18:31:45 -07:00
Josh Gao
34a478f572 adb: add ls_v2.
Add a 64-bit size/time variant of `adb ls`.

Bug: http://b/122955521
Test: adb shell dd if=/dev/zero bs=1m count=8192 of=/data/local/tmp/big
Test: adb pull /data/local/tmp/big
Test: adb ls /data/local/tmp
Change-Id: I6ff857239995bc7b5c5f8dfd65a36fad41e67d85
2019-08-12 13:46:34 -07:00
Josh Gao
51fcf3222b adb: rename syncmsg::*::time to mtime.
Test: mma
Change-Id: Ia7d743d523f7fb45d8be7518b2db763614edcc85
2019-08-12 13:46:34 -07:00
Songchun Fan
6e861740ff Merge "[adb] Cache features set inside the client process" 2019-08-09 00:40:51 +00:00
Songchun Fan
82834f1264 Merge "[adb] Speed up the streaming install" 2019-08-09 00:38:50 +00:00
Josh Gao
6c4cfd6af5 Merge changes I4d6bda45,I72576e1f
* changes:
  adb: fix transport acquisition for forward, reverse.
  adb: don't manually construct device selection prefix in forward.
2019-08-08 20:38:15 +00:00
Yurii Zubrytskyi
6eca0e6999 [adb] Speed up the streaming install
1. Use bigger buffer for transfers - 64kb is the default size
   for push, so let it be the same in streaming

2. Use abb when it's available for lower overhead

3. Add a posix_fadvise() on the source APK

4. Increase buffer sizes for the socketpair that's transferring
the data from adbd.

Overall this saves about 25% time for streaming installations
and makes it faster than the legacy push (at last!)

Test: manual
Change-Id: Ieb84284da2058944815e062ef6e4389b842565fa
2019-08-08 12:55:51 -07:00
Josh Gao
da9c767826 adb: don't manually construct device selection prefix in forward.
Use the existing infrastructure instead.

Test: test_adb.py
Test: test_device.py
Change-Id: I72576e1fb922af71852b50ddb3f4cb5c39eb333f
2019-08-06 16:43:34 -07:00
Elliott Hughes
91a531897a Merge "adb: fail better in install-multiple." 2019-08-06 19:33:34 +00:00
Elliott Hughes
dad291fc46 Merge "adb: add --abi to the adb install help." 2019-08-06 19:31:54 +00:00
Elliott Hughes
8c4db55f66 Merge "Fix adb install on very old Android releases." 2019-08-06 19:31:44 +00:00
Elliott Hughes
541d7408c1 adb: fail better in install-multiple.
If we're failing out, don't print any messages from the shutdown code:
it's not interesting (and actively confusing!) to talk about the
"Success" of finalizing an aborted session.

Also fail early if stat fails the first time (we have to tell
PackageManager how much data to expect, for some reason).

Also use `bool` as the boolean type and add quotes around filenames in
error messages.

`install_multi_package` looks like the same nonsense copy & pasted, but
I don't know what that is, and haven't seen any bug reports, so I'm
ignoring that for now.

Bug: http://b/133522725
Test: manual
Change-Id: Id054dff44f21f4c4cc5877dcc2735fc1eb25f9a0
2019-08-05 17:06:04 -07:00
Elliott Hughes
c0ebd59073 adb: add --abi to the adb install help.
A bit of a break with convention, but we do already document `-t` which
is actually a PackageManager option, not an adb option, and `--abi`
seems like it'll be seeing increased usage these next few years.

Also add a pointer to `adb shell pm help` for full details of
PackageManager options.

Bug: http://b/122487331
Test: manual
Change-Id: I93f48d202e5707b27caadb5af2a65c485c6d3407
2019-08-02 17:09:30 -07:00
Elliott Hughes
94350737e3 Fix adb install on very old Android releases.
See the code comment for the gory details.

Bug: https://issuetracker.google.com/37035817
Bug: http://b/37704384
Test: manual testing on a variety of devices & emulators
Change-Id: If9e481924a8a2f3ec1e926342b2ecd522fa933a2
2019-08-02 16:10:45 -07:00
Yurii Zubrytskyi
e800af5c23 [adb] Cache features set inside the client process
Test: manual
Change-Id: I99962edd85e9694c3ca309624368cda6355da008
2019-08-02 11:37:32 -07:00
Elliott Hughes
fc2f5f6728 adb: fix track-devices-l.
Also add a -l to the undocumented `adb track-devices` for easier
testing.

Bug: https://issuetracker.google.com/118470090
Test: manual
Change-Id: I436f6e45b249b98a073aa147ad4ed67d4d87f9bd
2019-07-31 14:14:59 -07:00
Elliott Hughes
690c8c8f25 Merge "Restore default port for adb connect." 2019-07-31 19:48:02 +00:00
Treehugger Robot
51406823c1 Merge "Clarify adb sync -l help text." 2019-07-31 19:44:49 +00:00
Elliott Hughes
573e67cbeb Restore default port for adb connect.
The default port of 5555 was removed a while back, but the help text was
never updated, and other contexts still allow a default port.

Bug: https://issuetracker.google.com/128561172
Test: manual
Change-Id: I6e5e6edeb2243386a0301c0a6cad569189f9910e
2019-07-30 21:55:56 -07:00
Elliott Hughes
4c8ea89afb Clarify adb sync -l help text.
Seems like the bug submitter thought that -l listed the partitions shown
on the line above, rather than the files. Be more explicit.

Bug: https://issuetracker.google.com/73122762
Test: treehugger
Change-Id: I6ed1027639a5b785a5992909430d739958d10ad7
2019-07-30 10:32:53 -07:00