Commit graph

1684 commits

Author SHA1 Message Date
Nick Kralevich
5358093225 Merge "adb: Make HOME=/data/local/tmp" 2015-12-08 04:56:05 +00:00
Erik Kline
79a3210eda Merge "Switch from using sockaddr to sockaddr_storage." am: 46b0b1c694 am: 4c1b3840f0
am: cbc6f68e32

* commit 'cbc6f68e320bd30d0cd7fbe73847deacbd54e073':
  Switch from using sockaddr to sockaddr_storage.
2015-12-08 04:54: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
Elliott Hughes
ef119a14b8 Merge "Track rename of base/ to android-base/." am: 912ed3d8ca am: e2a9563be1
am: 3608ee5e90

* commit '3608ee5e903689ea7c433587be664649689816e1':
  Track rename of base/ to android-base/.
2015-12-07 23:59:44 +00: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
02025afe2b Merge "adbd: split up writes longer than 16k." am: 1c6cd21c43 am: eb4426f2b4
am: 8e7bde369b

* commit '8e7bde369b8cdd8b65a3e91bf77d60c1c5ed308c':
  adbd: split up writes longer than 16k.
2015-12-03 23:02:51 +00: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
f681478787 Merge "adb: don\'t divide by zero" am: 1702f427b5 am: e53fadf4b3
am: 9f941b96f5

* commit '9f941b96f52e975e97f3f3c41bc5d931fe8fb0e6':
  adb: don't divide by zero
2015-12-02 22:09:56 +00:00
Josh Gao
1702f427b5 Merge "adb: don't divide by zero" 2015-12-02 21:56:04 +00:00
Elliott Hughes
b69320e215 Merge "Fix "adb sync" (and "adb push") error reporting." am: d0d87f78e5 am: 59021ad415
am: fa454c1faa

* commit 'fa454c1faab102458d18fc07d1f8211bd89da80b':
  Fix "adb sync" (and "adb push") error reporting.
2015-12-02 19:06:39 +00:00
Elliott Hughes
d0d87f78e5 Merge "Fix "adb sync" (and "adb push") error reporting." 2015-12-02 18:53:28 +00:00
Josh Gao
68e26811f0 Merge changes I25bdcbc5,I12314da5,I055b0821 am: a3892504ac am: 81d3447fa9
am: fd3770a5a2

* commit 'fd3770a5a26b23303d49686cd24bab2939e5776b':
  adb: don't pull symlinks when pulling a directory
  adb: remove extraneous newline from skip message
  adb: correctly count skipped files in push/pull
2015-12-01 02:52:46 +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
e68e3f458c Merge "Move SendLargeFile into SyncConnection." am: ddf41f1ad0 am: 49f4f575f9
am: d88988970c

* commit 'd88988970c72434eda97319882436b40fe348a6b':
  Move SendLargeFile into SyncConnection.
2015-11-21 01:55:27 +00: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
159b455fcb Merge "Avoid SIGPIPE in adb." am: 8c5511c692 am: 1146ae0205
am: bd9a852e10

* commit 'bd9a852e10c7af3f2eddd6c3b9401849b792a808':
  Avoid SIGPIPE in adb.
2015-11-20 20:28:48 +00: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
25092744d9 Merge "Don\'t send screen unless we\'re talking to a new adbd." am: 9f90368701 am: 5e3589da14
am: 7a2f48eb01

* commit '7a2f48eb01a64886fdf0064041daafe29a07289e':
  Don't send $TERM unless we're talking to a new adbd.
2015-11-19 05:46:53 +00: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
00be90244d Merge "adb: don\'t use adb_dirname in between getting and printing errno." am: 44901f1147 am: 975c9a6863
am: 01f7f6fb03

* commit '01f7f6fb0323187a413dda937b9b893964fca5c9':
  adb: don't use adb_dirname in between getting and printing errno.
2015-11-18 19:18:23 +00:00
Josh Gao
b5d763b053 Merge changes Ice07f892,Ie1f082a0 am: 74a33fbcef am: 053eba0bc1
am: cb601eb981

* commit 'cb601eb981f70d395e9bac5c1bf39c7773141eca':
  libcutils: don't build for Windows.
  adb: don't link against libcutils on Windows.
2015-11-18 19:17:39 +00: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
Elliott Hughes
9a373a160c Merge "Pass screen to the device." am: c40f213b67 am: 1fd0ea9e0e
am: cc1ef0afae

* commit 'cc1ef0afae0ebbd818232e0252454d5591847f85':
  Pass $TERM to the device.
2015-11-18 00:25: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
4fde9d5698 Merge "adb: don\'t pull symlinks." am: 29843cf141 am: e01de06892
am: b5706b5f08

* commit 'b5706b5f0830fa87244e3bf1685050a9b1da5703':
  adb: don't pull symlinks.
