Commit graph

13799 commits

Author SHA1 Message Date
Spencer Low
cf168a82e9 adb_test/libbase_test: win32: get some tests working
adb_test:

* Fix adb_utils directory_exists test for Windows. The test actually
fails because directory_exists() is not aware of junctions or symlinks,
but I'm not really sure if that is a bad thing (since these are rare on
Windows to begin with).

* Fix crash during transport tests due to mutex not being initialized.

* io tests fail for various reasons (see adb_io_test.cpp for more info).

libbase_test:

* Get it building on Win32 by implementing mkstemp() and mkdtemp().

* Run StringPrintf %z test on Windows because it passes because we build
with __USE_MINGW_ANSI_STDIO which implements %z.

* I didn't fixup the logging tests: some logging tests fail because when
abort() is called on Windows, by default it pops up UI asking whether a
crash dump should be sent to Microsoft. To some degree this makes sense,
as I think LOG(FATAL) does crash dumping in Chromium. This should be
revisited in the future.

Change-Id: Iaa2433e5294ff162e0b2aa9fe6e4ec09a6893f7a
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-08-03 12:44:43 -07:00
Yusuke Sato
b6c66dc0a3 perfboot.py: warn if dm-verity is disabled
Disabling the feature sometimes skews benchmark results.

Bug: 22207911
Change-Id: Idedc7eb14e3cc4e8687b0c0e2975f10a3c4154e5
2015-08-03 11:36:21 -07:00
Elliott Hughes
bb3b45d27c Merge "libbase_test: win32: get some tests working" 2015-08-03 17:55:12 +00:00
Spencer Low
40d0c7aead libbase_test: win32: get some tests working
* Get it building on Win32 by implementing mkstemp() and mkdtemp().

* Run StringPrintf %z test on Windows because it passes because we build
with __USE_MINGW_ANSI_STDIO which implements %z.

Change-Id: Ia01f94e8258503381a1df6d3da6e40de59e57125
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-08-03 10:54:17 -07:00
Tom Cherry
4247ebfd2f Merge "init: use std::vector<std::string> for argument passing" 2015-08-03 17:51:39 +00:00
Todd Kennedy
6782ca0b76 Merge "Add a trace constant for PackageManager" 2015-08-03 17:44:46 +00:00
Todd Kennedy
da106ad28c Add a trace constant for PackageManager
Change-Id: Iff63b3d31ba9b997bd61c58c9df5afe2dfd7be7a
2015-08-03 09:58:01 -07:00
Elliott Hughes
11ca81fc3c Merge "Remove adb's unused get_my_path for Windows." 2015-08-03 15:32:43 +00:00
Spencer Low
8df9032176 adb: win32: call SystemErrorCodeToString() from more places
Improve some error messages, or trace output.

Change-Id: Ib09fac33a296f090d37f125cad7556fc5b5e928e
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-08-02 18:50:17 -07:00
Spencer Low
e347c1dd47 adb: win32: define UNICODE/_UNICODE, Unicode error messages, misc
Define the UNICODE and _UNICODE preprocessor symbols to make passing
char* to Ansi/Unicode-agnostic Windows and C Runtime APIs break the
build. The solution is to call wide Windows and C Runtime APIs and use
widen(utf8).c_str(). Most code was already calling wide APIs. Defining
these symbols makes a call to CreateEvent() (which previously mapped to
CreateEventA()) turn into a call to CreateEventW().

Make SystemErrorCodeToString() use Unicode.

Add various comments.

Change-Id: I9b212412348a29826718e897a486489e1f142d16
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-08-02 18:13:54 -07:00
Spencer Low
a5b06b0ff8 adb: win32: fix USB device hang when resuming from sleep/hibernation
After resuming Windows from sleep or hibernation, USB connections are not
automatically disconnected. Writing to the USB connections does not return any
errors, but read never returns. My theory is that the device saw the host
sleep/hibernation as a disconnect, so the device is waiting for re-auth from the
host as if the host was just connected.

To solve this, detect resume from sleep/hibernation, disconnect all USB
connections and let the device poll thread re-detect the USB devices in 1 sec.

This is done by using a hidden window that receives power notifications. The
hidden window code is based on Chromium's similar code (platform-tools already
includes the Chromium Authors license).

