Commit graph

1001 commits

Author SHA1 Message Date
Elliott Hughes
3fe6de1c39 Merge "Add a simple test for using non-ASCII paths with adb." 2015-07-24 23:07:56 +00:00
Elliott Hughes
614e0a47d3 Add a simple test for using non-ASCII paths with adb.
Bug: https://code.google.com/p/android/issues/detail?id=8185
Change-Id: If28a0ff345f44b60d6651bb36afb0bf72fe55e16
2015-07-24 15:26:46 -07:00
Elliott Hughes
4f1d7b55d7 Fix Win32 adb build (for the second time today).
Change-Id: I83cb407660cd8b5ed65a80574875fe261e8a8926
2015-07-24 14:32:46 -07:00
Elliott Hughes
9dad4ec440 Merge "Clean up the locking in usb_linux.cpp." 2015-07-24 20:21:53 +00:00
Elliott Hughes
812f030477 Clean up the locking in usb_linux.cpp.
tsan complained that usb_bulk_write accesses usb_handle members outside
a lock. Fix that, but by moving everything over to C++11 locking.

Note that the old code was checking whether pthread_cond_timedwait returned
a negative value, which it will never do --- it will signal timeout (or
any other error) by returning a positive errno value. The rewrite does
what they appeared to intend to do (break out on timeout), rather than
what they actually did (keep trying forever).

Bug: http://b/22598587
Change-Id: Iab6869ffed4874143a7da97193d6b09e34cf2933
2015-07-24 12:35:50 -07:00
Elliott Hughes
d48dbd89c8 Fix Win32 adb build.
Change-Id: I0a07379c470b7fa7f9bdef68c17ccb7bd0bd2079
2015-07-24 11:35:40 -07:00
Elliott Hughes
381cfa9a8b Report getaddrinfo failures correctly.
Also move us off the "convenience" function because you can't get useful
error reporting from it.

Change-Id: I5fcc6a6d762f5f60906980a7835f01a35045be65
2015-07-23 21:14:38 -07:00
Elliott Hughes
61ee830ec9 Don't limit Windows USB reads.
In 3d2904cdf2 we removed the code that broke
Linux USB reads into 4KiB chunks. This patch does the same for Windows. This
improves Windows "adb pull" speeds 6x in my VM. (There was no equivalent
problem with writes, so this change only affects pull speeds.)

Change-Id: If19013e5f51975f4824bf9147b7b76cebd305b96
2015-07-22 15:59:06 -07:00
Elliott Hughes
6b40d0aaa1 Merge "adb: win32: fix exec-in and exec-out to use binary mode" 2015-07-22 22:43:45 +00:00
Tamas Berghammer
3d2904cdf2 Increase size of the the adb packets sent over the wire
The reason behing this change is to increase the adb push/pull speed
with reduceing the number of packets sent between the host and the
device because the communication is heavily bound by packet latency.

The change maintains two way compatibility in the communication
protocol with negotiating a packet size between the target and the
host with the CONNECT packets.

After this change the push/pull speeds improved significantly
(measured from Linux-x86_64 with 100MB of data):

           | Old push | Old pull || New push  | New pull  |
-----------------------------------------------------------
Hammerhead | 4.6 MB/s | 3.9 MB/s || 13.1 MB/s | 16.5 MB/s |
-----------------------------------------------------------
Volantis   | 6.0 MB/s | 6.2 MS/s || 25.9 MB/s | 29.0 MB/s |
-----------------------------------------------------------
Fugu       | 6.0 MB/s | 5.1 MB/s || 27.9 MB/s | 33.2 MB/s |
-----------------------------------------------------------

Change-Id: Id9625de31266e43394289e325c7e7e473379c5d8
2015-07-22 13:06:06 -07:00
Elliott Hughes
a5d0ca4f16 Merge "Show "(reverse)" in "adb reverse --list"." 2015-07-22 00:25:41 +00:00
Elliott Hughes
34c20bbdff Show "(reverse)" in "adb reverse --list".
Bug: http://b/17788586
Change-Id: I250a1459295ed38e8d962da8bea2a8d2f83c7ef0
2015-07-21 17:09:06 -07:00
Elliott Hughes
19d80b878c "adb tcpip" should require a numeric argument.
Defaulting to port 0 just breaks stuff.

