Commit graph

1626 commits

Author SHA1 Message Date
Josh Gao
d7b3749202 adb: sysdeps_win32: actually change ExitThread to _endthreadex.
Forgot to amend this into b5fea14e.

Change-Id: Id04e639eb87043901681db789d7a7925300fa867
2016-02-12 15:47:19 -08:00
Josh Gao
69c81c75df Merge "adb: make adb_thread_func_t return void, add adb_thread_exit." 2016-02-12 23:42:49 +00:00
Josh Gao
b5fea14e13 adb: make adb_thread_func_t return void, add adb_thread_exit.
Windows restricts the return value of threads to 32-bits, even on 64-bit
platforms. Since we don't actually return meaningful values from thread,
resolve this inconsistency with POSIX by making adb's thread abstraction
only take void functions.

Change-Id: I5c23b4432314f13bf16d606fd5e6b6b7b6ef98b5
2016-02-12 15:23:54 -08:00
Josh Gao
7fea044de9 Merge "adb: mkdirs fixes" 2016-02-12 23:18:36 +00:00
Josh Gao
6b42a2bfd5 adb: redact reference to secret internal time machine.
Change-Id: Ic6744cc7c858576d7e6172460b32902e007b6fd3
2016-02-12 11:33:53 -08:00
Josh Gao
dda68c0fcf Merge "adb: sysdeps: add support for joining threads." 2016-02-11 01:10:12 +00:00
Spencer Low
85c45bd5a1 adb: mkdirs fixes
Fix pathological case where the directory to be created can't be created
because there is already a file there. This was previously returning
success because the wrong var was passed to directory_exists().

Fix test to exercise this situation. Also clarify tests.

Change-Id: I0dc0f14084e0eda4e1498874d4ab2a6445d322ac
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2016-02-10 15:03:50 -08:00
Josh Gao
3b3e10d046 adb: sysdeps: add support for joining threads.
Bug: http://b/27105824
Change-Id: I44e4edbb2a59565c35f1f3e6a6394ac258591f95
2016-02-10 14:22:58 -08:00
Josh Gao
76d3308dd2 Merge "adb: allow wine's output for sysdeps_win32 strerror test." 2016-02-10 21:39:31 +00:00
Josh Gao
22554c9167 adb: allow wine's output for sysdeps_win32 strerror test.
Change-Id: Ia5d04a2347df1bcd8c7efcc1da9cec9725007a58
2016-02-10 13:38:32 -08:00
Yabin Cui
6bf323b97a adb: setsid() for adb host server.
To create a daemon for adb host server, we should call setsid()
for the daemon process. However, previously we call setsid() for
the adb client process, which results in nothing but EPERM error.

Bug: 26982628
Change-Id: I2763ae3d5a243706927d7ef6af5095138c0ce2d8
2016-02-09 16:15:56 -08:00
Josh Gao
b2803b5060 Merge "adb: make ctrl-c when spawning a daemon not kill the daemon." 2016-02-09 01:05:18 +00:00
Josh Gao
b72b3f8c92 adb: make ctrl-c when spawning a daemon not kill the daemon.
Previously, using ctrl-c in a command that needs to spawn a daemon
because one isn't already available would kill the daemon along with the
foreground process.

Bug: http://b/26982628
Change-Id: I7fefc531c3e4895423e7b466322b5426d01dc9ef
2016-02-08 16:59:10 -08:00
Josh Gao
1172b2ec71 adb: fix mkdirs test.
The behavior of mkdirs was changed a while ago, without updating the
test.

Change-Id: I2aaa73818933b281e911c42a14e3c843d8bd972a
2016-02-08 11:22:50 -08:00
Josh Gao
aae1eb2c4f Merge "adb: don't append a slash to a path that already ends with one." 2016-02-04 00:36:32 +00:00
Spencer Low
53a0a99fe8 adb: win32: fix start-server to properly display UTF-8 on the console
fwrite() is a macro that maps to adb_fwrite(), which can write UTF-8 to
the console. Use it to write the output that comes from the subprocess
adb server.