This depends on a change to AdbWinUsbApi.dll that makes AdbCloseHandle(endpoint)
abort any pending IOs and wait for those IOs to be aborted.

I expect that this should solve many adb and Android Studio related bugs
regarding hangs or errors.

Also in this change:

 - Add D() logging for any errors from AdbWinApi.dll API calls.

 - Stop setting errno to Win32 error values which the caller can't really do
   anything with. Stop calling SetLastError() because the callers don't check
   GetLastError() anyway.

 - Check the return value from writing zero length packets.

 - If the full amount of data isn't written, return an error.

 - Upon any usb_read/usb_write error, kick the connection instead of only
   kicking when ERROR_INVALID_HANDLE is encountered.

 - Restructure some code from nested-if-trees to goto-fail to make it easier
   to follow.

 - Delete usb_name() since it isn't thread-safe and it isn't used.

Change-Id: Iffcf5315ad8593d0c7e93012afaabe6fae354ac1
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-08-01 19:19:09 -07:00
Elliott Hughes
16d79c7318 Remove adb's unused get_my_path for Windows.
Change-Id: I3cfb4677acaf6acaf512b3cdce6c11bdb2bd0578
2015-07-31 17:54:24 -07:00
Yabin Cui
c70ac57db0 Merge "adb: poll for emulator connection." 2015-08-01 00:50:39 +00:00
Jorge Lucangeli Obes
a336cbcd5c Merge "Reserve new UID range for OEM." 2015-08-01 00:40:37 +00:00
Elliott Hughes
367fb50333 Merge "adb: win32: Unicode path names, env vars, some console support" 2015-07-31 23:50:52 +00:00
Yusuke Sato
b5d6ad81cb Merge "Stop calling fsck on shutdown by default" 2015-07-31 23:13:15 +00:00
Tom Cherry
96f67316a2 init: use std::vector<std::string> for argument passing
Change-Id: Ie7a64e65de3a20d0c7f7d8efc0f7c1ba121d07fe
2015-07-31 16:02:12 -07:00
Spencer Low
c3211557b3 adb: win32: file descriptor reliability improvements
When repeatedly opening and closing a file descriptor, the sequence of
fds returned was: 100...227,100,100,100,100,100... Basically, the first
wave was constantly increasing fds, but after the entire fd table was
traversed once, the alloc algorithm would switch to returning the first
free fd. This is sub-optimal for reliability because use-after-free bugs
would be more likely to be hit because right after a close, the same fd
would be given out next.

This change makes the alloc algorithm use a persistent clock hand that
walks forward through the fd table (wrapping around if necessary),
searching for a free fd.

This change adds locking for fd closing:

 - This prevents multiple concurrent closes of the same fd.

 - There was a race between alloc and close that wasn't guaranteed to be
   correct: close would set f->clazz to NULL last, but without any
   preceding memory barrier/fence, then the alloc thread would check for
   NULL. It probably worked out ok in practice, but it is probably best
   to fix this up with a lock (as in this change) or a memory barrier/fence
   (but this code isn't about performance, so why go with a complicated
   barrier/fence?)

Also in this change:

 - Use errno = EMFILE for the out of fds case.

 - Clear FH->name

Change-Id: Ic11d2a1a9d53996edfc1ca13566a2f46de4a4316
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-07-31 15:13:52 -07:00
Lee Campbell
0f91887868 Merge "init: Adding header guard to tokenizer" 2015-07-31 21:47:13 +00:00
Yabin Cui
0e2c194659 adb: poll for emulator connection.
Bug: 19974213
Change-Id: I336f3ad6f428277c54479e5b8c45d5343c64f472
2015-07-31 14:25:19 -07:00
Jorge Lucangeli Obes
b93b9d4867 Reserve new UID range for OEM.
Brillo will need to run new native system services, so reserve
a reasonable UID range to accomodate them. Having 1000 UIDs will
allow us to sub-partition this range if needed.

The range can be used by any OEM, not just Brillo, so name it
accordingly.

Bug: 22555869
Change-Id: I752428ee5025bf064a35ecbe6da50c041d87b724
2015-07-31 14:13:49 -07:00
Elliott Hughes
ec035950e6 Merge "Clean up -p handling slightly." 2015-07-31 21:02:01 +00:00
Spencer Low
cf4ff64f2d adb: win32: Unicode path names, env vars, some console support
Initial support for Unicode file/dir names. Unicode paths can be passed
on the command line, directory enumeration can enumerate Unicode paths,
Unicode paths are used for file access, and Unicode paths can be output
on the console correctly.