Bug: http://b/22636927
Change-Id: I6239900e0828e71b31171d0184c24824957c99c8
2015-07-21 16:27:46 -07:00
Elliott Hughes
3bcdaa2877 Merge "Recognize IPv6 addresses for "adb connect"." 2015-07-21 22:29:05 +00:00
Elliott Hughes
3d5f60dbba Recognize IPv6 addresses for "adb connect".
Bug: http://b/22559299
Change-Id: I32891d706b5010c38db84a056e76dd279b780f75
2015-07-21 15:25:14 -07:00
Spencer Low
8d8126a705 adb: logging: newlines, thread ids, error code overwriting
Add missing \n to uses of legacy D() macro. This should make the legacy
logging easier to read (and harder to miss important stuff).

On POSIX, use gettid() from libcutils instead of pthread_self() so that
the output shows a more reasonable number instead of a pointer value.
This should be ok since libbase's logging already uses gettid().

Win32:

Don't let the Win32 last error get overwritten by API calls after the
original error'ing API. When encountering an unknown error, log the
specific error code.

Change-Id: Ib8f72754efa7ba895d2f1cd914251fec2a1d894c
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-07-21 02:06:26 -07:00
Elliott Hughes
05418442ff Merge "Remove subproc events when ADB_HOST." 2015-07-20 22:50:25 +00:00
Elliott Hughes
64d303a0e7 Fix adbd/adb server confusion in an error message.
Change-Id: Iacb8bcfb1e8e1d46198ee4ba8cf0ec0d1b98c75a
2015-07-18 13:57:46 -07:00
Alex Vallée
947cb3e8ee Remove subproc events when ADB_HOST.
The code which triggers these events (via the SHELL_EXIT_NOTIFY_FD) are
only called from code which is already guarded by #if !ADB_HOST.

Change-Id: I184414f5e090c1f08ee117e4c8c434cd4a8b5221
2015-07-17 16:00:29 -04:00
Alex Vallée
1421614821 Move mkdirs to adb_utils.
There were duplicate implementations in commandline.cpp and
file_sync_client.cpp.

Change-Id: Ib448f76c0d7ffdcd577336b1c610a881425bc2db
2015-07-15 19:37:18 +00:00
Dan Albert
286bb6ddbd Revert "Turn on -Wformat-nonliteral."
One of my build aliases doesn't play nice with USE_MINGW=1, so my build lied to me. Will revert until I fix it up.

This reverts commit 459df8f3a1.

Change-Id: I7905c5ae5ee85fb2d228ce63d81c79f140998c18
2015-07-09 20:35:09 +00:00
Dan Albert
459df8f3a1 Turn on -Wformat-nonliteral.
Apparently there are two classes of this warning in clang.
-Wformat-security is only emitted for cases of
`func(nonliteral_fmt_string)` (no args), and -Wformat-nonliteral is
emitted for cases *with* arguments. For whatever reason, the latter
isn't included in -Wextra and must be manually enabled.

To make this more easily portable to Windows, move the existing
gnu_printf/__printf__ decision into base/macros.h as ATTRIBUTE_FORMAT.

Change-Id: I3b0990e1d1f0a2e9c13b32f5cd60478946cb5fc6
2015-07-09 10:47:24 -07:00
Elliott Hughes
a6241a0298 Merge "Replace HAVE_WIN32_IPC with _WIN32." 2015-07-09 17:16:13 +00:00
Elliott Hughes
095307ec49 Replace HAVE_WIN32_IPC with _WIN32.
Change-Id: Ie9dc064fb23a4e4bd4856c9668784dec0be9d2d6
2015-07-09 10:03:18 -07:00
Daniel Rosenberg
d6eba89f83 Fix "adb remount" for when the root directory is in system.img
When the root directory has been built into system.img, it is
mounted at /.

