Commit graph

142 commits

Author SHA1 Message Date
Josh Gao
b7b1edf974 adb: remove exit-time destructors.
On exit, these destructors get invoked while other threads might
still be using them, potentially causing a crash, and definitely
causing tsan to report a race condition.

Bug: http://b/23384853
Change-Id: I94de55d22f97f4edd1d7cc1f34e8c1f8dfd56a5a
2015-11-12 11:20:19 -08:00
Elliott Hughes
3c540aec24 Merge "Add -e to the adb shell documentation." 2015-11-10 19:25:14 +00:00
Elliott Hughes
0e42c2a4ad Add -e to the adb shell documentation.
Change-Id: I7be5d198ef174e969bbb670e629369894c7b0994
2015-11-10 10:54:44 -08:00
Elliott Hughes
28416d6d33 Fix adb shell escape handling.
Start of input is, by definition, the start of a line. Give the states
names to make the error clearer. We should also swallow the escape
character until/unless it's proven not to have been part of an escape
sequence. Finally, implement an ssh(1)-like -e option so the user can
choose -- or, more importantly, disable -- escape character handling.

Change-Id: I28a91db47e15f3e7de96303c0b9a98d302b9c92e
2015-11-09 13:57:47 -08:00
Todd Kennedy
6fa848adba use new cmd command
Instead of using the pm command, 'adb install' and 'adb uninstall' will now
use the cmd command. Additionally, the APK will be streamed directly to
package installer instead of creating a temporary file.

(cherry-pick of d039800a4e008b52c532f901e3bb34b40877cf30.)
Change-Id: Ie7529afa5b039d29cc8183f36085ff4e66b3457a
2015-11-06 18:00:05 -08:00
Josh Gao
11d18f1491 Merge changes I70c94c4b,Ifd8769ed
* changes:
  adb: make mkdirs/secure_mkdirs do what they say.
  adb: remove use of mkdirs from `adb backup`.
2015-11-05 01:45:22 +00:00
Josh Gao
09c5bbf0fb adb: remove use of mkdirs from adb backup.
`adb backup -f nonexistent/directories/foo <pkg>` shouldn't create the
directory structure if they don't already exist.

Change-Id: Ifd8769ed7ee5e733a6635751ad09b714ab58ea4b
2015-11-04 14:35:43 -08:00
Elliott Hughes
0fbf9618bb Fix Mac adb build.
The Mac doesn't have <termio.h>, and it looks like the canonical place for
struct winsize is <sys/ioctl.h> anyway.

  system/core/adb/commandline.cpp:44:10: fatal error: 'termio.h' file not found
  #include <termio.h>

Bug: http://b/19734542
Change-Id: I3bfbf58cdb9b582f3b7e2c9ef0977613001cd3ac
2015-11-04 13:07:47 -08:00
Elliott Hughes
c15b17f1ac adb shell SIGWINCH support.
Bug: http://b/19734542
Change-Id: Ic9404a132cb9c42cb6a378bcd4b3dea9188d0a44
2015-11-04 10:45:11 -08:00
Elliott Hughes
aff48cbb3f Merge "adb: fix adb reverse --no-rebind help text"
am: 4f23917299

* commit '4f2391729951ead5f0d15862bd19213962438776':
  adb: fix adb reverse --no-rebind help text
2015-11-03 02:44:13 +00:00
Elliott Hughes
4f23917299 Merge "adb: fix adb reverse --no-rebind help text" 2015-11-03 02:40:52 +00:00
Josh Gao
58ee99e454 Merge "adb: allow multiple args to push/pull."
am: fe54c96ab2

* commit 'fe54c96ab28a59a87c0c26ac4e6664826b4644ea':
  adb: allow multiple args to push/pull.
2015-11-03 02:27:39 +00:00
Josh Gao
fe54c96ab2 Merge "adb: allow multiple args to push/pull." 2015-11-03 02:22:08 +00:00
Spencer Low
587ea20f83 adb: fix adb reverse --no-rebind help text
There was a typo in the option.

Change-Id: I5c074a883a7b384663ed65cd8de0d891dc2b6606
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-11-02 17:34:49 -08:00
David Pursell
34e0d64719 Merge "adb: create unix_isatty() function."
am: d9ff9873df

* commit 'd9ff9873df4ef68c105bc84d8dbe098feaaa6c50':
  adb: create unix_isatty() function.
