Commit graph

1500 commits

Author SHA1 Message Date
Elliott Hughes
77f539ab49 Simplify adb LinePrinter newline handling.
We had mostly-working hacks before, but it's time to just modify LinePrinter
to suit our needs. If we tell LinePrinter what kind of output we're giving
it, it can manage things automatically.

This fixes the minor bug where we'd sometimes have a blank line after an
error message.

Change-Id: I07ff52437f2402de311e237dd1b2dd338d9b668a
2015-12-09 18:42:41 -08:00
David Pursell
663e949b2b Merge "adb: add help text for USB permission errors." 2015-12-08 16:12:22 +00:00
Nick Kralevich
5358093225 Merge "adb: Make HOME=/data/local/tmp" 2015-12-08 04:56:05 +00:00
Erik Kline
46b0b1c694 Merge "Switch from using sockaddr to sockaddr_storage." 2015-12-08 01:41:38 +00:00
Nick Kralevich
173eb396c7 adb: Make HOME=/data/local/tmp
Make the home directory for adb shell be /data/local/tmp and
automatically change into that directory.

Change-Id: Ib5cc6e1ecdd31a37e986cf03836f7589ebd40868
2015-12-07 16:56:12 -08:00
Erik Kline
7e16cc15b5 Switch from using sockaddr to sockaddr_storage.
This is to ensure sufficient space is always available.

Change-Id: Ifa87b93ecdc90dcacbfb24446c872344da6703d3
2015-12-07 16:07:46 +09:00
Elliott Hughes
4f71319df0 Track rename of base/ to android-base/.
Change-Id: Idf9444fece4aa89c93e15640de59a91f6e758ccf
2015-12-04 22:00:26 -08:00
Josh Gao
1c6cd21c43 Merge "adbd: split up writes longer than 16k." 2015-12-03 22:50:11 +00:00
Josh Gao
6b531c4e6d adbd: split up writes longer than 16k.
Also, inline the bulk_read and bulk_write functions which were only
being used by one other function.

Bug: http://b/25847115
Change-Id: I218a869030219f606577a5529601c542488115e0
2015-12-03 14:40:03 -08:00
David Pursell
d2acbd1931 adb: add help text for USB permission errors.
The current permission messages can be confusing for users who don't
know about udev and USB access permissions. This CL adds some checks to
try to identify common udev problems, and adds a link to online
documentation.

Example messages:

1) adb server is in plugdev group but access is still denied:
$ adb devices
List of devices attached
082f59270073e1e3  no permissions (verify udev rules); see [developer.android.com/tools/device.html]

2) plugdev group exists but adb server is not in it:
$ adb shell
error: USB permission failure: udev requires plugdev group membership.
See [developer.android.com/tools/device.html] for more information.

3) plugdev group does not exist:
$ adb shell
error: USB permission failure.
See [developer.android.com/tools/device.html] for more information.

Bug: http://b/25777880
Change-Id: I536565adc12ab657c75151309795674181205db0
2015-12-03 11:00:47 -08:00
Josh Gao
1702f427b5 Merge "adb: don't divide by zero" 2015-12-02 21:56:04 +00:00
Elliott Hughes
d0d87f78e5 Merge "Fix "adb sync" (and "adb push") error reporting." 2015-12-02 18:53:28 +00:00
Josh Gao
b0e039f4ca adb: don't divide by zero
If we stat a file and get a size of 0, and then successfully read bytes
from that file, we would previously divide by zero when calculating the
percentage completion of the file. This case happens either when we're
racing against something else writing to the file, or when we're pulling
magical files such as the ones in /dev/cpuctl/ that lie about their
size.

Bug: http://b/25925733
Change-Id: I980b9c14f44a1eb4a42bc8736c94fa6db06c08d1
2015-11-30 12:03:12 -08:00
Josh Gao
7b284b2f22 adb: don't pull symlinks when pulling a directory
The previous change to do this (f96dc73b) only skipped individually
named symlinks, not symlinks inside of a directory that was being
pulled.

Bug: http://b/25601283
Change-Id: I25bdcbc546a9d3a0dbd8dacdb065fb134d96022b
2015-11-30 11:02:44 -08:00
Josh Gao
d3266e058e adb: remove extraneous newline from skip message
Change-Id: I12314da589bf0db14b37ae4c1f526665182f4776
2015-11-30 11:02:21 -08:00
Josh Gao
dd6cc4d7ee adb: correctly count skipped files in push/pull
Bug: http://b/25650207
Change-Id: I055b08216938640c4f7c5e96a7ea3719bf90ba70
2015-11-30 10:42:37 -08:00
Elliott Hughes
cc65c3b9f8 Fix "adb sync" (and "adb push") error reporting.
This patch ensures that we read any error response from the server if the
server closes the connection. Unfortunately, that's not sufficient to ensure
that we always see the server's error message --- sometimes the data just
gets thrown away because we keep writing without reading. Setting SO_LINGER
avoids this.