To do this, dup the stdout/stderr file descriptor and make a duplicate
FILE* stream, in binary mode (since we're reading raw bytes from the
subprocess), and unbuffered.

Change-Id: I480761bae0bd576dc9e03fa4d31266f4e49635ed
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2016-02-03 16:24:37 -08:00
Josh Gao
323899b6d3 adb: don't append a slash to a path that already ends with one.
Bug: http://b/26964908
Change-Id: I1fbd752fd97f5414a306b46f7bfce3373362f8b3
2016-02-03 16:24:13 -08:00
Josh Gao
4323507a7e adb: report subprocess creation errors to the client.
Bug: http://b/26589627
Change-Id: I38e7a33ea8274f0eb47dc0ed87fcbca08a0ab22a
2016-02-03 15:52:07 -08:00
Josh Gao
6ad06b9ea9 adb: fix mistaken uses of SendFail in file_sync_service.cpp.
SendFail and SendSyncFail are similarly named, and have the same
prototype. Use `#pragma GCC poison` to prevent use of SendFail in
file_sync_service.cpp, and fix the places where it was used
accidentally.

Change-Id: I6b9a7e565b76dfab10f8ae38f889d046ad80a403
2016-02-03 23:50:32 +00:00
David Pursell
85c65dab42 Merge "adb: win32: handle incomplete UTF-8 in console output, other fixes" 2016-02-01 20:49:25 +00:00
David Pursell
79d8f07a6f Merge "base: add SystemErrorCodeToString() function." 2016-02-01 20:39:09 +00:00
David Pursell
5f787ed2b3 base: add SystemErrorCodeToString() function.
Pulls the Windows error string generation out of adb into libbase so
that it can be used by fastboot as well. Also makes a Unix equivalent
that just wraps strerror() so that upcoming fastboot error reporting
code can be platform-independent.

The intent here is just to provide a portable way to report an error to
the user. More general cross-platform error handling is out of scope.

Bug: http://b/26236380
Change-Id: I5a784a844775949562d069bb41dcb0ebd13a32bc
2016-02-01 12:18:26 -08:00
Josh Gao
d18aea9974 Merge changes I93287b87,I30a3eb0b
* changes:
  adb: add nullability specifiers to adb_client.h.
  adb: add adb_get_feature_set.
2016-02-01 18:48:13 +00:00
Josh Gao
a166e71e21 adb: add nullability specifiers to adb_client.h.
Change-Id: I93287b876cb06d871b4330d2733ef6f43c58fbbf
2016-01-31 19:22:04 -08:00
Josh Gao
f3f6a1d0d4 adb: add adb_get_feature_set.
Extract a feature set getter function from commandline.cpp.

Change-Id: I30a3eb0b060a88379e29be16264637816e378978
2016-01-31 19:12:26 -08:00
David Pursell
a9352202dd Merge "adb: fix subprocess termination for legacy shell." 2016-01-29 22:14:46 +00:00
Spencer Low
2e02dc630f adb: SIGWINCH support for Windows
- Introduces unix_read_interruptible() which is like unix_read() except
  that it can return EINTR.

- The big idea is that the Windows ReadConsoleInput() API will return an
  event on window resize and then we return EINTR from
  unix_read_interruptible() just like Unix.

- Only handles horizontal resize since Windows doesn't seem to give an
  event for vertical resize when no special screen buffer is used. This
  should be sufficient for the primary use case of adb on Windows
  (people are not running vi in the first place).

Change-Id: Id8d1710b559834c8098f2d7fbecedf2d0ade4b88
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2016-01-28 23:01:56 -08:00
Spencer Low
a30b79a2d9 adb: win32: handle incomplete UTF-8 in console output, other fixes
Previously, the various adb_printf, adb_fwrite, etc. functions did not
correctly handle the case of the passed buffer ending with an incomplete
UTF-8 sequence. This is fixed by buffering up incomplete UTF-8 sequences
in g_console_output_buffer (protected by the mutex
g_console_output_buffer) and outputting it later once the full sequence
is available.