2015-11-03 00:48:56 +00:00
David Pursell
c5b8ad88ce adb: create unix_isatty() function.
Our Windows code has several different ways it checks whether an FD is
a console or not, some of which aren't exactly correct as they may
treat character devices (e.g. NUL) as consoles.

This CL disallows using the builtin isatty() function and provides
unix_isatty() instead which correctly checks these corner cases.

Change-Id: I6d551c745dae691c7eb3446b585265d62c1e62fa
2015-11-02 16:44:34 -08:00
Josh Gao
05786779f3 adb: allow multiple args to push/pull.
Bug: http://b/25324823
Change-Id: I369dd97adbe1d08e18e84af776ce8b1d61251835
2015-11-02 12:48:24 -08:00
Josh Gao
dcaf6932fd Merge "adb: use correct _WIN32 macro."
am: 5c75b529f6

* commit '5c75b529f684b388c91c7e7d0b2c7fece376ac1d':
  adb: use correct _WIN32 macro.
2015-11-02 18:59:01 +00:00
Josh Gao
4a1397264b adb: use correct _WIN32 macro.
Change-Id: I5af7957162ae7f8472a5a262434eaba84e64325a
2015-10-30 18:39:20 -07:00
Elliott Hughes
edb78620fb Merge "adb: fix adb client running out of sockets on Windows"
am: 1e2382a027

* commit '1e2382a0277eb36fb57a3a54202945556dfd234b':
  adb: fix adb client running out of sockets on Windows
2015-10-30 23:33:26 +00:00
Spencer Low
351ecd15b2 adb: fix adb client running out of sockets on Windows
Background
==========

On Windows, if you run "adb shell exit" in a loop in two windows,
eventually the adb client will be unable to connect to the adb server. I
think connect() is returning WSAEADDRINUSE: "Only one usage of each
socket address (protocol/network address/port) is normally permitted.
(10048)". The Windows System Event Log may also show Event 4227, Tcpip.
Netstat output is filled with:

  # for the adb server
  TCP    127.0.0.1:5037         127.0.0.1:65523        TIME_WAIT
  # for the adb client
  TCP    127.0.0.1:65523        127.0.0.1:5037         TIME_WAIT

The error probably means that the client is running out of free
address:port pairs.

The first netstat line is unavoidable, but the second line exists
because the adb client is not waiting for orderly/graceful shutdown of
the socket, and that is apparently required on Windows to get rid of the
second line. For more info, see
https://github.com/CompareAndSwap/SocketCloseTest .

This is exacerbated by the fact that "adb shell exit" makes 4 socket
connections to the adb server: 1) host:version, 2) host:features, 3)
host:version (again), 4) shell:exit. Also exacerbating is the fact that
the adb protocol is length-prefixed so the client typically does not
have to 'read() until zero' which effectively waits for orderly/graceful
shutdown.

The Fix
=======

Introduce a function, ReadOrderlyShutdown(), that should be called in
the adb client to wait for the server to close its socket, before
closing the client socket.

I reviewed all code where the adb client makes a connection to the adb
server and added ReadOrderlyShutdown() when it made sense. I wasn't able
to add it to the following:

* interactive_shell: this doesn't matter because this is interactive and
  thus can't be run fast enough to use up ports.
* adb sideload: I couldn't get enough test coverage and I don't think
  this is being called frequently enough to be a problem.
* send_shell_command, backup, adb_connect_command, adb shell, adb
  exec-out, install_multiple_app, adb_send_emulator_command: These
  already wait for server socket shutdown since they already call
  recv() until zero.
* restore, adb exec-in: protocol design can't have the server close
  first.
* adb start-server: no fd is actually returned
* create_local_service_socket, local_connect_arbitrary_ports,
  connect_device: probably called rarely enough not to be a problem.

Also in this change
===================

* Clarify comments in when adb_shutdown() is called before exit().
* add some missing adb_close() in adb sideload.
* Fixup error handling and comments in adb_send_emulator_command().
* Make SyncConnection::SendQuit return a success boolean.
* Add unittest for adb emu kill command. This gets code coverage over
  this very careful piece of code.

Change-Id: Iad0b1336f5b74186af2cd35f7ea827d0fa77a17c
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-10-30 16:23:10 -07:00
Elliott Hughes
39f7a1f026 Merge "Show transfer progress in adb sync/pull/push."
am: 26352bf1fb