2015-11-13 23:34:33 +00: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
28f2388938 Merge "Improve adb help text and adb backup error reporting." am: 82a2b2441c am: da2319bf4d
am: 7274d3fdc7

* commit '7274d3fdc70dc6abb5780f110c113f078a195cf3':
  Improve adb help text and adb backup error reporting.
2015-11-13 20:36:29 +00: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
Elliott Hughes
846ba16767 Merge "adb: win32: Unicode USB device names" am: 76aefd5f9b am: 01f5c3afc8
am: 84a2145033

* commit '84a214503382d9bb335a12872aa404c4a643ec12':
  adb: win32: Unicode USB device names
2015-11-13 16:51:54 +00: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
Elliott Hughes
dd6543e4e8 Merge "adb: win32: remove widen()/narrow() in favor of UTF8ToWide()/WideToUTF8()" am: 61a560aeb1 am: 187858496b
am: 395156a270

* commit '395156a270f43eaf4f489b5ef76af6d0f1ddaf06':
  adb: win32: remove widen()/narrow() in favor of UTF8ToWide()/WideToUTF8()
2015-11-13 03:14:54 +00: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
80a9bc872c Merge changes Ic124ecb9,I94de55d2 am: 26f2e1fd4f am: 9a3f299ec0
am: 33bc6f38e7

* commit '33bc6f38e7946108ff2fba947e2a2be0c8d62d7f':
  libbase: remove exit-time destructors.
  adb: remove exit-time destructors.
2015-11-12 23:12:24 +00:00
Josh Gao
3bcdde6286 Merge "adb: properly handle path separators on Windows." am: 8591f719d0 am: 82f9eef468
am: 55e1c43714

* commit '55e1c4371402f202988fd961ab30e66167918588':
  adb: properly handle path separators on Windows.
2015-11-12 23:12:10 +00: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
14e74b1b92 Merge "Revert "Revert "adb/base: fix adb push of Unicode filenames on Win32""" am: dcb8b288ca am: 1391792ba4
am: 64de36a893

* commit '64de36a89355f2c021adef849654a9e91a3cc94b':
  Revert "Revert "adb/base: fix adb push of Unicode filenames on Win32""
2015-11-12 02:40:47 +00: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
Elliott Hughes
f99c144c15 Merge "adb: win32: fix adb shell" am: 524716889b am: ecdf5f3947
am: acab0b0054

* commit 'acab0b00544f11bd0c95478b1165e5d4831884c4':
  adb: win32: fix adb shell
2015-11-12 01:24:16 +00: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
bf5537dd2c Merge changes from topic \'adb_dir\' am: bf666599b3 am: f30d0aeb55
am: 1cc5459eac

* commit '1cc5459eac3a00eebc188a1b3bed41cfab655356':
  adb: don't explode directories when pushing/pulling.
  adb: improve error handling, comments.
2015-11-11 23:36:47 +00: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
abc3544c82 Merge "adb: add 100 column limit to .clang-format." am: 389cab802a am: ddb8244bc8
am: bc74fa9bed

* commit 'bc74fa9bedc4029594221b0b10f345f21d02d6ac':
  adb: add 100 column limit to .clang-format.
2015-11-11 22:31:42 +00:00
Josh Gao
32b24cfb5f adb: add 100 column limit to .clang-format.
Change-Id: I7d96a6d505d2ddd92ffe7ad12ffc777c03c63caf
2015-11-11 14:16:07 -08:00
Jorge Lucangeli Obes
5f160d907d Merge "Fix typo, caps in error messages." am: ae0f53cf69 am: af8f8a1561
am: 9155aa3035

* commit '9155aa30350b2ee444d4061f97d13c1200a79d41':
  Fix typo, caps in error messages.
2015-11-11 22:14:23 +00: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
eaeafe13b3 Merge "Revert "adb/base: fix adb push of Unicode filenames on Win32"" am: fdebc26ad5 am: 7d223253cb
am: 210111a0d0

* commit '210111a0d02511d379471700359d9065783b1cb9':
  Revert "adb/base: fix adb push of Unicode filenames on Win32"
2015-11-11 18:18:20 +00: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
b979a787ff Merge "adb/base: fix adb push of Unicode filenames on Win32" am: 332166a31a am: 9cadb93394
am: 9d7da02815

* commit '9d7da028150b1682ab3b686fe3a6a72a329dfd3e':
  adb/base: fix adb push of Unicode filenames on Win32
2015-11-11 17:23:24 +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
ef0ac03c4a Merge "Add -e to the adb shell documentation." am: 3c540aec24 am: eaf0ea050f
am: 992c0f4b5c

* commit '992c0f4b5ccbdd78e8b8a6754dc50b643c96f35c':
  Add -e to the adb shell documentation.
