Commit graph

166 commits

Author SHA1 Message Date
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
Spencer Low
d21dc825bb adb: win32: remove widen()/narrow() in favor of UTF8ToWide()/WideToUTF8()
Now that we have a more standardized API (also available in Chromium),
switch to it. Another benefit is real error handling instead of just
killing the process on invalid Unicode.

Make UTF8ToWide()/WideToUTF8() set errno to EILSEQ on bad input. This is
the same error code that wcsrtombs(3) uses.

Update the unittest to check for EILSEQ.

Change-Id: Ie92acf74d37adaea116cf610c1bf8cd433741e16
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-11-12 17:13:08 -08:00
Josh Gao
b7b1edf974 adb: remove exit-time destructors.
On exit, these destructors get invoked while other threads might
still be using them, potentially causing a crash, and definitely
causing tsan to report a race condition.

Bug: http://b/23384853
Change-Id: I94de55d22f97f4edd1d7cc1f34e8c1f8dfd56a5a
2015-11-12 11:20:19 -08:00
Elliott Hughes
b708d16283 Show transfer progress in adb sync/pull/push.
Change-Id: If5439877d060f9bab29cf84be996071cf680c2d4
2015-10-30 14:19:23 -07:00
Elliott Hughes
6d92997ec4 Don't use VLAs in adb.
This makes no measurable difference to the sync time; "adb sync" of
everything on /system for a Nexus 9 still takes 20s.

Change-Id: Ifa2626f7453937e43856b9c4ee06e1f5db0aa273
2015-10-27 15:46:41 -07:00
William Roberts
bd2d961cc2 init/adb: correct static lib dependencies for libselinux
Now that libselinux uses libpackagelistparser, in order
for libpackagelistparser to be properly statically linked
liblog must come after libselinux for all the liblog
references to be defined in libpackagelistparser which
is included in libselinux. This patch corrects that order.

Change-Id: I7aee10c9395310919779ed2463aab6b2f8b380cc
Signed-off-by: William Roberts <william.c.roberts@intel.com>
2015-10-22 15:21:26 -07:00
Sami Tolvanen
8ad80763e4 adb: use libfec in disable-verity
Use libfec to locate verity metadata and disable verity.

Needs changes from
  I02f83b0d1d4e7ef5cd5d13a37ff0b84f17e23376

Bug: 21893453
Change-Id: Ib43c352400a368664c949c7b8c9961829adf48f4
2015-10-20 13:55:24 +01:00
Yabin Cui
aed3c61c44 Adb: use VLOG() to replace D() for verbose logging.
As there are too many D(), we can keep both VLOG() and D() now, and get
rid of D() gradually.

Change-Id: I2f1cb70bcab3e82c99fed939341d03f6b2216076
2015-09-23 12:53:38 -07:00
Yabin Cui
c1b1f6ff5d Add unit tests for local socket.
Add has_write_error flag in asocket, so it will not wait on local_socket_closing_list
to write pending packets in local_socket_close(). Although it doesn't fix any problem,
it helps to make the code more stable.
Add a missing put_apacket() in error handling.
Add a check when adding local socket in local_socket_closing_list.

Bug: 23314034

Change-Id: I75b07ba8ee59b7f277fba2fb919db63065b291be
2015-09-16 15:00:59 -07:00
David Pursell
76f4a6533c Merge changes from topic 'adb_shell'
* changes:
  adb: add client side shell protocol and enable.
  adb: implement shell protocol.
2015-09-14 18:39:37 +00:00
David Pursell
b404dec85a adb: fix shell_service_protocol_test for Windows.
Adds missing #ifdef guards to shell_service_protocol_test.cpp so the
test compiles on Windows.

Also fixes a bug in Windows socketpair write implementation. Previously
it was only checking for a closed pipe if the write happened to block.
This adds an additional pre-check to exit immediately on a closed pipe.

These two changes allow the test to compile and pass on Windows.