* commit '26352bf1fbbc8efdfdd0ef4d7c008fcbec445f29':
  Show transfer progress in adb sync/pull/push.
2015-10-30 21:48:33 +00:00
Elliott Hughes
b708d16283 Show transfer progress in adb sync/pull/push.
Change-Id: If5439877d060f9bab29cf84be996071cf680c2d4
2015-10-30 14:19:23 -07:00
David Pursell
f856b39141 Merge "adb: fix -Tt options to match ssh."
am: 76e9236a42

* commit '76e9236a42d8652f46cc690e4fdb7636d5e8386f':
  adb: fix -Tt options to match ssh.
2015-10-27 15:45:33 +00:00
David Pursell
08a27094d9 adb: fix -Tt options to match ssh.
ssh has slightly more sophisticated -Tt options that we want to match.
This CL changes -Tt behavior to match ssh so that we allocate a remote
PTY in these cases:
     -T: never.
       : if stdin is a terminal and user wants an interactive shell.
     -t: if stdin is a terminal (otherwise print a warning message).
  -t -t: always.

Now this will work as expected:
  $ adb shell < my_script.sh

Also corrects a small unrelated bug with escape sequences so that only
a single tilde is accepted for the disconnect sequence.

Bug: http://b/24565284
Change-Id: Idab57ac98d81233b45c2613fe64ceb4398add961
2015-10-26 10:10:03 -07:00
Josh Gao
04c64dba9f Merge "adb: Mask SIGTTIN so that I/O works when backgrounded."
am: 69ccb9532c

* commit '69ccb9532cb822685d27142a5117d881be21ab01':
  adb: Mask SIGTTIN so that I/O works when backgrounded.
2015-10-24 01:43:23 +00:00
Josh Gao
8dcdb57daf adb: Mask SIGTTIN so that I/O works when backgrounded.
SIGTTIN gets sent to the process when we attempt to read from
stdin when we're in the background, which stops the process by
default. Mask the signal so that the read returns -1 with errno
set to EIO, instead.

Change-Id: I4ae626b0670c05a1a05165539b9eed709e83d536
2015-10-23 15:04:33 -07:00
David Pursell
2535ea1e18 am ca0d66d5: Merge "adb: non-interactive shell stdin."
* commit 'ca0d66d597dde0a76adc3f5da15aedff4b6cb70b':
  adb: non-interactive shell stdin.
2015-10-15 21:41:47 +00:00
David Pursell
1ed57f0dc3 adb: non-interactive shell stdin.
Non-interactive `adb shell` previously only read from the remote shell,
but we want it to write as well so interactive and non-interactive
shells can both send data. With this CL, we can now do:
  $ echo foo | adb shell cat
  foo

This is primarily usable with newer devices that support the shell_v2
features. Older devices will receive stdin but the shell will still
hang after all input has been sent, requiring user Ctrl+C. This seems
better than closing communication altogether which could potentially
miss an unpredictable amount of return data by closing too early.

Known issue: non-interactive stdin to a PTY shell isn't reliable.
However I don't think this is a common case as ssh doesn't seem to
handle it properly either. Examples:
  * echo 'echo foo' | adb shell
  * echo 'foo' | adb shell -t cat

Bug: http://b/24565284
Change-Id: I5b017fd12d8478765bb6e8400ea76d535c24ce42
2015-10-15 09:44:54 -07:00
Elliott Hughes
28a3e4958e am 1407b286: Merge "Fix adb -d/-e error reporting."
* commit '1407b28628afec6c06eb6cb818f800083df668e1':
  Fix adb -d/-e error reporting.
2015-10-07 22:49:15 +00: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
428f3434ae am de3faec6: am fd18d9e2: Merge "adb: put legacy shell: service back in."
* commit 'de3faec64d407e76013913cb39cf569f692e8f8f':
  adb: put legacy shell: service back in.
2015-09-30 23:59:55 +00:00
David Pursell
de3faec64d am fd18d9e2: Merge "adb: put legacy shell: service back in."
* commit 'fd18d9e254874557aa44d42bd6d6bdf4352b0e36':
  adb: put legacy shell: service back in.
