Commit graph

1161 commits

Author SHA1 Message Date
Spencer Low
3e7feda3c5 adb/test_device.py fixes for win32 and no use of ANDROID_SERIAL
If ANDROID_SERIAL was not set, test_device.py was failing.

Use posixpath.join instead of os.path.join for make_random_device_files.

Change-Id: I24bfa43ba2a89a9a768f505fc0bba9d873082b2f
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-07-30 01:19:52 -07:00
Yasuhiro Matsuda
dcf890914c Merge "Add a script to record Android boot time." 2015-07-30 05:21:41 +00:00
Yasuhiro Matsuda
ab3798399d Add a script to record Android boot time.
perfboot.py repeats the record of each event log during Android
boot specified times. By default, interval between measurements
is adjusted in such a way that CPUs are cooled down sufficiently
to avoid boot time slowdown caused by CPU thermal throttling.
This script also works around the issue of dropbox slowing down
boot time on userdebug build (http://b/20890386) by limiting
the number of files to be created by dropbox.
The result is output in a tab-separated value format.

BUG: 22207911
Change-Id: I0ddbac5d1c941efda87bc6db6388d8194d4bb3dd
2015-07-30 14:16:15 +09:00
Elliott Hughes
adbf442a51 Use _WIN32 rather than HAVE_WINSOCK.
Change-Id: I9855b6fe72e2f2f3a8360c0993a67cb988024ee4
2015-07-29 17:45:24 -07:00
Spencer Low
a6b340af12 fix adb {forward,reverse} --no-rebind
adb forward --no-rebind (and the matching reverse command) seem to have
been broken by 424af02f36. I fixed-up the
string parsing and also fixed the error message not to include
strerror(errno) since that does not apply because it is an
application-level error that doesn't have anything to do with the
OS/libc.

Change-Id: Iba7286283bfcf1782076355edcd9c355c0a0edfd
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-07-29 17:21:21 -07:00
Dan Albert
c0e8d0fc50 Merge "Fix AndroidDevice.get_prop, add tests." 2015-07-28 23:46:10 +00:00
Dan Albert
e2b4a5fee0 Fix AndroidDevice.get_prop, add tests.
Had messed this up while refactoring before I submitted and neglected
to add a test. Thanks to mazda@ for catching this.

Also disabled the root/unroot tests for user builds.

Change-Id: Icb819a820a2afa227d548d678ae471d5195f0b96
2015-07-28 16:42:58 -07:00
Elliott Hughes
3e7048c027 Fix const-ness of strrchr callers.
This causes build failures in google3 where they use GCC. glibc only
provides const-correct overloads for string functions for GCC >= 4.4,
but clang -- which is what we use -- pretends to be GCC 4.2.

Change-Id: I2a054823ea6201ebcea46d5e77b80a975eefc622
2015-07-28 08:07:21 -07:00
Dan Albert
8e1fdd7806 Create adb Python package.
This is mostly just the AdbWrapper that we used in our tests, but I've
cleaned up the API to be a little more Pythonic (mostly in the sense
that commands are passed as lists rather than strings that are
shlex.split() by the shell command), and implemented the workaround
error checking for adb shell.

Move the tests up a directory. Having them buried a level down has
only been annoying.

There are now two files containing Python tests. test_device.py
contains tests specifically checking the AndroidDevice API, and
test_adb.py checks the ADB client program. To run both, use

    python -m unittest discover [-v]

Change-Id: Ibd158c528d31126a5b048bd00bc93039dbc468bc
2015-07-27 15:52:15 -07:00
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
Jack Pham
a190c800bf adbd: enable USB SuperSpeed (again)
The descriptors to enable USB 3.0 SuperSpeed support had previously
been added in commit d6ee9f26a5
but were removed when the v1/v2 descriptor handling was refactored
in commits ab3446dd34 and again in
c49f51c451. Now that the dust has
settled, add back the SS descriptors to re-enable USB 3.0.

Change-Id: I8de7c7e50d9216a7492ce7863e3aaf92ff805eff
2015-06-08 11:31:47 -07: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
Dan Albert
d92fd41f69 Merge "Make connection states a proper type." 2015-05-19 00:29:54 +00:00
Dan Albert
dcd78a15d0 Make connection states a proper type.
Change-Id: I809f9b327c832b88dd63151bf7dcb012d88e81c4
2015-05-18 17:10:33 -07:00
Dan Albert
075e8608a7 Ignore whitespace/indent issues from cpplint.
Unfortunately this lint check also fires when public/private are not
indented by a single space. The indentation format in adb does not
match google style, so that's not going to happen.

Change-Id: I35e5654a2359222bb274ac5fb2961aee6a3a280f
2015-05-18 16:49:07 -07:00
Dan Albert
747a6f22cd Merge "adb: win32: fix key files reading/writing" 2015-05-16 01:04:21 +00:00
Dan Albert
569a130196 Make pty raw in adb shell when non-interactive.
The main goal here is fixing the line ending translation from \n to
\r\n, but we probably don't want any translation to happen.

Bug: http://b/19735063
Change-Id: I1d6d6c6b57cc741b046c2432cd864b344ce1f28a
2015-05-15 17:33:05 -07:00
Dan Albert
4e0008123d Merge "adb: win32: fix StringPrintf format string checking of %zd and PRIu64" 2015-05-15 22:49:59 +00:00
Dan Albert
0df06907b4 Merge "adb: win32: fix daemon acknowledgement" 2015-05-15 21:47:07 +00:00
Elliott Hughes
84b0bf2264 Fix ' escaping in adb.
You can't just use \' inside a single-quoted string.

Bug: http://b/20323053
Bug: http://b/3090932
Change-Id: I73754b097671d02dc11c35052f0534b6dd789e4f
2015-05-15 12:06:00 -07:00
Spencer Low
6001c87cbc adb: win32: fix StringPrintf format string checking of %zd and PRIu64
At runtime, vsnprintf (and android::base::StringPrintf which calls it)
call a mingw version of vsnprintf, not the vsnprintf from MSVCRT.DLL.
The mingw version properly understands %zd and PRIu64 (the latter,
provided that you #include <inttypes.h>).

The problem was that android::base::StringPrintf was causing
compile-time errors saying that %zd and PRIu64 were not recognized. It
seems that this was because the attribute on the function prototypes
specified `printf' instead of `gnu_printf'. Once that was fixed to match
vsnprintf's attribute, the warnings went away.

This uses similar preprocessor techniques as <android/log.h>.

Also restore a %zd usage to avoid a static_cast<>, and make
print_transfer_progress()'s format string compile-time checkable (and
tweak some types and %llu => PRIu64).

Change-Id: I80b31b9994858a28cb7c6847143b86108b8ab842
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-05-13 19:30:30 -07:00
Alan Jeon
4af3c40c4a adb: Do not share memory between multiple thread
When multiple client try to connect to other hosts, it failed because
memory corruption. Allocate memory for each thread like other command did.

Change-Id: I79959ce3dbfd11c7553736cd3f5a899815873584
Signed-off-by: Alan Jeon <skyisle@gmail.com>
2015-05-11 16:28:04 -07:00
Spencer Low
d396dc93a7 adb: win32: fix daemon acknowledgement
The daemon failed to startup because main.cpp was changed from calling
WriteFile() to android::base::WriteStringToFd(), the later which calls
write() in the C Runtime which by default has stdout in textmode which
does \n to \r\n translation.

The quick fix is to change stdout's mode from text to binary since right
after it is reopened to redirect to the daemon log file anyway.

Change-Id: I322fc9eae5d6abbf63f3d5917b0beb2171b5a15c
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-05-11 15:57:43 -07:00
Elliott Hughes
9aa4fda4e6 Failure to find an oem partition should not be a remount failure.
Many devices don't have an /oem partition, so find_mount should be
expected to fail, but shouldn't cause the overall remount to fail.

Also clean up all the error handling and reporting, and remove the
dead int* globals.

Bug: http://b/21024141
Change-Id: Ie31021b03c9cab8e972269d7d1ffe383cd30ee9e
2015-05-11 13:28:22 -07:00
Dan Albert
c89e0ccd40 Revert "Revert "Split adb_main.cpp into client and daemon.""
This reverts commit 218dbccefa.

Change-Id: I74088db34983dc99e316a07c6ddc294340e0eb71
2015-05-08 17:33:21 -07:00
Dan Albert
218dbccefa Revert "Split adb_main.cpp into client and daemon."
This reverts commit cf07494ac2.
2015-05-08 16:08:57 -07:00
Dan Albert
3e1cb6d98d Revert "Probably fix the Mac build."
This reverts commit 49513cbcc7.
2015-05-08 16:08:53 -07:00
Dan Albert
49513cbcc7 Probably fix the Mac build.
This was throwing an unused variable warning for kWorkaroundBug6558362
on Darwin.

Change-Id: I1cbf381708e9884180a37f3246af36795d07dfc2
2015-05-08 12:45:15 -07:00
Elliott Hughes
ee5ce0d14f Merge "Fix "adb remount" for devices without an oem partition." 2015-05-08 17:49:11 +00:00
Dan Albert
cf07494ac2 Split adb_main.cpp into client and daemon.
The name "client" is somewhat misleading as it also contains the host
side adb server, but it's a part of the client binary.

Change-Id: I128b7bab213e330eb21b5010cd1fec5f7a62c8af
2015-05-08 10:20:26 -07:00
Elliott Hughes
f85f111620 Merge "Try to include the SHA in a ddmslib-compatible way." 2015-05-08 16:02:04 +00:00
Elliott Hughes
5677c23e8d Fix "adb remount" for devices without an oem partition.
On a device without an oem partition, we now have an /oem directory
anyway. This causes find_mount to fail, and that was returning nullptr
from a std::string-returning function. Boom!

Also clean up the bits of code I had to trace through between "adb remount"
on the host to the crash on the device as I debugged this.

The only other meaningful change is the error checking in
adb_connect_command --- adb_connect can also return -2.

Bug: http://b/20916855
Change-Id: I4c3b7858e13f3a3a8bbc7d30b3c0ee470bead587
2015-05-08 08:43:10 -07:00
Elliott Hughes
f3bbfa6a21 Try to include the SHA in a ddmslib-compatible way.
Bug: http://b/20918202
Change-Id: I0c1a48459372b0d28aaf9d09d82540e44b438c9c
2015-05-07 21:56:31 -07:00
Elliott Hughes
aee80fb67b Add some missing 'const's.
Change-Id: I5bd26d4366e10fc8c6bc255b7ddb174a7a8b82a5
2015-05-07 21:38:41 -07:00
Spencer Low
9b9603148b adb: win32: fix key files reading/writing
The issue is that adb uses fopen() with "e" (presumably to open the file
with O_CLOEXEC), but that flag causes MSVCRT.DLL to return an error. So
when adb_auth_host.cpp goes to read or write the adbkey files, it fails.

The quick fix is to not use the "e" option on adb host code since it
isn't necessary there, compared to adbd.

An alternative fix would be to have a fopen() wrapper on Windows that
filters out the "e" option.

Change-Id: I7d8ba2847dab0ed558ffe156e79093251eb253c9
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-05-07 19:08:29 -07:00
Spencer Low
142ec75cf8 adb: win32: fix adb emu command
The adb emu command was never working because the socket connection to
the emulator was closed without reading all of the data that the
emulator sent. On Windows, this caused the emulator's recv() call to
error-out, so it never got the command that was sent.

Before settling on this fix, I also experimented changing the arguments
to the socket shutdown() call and that didn't seem to help. I also tried
removing the call to shutdown() and that didn't help. So that should
rule out shutdown() as the problem. One experiment that helped was
delaying before calling adb_close(), but that is of course fragile and
doesn't address the real issue, which is not closing the socket until
the commands have been read.

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

Change-Id: I8fa4d740a2faa2c9922ec50792e16564a94f6eed
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-05-06 18:54:08 -07:00
Dan Albert
d99d902abd Be tolerant of devices that don't report serials.
The USB spec explicitly says this is optional, so we shouldn't be
relying on it.

Bug: http://b/20883914
Change-Id: Icf38405b00275199bcf51a70c47d428ae7264f2b
2015-05-06 16:48:52 -07:00
Elliott Hughes
3edd54b3a8 Add some missing 'static's.
Change-Id: Id76bb1e954e8fa36a11a38b5445c87f4a64af799
2015-05-05 18:26:10 -07:00
Dan Albert
1ba1d7c1ee Include the git sha in the adb version.
Also add --version to adbd to display the same thing.

Change-Id: I47dfbad16c892c42ea938aedd085ba77492791ba
2015-05-05 18:04:37 -07:00
Dan Albert
3f05fb5d97 Merge "Disable adb tests for Windows." 2015-05-05 22:11:01 +00:00
Dan Albert
a7a67c3079 Disable adb tests for Windows.
The tests will need some massaging before they're ready to go for
Windows, so just disable them to unblock people trying to mm in adb.

Change-Id: I67f2cd3af1a2444dea9cbb61c0553989442ba44b
2015-05-05 14:50:09 -07:00
Elliott Hughes
2e4a2eeaf3 _beginthread returns uintptr_t.
64-bit Windows is a thing, and we'll have to support it some day...

Change-Id: Ib9e2da1a5625e95a0ffadfee8501825dfd4f9594
2015-05-05 14:34:41 -07:00
Elliott Hughes
9b0f354fa2 Simplify adb_thread_create.
Change-Id: I36d6021ef8fbc23e8bcd4ddbe1dac0eba467cc70
2015-05-05 13:41:21 -07:00
Elliott Hughes
3bd73c12c0 Give enum types CamelCase names for clarity.
Change-Id: I1c89f1cc155ee839f372fb14d972a288183b8bcd
2015-05-05 13:10:43 -07:00
Elliott Hughes
32687beaf2 Remove non-functional "adb persist".
It isn't documented, it doesn't work, and it was only hacked into
"adb shell" anyway. (It's not a bad idea, though, but if we do it
we should do it properly.)

Change-Id: I930a5c6dd1d2850bfdf131f2e989ae04100f7db9
2015-05-05 12:50:26 -07:00
Elliott Hughes
f25752dcfa Merge "Implement the ssh(1) escaping rules." 2015-05-05 19:42:50 +00:00
Elliott Hughes
2b10111d25 Implement the ssh(1) escaping rules.
The first rule of ssh(1) escaping is that there is no escaping.

This doesn't undo any of my recent security fixes because they're all
calling escape_arg themselves.

This fixes "adb shell rm /data/dalvik-cache/arm/*".

Also remove do_cmd which caused concern during code review.

Bug: http://b/20564385
Change-Id: I4588fd949d51e2a50cff47ea171ed2d75f402d0d
2015-05-05 11:17:03 -07:00
Elliott Hughes
2e57163f53 Make test_track_devices.cpp output easier to read.
Change-Id: I2d85cdbe591a6ee9763e742805f281cb26d7b122
2015-05-04 15:51:50 -07:00
Elliott Hughes
ab52c181fa Add WriteFdFmt and clean up more code.
Also say *which* device wasn't found.

Bug: http://b/20666660
Change-Id: I50e234ad89e39ae0a8995083c0b642c61275c5a3
2015-05-01 17:36:46 -07:00
Elliott Hughes
e67f1f87d9 More adb buffer fixes.
This patch factors out a lot of the basic protocol code: sending OKAY,
sending FAIL, and sending a length-prefixed string.

ADB_TRACE has been non-optional for a long time, so let's just remove
the #ifs.

Also actually build the device tracker test tool (and remove its duplicate).

Bug: http://b/20666660
Change-Id: I6c7d59f18707bdc62ca69dea45547617f9f31fc6
2015-05-01 15:55:37 -07:00
Elliott Hughes
6452a89aa8 More fixed-length buffer removal.
Bug: http://b/20666660
Change-Id: I0c738e9fed2defed48a9cf2d0a4f7b99c08dcf3d
2015-04-30 11:25:05 -07:00
Elliott Hughes
3ce9575af7 Add missing 'else' to fix all devices showing up as "host".
Bug: http://b/20705355
Change-Id: I4f7830278f0c2bc87d95d148d85455b8da894645
2015-04-29 22:37:25 -07:00
Elliott Hughes
1b600a902c Fix Win32 build.
Change-Id: Icf2c8df99b4b88bbf85a4097731733c5795fba44
2015-04-29 12:36:06 -07:00
Elliott Hughes
078f0fcf4c Move __adb_error to std::string, and improve various errors.
Also remove an sprintf. Also fix various bits of code that were
reporting stale adb_error values when they meant strerror.

Bug: http://b/20666660
Change-Id: Ibeb48b7bc21bb0ec30ba47889d1d671ee480e1b7
2015-04-29 11:28:37 -07:00
Elliott Hughes
8d5fa6da44 Remove strtok from adb.
Also fix android::base::Split to behave like Java, Python, and google3.

Change-Id: Ifbffd4e92950a79e7aea5d153c95fe0980648417
2015-04-27 19:42:20 -07:00
Elliott Hughes
9309ecbcec Support the full length of USB serial numbers.
Two bugs: we couldn't report the serial number correctly if it was long
enough, and it wasn't possible to connect to a device whose serial number
was long enough to overflow a different fixed-length buffer.

Bug: http://b/20317730
Change-Id: Ic9cf3c847066449ac78069bd1718184935098ac7
2015-04-27 14:52:17 -07:00
Elliott Hughes
ce6363bbbc Improve logging of USBDEVFS_CLAIMINTERFACE failures.
Bug: https://code.google.com/p/android/issues/detail?id=170054
Change-Id: I9b11eb019093e3322da0a8e70d6e17de4c25ab75
2015-04-25 14:44:23 -07:00
Elliott Hughes
876881b22a Merge "Add missing null checks after allocations." 2015-04-22 20:05:46 +00:00
Elliott Hughes
dc3b459ff9 Add missing null checks after allocations.
Bug: http://b/20317729
Change-Id: I62bb761d48ee59a1f4ddd0cdd0632432305ca2ca
2015-04-21 19:43:22 -07:00
Elliott Hughes
1555147bc4 Plumb more of the error reporting through.
This doesn't fix the bug, but it does flatten the bug to the well-known
and long-standing "adb shell" doesn't return exit statuses, so when we
fix that, this one will fix itself.

Bug: http://b/20423886
Change-Id: I48351e46f05dd3f2f6e57f0df1d851333458d0ef
2015-04-21 17:58:55 -07:00
Elliott Hughes
8e6edc0d89 Add a couple more adb shell regression tests.
Bug: http://b/15479704
Change-Id: Id3e7f0df101ad61db509df313c13210a8bd8b124
2015-04-21 16:25:54 -07:00
Badhri Jagan Sridharan
82b0f7ba92 Merge "adb: set sys.usb.ffs.ready to signal usb pullup" 2015-04-21 19:58:46 +00:00
Badhri Jagan Sridharan
5f97370bab adb: set sys.usb.ffs.ready to signal usb pullup
This change sets sys.usb.ffs.ready to 1 to
trigger configfs based enumeration.

Change-Id: I222495fc667cce59675579069d164b0b484f3653
2015-04-21 12:44:31 -07:00
Elliott Hughes
0053bb3f1a Add a test for shell escaping.
Until I fixed this, we would fail this example:

  $ adb shell sh -c 'echo hello; echo world'
  hello
  /system/bin/sh:  echo world: not found

Bug: http://b/19734868
Change-Id: I11a437cd0c0362303028f23fbaa103611b75707e
2015-04-21 12:15:31 -07:00
Elliott Hughes
d236d071b9 Fix "adb sync" for devices without vendor and oem.
Bug: http://b/20440110
Change-Id: I2481992198890f5ca50412c2b7ca361101961413
2015-04-21 10:17:07 -07:00
Elliott Hughes
e434ad1dd7 Merge "Always explain why bind(2) failed." 2015-04-21 16:52:21 +00:00
Elliott Hughes
14b65736c5 Merge "Use ' quoting to escape arguments." 2015-04-21 16:47:43 +00:00
Colin Cross
dc1e482b20 Fix windows adb build
libc++ is not available on windows yet, but it already defaults to
static libstdc++.

Change-Id: I85a766ead84f71fe1f2f59be6ac739b0b833b6db
2015-04-20 12:43:02 -07:00
Colin Cross
b2b06de5fc Merge "statically link adb and fastboot against libc++" 2015-04-20 18:05:29 +00:00
Elliott Hughes
7b506090e1 Always explain why bind(2) failed.
This has confused several people lately.

Bug: http://b/20219978
Change-Id: I2537ceb83bff0b3166c230c728d4389a983db858
2015-04-20 08:09:20 -07:00
Elliott Hughes
53daee6a2b Fix the Windows adb build.
It looks like we can't use clang on Windows yet because libc++ isn't ready.
So move back to GCC for the Windows host clang. Work around the mingw
printf format string problems that made us want to switch to clang in the
first place, and #include "sysdeps.h" in adb_utils.cpp to work around the
absence of lstat(2) on Windows.

Change-Id: Icd0797a8c0c2d1d326bdd704ba6bcafcbaeb742f
2015-04-19 13:17:01 -07:00
Elliott Hughes
5498adefb0 Use ' quoting to escape arguments.
The specific motivating case is "text;ls;1.apk", but rather than continue
adding individual characters to the list of characters to be escaped, let's
just switch to quote all arguments with ', which only leaves ' itself to be
escaped.

Bug: 20323053
Bug: 19734868
Change-Id: I8bd71db9373bc2d1169fc11e46c889da6638550a
2015-04-17 20:55:04 -07:00
Elliott Hughes
6c34bbaa68 Use escape_arg in "adb backup".
This doesn't fix the injection vulnerability, but it makes "adb backup"
no worse than the other commands, and lets me fix them all at once.

Bug: 20323053
Change-Id: I39843c065d9d738b6b7943b2ffd660e4a031cc36
2015-04-17 20:30:09 -07:00
Elliott Hughes
a7090b94c1 Remove yet more fixed-length buffers (and their overruns).
Bug: 20317724
Change-Id: If137fc96f5f23576ccecd388ac87afefa47337c6
2015-04-17 17:58:35 -07:00
Elliott Hughes
2083fa6b01 Switch adb over to clang.
Change-Id: Ib5511dcba56e80ffce6bc293d99251ccfd61c330
2015-04-17 15:27:13 -07:00
Elliott Hughes
61a004c05f Merge "Fix more buffer overruns." 2015-04-17 22:24:27 +00:00
Elliott Hughes
5830577bd8 Fix more buffer overruns.
Also add some tests.

Bug: 20323050
Change-Id: I9eaf3dc04efd85206663c4cca4f8c1208620a89a
2015-04-17 15:23:31 -07:00
Elliott Hughes
2940ccff86 Use PRI* macros to fix the Windows build.
Change-Id: Icd400be05c2bc726265832875b5a05dba7966847
2015-04-17 14:07:52 -07:00
Elliott Hughes
2baae3a876 Remove various fixed-length buffers (and their overflows).
Bug: 20323052
Bug: 20323051
Bug: 20317728
Bug: 20317727
Bug: 20317726
Bug: 20317725
Change-Id: I57a5e30a5b7867715f55cee7429aa36d7ce21484
2015-04-17 10:59:34 -07:00
Elliott Hughes
0b8ecb3290 Merge "Remove extern "C" barriers to using C++." 2015-04-17 17:31:51 +00:00
Elliott Hughes
2d4121c0dc Remove extern "C" barriers to using C++.
Change-Id: Ic046d6aa540738cb46b54531bc59ba3b47b0136d
2015-04-17 09:47:42 -07:00
Elliott Hughes
7be29c819b Show $ADB_VENDOR_KEYS if authentication fails.
Incorrectly set $ADB_VENDOR_KEYS is the most likely cause of failed
adb connections. Make it easier to debug such problems by including
the value in use in the error message.

Bug: 20165551
Change-Id: I64c1d98ae6d3fb40eea9e1f0ddcfcf4f2d9d7318
2015-04-16 22:54:44 -07:00
Dan Albert
a4802ca08b Merge "Move usb_osx to C++." 2015-04-17 04:37:47 +00:00
Dan Albert
c4f8fa7b36 Merge "Link libraries needed for Darwin adb tests." 2015-04-17 04:37:41 +00:00
Dan Albert
7447dd05bd Move usb_osx to C++.
Change-Id: I21673211a702cc4f31d4311c36e2a4b22e55fac8
2015-04-16 19:20:40 -07:00
Dan Albert
f8d6b9b1ef Link libraries needed for Darwin adb tests.
Change-Id: I1c3c3a7bbd3824f5f3a37ee80c24d1c2a9b98748
2015-04-16 19:13:58 -07:00
Colin Cross
55bf5f0017 statically link adb and fastboot against libc++
libc++.so is not widely available on the host, so we compile against
one built as part of the platform.  This causes problems for adb and
fastboot, which are distributed through a number of channels - the
sdk, distro packages, downloaded from the build server, or manually
copied.  Instead of forcing all users to handle libc++.so too,
statically link against libc++.

Change-Id: I51b75258653a23558c8b598802005f6c1166a439
2015-04-16 17:09:46 -07:00
Elliott Hughes
a2f2e56796 Move sysdeps_win32 to C++.
Change-Id: I27ca41b64d62bb3611b3a39a5c3bb4377d0773bc
2015-04-16 16:47:02 -07:00
Elliott Hughes
2acec9153e Switch usb_linux_client to C++.
Change-Id: I8172e81e6c4665aa16e9e8e0c33b048dbb9ad848
2015-04-16 14:38:37 -07:00
Elliott Hughes
1a4d85a5e8 Move get_my_path_darwin to C++.
As long as we have C in here, we can't use C++ in our headers.

Change-Id: Ibccaa77a5af506dc504aa9c39c8dca5dcdbeccab
2015-04-16 13:24:58 -07:00
Sami Tolvanen
284c5cb2a1 Merge "Set verity mode as the verified property value" 2015-04-07 08:45:24 +00:00
Alistair Buxton
dfa09fd635 Disable CR/LF translation for adb interactive shell.
adb shell uses termios to disable canonical input processing in order to
get raw control codes but it does not disable CR/LF translation. The default
for Linux terminals is to convert CR to LF unless the running program
specifically asks for this to be disabled. Since adb does not, there is no
way to send a CR to any program run on adb shell. Many programs do in fact
differentiate and so are broken by this behaviour, notably nano. This patch
sets the termios flags to disable all line ending translation.

Change-Id: I8b950220f7cc52fefaed2ee37d97e0789b40a078
Signed-off-by: Alistair Buxton <a.j.buxton@gmail.com>
2015-04-05 10:02:34 -07:00
Elliott Hughes
09a45a1927 Fix "adb devices -l".
Change 055f1aa4ff switched to using isalnum(3)
but didn't take into account that isalnum has the opposite sense to the
function it replaced, so the tests should have been inverted.

Bug: http://b/20056546
Change-Id: I90630c0bea69ddbb4a95dc09f79f49d23fd497de
2015-04-03 16:12:15 -07:00
Elliott Hughes
bcc2b5f44a Remove LOCAL_ADDITIONAL_DEPENDENCIES in cases where it's not needed.
Change-Id: I720b8ef1050da45a7833adef8219b6acb2cf3a38
2015-04-02 14:31:07 -07:00
Sami Tolvanen
454742392f Set verity mode as the verified property value
Set the verity mode as the value for partition.%s.verified to make it
easier for userspace to determine in which mode dm-verity was started.

Change-Id: Icc635515f8a8ede941277aed196867351d8387cb
2015-03-31 09:12:00 +01:00
Tao Bao
175b7bbfb4 adb: Add option to reboot into sideload mode in recovery
Currently it requires manual key press to enter the sideload mode. This
CL adds 'adb reboot sideload' to reboot the device into sideload mode
directly with text display on. With 'adb reboot sideload-auto-reboot',
it will reboot after the sideload regardless of the installation result,
unless interrupted by user.

Since it needs to write to /cache/recovery/command file, 'adb root' is
required before calling 'adb reboot sideload' and the one with
'-auto-reboot'.

Also it requires the matching CL in bootable/recovery.

Change-Id: Ib7bd4e216a1efc01e64460659c97c6005bbaec1b
2015-03-31 00:19:52 +00:00
Dan Albert
868402e5bf Revert "Remove the emulator special case from the "adb root" code."
adb root doesn't work on the emulator, so this prevents root access
to a userdebug emulator.

Since the emulator has always been root even on userdebug builds, it
may be that adb root has never worked on the emulator.

Bug: 19974213

This reverts commit abd6773b41.
2015-03-28 19:04:15 +00:00
Spencer Low
50184062b8 adb shell: Win32: fix Ctrl-C, tab completion, line editing, server echo
The 'adb shell' command on Windows has had problems:

* Ctrl-C killed the local Windows adb.exe process instead of sending the
Ctrl-C to the Android device.

* Local echo was enabled, causing everything typed to be displayed twice.

* Line input was enabled, so the Android device only received input
after hitting enter. This meant that tab completion did not work because
the tab wasn't seen by the shell until pressing enter.

* The usual input line editing keys did not work (Ctrl-A to go to the
beginning of the line, etc.).

This commit fixes these issues by reconfiguring the Win32 console and
then translating input into what Gnome Terminal would send, in effect
somewhat emulating a Unix terminal.

This does not fix all Win32 console issues, but is designed to be better
than what we had before, and to make the common day-to-day usage much
more comfortable and usable.

Change-Id: Idb10e0b634e27002804fa99c09a64e7176cf7c09
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-03-26 12:26:08 -07:00
Dan Albert
8743ef9841 Additional cleanup of start_device_log.
Addresses nnk's post commit review comments on
https://android-review.googlesource.com/#/c/139381/

Remove unneeded code for creating /data/adb.

Add an O_CLOEXEC.

Move the closing of stdin out to main().

Append the pid of the current process to the log file to avoid
clobbering the log if the process crashes and restarts within the same
second.

Change-Id: Ide0be86b4b33256486634c29ba02efaf10cf913d
2015-03-20 09:49:15 -07:00
Dan Albert
ea2175ab6b Use text based trace masks for adbd.
Previously the adbd trace mask had to be set as raw hex rather than
with the colon separated list. We all have better things to do than
memorize bitmasks, so make adbd use the same trace mask setting code
as adb.

Change-Id: I0bf0ab61c070d06d1cc2acf1ed90b2b77ccd261b
2015-03-19 21:50:10 -07:00
Dan Albert
a16b0f4c3a Merge "The generic failure case disappeared..." 2015-03-20 03:50:36 +00:00
Dan Albert
28f07697eb Merge "File header cleanup." 2015-03-20 03:14:28 +00:00
Dan Albert
08f66bc771 The generic failure case disappeared...
Was manifesting as a write to a full disk hanging indefinitely.

Bug: 19846181
Change-Id: Ia581e0bbbb331c221bdb68882c238d0cb9f8a0b3
2015-03-19 20:10:30 -07:00
Dan Albert
3313426fad File header cleanup.
* sysdeps.h should always be included first.
 * TRACE_TAG needs to be defined before anything is included.
 * Some files were missing copyright headers.
 * Save precious bytes on my SSD by removing useless whitespace.

Change-Id: I88980e6e00b5be1093806cf286740d9e4a033b94
2015-03-19 15:32:33 -07:00
Dan Albert
683238c3c4 Fix clang-format file for correct indent settings.
Change-Id: I8786baf33c0b84e3614e9d40c404eeef94b91236
2015-03-19 13:27:20 -07:00
Dan Albert
b4ebc475e6 Merge "Fix memory leak on jdwp_process_free()" 2015-03-19 16:53:57 +00:00
Pavel Labath
64d9adcea8 Fix file descriptor leakage in adbd
adb_auth_init in adb_auth_client.cpp sets FD_CLOEXEC on the control
socket, which prevents the leakage. However if ro.adb.secure
property is unset (as it is on the emulator), adb_auth_init is not
invoked, which results in the control socket fd leaking into any
process started by the deamon (specifically, any command executed
through adb shell).

Split the fd cleanup into a separate function that is called
unconditionally.

Change-Id: I73ea84977542ddfc4ac20599593ecf3745ae9108
2015-03-17 11:24:34 -07:00
Elliott Hughes
ec7a667131 Revert "Revert "adb: support /oem partition""
This reverts commit 6084a0124f.

The original build breakage is fixed by (a) building the verity
code for eng builds as well as userdebug builds and (b) moving
the exported remount service functions into a new header file.

Change-Id: Ice0c4f97d4db38ab7eb333c7a6e56bbd11123f5b
2015-03-16 20:05:21 -07:00
Dan Albert
6084a0124f Revert "adb: support /oem partition"
This is broken on userdebug builds, and it isn't completely clear why. The declaration for make_block-device_writable in adb.h wasn't updated to match the definition (which uses a std::string instead of a char*). adb.h is currently extern "C", and it isn't clear why this is only broken for userdebug, so I'd like to revert while we investigate.

This reverts commit 81416fdb18.

Change-Id: I47f321574f9f21052e2c7332e8b0f6ef9ab98277
2015-03-16 21:35:53 +00:00
Mårten Kongstad
81416fdb18 adb: support /oem partition
Add support for /oem partition in commands 'adb remount' and 'adb sync'.

Change-Id: I5defc74ccaa37feaef74b9268e22b4075f98a59f
2015-03-16 11:17:13 -07:00
Dan Albert
98ff77204c Create libbase.
Move StringPrintf and the string based file I/O from libutils to
libbase.

Change-Id: I0297a6063874b9d92100e0dd5123fddfbda932fe
2015-03-14 16:36:18 -07:00
Elliott Hughes
46270d233a adb doesn't actually use libzipfile.
Change-Id: Ia7d22214bc8422c88edaaf9bb716d7e12e0bb381
2015-03-13 09:40:45 -07:00
Dan Albert
83ca56ac98 Fix build from -Werror=maybe-uninitialized.
This won't actually ever be uninitialized because the code will take a
failure path if the code that initializes it fails. The goto seems to
thwart this check though.

Not sure why this is only firing on userdebug builds yet. I'll look in
to it tomorrow.

Change-Id: Ie9d837d6baea255d2a4d169355b53dfd775eacce
2015-03-09 18:29:07 -07:00
Dan Albert
bac3474a82 Move adb to C++.
I keep trying to clean things up and needing std::strings. Might as
well just do this now.

usb_linux_client.c is going to stay as C because GCC isn't smart
enough to deal with the designated initializers it uses (though for
some reason it is in C mode).

The Darwin files are staying as C because I don't have a way to test
that they build.

The Windows files are staying as C because while I can actually build
for them, it's slow and painful.

Change-Id: I75367d29205a9049d34460032b3bb36384f43941
2015-03-09 14:06:11 -07:00
Dan Albert
9b1fd969a7 Merge "Fix a writex transcription error." 2015-03-09 20:29:07 +00:00
Dan Albert
f3519a8747 Fix a writex transcription error.
Change-Id: I71b11127d41ebac6caf68926089c5a3b99d8c21e
2015-03-09 13:22:02 -07:00
Dan Albert
857d7db69d Make the root/unroot test more robust.
* Check the current adb user to choose the order of root/unroot.
* Re-root the device when finished.

Change-Id: I47a14b89e2c405bd63722e4d2043fcc629fb5e58
2015-03-09 10:45:50 -07:00
SungHyun Kwon
abb80e0f95 Fix memory leak on jdwp_process_free()
if many jdwp connection are created(), the memory will be leaked.

When it deletes heap memory on jdwp_process_free(),
the proc->fde just set to null.

so it need to free() in fdevent_destory().
2015-03-03 17:56:18 +09:00
Nick Kralevich
268eb4f384 check if uid=0 before attempting remount
If "adb remount" is done without having done "adb root" first,
scary looking SELinux denials are emitted before the operation
eventually fails. Avoid the scary looking messages by refusing
remount attempts if we're not running with privileges.

Change-Id: I298621251a10e38345ef77875003a97c8b5a0270
2015-02-25 16:27:31 -08:00
Dan Albert
cc731cc767 Test readx/writex (now renamed).
Renamed readx/writex to ReadFdExactly/WriteFdExactly respectively.
These read/write a full fixed-size buffer. If the whole buffer cannot
be read/written, these functions return an error.

Rename write_string to WriteStringFully.

Move the TEMP_FAILURE_RETRY definition in sysdeps.h out of the
!Windows section. It seems Windows won't actually interrupt a call,
but it's easier to just define it than to #ifdef each call.

Change-Id: Ia8ddffa2a52764a2f9a281c96c937660e002b9b9
2015-02-25 15:07:57 -08:00
Dan Albert
7fd821e907 Remove _(GNU|XOPEN)_SOURCE makefile cruft.
None of the functions that require these are used.

Change-Id: I10cffab127795b94340131f8737f7924b9138f9e
2015-02-25 11:08:21 -08:00
Dan Albert
055f1aa4ff Add some basic tests to adb.
Change-Id: I946b5b1e5650540db3b4f75892214c4218b3baf3
2015-02-25 10:57:26 -08:00
Dan Albert
dc0f8ecb24 Fix the mac build.
Change-Id: Ieb6f2650ce5f39f1d8c938d0ca8cbec459d8e2fd
2015-02-25 10:26:17 -08:00
Dan Albert
72bf2a7100 Merge "Move transport declarations into transport.h." 2015-02-25 05:33:35 +00:00
Dan Albert
7664901a35 Move transport declarations into transport.h.
There are a few cloexec issues in here as an added bonus.

Change-Id: I1699d719d733f47878bdba0454230cf5ab6a60b6
2015-02-24 21:30:22 -08:00
Dan Albert
103c1be03f Add .clang-format file.
Not going to format the whole world just yet, but this helps for `git
clang-format`.

Change-Id: I482819419647e4c752d3b044bde8d637e1fae1e5
2015-02-24 16:56:39 -08:00
Dan Albert
5329d3fd54 Merge "Add a project wide clang switch." 2015-02-25 00:20:39 +00:00
Dan Albert
9697ce520d Add a project wide clang switch.
I'll probably make this the default soon, but I'm not brave enough to
do that without checking the recovery image first.

Change-Id: I9cde687b08a588e3797645a308f381e4ec553447
2015-02-24 15:54:34 -08:00
Elliott Hughes
70385f3017 Merge "Remove the emulator special case from the "adb root" code." 2015-02-24 23:53:55 +00:00
Dan Albert
b2e57b738f Make Python tests only check the current device.
In practice testing all connected devices is a pain, since it's
probably each device is running a different build. It would probably
make sense to just move this functionality up into a higher level test
runner (which could just live in main).

Also rename test_devices to test_shell, since it doesn't really test
`adb devices`.

Change-Id: Ie96d3e83b30acfac4e3bcbd9821690c0ad4d2f7e
2015-02-24 14:36:03 -08:00
Dan Albert
fdf8722491 Fix Mac build.
Prior to https://android-review.googlesource.com/#/c/134253/ the
makefile had assumed !Windows was the same as Linux, so the Mac was
actually getting all the Linux sources as well. I mistakenly didn't
add fdevent.cpp to the Darwin sources in that change.

Change-Id: I4e12a394e9a2baf7c1e3c711a01a6b5fccbf79d9
2015-02-24 14:27:33 -08:00
Elliott Hughes
abd6773b41 Remove the emulator special case from the "adb root" code.
The emulator is essential an "eng" build, so the regular properties
should suffice.

Change-Id: Id63b3918f9b0b04b0d887ed886535b9976a9cc85
2015-02-24 14:10:51 -08:00
Dan Albert
88cf1c8c4a Fix Windows SDK build.
Change-Id: I9c0f9c92c28867ff17f1ec83aac935d18348c335
2015-02-24 14:08:03 -08:00
Elliott Hughes
3b967f52f2 Add missing <stdlib.h> to adb_listeners.c.
Change-Id: If9505880a33131b27bfaa19f3efd45c83a6810ed
2015-02-24 12:37:13 -08:00
Dan Albert
a75b4935a4 Merge "Move more into libadb and libadbd." 2015-02-24 19:44:34 +00:00
Dan Albert
9f3540d017 Merge "Oops. Fix make variable name. Thanks again, make." 2015-02-24 19:44:12 +00:00
Dan Albert
8ef39424e8 Merge "Ignore another stupid lint warning." 2015-02-24 19:44:05 +00:00
Nanik Tolaram
b627a0e2ed Add more logging message and dead code
* Add more logging message to aid in easier debugging

* Remove unnecessary dead/commented code

Change-Id: I9c7fe8f6b674cab41601001458010ab176b89776
Signed-off-by: Nanik Tolaram <nanikjava@gmail.com>
2015-02-23 22:38:39 +00:00
Dan Albert
3c43858986 Move more into libadb and libadbd.
None of this needs to be shared with minadbd, but these sources are
still needed for anything linking libadb (such as tests).

Change-Id: I3024f714da42364bf27a991986f00676e2bbbf2c
2015-02-20 17:24:30 -08:00
Dan Albert
bf10647b61 Oops. Fix make variable name. Thanks again, make.
Change-Id: Iecbb41acc835bb8eb20b668c89a3ff065470fcb7
2015-02-20 17:20:37 -08:00
Dan Albert
f1591691ee Ignore another stupid lint warning.
Change-Id: I8e586e472a139cc3039f1371f8a99935d20aa0f0
2015-02-20 17:19:22 -08:00
Dan Albert
7e84308b74 Merge "Lose adb.c and sockets.c to libadb." 2015-02-19 23:47:18 +00:00
Dan Albert
e1ca623faa Lose adb.c and sockets.c to libadb.
Also kill the device side libadb. This was added for the now dead
device side adb, and is no longer used.

Bug: 17626262
Change-Id: I3b28915641fd5b4f16fc86cf1f4f4e9711093001
2015-02-19 13:49:35 -08:00
Dan Albert
18daa159ec Merge "Document the behavior of props affecting adb root." 2015-02-19 20:33:31 +00:00
Dan Albert
13f9c406d7 Document the behavior of props affecting adb root.
Change-Id: Icfdc3ba696556d6db64835e61dde6f40b491d1a7
2015-02-19 12:29:01 -08:00
Dan Albert
6795cd8db5 Fix Windows adb build.
Change-Id: I560bedfcf77556b36acadc19f5dac71b3628ea2b
2015-02-19 11:36:53 -08:00
Dan Albert
bd0b750897 Move adb_main to its own file.
Change-Id: If6e98c089b39f73bd8f4a878a82669bfeee367f3
2015-02-18 18:32:54 -08:00
Dan Albert
e9fca14c9e Move the listener code into its own file.
Change-Id: I7332455ed1a213daedeaa4a81260edf08b2fd131
2015-02-18 18:22:52 -08:00
Dan Albert
ba3a251749 Move the adb auth code into its own file.
Change-Id: I84cf0bd7777f0147119e7c6afc4096c2e93156a2
2015-02-18 18:22:52 -08:00
Dan Albert
1403aa36b2 Merge "Move emulator tracing into its own file." 2015-02-19 02:10:10 +00:00
Dan Albert
21c3eaf4cc Move emulator tracing into its own file.
adb.c is far too monolithic.

Change-Id: I4a9ee97927e4a96a38ea5859d84efac86bfdfc35
2015-02-18 17:21:17 -08:00
Elliott Hughes
4c9d24a3ed Fix build.
Change-Id: I31fc562068ebbba5e9872ee91694feb611fc957f
2015-02-18 16:57:30 -08:00