Change-Id: Ib8853ed72f015fc0d623da47c32982cb3ffa4a3d
2015-09-11 18:28:27 -07:00
Elliott Hughes
2f577205fc Fix (Windows) build.
Change-Id: Ib9afd101d255d748ba6c15ed8075f3d10338c95c
2015-09-11 16:18:24 -07:00
Elliott Hughes
0ad13cf298 Merge "fix adb_test Windows build" 2015-09-11 23:13:40 +00:00
Spencer Low
e6ae573571 adb: win32: make adb_getenv() case-insensitive
adb_getenv() should be case-insensitive just like the real getenv() on
Windows.

Added a unittest for adb_getenv(). In the process, made adb_test link
with -municode so that the environment block is Unicode.

Move wmain() from main.cpp to sysdeps_win32.cpp so that adb_test could
also use it.

Because wmain() moved, it wasn't as easy to do the runtime check to
verify that -municode was used, so do that check in _ensure_env_setup()
since adb_getenv() is called early in adb anyway.

Added a utility ToLower() which is good enough for env vars whose keys
are probably always ASCII to begin with.

Change-Id: I082f7fdee9dfe2c7f76b878528d2f7863df6d8d1
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-09-11 15:53:08 -07:00
Spencer Low
ebf770fd73 fix adb_test Windows build
adb/Android.mk: adb_test should build on Windows (and Darwin), so add to
the whitelist.

Change-Id: I778f6a7dff4caec92c48e0957591abf32f86ab1b
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-09-11 15:47:20 -07:00
David Pursell
0955c66b22 adb: implement shell protocol.
Adds functionality for handling stdin/stdout/stderr streams and exit
codes using the shell protocol.

This CL just contains implementation for adbd which will not yet be
enabled. Once we have the ability to query transport features from the
adb client, another CL will add the implementation for the client side
and update the feature list to turn this on.

Note: this CL must be submitted together with a minadbd CL to update
the service_to_fd() function signature.

Bug: http://b/23030641

Change-Id: Ibed55e9c1946d8a35190696163ff63e8fb880238
2015-09-11 11:27:50 -07:00
David Pursell
31139af04f Merge "adb: create shell protocol class (take 2)." 2015-09-11 18:17:55 +00:00
Dan Willemsen
aaf4fcf482 Merge "Remove HOST_OS==windows check" 2015-09-09 18:13:22 +00:00
Yabin Cui
cb992d9a21 adb: remove unnecessary dependencies of liblog.
Change-Id: I1aaa9e6c1b47a70f8daf91745f6aec13c92b789f
2015-09-08 18:27:10 -07:00
David Pursell
b9e2e84e7e adb: create shell protocol class (take 2).
Adds a new class ShellProtocol to help read and write data with
`adb shell`. This will allow splitting streams and sending out-of-band
data such as exit codes.

Nothing uses the new class yet except the unit tests.

This is the second attempt at this CL, the first is at
http://r.android.com/169600. The problems was using sighandler_t
which is not available on mac. sig_t is used instead which is available
due to _GNU_SOURCE being defined in Android.mk, which causes
_BSD_SOURCE -> __USE_BSD -> sig_t to be defined. Nothing else has been
changed from the original CL.

Bug: http://b/23030641
Change-Id: I7bd7f5a82ad811fbca7a3eee1236d2c55ae57c48
2015-09-08 10:04:10 -07:00
David Pursell
da0b0116ba Merge "Revert "adb: create shell protocol class."" 2015-09-06 02:34:02 +00:00
David Pursell
d9b74192b8 Revert "adb: create shell protocol class."
This CL broke the mac build. I'll revert for now and take a look at how to get it working next week.

This reverts commit 73096f2e1d.

Change-Id: Icb3e015250bcbbc69a45675a1358699ebe01e77b
2015-09-06 01:18:47 +00:00
David Pursell
215415318d Merge changes from topic 'adb_shell_prework'
* changes:
  adb: create shell protocol class.
  adb: refactor subprocess code.
  adb: move shell service to a separate file.
