Commit graph

105 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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
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
74b6e8ecfd am e4c1bb53: Merge "adb: features passes transport features."
* commit 'e4c1bb53068db184ee4cb19513ffe7764a09722f':
  adb: `features` passes transport features.
2015-09-05 00:07:54 +00:00
David Pursell
880be434a9 adb: features passes transport features.
`adb features` previously returned a list of host features which was
not terribly useful. This CL changes functionality to return the
transport features instead using the standard targeting args:
  $ adb features  # default target.
  $ adb -e features
  $ adb -s 123456 features

Also adds a "check-feature" service which is currently unused but will
allow the adb client to easily check for a specific feature.

Bug: http://b/23824036
Change-Id: Ibc0c420c75f73d363f3bba7705af616ba2059348
2015-09-04 16:47:21 -07:00
Yabin Cui
7d0b4ada0b am 6562c151: Merge "adb: clean up debug tracing a little."
* commit '6562c1513b2b7bd88da8b1d0c88b89e66b2dcd69':
  adb: clean up debug tracing a little.
2015-09-03 17:38:57 +00:00
Yabin Cui
7a3f8d6691 adb: clean up debug tracing a little.
Always use LOG() for debug tracing.
Remove useless D_lock. I believe it is useless to lock just before and after fprintf.

I verified the log output both on host and on device. The output looks fine to me.

Change-Id: I96ccfe408ff56864361551afe9ad464d197ae104
2015-09-02 20:21:00 -07:00
Siva Velusamy
1f9d3b07a6 am c9525ec3: Merge "adb: set thread names (linux & mac)"
* commit 'c9525ec366232aa6a0968be1cc8e8abc37df789f':
  adb: set thread names (linux & mac)
2015-09-01 16:36:29 +00:00
Siva Velusamy
49ee7cf9a1 adb: set thread names (linux & mac)
Bug: 23423333
Change-Id: I0069f32ddbae2a10fb130064f721facf45b2cc09
2015-08-31 07:52:52 -07:00
Elliott Hughes
e4baae6d06 am 12d762e1: am e8e272c5: Merge "EINTR is handled by adb_read/unix_read and friends."
* commit '12d762e17694c0137aa7570b4b71536e59643bb0':
  EINTR is handled by adb_read/unix_read and friends.
2015-08-25 20:02:46 +00:00
Elliott Hughes
8fcd8bc046 EINTR is handled by adb_read/unix_read and friends.
No need to clutter the code with cases that won't happen.

Change-Id: I47c5a2e6170f902d2618719f44492234a4869567
2015-08-25 10:59:45 -07:00
Elliott Hughes
6b5f77c9bb am c583c511: am 186f1dee: Merge "adb sync cleanup."
* commit 'c583c5112bb6634114cd9759c1cfbad61a13b397':
  adb sync cleanup.
2015-08-24 20:59:50 +00:00
Elliott Hughes
aa24549190 adb sync cleanup.
We can double the speed of "adb sync" (on N9) if we increase SYNC_DATA_MAX
from 64KiB to 256KiB. This change doesn't do that, because I still haven't
managed to plumb through the information about whether we're a new adb/adbd
to file_sync_client.cpp and file_sync_service.cpp. But this is already a big
change with a lot of cleanup, so let's do the cleanup and worry about the
intended change another day...