Bug: http://b/25230872
Change-Id: I96c019cc72bd139198de79bf29e6536cc462c20f
2015-11-20 22:01:06 -08:00
Elliott Hughes
6aab58c499 Move SendLargeFile into SyncConnection.
Just a trivial refactor. Code change comes later.

Change-Id: If9e509a8c44649e5be4daaca57972939b037b8db
2015-11-20 17:35:17 -08:00
Elliott Hughes
65433da1cb Avoid SIGPIPE in adb.
We're now able to send packets faster than the device can handle them,
meaning that sometimes we're several packets through before the device
says "hey, wait, I can't write" and closes the connection. At best this
led to us reporting that we couldn't sync because "Connection reset";
at worst we'd get SIGPIPE because we were still streaming to a connection
that had already been closed.

This change renames adb_main adb_server_main, and moves the ignoring of
SIGPIPE into adb_commandline so it applies to both client and server (but
not adbd).

This change doesn't address the "wrong error message" part of the problem,
but at least it means you'll get *an* error message.

Bug: http://b/25230872
Change-Id: Ic60e4d13ed03fdcdf0d5cbc97201ebd1097c16ed
2015-11-20 09:42:23 -08:00
Elliott Hughes
c2252df25a Don't send $TERM unless we're talking to a new adbd.
I put the conditional in the wrong place, not realizing that even the
old shell system allowed one 'argument'.

Bug: http://b/25765657
Change-Id: I2752fb838d6377bf24e5b4cf959462557a196c87
2015-11-18 12:45:48 -08:00
Josh Gao
44901f1147 Merge "adb: don't use adb_dirname in between getting and printing errno." 2015-11-18 00:44:05 +00:00
Josh Gao
f6e65e3f80 adb: don't use adb_dirname in between getting and printing errno.
adb_dirname might trample over the errno value we want to print. Move
the adb_dirname call out to a local to prevent this.

Change-Id: I8a62cb2e1be8704225a9c3b72dd01259c7eaaae4
2015-11-17 14:41:57 -08:00
Josh Gao
a629e2e578 adb: don't link against libcutils on Windows.
Bug: http://b/25693157
Change-Id: Ie1f082a094371124b4d66c87c7ab1a0706271b9d
2015-11-16 16:17:16 -08:00
Elliott Hughes
18ddf5c6a2 Pass $TERM to the device.
Unfortunately, this isn't backwards-compatible with the current shell
protocol because we made unknown shell: arguments errors. We could try
to commit the change to make them just warnings first, but how would
we know when everyone was running adbd with that change? Bumping the
protocol version doesn't help because that only affects the code running
on the host. And although we could add another feature to the reported
features, since shell_v2 is still in development, that doesn't seem
worthwhile.