A unittest for the main worker function, ParseCompleteUTF8(), was added
to adb_test.

Other fixes:

- Fix the return value of number-of-chars written to be number of UTF-8
  bytes instead of number of UTF-16 characters.

- Don't overwrite errno in success cases of various adb_printf, etc.
  functions. This might be excessive, but might be useful in the case
  when these functions are used for debugging/tracing.

- Add missing UTF-8 stdio functions that aren't currently used by adb,
  but might be in the future: vprintf, putc, putchar, puts.

- stdin_raw_init: If we can't get the console handle, don't call
  SetConsoleMode(). Not a big deal, but this will prevent erroneous
  trace output.

Change-Id: I8730e8af92882c42b884ad921b39a17b54465085
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2016-01-28 16:31:28 -08:00
Rubin Xu
8dfe21eaad Merge "ADB security logging" 2016-01-28 19:50:58 +00:00
David Pursell
57dd5ae1e3 adb: fix subprocess termination for legacy shell.
http://r.android.com/166419 changed `adb shell` behavior to not
allocate a remote PTY for non-interactive commands, but adbd relied on
having a PTY to properly terminate the subprocess.

One impact of this is that when using older versions of adb or passing
the -x flag, `adb screenrecord` wasn't properly terminating and closing
out the video file.

This CL restores the old behavior for legacy shell connections: always
use a PTY, but put it in raw mode if the client is doing local PTY
input/output processing itself.

Bug: http://b/26742824
Change-Id: I9ee630c0ff0d2d6a0db367387af7123deea79676
2016-01-27 17:13:41 -08:00
David Pursell
0aacbbe9f3 adb: fix GetFeatureSet() to indicate failure.
Previously GetFeatureSet() on an invalid target would just return an
empty feature set, leading to some invalid assumptions, e.g. if there
isn't exactly one device connected this happens:

$ adb shell -t
error: target doesn't support PTY args -Tt

This CL adds a success/failure return value to GetFeatureSet(), and
also adds an option to print errors to stderr since that's the most
common behavior.

This will cause a slight difference in behavior for install/uninstall.
Previously they would block until the device was available, now they
print an error and quit immediately, which seems to be the more common
behavior for adb functions.

Bug: http://b/26387641
Change-Id: I0ea6ffaec922e04b9946e84f05c3870e5b549fde
2016-01-22 08:49:15 -08:00
David Pursell
706955ff0d base: add network address parsing function from adb.
This CL moves the network address parsing function from adb to libbase
so that it can be used by fastboot as well as adb.

libbase seemed like the right choice because:
  1. It already has some parsing functions (parseint)
  2. The net address parsing function uses the libbase string
     functions so we have a libbase dependency anyway.

The parsing function has been modified slightly to make the canonical
address optional, and debug logging on success has been removed.

For adb the only functional difference is that parsing a network
address will no longer print the result to the debug log, which seemed
unnecessary.

Bug: http://b/26236380
Change-Id: Ife6df02937225fc66de87884d3572d79c092c522
2016-01-21 20:03:33 -08:00
Rubin Xu
d61a25c172 ADB security logging
Log adb shell, pull and push operations to the security log.

Bug: 22860162
Change-Id: I5d24e9d51040ae05a41d9fcb079e84351a217bd3
2016-01-21 15:57:02 +00:00
Josh Gao
b5028e46b0 adbd: use pty to determine whether a session is interactive.
Bug: http://b/26236990
Change-Id: I8baa4009a2fbe9a4c93f6ef5350ce61161b7237d
2016-01-20 15:32:56 -08:00
Josh Gao
c65fae9ef5 adbd: don't leave zombies when subprocess creation fails.
Bug: http://b/26660675
Change-Id: I8e65d51af73f409c30be47575f76bc6b0f227c54
2016-01-20 11:40:31 -08:00
Josh Gao
7db2cb67be Merge "adb: tag fatal, fatal_errno with printf attribute." 2016-01-15 23:51:05 +00:00
Josh Gao
56e9bb9bd6 adb: tag fatal, fatal_errno with printf attribute.
Also, fix bugs that this uncovered. In particular, the sysdeps_win32
FATAL macro would only print __FUNCTION__.