This change does improve performance somewhat by halving the number of
lstat(2) calls made on the client side, and ensuring that most packets are
sent with a single write. This has the pleasing result of making the null
sync on an AOSP N9 go from just over 300ms to around 100ms, which means it
now seems instantaneous (https://en.wikipedia.org/wiki/Mental_chronometry).

Change-Id: If9f6d4c1f93ec752b95f71211bbbb1c513045166
2015-08-24 11:15:01 -07:00
David Pursell
f3f5bce204 am 6a701bd9: am b53b521e: Merge "Add adb features."
* commit '6a701bd94b067c2ab873964f63c3d954bc59610f':
  Add `adb features`.
2015-08-14 16:13:13 +00:00
Dan Albert
90d4b739ab Add adb features.
Shows the features supported by the active adb server.

Change-Id: I4a58a2ca082823c43f7a49e2c62ff80df6426756
2015-08-14 08:25:23 -07:00
Elliott Hughes
56d11898aa am 80e83972: am 9537ca80: Merge "adb: start-server and kill-server error output"
* commit '80e83972d0bce74d218f72b76339e6761ad6b03b':
  adb: start-server and kill-server error output
2015-08-13 16:46:46 +00:00
Spencer Low
f18fc0879b adb: start-server and kill-server error output
- handle_host_request
  - When the host:kill command comes in, shutdown the socket before
    calling exit(). If we don't do this, the client will output error info
    even though everything is working ok.

- adb_connect()
  - If we can't parse the version string, explain this in error output
    and don't goto error which would try to close an fd we already closed.
  - If host:kill doesn't work, output error info. Don't try to close
    already closed fd.

- adb_main()
  - If writing the ACK somehow has an error, output error info (I doubt
    this will ever get hit).

- adb_commandline()
  - Fix typo about max port number.
  - Make 'adb kill-server' and 'adb start-server' output any detailed
    error info.

Change-Id: Id1a309cc1bf516f7f49bd332b34d30f148b406da
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-08-12 20:14:55 -07:00
Elliott Hughes
efc8077246 am c01231b3: am 2fb00423: Merge "Always include the adb version in the log."
* commit 'c01231b399c38f00afe0872b3a51837518b713dc':
  Always include the adb version in the log.
2015-08-12 17:45:41 +00:00
Elliott Hughes
42ae2604f4 Always include the adb version in the log.
"Are you running the right version?" seems to be a common cause of debugging
confusion.

Change-Id: I4a4ba95e876dafc05e515058ca059ea370273f78
2015-08-12 08:32:10 -07:00
Elliott Hughes
6396f64fd7 am 61ff977b: am 1f36ae49: Merge "adb: win32: write ACK to separate pipe instead of stdout"
* commit '61ff977ba49f43d87fed86eb5b2e2bfc279f902b':
  adb: win32: write ACK to separate pipe instead of stdout
2015-08-11 01:50:26 +00:00
Spencer Low
5c398d2ce9 adb: win32: write ACK to separate pipe instead of stdout
The win32 version of 9f2d1a9cfc. The big
technique is to fit a Win32 HANDLE value in an int because it only uses
32-bits. This allows most of the other adb code to stay the same.

Also, fix a regression in the 'adb server nodaemon' command that was
erroneously returning an error when --reply-fd was not used, which
should not be necessary for this particular command.

Change-Id: I37e9c609014b813af93bf0d6c12f665b59c93c41
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-08-08 15:07:07 -07:00
Elliott Hughes
184585c417 am af60acef: am 98714882: Merge "adb start-server: Use a separate fd for sending initial OK"
* commit 'af60acef8231f03f7c736ed8ce86bd59979f9f6c':
  adb start-server: Use a separate fd for sending initial OK
2015-08-07 21:17:00 +00:00
Siva Velusamy
9f2d1a9cfc adb start-server: Use a separate fd for sending initial OK
When "adb start-server" is issued, and a server needs to be launched,
adb client forks itself and the child process runs the server routine.
Once the server initializes its various components, it sends an "OK\n"
back to the client via its stderror (or stdout on Windows).

This sequence breaks down if before sending the "OK\n", the server
happens to log something on its stderr. In order to avoid this, the
client now expects the ack to come on a different fd rather than one
of the standard streams.

Bug: https://code.google.com/p/android/issues/detail?id=182150

Change-Id: I9d58a08068d71eb3b77e8a7377e934631c016466
2015-08-07 11:31:07 -07:00
Elliott Hughes
5e6d1dcfac am 3d561748: am ec035950: Merge "Clean up -p handling slightly."
* commit '3d5617487c07f1fcbdf23755e0ca01559e3c5f3b':
  Clean up -p handling slightly.
2015-07-31 22:32:00 +00:00
Elliott Hughes
048b27c066 Clean up -p handling slightly.
Change-Id: I8a5cd4a7adb0dde9d09e0cbb620874b1bca35e43
2015-07-31 13:18:22 -07:00
Elliott Hughes
e0b43a1785 resolved conflicts for merge of 4e90b0ae to mnc-dev-plus-aosp
Change-Id: Iff0f469f09a0ad442db5b593345eaf52c3ca8104
2015-07-30 20:07:12 -07:00
Elliott Hughes
5c74270f95 More adb cleanup.
This removes adb_dirstart and adb_dirstop. It also fixes a couple of memory
leaks by switching to std::string. This also fixes the bug in the previous
change --- mkdirs is given input like "/system/bin/sh" and only expected to
create "/system/bin". In a later change, we should remove mkdirs and only
expose the intended "unlink && mkdirs && create" functionality.

Change-Id: I30289dc1b3dff575cc1b158d993652178f587552
2015-07-30 17:46:58 -07:00
Elliott Hughes
d2117974e4 resolved conflicts for merge of 486645ee to mnc-dev-plus-aosp
Change-Id: I027a4de6e4ebae3bee6b7d2e56bd39c284b8a062
2015-07-30 16:33:50 -07:00
Alex Vallée
47d67c96ec Write mkdirs in more idiomatic C++ style.
~ Rewrote mkdirs to be in C++ style.
~ Replaced adb_dir{start,stop} with std::string params and (r)find.
+ Added test for mkdirs.

Also make base/test_utils.h public and support temporary directories
as well as files.

Change-Id: I6fcbdc5e0099f3359d3aac6b00c436f250ca1329
2015-07-30 15:08:53 -07:00
Elliott Hughes
24419f3c2e am ce2047a9: am 1a706865: Merge "Fix const-ness of strrchr callers."
* commit 'ce2047a947eaf3c02e39c22a7b461e8a0acd87f2':
  Fix const-ness of strrchr callers.
2015-07-28 21:54:23 +00:00
Elliott Hughes
3e7048c027 Fix const-ness of strrchr callers.
This causes build failures in google3 where they use GCC. glibc only
provides const-correct overloads for string functions for GCC >= 4.4,
but clang -- which is what we use -- pretends to be GCC 4.2.

Change-Id: I2a054823ea6201ebcea46d5e77b80a975eefc622
2015-07-28 08:07:21 -07:00
Elliott Hughes
d704ede392 am 2fc8a91e: am 6b40d0aa: Merge "adb: win32: fix exec-in and exec-out to use binary mode"
* commit '2fc8a91eb35556b6f2bb4018b0fe2c08de55fe1c':
  adb: win32: fix exec-in and exec-out to use binary mode
2015-07-23 18:47:50 +00:00
Elliott Hughes
fee0648121 am d66e949b: am 2e7c39ec: Merge ""adb tcpip" should require a numeric argument."
* commit 'd66e949b14305b367d3de4ba00901bff1122bb0e':
  "adb tcpip" should require a numeric argument.
2015-07-23 02:06:36 +00:00
Elliott Hughes
6b40d0aaa1 Merge "adb: win32: fix exec-in and exec-out to use binary mode" 2015-07-22 22:43:45 +00:00
Elliott Hughes
19d80b878c "adb tcpip" should require a numeric argument.
Defaulting to port 0 just breaks stuff.

Bug: http://b/22636927
Change-Id: I6239900e0828e71b31171d0184c24824957c99c8
2015-07-21 16:27:46 -07:00
Elliott Hughes
e45a665040 am c06c3001: am a1c344b9: Merge "Move mkdirs to adb_utils."
* commit 'c06c3001156cbbdf8d6b3e187e0f92c51c5a80b3':
  Move mkdirs to adb_utils.
2015-07-16 21:39:46 +00:00
Alex Vallée
1421614821 Move mkdirs to adb_utils.
There were duplicate implementations in commandline.cpp and
file_sync_client.cpp.

Change-Id: Ib448f76c0d7ffdcd577336b1c610a881425bc2db
2015-07-15 19:37:18 +00:00