Change-Id: If01d12efeaa53b4ae59e801a6e9b802a9ae5882d
2015-07-08 19:36:19 +00:00
Derrick Bonafilia
36da715f2f Fixed a documentation error in protocol.txt
Prior to the documentation told users to pass 0 in as
the first argument to write messages, when they should
be outting in their local-id. It is now corrected.

Change-Id: Ia2c6c84f95383baa5ca471493a29a39e5173b604
Signed-off-by: Derrick Bonafilia <dbonafilia@google.com>
2015-07-06 10:19:28 -07:00
Elliott Hughes
b80ed90696 Merge "adb server: don't close stale fd when TCP transport is closed" 2015-06-29 22:32:19 +00:00
Elliott Hughes
e2d3677cc2 Improve the "device '(null)' not found" error.
Now we'll say "no devices found" if you haven't set ANDROID_SERIAL and
there's no device connected to default to.

Also clean up the relevant code a little.

Change-Id: Id254929629ce0888628d5ba8e67cd996ffbf9c8a
2015-06-24 10:36:41 -07:00
Elliott Hughes
5cba504215 Ignore ro.adb.secure in user builds.
Require authorization by default, and remove the ability to override
that in user builds. (userdebug and eng are still free to do whatever
they want.)

Bug: http://b/21862859
Change-Id: Ibf8af375be5bf1141c1ad481eee7a59fb10a7adb
2015-06-18 10:19:30 -07:00
Nick Kralevich
4d87095ebf Remove calls to is_selinux_enabled()
d34e407aeb removed support for
running with SELinux completely disabled. SELinux must either be
in permissive or enforcing mode now.

Remove unnecessary calls to is_selinux_enabled(). It always returns
true now.

Change-Id: Ife3156b74b13b2e590afe4accf716fc7776567e5
2015-06-12 22:12:33 -07:00
Elliott Hughes
7e067cff7a Minor "adb help" fixes.
One day we should slim this down. (Maybe implement the "help" versus
"help all" distinction that doesn't currently exist but was documented
before this change.)

Bug: https://code.google.com/p/android/issues/detail?id=158394
Change-Id: Ie24b588ffea00d262ce7ab0e5c328120ba8af240
2015-06-12 14:33:17 -07:00
Spencer Low
3abd31d8f4 adb server: don't close stale fd when TCP transport is closed
I think this fixes a scary bug that could be on all host platforms.

When running 'adb unroot' with an emulator, the connection to the
emulator is dropped (as expected). I noticed that the adb.log showed:

_fh_from_int:  1168: 5280 | _fh_from_int: invalid fd 106 passed to adb_close

Background: Every transport has a socketpair (two bidirectional sockets
connected to each other to form one 'pipe') that are used as follows:

* When adb wants to write to a transport, it writes to
t->transport_socket (half of the socketpair). An input thread reads from
t->fd (the other half of the socketpair) and writes the data to the
underlying transport (TCP, USB).

* An output thread reads from the underlying transport (TCP, USB) and
writes the data to t->fd. The main thread runs fdevent_loop() which
reads from t->transport_socket and processes the packets (that really
came from the underlying transport).

So t->fd and t->transport_socket are just an intermediate pipe between
transport agnostic code in adb and the underlying transport (TCP, USB).

Here's what I think is going on:

1. When the TCP transport is closed (such as when running adb unroot),
adb server's output thread notices this (adb_read() returns zero), and
it writes a special packet to t->fd.

2. The main thread processes the special packet by writing the special
packet to the input thread.

3. input_thread() sees the special packet, so it breaks out of a read
loop and calls transport_unref() which calls transport_unref_locked().

4. transport_unref_locked() calls t->close() which is a function pointer
that points to transport_local.cpp: remote_close() which calls
adb_close(t->fd). <----- ****THIS IS THE BUG****

I think this is a (very old) typo and it should instead be
adb_close(t->sfd) (the transport’s actual TCP socket) because it does
not make sense for the particular transport mechanism (TCP, USB) to be
messing with a socket of the socketpair of the transport agnostic code
(t->fd).

5. transport_unref_locked() calls remove_transport() which writes an
action to another special socketpair.