Change-Id: I6307ec9749edec21b4fee192e135a86ec445c84b
2016-01-15 15:25:31 -08:00
Josh Gao
3472410eac Merge "Increase the maximum shell command length to 4096ish." 2016-01-15 23:06:37 +00:00
Josh Gao
7e6683ce40 Increase the maximum shell command length to 4096ish.
The actual maximum length will depend on the version of the shell
protocol being used, and any additional parameters being passed through
(e.g. TERM=xterm-256color). This should be able to be raised to 64K for
devices with commit 3d2904c (L-MR1 and above), but that'll require some
plumbing.

Bug: http://b/20467103
Change-Id: Idf0c46af5b18b854110aba58df13a53297d2475f
2016-01-15 15:02:19 -08:00
Dan Albert
bac7bb5c16 Fix a couple sign-comparison warnings.
Bug: http://b/26523949
Change-Id: Id33146b5544147945fee3f14f7f72f39bae449f6
2016-01-15 12:18:14 -08:00
Jorge Lucangeli Obes
6fe9930722 Merge "adbd: Depend only on libminijail." 2016-01-08 23:59:32 +00:00
Elliott Hughes
d68ad69d1d Improve dumb terminal support (emacs is dumb).
Bug: http://b/26444032
Change-Id: Iaff4b09b613fd30ab7c4c73e096da34f37e0de07
2016-01-08 15:47:07 -08:00
Jorge Lucangeli Obes
218eb7c820 adbd: Depend only on libminijail.
With https://android-review.googlesource.com/#/c/195460,
adbd can depend only on libminijail, without having to include its
dependencies.

Bug: 26099611
Change-Id: I2312d8584dda88b4a4619d3100d0983fa2833ba5
2016-01-08 13:33:01 -08:00
Jorge Lucangeli Obes
fd79a5d9c1 adbd: Remove check for set_supplementary_gids.
With https://android-review.googlesource.com/#/c/195400, Minijail will
check for this failure so there's no need to do it here, which allows
to simplify the code.

Bug: 26099611
Change-Id: I7c876fdcab874ed403f82bdd5a4048c0f1e5db58
2016-01-08 10:56:20 -08:00
Leo Sartre
94e0776eb8 WA: Fix adb wait-for-device command
Without -s argument, adb wait-for-device will make a call to
acquire_one_transport() with sinfo->serial.c_str() == "".
Waiting for acquire_one_transport() to be reworked to use std::string
rather than const char * for serial, work around this by passing NULL
when sinfo->serial is not initialized in host_service_to_socket().

Change-Id: Ifef53e0e82850364f5029ee36560376f2a4a5104
Signed-off-by: Leo Sartre <leox.sartre@intel.com>
2016-01-05 12:13:24 +01:00
Dan Willemsen
1e20e0aa1d Limit adb_test to first multilib
It uses libadb, which is also only compiled for the primary
architecture. BUILD_HOST_NATIVE_TEST is changing the default
LOCAL_MULTILIB to match BUILD_NATIVE_TEST.

Change-Id: Ia9c002e641125eb996a7f198af1f182d0d6171c6
2015-12-21 16:17:24 -08:00
Elliott Hughes
a00e6ef1ff Give adb a proper progress bar.
This factors out the duplication in the single-file progress, and adds a
whole-sync progress percentage to the front of the line. A number that's
both more interesting and easier to read.

This also fixes the >100 percentage reporting for files of unknown size.