Also Unicode environment variable access.

Initial support for Unicode output from adb shell (which uses
adb_fwrite()). This is partial because the corner case of an
adb_fwrite() call with an incomplete UTF-8 multi-byte sequence does not
output correctly, but this should be uncommon, is better than what we
had before (*always* incorrect UTF-8 multi-byte sequences) and can be
fixed in the future.

Calls to Windows APIs with char strings were changed to pass wchar_t
strings to the FooW() variants.

For more details, see the giant comment in sysdeps_win32.cpp.

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

Change-Id: I7ebf6713bb635638b986ccee97b354428837c9c5
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-07-31 13:30:41 -07:00
Elliott Hughes
048b27c066 Clean up -p handling slightly.
Change-Id: I8a5cd4a7adb0dde9d09e0cbb620874b1bca35e43
2015-07-31 13:18:22 -07:00
Elliott Hughes
cf4dba5ab3 Merge "adb: win32: initial IPv6 support and improved Winsock error reporting" 2015-07-31 18:11:45 +00:00
Yabin Cui
dc1fb361f3 Merge "Make clear of the data length sent by write_packet." 2015-07-31 16:48:25 +00:00
Spencer Low
5200c6670f adb: win32: initial IPv6 support and improved Winsock error reporting
Call getaddrinfo() for connecting to IPv6 destinations.

Winsock APIs do not set errno. WSAGetLastError() returns Winsock errors
that are more numerous than BSD sockets, so it really doesn't make sense
to map those to BSD socket errors. Plus, even if we did that, the
Windows C Runtime (that mingw binaries use) has a strerror() that does
not recognize BSD socket error codes.

The solution is to wrap the various libcutils socket_* APIs with
sysdeps.h network_* APIs. For POSIX, the network_* APIs just call
strerror(). For Windows, they call SystemErrorCodeToString() (adapted
from Chromium).

Also in this change:

 - Various other code was modified to return errors in a std::string*
   argument, to be able to surface the error string to the end-user.

 - Improved error checking and use of D() to log Winsock errors for
   improved debuggability.

 - For sysdeps_win32.cpp, added unique_fh class that works like
   std::unique_ptr, for calling _fh_close().

 - Fix win32 adb_socketpair() setting of errno in error case.

 - Improve _socket_set_errno() D() logging to reduce confusion. Map
   a few extra error codes.

 - Move adb_shutdown() lower in sysdeps_win32.cpp so it can call
   _socket_set_errno().

 - Move network_connect() from adb_utils.cpp to sysdeps.h.

 - Merge socket_loopback_server() and socket_inaddr_any_server() into
   _network_server() since most of the code was identical.

Change-Id: I945f36870f320578b3a11ba093852ba6f7b93400
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-07-30 23:07:55 -07:00
Yabin Cui
6264129434 Make clear of the data length sent by write_packet.
Change-Id: If51b4feaa19a710874999ad7e6131ff2e56a9f8a
2015-07-30 20:01:10 -07:00
Lee Campbell
06584400dd init: Adding header guard to tokenizer
Fixing missing header guard

BUG: 22843198
Change-Id: Ice5d29d343ffe093aae46d4ac3fd72de628fb12e
2015-07-30 18:48:50 -07:00
Elliott Hughes
7b98bfcc9f Merge "More adb cleanup." 2015-07-31 01:01:20 +00:00
Elliott Hughes
5c74270f95 More adb cleanup.
This removes adb_dirstart and adb_dirstop. It also fixes a couple of memory
leaks by switching to std::string. This also fixes the bug in the previous
change --- mkdirs is given input like "/system/bin/sh" and only expected to
create "/system/bin". In a later change, we should remove mkdirs and only
expose the intended "unlink && mkdirs && create" functionality.

Change-Id: I30289dc1b3dff575cc1b158d993652178f587552
2015-07-30 17:46:58 -07:00
Elliott Hughes
0cf93dc345 Merge "Write mkdirs in more idiomatic C++ style." 2015-07-30 22:56:01 +00:00
Alex Vallée
47d67c96ec Write mkdirs in more idiomatic C++ style.
~ Rewrote mkdirs to be in C++ style.
~ Replaced adb_dir{start,stop} with std::string params and (r)find.
+ Added test for mkdirs.