Bug: http://b/25601436
Change-Id: I12b81aa656cd25b91d14ef691dcbd2b7dab49535
2015-11-16 10:55:34 -08:00
Josh Gao
f96dc73b9f adb: don't pull symlinks.
Pulling symlinks was broken for directories, and it doesn't seem like
there's a good way to make it not broken, given that the protocol doesn't
have readlink (and we don't want to create symlinks on Windows, anyway).
The behavior for files doesn't seem to be especially useful, either.

Bug: http://b/25601283
Change-Id: Ie1d27e93dd09cbc0c178623b390041d1cb11f726
2015-11-13 15:17:02 -08:00
Elliott Hughes
56e6813e27 Improve adb help text and adb backup error reporting.
Bug: https://code.google.com/p/android/issues/detail?id=188220
Bug: http://b/25677893
Change-Id: If174049e86d65d95db93a6e071c089dcd1d7cd4f
2015-11-13 11:04:10 -08:00
Spencer Low
bb2900098a adb: win32: Unicode USB device names
Cleanup TODO and instead of (poorly) converting the device name from
wchar_t to char, just retrieve and store it as wchar_t, simplifying the
code.

This probably isn't necessary since device names are probably always
ASCII, but this cleans things up.

Change-Id: Ib780dcdc1e0e06b97b61e25d29a23874b35d7800
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-11-12 20:13:21 -08:00
Spencer Low
d21dc825bb adb: win32: remove widen()/narrow() in favor of UTF8ToWide()/WideToUTF8()
Now that we have a more standardized API (also available in Chromium),
switch to it. Another benefit is real error handling instead of just
killing the process on invalid Unicode.

Make UTF8ToWide()/WideToUTF8() set errno to EILSEQ on bad input. This is
the same error code that wcsrtombs(3) uses.

Update the unittest to check for EILSEQ.

Change-Id: Ie92acf74d37adaea116cf610c1bf8cd433741e16
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-11-12 17:13:08 -08:00
Josh Gao
26f2e1fd4f Merge changes Ic124ecb9,I94de55d2
* changes:
  libbase: remove exit-time destructors.
  adb: remove exit-time destructors.
2015-11-12 22:50:03 +00:00
Josh Gao
8591f719d0 Merge "adb: properly handle path separators on Windows." 2015-11-12 21:25:00 +00:00
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
c1fd492ac5 Revert "Revert "adb/base: fix adb push of Unicode filenames on Win32""
This reverts commit cc8cd59456.

With the dependency on libcutils (for gettid for non-bionic) removed,
this no longer breaks the build.

Change-Id: I645bd6876e2502ddc1535b69af1e645c0df9d178
2015-11-11 18:23:00 -08:00
Spencer Low
32762f4afd adb: win32: fix adb shell
28416d6d33 broke adb shell on Windows
because it was calling unix_read() with a buffer size of 1 byte which
wasn't supported by unix_read()/_console_read().

This change makes _console_read() support such a small buffer by
maintaining an internal input buffer.

This lets us simplify the existing code that was already maintaining a
cached INPUT_RECORD.

Also eliminate some duplicate code in the big switch statement.

Change-Id: I8f0aed4fb9f6f2f5b9a6b68ce60d2e368fec81c7
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-11-11 16:59:06 -08:00
Josh Gao
bf666599b3 Merge changes from topic 'adb_dir'
* changes:
  adb: don't explode directories when pushing/pulling.
  adb: improve error handling, comments.
2015-11-11 23:22:48 +00:00
Josh Gao
32b24cfb5f adb: add 100 column limit to .clang-format.
Change-Id: I7d96a6d505d2ddd92ffe7ad12ffc777c03c63caf
2015-11-11 14:16:07 -08:00
Josh Gao
1a0253092d adb: properly handle path separators on Windows.
Bug: http://b/25573669
Change-Id: Ic82981e1dfe40d5e3b3ffa06e18e62ecf80d81fc
2015-11-11 14:01:46 -08:00
Josh Gao
07db1196e7 adb: don't explode directories when pushing/pulling.
Previously, `adb pull /data/local/tmp` would spew all of the contents of
/data/local/tmp into the current directory. This patch makes push/pull
keep directories intact.

Bug: http://b/25394682
Change-Id: I2304ae9e61745a2b9536f58a6012640bf8ff422a
2015-11-11 14:01:45 -08:00
Josh Gao
12a2ae9a0c adb: improve error handling, comments.
This commit fixes two cases:
  `adb pull /data/local/tmp nonexistent/path` would succeed.
  `adb pull /data/local/tmp nonexistent/` would fail.

Change-Id: I60c39eb2816946686241af42cfa2ad5cdc63fb0e
2015-11-11 14:00:11 -08:00
Jorge Lucangeli Obes
f39c56456d Fix typo, caps in error messages.
Bug: None
Change-Id: I673189f84812637c240321b72cf77b26b170b6ad
2015-11-11 11:34:14 -08:00
Elliott Hughes
fdebc26ad5 Merge "Revert "adb/base: fix adb push of Unicode filenames on Win32"" 2015-11-11 18:01:34 +00:00
Elliott Hughes
cc8cd59456 Revert "adb/base: fix adb push of Unicode filenames on Win32"
This reverts commit ac9514a452.

The new gettid dependency caused other breakage.

Change-Id: I74a75e40c30a45beb275f9dd38eb5c7beac15fbd
2015-11-11 18:01:12 +00:00
Elliott Hughes
332166a31a Merge "adb/base: fix adb push of Unicode filenames on Win32" 2015-11-11 17:10:01 +00:00
Spencer Low
ac9514a452 adb/base: fix adb push of Unicode filenames on Win32
ae5a6c06cd made adb push use
android::base::ReadFileToString() for small files, but that API did not
support UTF-8 filenames on Windows, until this fix which does the
following:

- Add android::base::{WideToUTF8,UTF8ToWide}() which are only available
  on Windows. The signatures are based on Chromium's APIs of the same
  name.

- Add the namespace android::base::utf8 which has versions of APIs that
  take UTF-8 strings. To use this, make sure your code is in a namespace
  and then do "using namespace android::base::utf8;". On Windows, this will
  make calls to open() call android::base::utf8::open(), and on other
  platforms, it will just call the regular ::open().

- Make ReadFileToString() and WriteStringToFile() use utf8::open() and
  utf8::unlink().

- Adapt unittests from Chromium.

- fastboot needs to link with libcutils because it links with libbase
  which depends on libcutils for gettid() for logging.

Change-Id: I1aeac40ff358331d7a1ff457ce894bfb17863904
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-11-10 15:48:54 -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
Josh Gao
0bb1ce06ea Merge "adb: don't try to pull character or block devices." 2015-11-10 02:22:47 +00:00
Josh Gao
8d00a39eff adb: don't try to pull character or block devices.
Change-Id: I1a9e2c0097fe9c4017a9b338e812366c8e1154f0
2015-11-09 18:12:10 -08:00
Josh Gao
21abf5a7c1 adb: demote skipping a file from an error to a warning.
Change-Id: If6c88e8855369bd7feb570ac5310fc7f44994083
2015-11-09 17:47:56 -08:00
Elliott Hughes
79964cdf86 Merge "Fix adb shell escape handling." 2015-11-10 01:06:58 +00: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