2015-09-30 23:44:31 +00: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
b8db64313a am 56ece709: am e4975da3: Merge "Adb: use VLOG() to replace D() for verbose logging."
* commit '56ece709b093aa7570aa2915fa98682113acc5cb':
  Adb: use VLOG() to replace D() for verbose logging.
2015-09-23 23:16:09 +00:00
Yabin Cui
56ece709b0 am e4975da3: Merge "Adb: use VLOG() to replace D() for verbose logging."
* commit 'e4975da33326295885f4c606288516d73459c68e':
  Adb: use VLOG() to replace D() for verbose logging.
2015-09-23 23:00:18 +00: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
90f297ada1 am b0d84d16: am 36856b73: Merge "adb: add -Tt options to adb shell."
* commit 'b0d84d16ffeabd3aa1b9d9ecf48110ff4f8508e7':
  adb: add -Tt options to `adb shell`.
2015-09-22 20:38:57 +00:00
David Pursell
b0d84d16ff am 36856b73: Merge "adb: add -Tt options to adb shell."
* commit '36856b7306b50e22f98c3299a6c951cb74fd1854':
  adb: add -Tt options to `adb shell`.
2015-09-22 20:31:25 +00: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
de6aed81c8 am a3ef4fad: am 0af19a0e: Merge "adb: Fix missing shell protocol usage."
* commit 'a3ef4fad70692c88819b95a41437c03e9a3398a6':
  adb: Fix missing shell protocol usage.
2015-09-15 15:18:55 +00:00
David Pursell
a3ef4fad70 am 0af19a0e: Merge "adb: Fix missing shell protocol usage."
* commit '0af19a0e82d7808678f3b92a8c5b4b8cb80ee216':
  adb: Fix missing shell protocol usage.
2015-09-15 15:12:33 +00:00
David Pursell
71c83126a8 adb: Fix missing shell protocol usage.
Some adb commands use the shell service but weren't using the
shell protocol, causing a protocol mismatch between the client and
the device. This CL uses the shell protocol whenever possible.

Change-Id: I4c9c75b7fd1d5bf3dc1f73900711840270527682
2015-09-14 15:33:50 -07:00
David Pursell
e4c0454083 am 07448e07: am 76f4a653: Merge changes from topic \'adb_shell\'
* commit '07448e072e50703b01aca9f99cf03ead030746de':
  adb: add client side shell protocol and enable.
  adb: implement shell protocol.
2015-09-14 18:52:42 +00:00
David Pursell
07448e072e am 76f4a653: Merge changes from topic \'adb_shell\'
* commit '76f4a6533c6b803e267225b42c5dda63f23bf3ea':
  adb: add client side shell protocol and enable.
  adb: implement shell protocol.
2015-09-14 18:45:34 +00:00
David Pursell
606835ae5c adb: add client side shell protocol and enable.
Adds the shell protocol functionality to the client side and enables it
if the transport supports the feature.

Bug:http://b/23031026
Change-Id: I9abe1c8b1d39f8dd09666321b1c761ad708a8854
2015-09-11 13:02:17 -07:00
Yabin Cui
824a51eae4 am bd9305ee: am 0df24ea2: Merge "adb: refactor _is_valid_ack_reply_fd"
* commit 'bd9305eeb7152058ba8255f0c2601d512c906f98':
  adb: refactor _is_valid_ack_reply_fd
2015-09-09 18:03:25 +00:00
Yabin Cui
bd9305eeb7 am 0df24ea2: Merge "adb: refactor _is_valid_ack_reply_fd"
* commit '0df24ea234fcfb9ac57ed94701868426a41d8642':
  adb: refactor _is_valid_ack_reply_fd
2015-09-09 17:57:34 +00:00
Spencer Low
a13df3070f adb: refactor _is_valid_ack_reply_fd
Visual Studio's 'jump to reference' feature couldn't parse
adb_commandline() because I used an #ifdef in the middle of an if
statement, so this refactors the code into a separate helper function. I
just copied the code and inverted the comparisons.

No need for sysdeps since this is pretty minor.

Change-Id: Ifd5c62b0b505080ada6db5cc19739c6f07b94de9
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-09-07 16:20:13 -07:00
David Pursell
04aa49346a am 74b6e8ec: am e4c1bb53: Merge "adb: features passes transport features."
* commit '74b6e8ecfdb4e7f46d53f174e8ba21ce74f90482':
  adb: `features` passes transport features.
2015-09-05 00:16:00 +00:00