Bug: http://b/26189482
Change-Id: I51501ccef6ae1f52425db0eb0862d87e90947a6c
2015-12-18 14:43:31 -08:00
Elliott Hughes
82509e7925 Merge "adb host: add device state in "adb wait-for-*"" 2015-12-17 22:44:15 +00:00
Josh Gao
1ff73936a7 Merge "adb: extract USB FFS read/write limit constants." 2015-12-17 22:29:12 +00:00
Josh Gao
ae72b5aa4b adb: extract USB FFS read/write limit constants.
Change-Id: I5e9fb7959a1c4744cb8d53ece4634138239d4e49
2015-12-17 14:28:24 -08:00
Elliott Hughes
d361582dc0 Merge "Improve "adb install"'s error message slightly." 2015-12-17 22:17:38 +00:00
Elliott Hughes
fe01885c9b Improve "adb install"'s error message slightly.
We still don't really have a clue what went wrong, but "Failed to write"
made it sound like we did.

Change-Id: Ic58b13202e2d8ea6b095f7046db9d0771d77ce65
2015-12-17 14:04:38 -08:00
Jorge Lucangeli Obes
683dc4817f adb: Use Minijail for privilege dropping.
By using Minijail we avoid writing the same priv-dropping code over
and over again. This also enables future hardening opportunities.
We're already using Minijail for priv-dropping on Brillo.