2015-09-04 23:54:19 +00:00
Dan Willemsen
66680c506a Remove HOST_OS==windows check
With the HOST_CROSS_OS build system change, LOCAL_MULTILIB := first now
behaves the same way.

Change-Id: I03294403e5a106a53d4a0d48b176434221284901
2015-09-04 14:05:19 -07:00
David Pursell
73096f2e1d adb: create shell protocol class.
Adds a new class ShellProtocol to help read and write data with
`adb shell`. This will allow splitting streams and sending out-of-band
data such as exit codes.

Nothing uses the new class yet except the unit tests.

Bug: http://b/23030641

Change-Id: Ieb02e127095c6dda25b7cb188a2e599173fd97e6
2015-09-04 11:30:11 -07:00
David Pursell
80f67029e0 adb: move shell service to a separate file.
Upcoming changes to the shell will require significant additions to
the subprocess code, and it will be cleaner if it's in a separate file.

The only functional change here is a new debug tag specifically for
the shell service. Everything else has been copied exactly as-is in
order to make it easier to determine what's changing in upcoming CLs.

Change-Id: I13bd4294059051ee10e0d0c6a06affd8eca62967
2015-09-04 08:52:35 -07:00
Tom Cherry
2270dbbc84 combine adbd.rc with init.usb.rc
init.usb.rc and adbd.rc contain similar contents and belong in the same
file.

This file also belongs on the ramdisk as adbd is on the ramdisk, not the
system partition, therefore resolving to keep init.usb.rc in its current
location and combining the contents of adbd.rc is the best approach

Change-Id: I430f8fea58694679e7b8b7be69ce87daadd616f4
2015-09-03 16:19:04 -07:00
Dan Willemsen
87a419c8b1 Remove USE_MINGW/CYGWIN; Whitelist windows modules
CYGWIN is not supported, USE_MINGW and HOST_OS==windows are being
replaced with LOCAL_..._windows variables.

Bug: 23566667
Change-Id: I3e4a1e4097dc994cf5abdce6939e83a91758fd75
2015-09-02 17:10:35 -07:00
Yabin Cui
2ae47a0b54 Merge "adb: add unit test for fdevent." 2015-08-31 22:40:04 +00:00
Yabin Cui
c6424585a2 adb: remove workaround for b/6558362.
I believe the problem has been fixed in https://android-review.googlesource.com/#/c/168412/.
So it's time to remove the workaround.

Bug: 6558362
Change-Id: I399c18eda0693f3c51feac07ff59a0a4b5558128
2015-08-31 12:10:11 -07:00
Yabin Cui
bec02fc43d adb: add unit test for fdevent.
Change-Id: Ic26cda5d8e84425bc60ce36bc686bb6917c4ca3c
2015-08-28 21:33:22 -07:00
Elliott Hughes
bd4b1fa4a9 Improve adb tracing.
The existing format was unreadable; putting the pid and tid first helps
somewhat. Also remove the unused qemu tracing which wasn't called anywhere.

Change-Id: I37ef3c556fe17b237ba1d8ca3216e2155ce5d0de
2015-08-28 14:46:33 -07:00
Elliott Hughes
daa6c463a9 Don't build 32-bit host libadb.
Change-Id: Ib6ad3db2dc160273d20fa14e0820f29ed649d75a
2015-08-25 19:38:14 -07:00
Tom Cherry
20391b1de5 bundle init.rc contents with its service
Bug: 23186545
Change-Id: I52616b8ab1165fdef716f9b8f958665f2308c12e
2015-08-21 10:14:43 -07:00
Elliott Hughes
6b940e1349 Merge "adb: win32: define UNICODE/_UNICODE, Unicode error messages, misc" 2015-08-03 21:16:26 +00:00
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
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
Elliott Hughes
16d79c7318 Remove adb's unused get_my_path for Windows.
Change-Id: I3cfb4677acaf6acaf512b3cdce6c11bdb2bd0578
2015-07-31 17:54:24 -07: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
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
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
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
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
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
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