2015-11-10 19:34:25 +00: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
5a499973ac Merge "adb: don\'t try to pull character or block devices." am: 0bb1ce06ea am: 85a4b33302
am: 155d62feb0

* commit '155d62feb0ae0fe5e119b28a23bb69f22ca52ec5':
  adb: don't try to pull character or block devices.
2015-11-10 02:37:52 +00:00
Josh Gao
bae6190af8 Merge "adb: demote skipping a file from an error to a warning." am: 5a08fd35c9 am: 234dbb840a
am: 1a770d624d

* commit '1a770d624df978444c12ce9af66e807f19463412':
  adb: demote skipping a file from an error to a warning.
2015-11-10 02:36:59 +00: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
cd8bcd812f Merge "Fix adb shell escape handling." am: 79964cdf86 am: a55d6810b7
am: 1098a6202b

* commit '1098a6202b58989048fc7d9e78b5807583fb8057':
  Fix adb shell escape handling.
2015-11-10 01:14:37 +00:00
Elliott Hughes
79964cdf86 Merge "Fix adb shell escape handling." 2015-11-10 01:06:58 +00:00
Todd Kennedy
51c05ec568 Revert "Revert "use new cmd command""
This reverts commit 3e3b4ec007.

Change-Id: I8bfcd8a2a285f4254539ebca9f70222aa2448ef4
2015-11-09 16:11:09 -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
Nick Kralevich
bdf20142b9 Merge "Enable hidepid=2 on /proc" am: 2d8f1d4c47 am: ea8452cc72
am: 7dafe5b818

* commit '7dafe5b818f7771cb00c4a0ea3ab1dbf74593185':
  Enable hidepid=2 on /proc
2015-11-09 20:41:19 +00:00
Nick Kralevich
2d8f1d4c47 Merge "Enable hidepid=2 on /proc" 2015-11-09 20:05:22 +00:00
Elliott Hughes
4cb77fc2a3 Merge "adb/base: minor compiler portability improvements" am: 892f0e9300 am: 8163cbc535
am: 3396ad2c16

* commit '3396ad2c16037c0fda6273708a750eb6a15e2038':
  adb/base: minor compiler portability improvements
2015-11-09 18:29:18 +00:00
Spencer Low
363af568b8 adb/base: minor compiler portability improvements
I've been using these changes to compile with Visual Studio.

- GetFileBasename(): __FILE__ uses \ with Visual Studio.

- adb_trace.cpp: Apparently VS needs an ampersand before the function name.

- "expr1 ? : expr2" is a GCC extension.

- <algorithm> contains std::min().

- seekdir can't always be #define'd because some headers have members
  named seekdir.

- adb_utils.cpp: Not really a compiler issue, just a random fix:
  0x7F/DEL is not printable.

Change-Id: I0dfb634f1ba4ccbc0d1b9f71b00e838fbebb3b41
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-11-09 10:22:13 -08:00
Guang Zhu
ccf1335e3b Merge "Revert "use new cmd command"" 2015-11-09 18:10:55 +00:00
Nick Kralevich
c39ba5ae32 Enable hidepid=2 on /proc
Add the following mount options to the /proc filesystem:

  hidepid=2,gid=3009

This change blocks /proc access unless you're in group 3009
(aka AID_READPROC).

Please see
  https://github.com/torvalds/linux/blob/master/Documentation/filesystems/proc.txt
for documentation on the hidepid option.

hidepid=2 is preferred over hidepid=1 since it leaks less information
and doesn't generate SELinux ptrace denials when trying to access
/proc without being in the proper group.

Add AID_READPROC to processes which need to access /proc entries for
other UIDs.

Bug: 23310674
Change-Id: I22bb55ff7b80ff722945e224845215196f09dafa
2015-11-09 09:08:46 -08:00
Todd Kennedy
3e3b4ec007 Revert "use new cmd command"
This reverts commit d039800a4e.

Change-Id: Ia9b81c47120088593a56ae09a9b002338d524b8a
2015-11-09 15:36:35 +00:00
Elliott Hughes
d7122586f7 Revert "AOSP master doesn't have "cmd"."
This reverts commit 79e1c7a7f8.