Minijail is unit- and integration-tested on the
Chrome OS CI infrastructure (pulling from the same repo, see
https://wmatrix.googleplex.com/security?tests=security_Minijail0).
Once CI comes to Android, it will be continuously tested there as well.

Both 'adb root' and 'adb unroot' still work.

Bug: 26099611
Change-Id: I52c456ea272d27bd6fbc71200f4fdd928a592158
2015-12-17 10:49:53 -08:00
Tom Cherry
64cc0825a6 Merge "Use selinux_android_setcon() instead of setcon()" 2015-12-17 17:54:05 +00:00
Leo Sartre
1fbc9dbd0f adb host: add device state in "adb wait-for-*"
The current implementation of the host commands "adb wait-for-*" allows
to specify only the transport layer (local, usb or any).
This patch allows the specification of the expected device state
(bootloader, recovery, device or sideload), this is usefull for
scripting purposes.

Use case:
$ adb reboot sideload-auto-reboot
$ adb wait-for-usb-sideload && adb sideload package.zip

Change-Id: I276a6be4d82f8b7901f74e1e5395b86d16548e8f
Signed-off-by: Leo Sartre <leox.sartre@intel.com>
2015-12-16 18:11:18 -08:00
Tom Cherry
38cd57a145 Use selinux_android_setcon() instead of setcon()
Bug 26114086

Change-Id: I02d20ee7a5f487fc73d7a33d50b0b8f1cd9ad3a4
2015-12-16 17:42:08 -08:00
Josh Gao
0b19540dee adb: split up reads longer than 16k.
Reads from functionfs allocate contiguous buffers in the kernel, causing
long ones to sometimes fail because of memory fragmentation.

Bug: http://b/26206622
Change-Id: Id40753d6f29b37b5ca97c3e2fa3921f52b4242de
2015-12-16 11:40:38 -08:00
Elliott Hughes
9e7893bf86 More idiomatic cleanup of 9f75a03571.
Change-Id: Id936946375d2be56ba10bf3aa5804f52cdbecc2d
2015-12-16 08:45:05 -08:00
Nick Kralevich
9f75a03571 adbd: make a PR_CAPBSET_DROP error fatal.
Back in 080427e4e2, we said:

  If the kernel doesn't support file capabilities, we ignore
  a prctl(PR_CAPBSET_DROP) failure. In a future CL, this could
  become a fatal error.

Make it a fatal error. With SELinux support, all devices are
required to support file capabilities.

Change-Id: I0ce0c4cb9387c42e325cbf1a63c5d82e6aab530c
2015-12-15 16:54:53 -08:00
Elliott Hughes
1b708d368f Share the new adb USB diagnostic code with fastboot.
Bug: http://b/26134129
Change-Id: Ieaf0651c7b3f8a028760982091ec63a21a5484ba
2015-12-14 10:50:21 -08:00
Josh Gao
80f3b0438d Merge "adb: handle some edge cases with process environments." 2015-12-12 00:43:38 +00:00
Josh Gao
e03c988748 adb: handle some edge cases with process environments.
Change-Id: I0c20e58e14ef756a8c45dd5ea85f7301157a3c8e
2015-12-11 15:58:32 -08:00
Josh Gao
5e15568c07 Merge "adb: don't use setenv after forking." 2015-12-11 23:32:19 +00:00
Josh Gao
9b3fd67213 adb: don't use setenv after forking.
Previously, for `adb shell`, we were using setenv after forking to set
up the child's environment. This would occasionally deadlock in the
child, which would cause the main thread to deadlock waiting for the
child to complete. This patch constructs the environment before forking
and passes it to execle, eliminating the deadlock.

Bug: http://b/25847115
Change-Id: I720d472770564b1449819ddaab945a89844244a8
2015-12-11 15:10:12 -08:00
Josh Gao
c8e793685c Merge "adb: make pulling symlinks and devices work." 2015-12-11 21:04:25 +00:00
Josh Gao
f264224191 adb: make pulling symlinks and devices work.
Bug: http://b/25972989
Bug: http://b/26085751
Change-Id: I43842871522ea5f67a8c258dcb6ddafa8dd744c8
2015-12-11 12:51:38 -08:00
Mike Frysinger
6945e36060 Merge "adbd: refactor priv dropping logic" 2015-12-11 17:03:19 +00:00
Josh Gao
aae38d9704 Merge "adb: shell: add -n flag to not read from stdin." 2015-12-10 21:30:19 +00:00
Josh Gao
7d58607360 adb: shell: add -n flag to not read from stdin.
Shell scripts of the following form do not work properly with adb:
    echo "foo\nbar\nbaz" | {
        read FOO
        while [ "$FOO" != "" ]; do
            adb shell echo $FOO
            read FOO
        done
    }
The first run of adb shell will consume all of the contents of stdin,
causing the loop to immediately end. ssh solves this by providing a -n
flag that causes it to not read from stdin. This commit adds the same.

Bug: http://b/25817224
Change-Id: Id74ca62ef520bcf03678b50f4bf203916fd81038
2015-12-10 12:52:06 -08:00
Nick Kralevich
ce4bbcfb08 Merge "Revert "adb: Make HOME=/data/local/tmp"" 2015-12-10 20:48:08 +00:00
Nick Kralevich
b118762241 Revert "adb: Make HOME=/data/local/tmp"
During early boot, we may be mounting and unmounting /data.
Having the home directory for adb shell commands, such as
"adb shell logcat", on the /data directory prevents unmounting.

This reverts commit 173eb396c7.

Bug: 26132185
Change-Id: Ib7c2f9e696f52bf5bbb79223d90dd76791779587
2015-12-10 20:42:18 +00:00
Mike Frysinger
4120ebc635 adbd: refactor priv dropping logic
Makes the code a little cleaner.

Change-Id: I961b6fc8730c45d8fd4f9fd2981a6d6ab8f51fb6
2015-12-10 13:35:10 -05:00
Josh Gao
f31aba9e8d Merge "adb: make the test_pull_dir test actually test something." 2015-12-10 18:09:53 +00:00
Josh Gao
4d0e10b24e Merge "Move adb tests to system/core/adb." 2015-12-10 18:09:47 +00:00
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
Josh Gao
ce8f2cdcd0 adb: make the test_pull_dir test actually test something.
Change-Id: I8b525377557528d5bc70c44d587891fad9f739bd
2015-12-09 14:41:33 -08:00
Josh Gao
191c154832 Move adb tests to system/core/adb.
Change-Id: If240f45817a46d1e055a8e5173ee7191b9d6c8ea
2015-12-09 11:26:11 -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