6. The action is read and eventually transport_registration_func() is
called and it calls adb_close(t->fd). But t->fd was already
(erroneously) closed in #4 above!! Anyway, this causes the adb.log
output.

The fix is to fix the typo changing t->fd to t->sfd and adding some
resiliency around whether the socket has already been closed (probably
by remote_kick()).

I tested this by putting a new adbd on an emulator, a new adb on Linux
and Windows and running the adb unroot scenario and checking adb.log. I
also ran test_adb.py (which doesn't totally work without problems with
an emulator, but I'll leave that to another day.)

Change-Id: I188b6c74917a3d721c150fd17ed0f2b63a2178c3
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-06-09 12:32:17 -07:00
Spencer Low
b7dfb79b53 adb: win32: fix exec-in and exec-out to use binary mode
adb exec-in and exec-out are designed to read/write binary data
according to the commit description at:
https://android.googlesource.com/platform/system/core/+/5d9d434%5E!/

On Windows, when adb_read and adb_write are used, they are always in
binary mode (because sysdeps_win32.cpp calls Windows APIs direct). But
unix_read, unix_write, fread, fwrite, read, write use the text
translation mode of the C Runtime file descriptor, which is by default
textmode.

adb exec-in and exec-out use copy_to_file() which uses unix_read() and
fwrite() when reading/writing stdin and stdout, thus, copy_to_file()
should switch to binary mode for those cases (it already uses binary
mode for file descriptors other than stdin and stdout).

copy_to_file() is also called by adb backup, adb restore, and adb
install-multiple, but those do not use stdin or stdout, so those
codepaths should not be affected by this change.

Change-Id: I3446d9b363d20a2c2f6be2b96e55b653d99df2f9
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-06-08 17:41:53 -07:00
Elliott Hughes
fa76ffccaa Merge "adb: win32: fix logging to adb.log" 2015-06-08 22:21:31 +00:00
Elliott Hughes
a945643831 Merge "Fix test_adb.py against production builds." 2015-06-06 00:16:23 +00:00
Paul Lawrence
6f009d9496 adb shouldn't trace unless told to
Prevents clean unmount of /data in crypto bounce

Bug: 21516860
Change-Id: I1f761dfdf216dcb35b4609cd46cc4d0644cc4a81
2015-06-05 16:01:48 -07:00
Elliott Hughes
3595328564 Fix test_adb.py against production builds.
Also use assertEqual for better errors. (I accidentally tested against
a non-AOSP build that doesn't have the \r fix.)

Change-Id: Ib032c01efa4e1efb14467ca776a14160fff4ad39
2015-06-05 13:11:43 -07:00
Elliott Hughes
f9ae390f63 Merge "adb: win32: get test_adb.py running and passing 100%" 2015-06-05 00:50:08 +00:00
Elliott Hughes
ebce147077 Merge "adb: fix adb_close() vs. unix_close() usage" 2015-06-04 22:28:50 +00:00
Spencer Low
d0f66c3616 adb: win32: fix logging to adb.log
In the adb client, redirect stdin and stderr of the adb server to `nul',
so that when the adb server starts up, it avoids issues in the C Runtime
where it closes stderr, making it hard to properly reopen. There are
probably other ways to avoid this issue, but I think this is the
cleanest that will keep working over the years and will exercise the
most commonly used code-paths in the C Runtime.

Fix some adb_close() calls to be unix_close() (only really matters on
Windows).

Make stderr non-buffered on Windows, to match the (sensible) Linux
behavior.

Change-Id: I1b15c64240e50dbeb56788b0d0d901f4536ad788
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-06-02 21:04:56 +00:00
Elliott Hughes
424af02f36 Fix error handling/reporting for "adb forward" and "adb reverse".
We really need better infrastructure for parsing adb subcommands, but
in the meantime...

At least this cleans up a little more of the implementation too.

Bug: http://b/20736014
Change-Id: I76209847da3724906c71924017bcb69fa31e0b49
2015-05-29 18:03:57 -07:00
Spencer Low
62b6b4a1ea adb: win32: get test_adb.py running and passing 100%
* Use posixpath instead of os.path, because os.path uses '\' instead of
'/' when running on Windows.

* tempfile.NamedTemporaryFile() does not work right on Windows because
it holds the file open, preventing other processes from accessing the
same file (https://bugs.python.org/issue14243). To work-around this, use
the mechanical transformation described at
http://stackoverflow.com/questions/15169101/how-to-create-a-temporary-file-that-can-be-read-by-a-subprocess

* Use pipes.quote() to quote path arguments, to prevent C:\foo\bar from
turning into C:foobar.

* Open files in binary mode with "b".

* Fix line-ending test to allow for \r\n on Windows, but to still test
for adbd incorrectly sending \r\n (which is then translated to \r\r\n).

Change-Id: Ib6ba94b919b747a878ba3ab54a4dea0801f76947
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-05-24 23:26:05 -07:00
Spencer Low
6ac5d7dc56 adb: fix adb_close() vs. unix_close() usage
Document the differences between adb_*() and unix_*() in the function
prototypes in sysdeps.h. See the file for the details (CR/LF
translation, well-known file descriptors, etc.).

Fix adb_read(), adb_write(), and adb_close() calls that should really be
unix_read(), unix_write(), and unix_close(). Note that this should have
no impact on unix because on unix, unix_read/unix_write/unix_close are
macros that map to adb_read/adb_write/adb_close.

Improve sysdeps_win32.cpp file descriptor diagnostic logging to output
the name of the function that was passed a bad file descriptor.

Change-Id: I0a1d9c28772656c80bcc303ef8b61fccf4cd637c
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-05-22 20:20:49 -07:00
Dan Albert
9313c0df20 Improve logging.
Any output from the LOG family will now go to stderr and logcat on the
device. stderr is usually redirected to a log file, but that is now
inhibited for adbd if being run from a tty (useful when debugging with
the serial console).

This also fixes sending logs to the file on device for the trace mask
of "all". The "all" tag was specifically handled to return early from
the function, preventing the file initialization from happening.

Change-Id: Id253577bfd1500fbce92dbfba0f9be23dbfd5ee4
2015-05-21 16:25:57 -07:00
Dan Albert
36473768ef Merge "Clean up adb_trace_init." 2015-05-21 23:03:50 +00:00
Dan Albert
db037bcd22 Merge "Make atransport be a real class." 2015-05-21 22:53:40 +00:00
Dan Albert
c7915a3470 Make atransport be a real class.
Using non-POD types in atransport means we'll need to start treating
it as a real class (specifically with regards to new/delete rather
than malloc/free).

I've also cleaned up the home grown linked lists for transport_list
and pending_list to just be std::lists. We might want to refactor that
again to be an std::unordered_map keyed on serial, since that seems to
be a common way to search it.

Change-Id: I7f5e23cdc47944a9278099723ca029585fe52105
2015-05-21 15:49:05 -07:00
Dan Albert
23fee8fcf5 Turn on -Wextra.
Change-Id: I3cddd6d949fdfa79312246670c37475276734f41
2015-05-21 15:15:11 -07:00
Dan Albert
e246219d0c Clean up adb_trace_init.
Old code was a mess for splitting a string and then searching a list
when they really wanted a map.

To more closely match ANDROID_LOG_TAG, only use a space separated list
rather than space/colon/semi-colon/comma.

Change-Id: I915ff4968e42d5f8dec1b43b6eacc0c8d7b44d7b
2015-05-21 15:03:44 -07:00
Spencer Low
ac3f7d9a78 adb / libbase: clean up NOGDI and evil ERROR macro
Instead of defining and undefining NOGDI:

1. Always #include "base/logging.h" after #include <windows.h>.
Unfortunately, I could not find an easy way to give the user a
warning/error if they include in the wrong order.

2. base/logging.h does #undef ERROR to undefine the evil ERROR macro
that is from another era and probably a bad idea to begin with.

Change-Id: I995d89620611e849af9d7ec47eb55fc0512377f2
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-05-20 12:25:19 -07:00