Internal master (where I'm reverting this) does have "cmd".
2015-11-07 09:15:50 -08:00
Elliott Hughes
79e1c7a7f8 AOSP master doesn't have "cmd".
Change-Id: I0f524b779a623a9e2db923fd9003b102460ae46f
2015-11-06 18:05:16 -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
7fc45c3326 Merge "adb: pull empty directories." 2015-11-07 00:53:03 +00:00
Josh Gao
a837df8590 adb: remove superfluous checks.
Change-Id: I4d9ceb301b0d242b0bad9a0faa8e2a1824f36cca
2015-11-06 15:19:53 -08:00
Josh Gao
6580096c97 adb: pull empty directories.
Pushing empty directories is more troublesome, and probably either
requires changes to the server, or hacky `adb shell mkdir` stuff.

Bug: http://b/25395071
Change-Id: I4db6a993429a56e5c5ca994752418503b6f5d7c4
2015-11-06 15:04:24 -08:00
Josh Gao
f00db9d8b8 Merge "adb: add basename_lock to mutex_list.h." 2015-11-06 20:43:49 +00:00
Josh Gao
250107e9f7 adb: add basename_lock to mutex_list.h.
Fixes crash on Windows.

Change-Id: Ic87d8ff30a2e824b6012e7e94b8d83442e17d000
2015-11-06 12:19:23 -08:00
Todd Kennedy
d039800a4e 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.

Change-Id: Ie7529afa5b039d29cc8183f36085ff4e66b3457a
2015-11-05 15:10:55 -08:00
Josh Gao
cd7c1ed700 adb: make local_build_list match remote_build_list.
local_build_list previously was returning an int, 0 on success and -1 on
failure, while remote_build_list was returning a bool, true on success
and false on failure.

Change-Id: Iced6c4142e2f843048d81c4e133d6b6dc75a35dd
2015-11-04 17:46:11 -08:00
Josh Gao
d97315731f adb: C++ify more of the push/pull functions.
Change-Id: Ie82d51ecadf5c94f3b138f5b13a17c3b46c61899
2015-11-04 17:46:11 -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
45b6fc878a adb: make mkdirs/secure_mkdirs do what they say.
Previously, mkdirs/secure_mkdirs wouldn't create a directory at the
specified path, only the ones above it.

Bug: http://b/25459942
Change-Id: I70c94c4b44d90723cb4a063657fc40e5bcb3b10e
2015-11-04 14:51:23 -08: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
Josh Gao
77cdfbd50c Merge "adb: make adb_basename match the POSIX behavior." 2015-11-04 22:26:32 +00:00
Josh Gao
787f3442cc adb: make adb_basename match the POSIX behavior.
Previously, adb_basename was behaving according to the GNU, POSIX-incompatible
basename, despite POSIX adb_dirname existing alongside it. This patch changes
adb_basename to pass through to the POSIX basename.

Bug: http://b/25456821
Change-Id: I62a4865cccf3b9cdbc112e3e53ff475aa4a23bd9
2015-11-04 14:21:35 -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
1358e2869c Merge "adb shell SIGWINCH support." 2015-11-04 20:46:56 +00:00
Joon :ee
c288d48513 Fix adb GCC build (for google3).
Allow adb to build using gcc by explicitly using global scope for the
type for pollfd. An alternative would be to rename the pollfd field to
different, but I did not have a better name in mind.

Change-Id: I7925df1dca7e1acc5a289256f228e5fc3755e86e
2015-11-04 10:50:16 -08:00
Elliott Hughes
c15b17f1ac adb shell SIGWINCH support.
Bug: http://b/19734542
Change-Id: Ic9404a132cb9c42cb6a378bcd4b3dea9188d0a44
2015-11-04 10:45:11 -08:00
Josh Gao
fc7c3b682b adb: rename 'flag' to something less meaningless.
Change-Id: I7f7644a0a6f9a7d48508ddaad2e6a51266ae8ee6
2015-11-03 14:46:31 -08:00
Josh Gao
19d9454ee3 Merge "adb: C++ify local_build_list and remote_build_list." 2015-11-03 21:21:50 +00: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
Josh Gao
9ea31c7285 Merge "adb: add SyncConnection::Printf."
am: e9af735de3

* commit 'e9af735de36eade81adc490635ee0076bdb6c79e':
  adb: add SyncConnection::Printf.
2015-11-03 01:33:54 +00:00
Josh Gao
cda6a2bd3e adb: C++ify local_build_list and remote_build_list.
Change-Id: I71586488869c4827c5bd7294faa7c0f433bb9fbc
2015-11-02 17:24:04 -08:00
Josh Gao
983c41c353 adb: add SyncConnection::Printf.
Replaces `sc.Print(android::base::StringPrintf(...)` with one call
to sc.Printf.

Change-Id: Ib7c98103dbca0b6a951f8e5a0f860ec6eacf6772
2015-11-02 17:21:43 -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
Elliott Hughes
5b51ac7a59 Merge "Set HOME, LOGNAME, SHELL, and USER from adbd."
am: 36d7af4cf6

* commit '36d7af4cf635816ecbcb9bd300f4c9d60cb012d4':
  Set HOME, LOGNAME, SHELL, and USER from adbd.
2015-11-02 22:09:09 +00:00
Elliott Hughes
36d7af4cf6 Merge "Set HOME, LOGNAME, SHELL, and USER from adbd." 2015-11-02 22:05:07 +00:00
Elliott Hughes
fbe4332e37 Set HOME, LOGNAME, SHELL, and USER from adbd.
Previously we've set these from /system/etc/mkshrc, which caused a behavioral
difference between interactive and non-interactive shells.

Bug: http://b/19635681
Change-Id: I4608c42dd3de821046220fdb1770ab3216b5d5eb
2015-11-02 13:53:39 -08:00
Yabin Cui
7782bbdef3 Merge "adb: run reverse_service() in main thread."
am: 1060739bfe

* commit '1060739bfe26a6c0eb74e10a40787ed1d781e296':
  adb: run reverse_service() in main thread.
2015-11-02 21:39:18 +00:00
Yabin Cui
1060739bfe Merge "adb: run reverse_service() in main thread." 2015-11-02 21:34:39 +00: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
Yabin Cui
fbfa84045d adb: run reverse_service() in main thread.
reverse_service() calls handle_forward_request(), which calls
functions in fdevent.cpp. fdevent functions is only supposed
to be called in the main thread.
Add check in fdevent.cpp to make sure all operations come from
main thread.

Bug: 25355808
Change-Id: Iceb9273f3056acc0713eaafe086ac950ca80ff4f
2015-11-02 10:39:09 -08: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
Elliott Hughes
ebd5badd84 Merge "Don\'t use VLAs in adb."
am: 24704399cd

* commit '24704399cdd58a396831fce2ba678642bd3a8ba5':
  Don't use VLAs in adb.
2015-10-27 22:52:26 +00:00
Elliott Hughes
24704399cd Merge "Don't use VLAs in adb." 2015-10-27 22:47:05 +00:00
Elliott Hughes
6d92997ec4 Don't use VLAs in adb.
This makes no measurable difference to the sync time; "adb sync" of
everything on /system for a Nexus 9 still takes 20s.

Change-Id: Ifa2626f7453937e43856b9c4ee06e1f5db0aa273
2015-10-27 15:46:41 -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
Elliott Hughes
d75b1ff0d3 Merge "Fix adb sync/pull/push error reporting."
am: b42e7e8f05

* commit 'b42e7e8f05d4ad3aa0fc3cfcc997684a4446c7b4':
  Fix adb sync/pull/push error reporting.
2015-10-26 16:37:04 +00:00
Elliott Hughes
8b43c3e65a Fix adb sync/pull/push error reporting.
I fixed the server side to send detailed error reports, but the client-side
code for pull was broken because it had already read the "FAIL" header before
calling the general error reporting code that expects to be able to read
the header. This meant we'd always report that we failed to read the failure
message.

Also add a couple of missing "\n"s, make sure every error message is prefixed
by "adb: ", and remove a useless path length check that would silently ignore
over-long paths rather than relying on SendRequest to detect and report the
problem.

Bug: http://b/6205106
Change-Id: I23862ececf03b761115ffa3f7725b7e1cecb48c7
2015-10-23 22:27:11 -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
Daniel Cashman
27ff12443d Merge "init/adb: correct static lib dependencies for libselinux"
am: 38aee48fc6

* commit '38aee48fc695c25e15435e4ef235c8bc2e0afde9':
  init/adb: correct static lib dependencies for libselinux
2015-10-22 23:12:22 +00:00
William Roberts
bd2d961cc2 init/adb: correct static lib dependencies for libselinux
Now that libselinux uses libpackagelistparser, in order
for libpackagelistparser to be properly statically linked
liblog must come after libselinux for all the liblog
references to be defined in libpackagelistparser which
is included in libselinux. This patch corrects that order.

Change-Id: I7aee10c9395310919779ed2463aab6b2f8b380cc
Signed-off-by: William Roberts <william.c.roberts@intel.com>
2015-10-22 15:21:26 -07:00
Elliott Hughes
5d5e8c2f4d Merge "Fix lseek argument order."
am: 56543606b5

* commit '56543606b55e1e1455ef5c0bf9aa9f4febab967f':
  Fix lseek argument order.
2015-10-20 20:37:05 +00:00
Elliott Hughes
56543606b5 Merge "Fix lseek argument order." 2015-10-20 20:28:05 +00:00
Elliott Hughes
c96de0d36e Fix lseek argument order.
Change-Id: I12feed2de8a4e0782f90609254a3e2ec66d7d98e
2015-10-20 13:18:22 -07:00
Sami Tolvanen
17e80ff5fc Merge "adb: use libfec in disable-verity"
am: ed38714426

* commit 'ed38714426b0f6bf67057dd28d6417a13807590c':
  adb: use libfec in disable-verity
2015-10-20 14:41:03 +00:00
Sami Tolvanen
8ad80763e4 adb: use libfec in disable-verity
Use libfec to locate verity metadata and disable verity.

Needs changes from
  I02f83b0d1d4e7ef5cd5d13a37ff0b84f17e23376

Bug: 21893453
Change-Id: Ib43c352400a368664c949c7b8c9961829adf48f4
2015-10-20 13:55:24 +01:00
Elliott Hughes
3f9ad41e0a am c2492937: Merge "adb: win32: Improve Winsock error code mappings and strings"
* commit 'c24929373ec0686e0695320d8f10f3bf4fc4547e':
  adb: win32: Improve Winsock error code mappings and strings
2015-10-19 14:09:12 -07:00
Spencer Low
0a79600e72 adb: win32: Improve Winsock error code mappings and strings
Improved mapping of Winsock error codes to POSIX error codes, especially
WSAECONNABORTED to EPIPE (which WriteFdExactly() looks for) when sending
to a closed socket and WSAECONNRESET to ECONNRESET when the peer resets
the connection.

Use a macro to map strerror() to adb_strerror() which handles these
POSIX error codes that the Windows C Runtime doesn't recognize.

Also:

* Unittest for adb_strerror().

* Don't trace when send() returns WSAEWOULDBLOCK because that is
  expected.

Change-Id: If46aeb7b36de3eebfbbccf5478ff5b1bb087714b
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-10-18 16:45:09 -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
Badhri Jagan Sridharan
4b542afe05 am ba000511: Merge "adbd: Add os descriptor support for adb."
* commit 'ba0005118b78dc8ff456492bb1e16947ab26be9e':
  adbd: Add os descriptor support for adb.
2015-10-14 17:32:55 +00:00
Badhri Jagan Sridharan
ba0005118b Merge "adbd: Add os descriptor support for adb." 2015-10-14 17:28:53 +00:00
Elliott Hughes
ebe9ffc48e am 21f99c08: Merge "Use const auto&/auto&& in adb."
* commit '21f99c089e2691f308cb5f24ca3db5eef4aa59ae':
  Use const auto&/auto&& in adb.
2015-10-08 00:04:02 +00:00
Elliott Hughes
65fe2516b4 Use const auto&/auto&& in adb.
Change-Id: I74a7e511302e15e207906f572d181634e0ed5604
2015-10-07 16:11:17 -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
1407b28628 Merge "Fix adb -d/-e error reporting." 2015-10-07 22:38:50 +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
Badhri Jagan Sridharan
ca2a0bdcb5 adbd: Add os descriptor support for adb.
Eventhough windows does not rely on extended os
descriptor for adbd, when android usb device is
configures as a composite device such as mtp+adb,
windows discards the extended os descriptor even
if one of the USB function fails to send
the extended compat descriptor. This results in automatic
install of MTP driverto fail when Android device is in
"File Transfer" mode with adb enabled.

https://msdn.microsoft.com/en-us/library/windows/hardware/gg463179.aspx

BUG=24583401
BUG=chromium:43409

Change-Id: I87341683a9337848cac66daf9055b0d05cedd3d3
2015-10-07 06:04:00 +00:00
Yabin Cui
ff32110e1e am 7f9d4c97: Merge "adb: keep file flags in fdevent_install."
* commit '7f9d4c97c35bbc5357126731bbb9faad1825c090':
  adb: keep file flags in fdevent_install.
2015-10-06 23:42:37 +00:00
Yabin Cui
6dfef255b8 adb: keep file flags in fdevent_install.
Bug: 24615098
Change-Id: Ia791ecbe612f09aca3bbd5787513f121fae54da5
2015-10-06 16:15:30 -07:00
Elliott Hughes
7d46e88936 am 8c47bb52: am 8a69e031: Merge "Speed up adb sync."
* commit '8c47bb52c41f461ee15bf0bc94378f0cc4fcb7d4':
  Speed up adb sync.
2015-10-05 19:53:45 +00:00
Elliott Hughes
8c47bb52c4 am 8a69e031: Merge "Speed up adb sync."
* commit '8a69e0315a3288ca14213602f5bec1173bc3216e':
  Speed up adb sync.
2015-10-05 19:48:00 +00:00
Elliott Hughes
8a69e0315a Merge "Speed up adb sync." 2015-10-05 19:42:03 +00:00
Elliott Hughes
49a59bf317 am 450b592d: am 42b8df38: Merge "adb: win32: specify socket protocol"
* commit '450b592da5e630fad028e3a112651b7071971fd7':
  adb: win32: specify socket protocol
2015-10-03 03:14:55 +00:00
Elliott Hughes
fb068b39e0 am f6d28fca: am e412cc89: Merge "Explain adb client/server version mismatch better."
* commit 'f6d28fcaf048dba2e422824f52ac687b48768c0b':
  Explain adb client/server version mismatch better.
2015-10-03 03:14:53 +00:00
Elliott Hughes
450b592da5 am 42b8df38: Merge "adb: win32: specify socket protocol"
* commit '42b8df38439b390f9c67eee567717f30143cf64f':
  adb: win32: specify socket protocol
2015-10-03 03:09:08 +00:00
Elliott Hughes
f6d28fcaf0 am e412cc89: Merge "Explain adb client/server version mismatch better."
* commit 'e412cc891ebdbcc64137ef3c91950124ff633d6f':
  Explain adb client/server version mismatch better.
2015-10-03 03:09:07 +00:00
Elliott Hughes
42b8df3843 Merge "adb: win32: specify socket protocol" 2015-10-03 03:06:24 +00:00
Elliott Hughes
5b73a10f64 Explain adb client/server version mismatch better.
"Out of date" is only probably true. You might equally well have an older
client talking to a newer server. So tell the truth and include the actual
version numbers.

Change-Id: I821de88f5baf65bf2623363129c60c496b407bff
2015-10-02 19:49:10 -07:00
Elliott Hughes
ae5a6c06cd Speed up adb sync.
Sending the SEND/DATA/DONE packets all in one write makes small file and
symbolic link transfer orders of magnitude faster. Transferring all the
symbolic links in /system/bin or all the cacerts in /system/etc goes down
from about 6s in each case to less than 0.5s.

Change-Id: Ia1706cef25535d0b685d3744241a0557a52b22ff
2015-10-02 14:48:58 -07:00
Yabin Cui
40bc602445 am fb070f3c: am 7377398b: Merge "adb: fdevent fixes"
* commit 'fb070f3c2b1b2e5398a4cb0e67801192a5d90a94':
  adb: fdevent fixes
2015-10-01 19:04:23 +00:00
Yabin Cui
fb070f3c2b am 7377398b: Merge "adb: fdevent fixes"
* commit '7377398be81a9a8a4256b4c11e7ed25b059c32bb':
  adb: fdevent fixes
2015-10-01 18:57:59 +00:00
Spencer Low
888a748bf2 adb: fdevent fixes
* fdevent_{set,add,del}()

  * CHECK() that the fdevent is FDE_ACTIVE, otherwise the caller would
    be waiting for events that will never arrive.

  * Remove ~ from "fde->events &= ~events" to keep desired bits instead
    of turning off desired bits.

* fdevent_call_fdfunc()

  * CHECK(FDE_PENDING) since it should always be true if the fdevent was
    on the pending list, or if fdevent_subproc_event_func() is faking
    things. The goal is to try to avoid losing events.

Change-Id: I979c2fffa0b3d6b635488cde11dc544691193018
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-09-30 23:29:25 -07:00
Yabin Cui
5027ffd873 am 4b3ee266: am ffa866f5: Merge "adb: detect sockets in CLOSE_WAIT state to prevent socket leak on linux."
* commit '4b3ee2666cdddbace5b7115853780e1d969c2776':
  adb: detect sockets in CLOSE_WAIT state to prevent socket leak on linux.
2015-10-01 00:14:43 +00:00
Yabin Cui
4b3ee2666c am ffa866f5: Merge "adb: detect sockets in CLOSE_WAIT state to prevent socket leak on linux."
* commit 'ffa866f5caefb13412f1814d0de06cda385feaa4':
  adb: detect sockets in CLOSE_WAIT state to prevent socket leak on linux.
2015-10-01 00:10:00 +00:00
Yabin Cui
ffa866f5ca Merge "adb: detect sockets in CLOSE_WAIT state to prevent socket leak on linux." 2015-10-01 00:03:50 +00: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
aa77e22d73 adb: detect sockets in CLOSE_WAIT state to prevent socket leak on linux.
It is possible that the adb server on host has many sockets in
CLOSE_WAIT state. To prevent socket leak, always enable POLLRDHUP
in fdevent.cpp to detect sockets in CLOSE_WAIT state.

Update LocalSocketTest unit tests:
Change half_close_with_packet to read_from_closing_socket, as reading
from a SHUT_WR socket is not needed in adb.
Change close_with_no_events_installed to close_socket_in_CLOSE_WAIT_state,
as the latter is more close to the real situation in use.

Bug: 23314034

Change-Id: Ice4f4036624e5584eab6ba5848e7f169c92f037f
2015-09-30 15:03:26 -07:00
Spencer Low
677fb43b0f adb: win32: specify socket protocol
Instead of using socket(..., 0), pass IPPROTO_TCP or IPPROTO_UDP. Using
zero wasn't buying us anything and was different than popular apps like
Chrome. We should stick to what everyone else does so that we don't go
down different code-paths and potentially hit Winsock service provider
issues that everyone else is (accidentally) avoiding.

Also CHECK() if send() returns an erroneous value as described in the
Chromium source.

Also add comment about socket buffer sizing and Windows Vista.

Change-Id: I63db8f6de352fe1e9525cbc9cfc040eb02a4b9cd
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-09-29 15:05:29 -07:00
David Pursell
88b71d41af am edf0728e: am a36f4d68: Merge "adb: bump server version to prevent feature mismatch."
* commit 'edf0728e2de358bc1a0eb73626c2c7788a3cc808':
  adb: bump server version to prevent feature mismatch.
2015-09-28 16:14:32 +00:00
David Pursell
0f427fead7 am 5d1a943d: am 002f9d5c: Merge "adb: fix adbd feature parsing for no features."
* commit '5d1a943dc49dcb1513d64e281efb522d704dea02':
  adb: fix adbd feature parsing for no features.
2015-09-28 16:14:30 +00:00
David Pursell
edf0728e2d am a36f4d68: Merge "adb: bump server version to prevent feature mismatch."
* commit 'a36f4d680a02dbf2bf2166f148f4c5200ec1d8f4':
  adb: bump server version to prevent feature mismatch.
2015-09-28 16:06:24 +00:00
David Pursell
5d1a943dc4 am 002f9d5c: Merge "adb: fix adbd feature parsing for no features."
* commit '002f9d5c70058e8db78a61d65384fd9510cf4ffd':
  adb: fix adbd feature parsing for no features.
2015-09-28 16:06:22 +00:00
David Pursell
a36f4d680a Merge "adb: bump server version to prevent feature mismatch." 2015-09-28 16:03:21 +00:00
David Pursell
d2b588e239 adb: fix adbd feature parsing for no features.
Previously the transport features list was only overwritten if a
new feature list was found. However, adbd can reuse the same atransport
object even if the adb server is killed and restarted, so the feature
list was not cleared properly if the newly started adb server didn't
provide one.

This CL fixes the bug by clearing the transport features list whenever
a connection banner is parsed.

Bug: http://b/24405971
Change-Id: Ia6ee6c9a46a621534681f6d4d7df77156b885eb9
2015-09-25 13:10:17 -07:00
David Pursell
bbe3d210ba adb: bump server version to prevent feature mismatch.
Devices get a list of supported features from the adb server, not the
client, so a mismatch between client and server features can cause the
device to use an incorrect feature set.

Bumping the server version is the easiest way to make sure the client
and server features match and seems like the best solution at the
moment.

A more automated fix could be to compare client/server features on each
connection and restart if they don't match. This requires an extra
client <-> server round-trip per command, but removes the need to
manually bump the server version number on feature change. Unless the
feature set changes often it didn't seem worth the extra overhead.

Bug: http://b/24370690
Change-Id: I4e43825d1c15c61e5d924fc8d4110b467debde37
2015-09-25 09:59:31 -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
Yabin Cui
03581ce1ea am 46a005c3: am 2b5f5fb9: Merge "base logging: fix errno restoring, severity conditionality, dangling ifs"
* commit '46a005c3d9a6557985316a1ee802880e99cc2407':
  base logging: fix errno restoring, severity conditionality, dangling ifs
2015-09-21 20:13:06 +00:00
Yabin Cui
46a005c3d9 am 2b5f5fb9: Merge "base logging: fix errno restoring, severity conditionality, dangling ifs"
* commit '2b5f5fb9d94d13809af6967fb3adb40669ddfb49':
  base logging: fix errno restoring, severity conditionality, dangling ifs
2015-09-21 20:04:54 +00:00
Yabin Cui
2b5f5fb9d9 Merge "base logging: fix errno restoring, severity conditionality, dangling ifs" 2015-09-21 19:56:52 +00:00
Spencer Low
765ae6bcfc base logging: fix errno restoring, severity conditionality, dangling ifs
Fix LOG() to properly save and restore errno. Test this properly.

Only do logging if severity is >= the minimum.

Fix dangling if statements in CHECK(), CHECK_STR{EQ,NE}(). Test this
properly.

Fix base logging tests on Windows. All libbase_tests now pass on
Windows.

Change place to lock, so the lock can protect logging of all data in
LogMessage.

Change-Id: I7ff531c67ae10a99ef0a2bbfe279aa77282d5ae9
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-09-21 12:46:12 -07:00
Dan Albert
82b9e94173 am 1bcb4677: am 71f878f8: Merge "Move python-adb to development/python-packages."
* commit '1bcb4677b0a9aaf4c62db073bc878a7249c8028c':
  Move python-adb to development/python-packages.
2015-09-21 17:42:11 +00:00
Dan Albert
1bcb4677b0 am 71f878f8: Merge "Move python-adb to development/python-packages."
* commit '71f878f89b6bc6df960e857836467a059802c61e':
  Move python-adb to development/python-packages.
2015-09-21 17:34:29 +00:00