Also make base/test_utils.h public and support temporary directories
as well as files.

Change-Id: I6fcbdc5e0099f3359d3aac6b00c436f250ca1329
2015-07-30 15:08:53 -07:00
Tom Cherry
d548e30f04 Merge "init: Create classes for Action and Command" 2015-07-30 21:03:48 +00:00
Andreas Gampe
eb0b151369 Merge "Toolbox: Disable unused-const-variable warning" 2015-07-30 20:38:04 +00:00
Tom Cherry
fa0c21c94c init: Create classes for Action and Command
This creates the concept of 'event_trigger' vs 'property_trigger'

Previously these were merged into one, such that 'on property:a=b &&
property:b=c' is triggered when properties a=b and b=c as expected,
however combinations such as 'on early-boot && boot' would trigger
during both early-boot and boot.  Similarly, 'on early-boot &&
property:a=b' would trigger on both early-boot and again when property
a equals b.

The event trigger distinction ensures that the first example fails to
parse and the second example only triggers on early-boot if
property a equals b.

This coalesces Actions with the same triggers into a single Action object

Change-Id: I8f661d96e8a2d40236f252301bfe10979d663ea6
2015-07-30 13:37:23 -07:00
Lee Campbell
138c540f53 Merge "init: Add C++ tokenizer." 2015-07-30 20:30:07 +00:00
Andreas Gampe
3294ad163f Toolbox: Disable unused-const-variable warning
For build-system CFLAGS clean-up, disable unused-const-variable
warning.

Bug: 18632512
Change-Id: I1be1ac744f8c77bd0a8378578072285a2c035245
2015-07-30 11:52:11 -07:00
Lee Campbell
220ca84223 init: Add C++ tokenizer.
Adds a C++ tokenizer along with unit tests.

This tokenizer will replace the current C implementation
which does a poor job of keeping track of pointers.

This CL is a prerequisite for up coming changes to
the parser. This CL does not wire up this tokenizer and
changes no exsiting code. All that builds is the unit tests.

Change-Id: Iec3740bce7153640adc5e5bbdc57e644cedf0038
TEST: Unit tests all pass. No leaks under valgrind
BUG: 22843198
2015-07-30 18:45:17 +00:00
Dan Albert
480bea3372 Merge "Add top level sanitize options for ADB." 2015-07-30 18:44:37 +00:00
Elliott Hughes
9bc4e7a553 Merge "bionic no longer sends SIGPIPE to debuggerd." 2015-07-30 17:33:16 +00:00
Dan Albert
9113b47eac Add top level sanitize options for ADB.
Host and target are split here because the target can really only use
ubsan (most sanitizers don't support static executables).

Change-Id: I8a5a5adeeef5c27aaaa3d8145b1570760b764ce3
2015-07-30 10:25:32 -07:00
Dan Albert
3b5b132817 Merge "adb/test_device.py fixes for win32 and no use of ANDROID_SERIAL" 2015-07-30 17:04:52 +00:00
Elliott Hughes
e6e71608bd Merge "Use __ANDROID__ instead of HAVE_ANDROID_OS." 2015-07-30 16:34:47 +00:00
Elliott Hughes
9b828adfad Use __ANDROID__ instead of HAVE_ANDROID_OS.
Change-Id: I9967f3fd758c2a5b40be5b60ae72be7e2fb75136
2015-07-30 09:33:43 -07:00
Elliott Hughes
f39383103b bionic no longer sends SIGPIPE to debuggerd.
Static binaries don't get the signal handler installed (that's done by the
dynamic linker) so we don't need to worry about seeing SIGPIPE crashes from
old binaries.

Bug: http://b/20659371
Change-Id: I3b5566634fadd3e822262561188d29814bccd1fd
2015-07-30 08:15:57 -07:00
Elliott Hughes
44443bead6 Merge "Use _WIN32 rather than HAVE_WINSOCK." 2015-07-30 14:49:56 +00:00
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
b10e562b4c Merge "Introduce a mechanism to trace boot sequence." 2015-07-30 07:42:09 +00:00
Yasuhiro Matsuda
dcf890914c Merge "Add a script to record Android boot time." 2015-07-30 05:21:41 +00:00