Commit graph

2676 commits

Author SHA1 Message Date
Elliott Hughes
771f2c2a3e Merge "Remove unused #include." 2018-07-11 20:16:21 +00:00
Treehugger Robot
3eb5d77913 Merge "adb: work around adbd push bug." 2018-07-11 18:37:39 +00:00
Elliott Hughes
cd0f5c33fa Remove unused #include.
Bug: N/A
Test: builds
Change-Id: I792bfdb38672f7a51991c19a9838dd12500036c7
2018-07-11 11:21:36 -07:00
Ryan Prichard
e4fded2c48 adb: fix escape_arg for multiple quotes
escape_arg reuses the same index for the source (s) and the destination
(result), so it breaks on strings containing more than one quote, e.g:

 * a'b'c    ==> 'a'\''b'c'
 * a'bcde'f ==> 'a'\''b'\'cde'f'

Also make the function more efficient by doing fewer string copies. This
code is based on the android::base::Split code.

Use EXPECT_EQ because the tests can keep going if one fails.

Bug: none
Test: adb_test --gtest_filter=adb_utils.escape_arg
Change-Id: I6ca6e905fa53cc61b9a87276cb7116a5df7e8017
2018-07-10 23:32:09 -07:00
Josh Gao
0cee7ccc59 adb: work around adbd push bug.
We shipped (well, are about to ship) an adbd that spuriously fails to
create directories upon push. Work around this in the adb client by
running a mkdir on all of the directories we would have otherwise
created.

On devices where we perform the workaround, this coincidentally fixes
a historic bug where we failed to push empty directories.

Bug: http://b/25566053
Bug: http://b/110953234
Test: python test_device.py
Change-Id: I690ec356c206fed4e5ab2c681c5570c8b231e26b
2018-07-10 13:20:40 -07:00
Josh Gao
4c0078d67a adbd: fix spurious failure to create dirs when pushing.
When pushing to a path, we first try to ensure the directory path
exists and has the permissions expected by fs_config. Due to a change
that changed the fs_config check from a blacklist to a whitelist, we
started doing this for /data (which doesn't begin with /data/), and the
UID/GID for that path was accidentally being reused for following path
segments that didn't exist, leading to a failed attempt to chown
/data/local/tmp/foo to be owned by system.

Bug: http://b/110953234
Test: python test_device.py
Change-Id: Ie798eec48bcf54aea40f6d90cc03bb2170280ee8
2018-07-09 14:25:51 -07:00
Elliott Hughes
d8a4c60276 Simplify __attribute__((__printf__)) use.
We don't need this now everyone's using clang...

Bug: http://b/69933068
Test: ran tests
Change-Id: I88f0cf03981ade47e210387fd6f3a2706dfeb9b8
2018-06-26 13:07:21 -07:00
Treehugger Robot
b8f4fe4fd4 Merge changes from topic "mingw-clang"
* changes:
  Do not customize __format__ for Windows/MinGW to gnu_printf
  Adapt to switch to Clang for Windows host builds
  Update cflags for building Windows modules with Clang
2018-06-26 19:47:53 +00:00
Pirama Arumuga Nainar
a2df1ef441 Do not customize __format__ for Windows/MinGW to gnu_printf
Bug: http://b/69933090
Bug: http://b/69933068

MinGW uses gnu_printf to force C99 printf analysis with GCC, but clang
does not support gnu_printf.  So just use the default that's used for
other platforms.  This also mirrors upstream commit
015e637b4b/.

Test: m native-host-cross with Clang.
Change-Id: I3deb266d70e25296c4ae1d58637afbabc3d949c1
2018-06-25 11:52:54 -07:00
Treehugger Robot
409465a241 Merge "adb: fix obsolete documentation." 2018-06-23 00:57:20 +00:00
Elliott Hughes
accc95dc6b adb: fix obsolete documentation.
Bug: http://b/110564383 Obsolete adb document, inconsistent with current implementation
Test: N/A
Change-Id: If12ba8546991ee6f2a89ca0ff8036b598742dc11
2018-06-22 13:12:19 -07:00
Josh Gao
04b9ca8c31 Revert "adb: detect some spin loops and abort."
This seems to be falsely triggering.

This reverts commit 3bbc8164b1.

Test: none
2018-06-22 13:07:22 -07:00
Pirama Arumuga Nainar
7982178b7b Update cflags for building Windows modules with Clang
Bug: http://b/69933068

- Add -Wexit-time-destructor globally after fixing one warning
- Enable -Wthread-safety only for non-windows targets.  The version of
libstdc++ we use for Windows doesn't have the correct thread-safety
annotations.

Test: Run Clang-built adb_test.exe under wine
Change-Id: I76a43060342e7d1dc370ce3e117f3563c82b7751
2018-06-19 20:27:37 -07:00
Treehugger Robot
9674bcbd23 Merge changes Ibfa5e7e6,I706b57a9,I53d21134,I69d4d585
* changes:
  adb: detect some spin loops and abort.
  adb: add an id field to fdevent.
  adb: delete unused members in fdevent.
  adb: add `adb raw` to connect to an arbitrary service.
2018-06-19 02:39:28 +00:00
Josh Gao
3bbc8164b1 adb: detect some spin loops and abort.
Track pending fdevents, and abort if we see an fdevent ready for
read/write for 5 minutes continuously.

Also, add a service that intentionally starts spinning, to test this.

Test: manually changed timeout to a minute, `adb raw spin`
Change-Id: Ibfa5e7e654996587f745887cb04987b982d79bed
2018-06-18 17:46:34 -07:00
Treehugger Robot
812ba6a469 Merge "adb: add nonblocking fd Connection." 2018-06-18 21:59:12 +00:00
Josh Gao
ded557fa58 adb: add an id field to fdevent.
Tracking fdevents by pointer is dangerous because an fdevent can be
destroyed and recreated at the same address. Add a monotonically
increasing id field to fdevent for this purpose.

Test: treehugger
Change-Id: I706b57a9e669290ef2db258f85489a5155fc1152
2018-06-18 14:55:27 -07:00
Josh Gao
e44d38d680 adb: delete unused members in fdevent.
Forgot to clean this up after removing fdevent_install...

Test: treehugger
Change-Id: I53d21134a4bc8bf7b16210318c6fac5075445b39
2018-06-18 14:54:40 -07:00
Josh Gao
172d0d44bc adb: add adb raw to connect to an arbitrary service.
Add a command to connect to an arbitrary service, for debugging
purposes.

Test: `adb raw shell:ls`
Change-Id: I69d4d585e5ecfa7cb8c7a543a2a27df7033b26c7
2018-06-18 14:51:56 -07:00
Elliott Hughes
5587aba58d Merge "Fix adb logcat return code." 2018-06-14 19:38:08 +00:00
Elliott Hughes
31f0f1bcee Fix adb logcat return code.
`adb shell logcat` works, and `adb logcat` should too.

Bug: http://b/110202648
Test: suspended the logd process and manually removed the socket
Change-Id: If14de7c2eb178c7b4210d6bdb44df084615db33a
2018-06-14 10:47:00 -07:00
Josh Gao
6082e7dafb adb: add nonblocking fd Connection.
Implement a nonblocking version of FdConnection. The initial
implementation will be somewhat slower than the blocking one for large
packet sizes, due to an extra copy when coalescing an IOVector into an
apacket, but is still substantially faster for small packets.

Test: adb_benchmark
Change-Id: I4900c9ddf685d3bd557b8cb43958452ecb23db53
2018-06-12 17:04:34 -07:00
Jiyong Park
011ee12b1d Shared libs are supported in recovery mode
adbd has been built as a static executable since the same binary was
copied to the recovery partition where shared library is not supported.
However, since we now support shared library in the recovery partition,
adbd is built as a dynamic executable.

In addition, the dependency from adbd to libdebuggerd_handler is removed
as debuggerd is handled by the dynamic linker.

A few more modules in /system/core are marked as recovery_available:
true as they are transitive dependencies of the dynamic linker.

This change also includes ld.config.recovery.txt which is the linker
config file for the recovery mode. It is installed to /etc/ld.config.txt
and contains linker namespace config for the dynamic binaries under
/sbin.

Bug: 63673171
Test: `adb reboot recovery; adb devices` shows the device ID
Test: Select 'mount /system' in the recovery mode, then `adb shell`.
$ lsof -p `pidof adbd` shows that libm.so, libc.so, etc. are loaded from
the /lib directory.

Change-Id: I363d5a787863f1677ee40afb5d5841321ddaae77
2018-06-10 08:32:24 +09:00
Treehugger Robot
ae74e42d25 Merge "Fix exit-time-destructor warning" 2018-06-06 23:28:07 +00:00
Pirama Arumuga Nainar
8b47d316d2 Fix exit-time-destructor warning
By initializing the global handle_list on the heap.

Test: Run Clang-built adb_test.exe under wine
Change-Id: I2326011b7e44c6d0cb4721d4b68fde7188b87c38
2018-06-06 14:41:26 -07:00
David Anderson
07445f4a71 adb: add remount -R for deduplicated ext4
When using "adb remount" on a deduplicated filesystem, the current
response is a warning that the remount will not work. This patch
allows the user to specify an -R option. This option will reboot to recovery,
run e2fsck to undo deduplication, and then reboot the device where "adb
remount" will then succeed.

In addition, if verity needs to be disabled to remount, it will be disabled in
the same reboot cycle to minimize reboots.

Bug: 64109868
Test: adb remount -R on a deduplicated filesystem
Change-Id: I812407499b2df6f4d2509e8d51878117108a6849
2018-05-31 15:38:25 -07:00
Josh Gao
e82401e592 Merge "adb: really fix the mac build." 2018-05-25 05:59:58 +00:00
Josh Gao
6e1246c234 adb: really fix the mac build.
Test: changed `#if !defined(__APPLE__)` to `#if 0` and ran mma
Change-Id: I173cccbfb7bad348ac4796a2d6cebb8490f63479
2018-05-24 22:58:08 -07:00
Treehugger Robot
6c9bb058c5 Merge "Build adbd for recovery" 2018-05-25 05:58:01 +00:00
Josh Gao
99c27d3e99 adb: fix mac build.
Test: none
Change-Id: I93ff87338aa503588e36404f7566651e18f50292
2018-05-24 00:47:05 -07:00
Jiyong Park
a0e75045e6 Build adbd for recovery
adbd (and its dependencies) are marked as recovery_available:true so
that recovery version of the binary is built separately from the one for
system partition. This allows us to stop copying the system version to
the recovery partition and also opens up the way to enable shared
libraries in the recovery partition. Then we can also build adbd as a
dynamic executable.

Bug: 79146551
Test: m -j adbd.recovery
Change-Id: Ib95614c7435f9d0afc02a0c7d5ae1a94e439e32a
2018-05-24 14:11:11 +09:00
Josh Gao
fd3fd937b1 adb: add benchmark script.
Test: ./benchmark_device.py
Change-Id: I9f36cc267b1cbef2d90a30009c87ccc2a8e21795
2018-05-23 11:26:04 -07:00
Josh Gao
7c738cdb53 adb: add IOVector.
An IOVector is a collection of immutable reference counted blocks which
can have its head detached at an arbitrary index. This is extremely
useful for implementing packet-framed protocols like adb on top of a
stream protocol like TCP: a stream reader can read blocks, append them
to the end of the IOVector, and then pull packets off of the front.
This also lends itself naturally towards scatter/gather I/O, which will
enable us to read data from disk and send it across the wire with a
theoretical minimum number of copies in USB, and one extra copy over
TCP.

Since this is basically a generalization of std::deque<Range>, delete
Range and replace its uses with IOVector.

Test: adb_test
Test: wine adb_test.exe
Change-Id: I06561ad0bb25a3a51b378b61d257b5b04b41d9c4
2018-05-23 11:26:04 -07:00
Josh Gao
9da1a9118b Revert "Revert "adb: add support for O_CLOEXEC to unique_fd pipe wrapper.""
Implement pipe2 ourselves on darwin.

This reverts commit f139ba47a1.

Test: none!
Change-Id: I42c2a8d07712fe4ac75b5824f754e79a5b9f5cb4
2018-05-23 11:14:57 -07:00
Josh Gao
a2157a7d92 Merge "Revert "adb: add support for O_CLOEXEC to unique_fd pipe wrapper."" 2018-05-23 16:45:31 +00:00
Josh Gao
f139ba47a1 Revert "adb: add support for O_CLOEXEC to unique_fd pipe wrapper."
This reverts commit 948b3e1068.

Reason for revert: mac doesn't have pipe2

Change-Id: Id6a517bb500cbea602839f06452bc5e6d92289f1
2018-05-23 16:44:53 +00:00
Treehugger Robot
812a6b77c6 Merge "adb: add support for O_CLOEXEC to unique_fd pipe wrapper." 2018-05-23 00:17:32 +00:00
Josh Gao
7a223584c5 Merge changes I465804fd,Ib5a684bb,If5e66570,I8471cc00,I8ba0a70a
* changes:
  adb: convert fdevent over to unique_fd.
  adb: move towards using unique_fd.
  adb: delete FDEVENT_DONTCLOSE.
  adb: remove fdevent_install, fdevent_remove.
  adb: fix uninitialized variable in AsyncServiceRef.
2018-05-23 00:01:29 +00:00
Josh Gao
948b3e1068 adb: add support for O_CLOEXEC to unique_fd pipe wrapper.
Change-Id: I8fd22fe55db4d3dbcbb7318cf4a364eb07323ed0
2018-05-22 14:55:36 -07:00
Josh Gao
3b37fa256f adb: convert fdevent over to unique_fd.
This adds fdsan deallocation sanitization to all fds monitored by
fdevent, which is most of the ones in adb.

Bug: http://b/79786774
Test: python test_device.py
Change-Id: I465804fdb0fd0ac019445900a30ba3403f5bf711
2018-05-22 14:55:36 -07:00
Josh Gao
ae9c1dc44a adb: move towards using unique_fd.
Bug: http://b/79786774
Test: treehugger
Change-Id: Ib5a684bba88e87e1aad9da452dcdd5edd11f18f4
2018-05-22 14:55:36 -07:00
Josh Gao
e5353021ba adb: delete FDEVENT_DONTCLOSE.
The only existing usage of this doesn't actually need it.

Bug: http://b/79786774
Test: mma
Change-Id: If5e665705393e938cfdbf1526beb5496a8b99a9b
2018-05-22 14:55:36 -07:00
Josh Gao
71f775a944 adb: remove fdevent_install, fdevent_remove.
Remove fdevent_install and fdevent_remove in favor of using
fdevent_create and fdevent_destroy, so that we can put RAII types (i.e.
unique_fd) into fdevent without worrying about -Wexit-time-destructors
or structs that are freed instead of deleted.

Bug: http://b/79786774
Test: python test_device.py
Change-Id: I8471cc00574ed492fe1b196944976cdaae8b7cff
2018-05-22 14:54:49 -07:00
Treehugger Robot
2fa9770c3a Merge changes I4d6da40d,I91c7ced5,I7b9f6d18
* changes:
  adb: Add a test for emulator connection
  adb: Improve test_adb a bit more
  adb: Add a way to reconnect TCP transports
2018-05-21 22:37:21 +00:00
Treehugger Robot
93e4501611 Merge "adb: Retry io in case of interrupt" 2018-05-17 01:17:11 +00:00
Treehugger Robot
adf07c5428 Merge "adb: Move io_setup to usb_handle init" 2018-05-16 23:25:15 +00:00
Luis Hector Chavez
3255974169 adb: Add a test for emulator connection
This should prevent regressions in the future.

Bug: 78991667
Test: python system/core/adb/test_adb.py
Change-Id: I4d6da40da82c6d79797cec82ffaf071d4b56ddc7
2018-05-16 15:20:48 -07:00
Luis Hector Chavez
fbee0a9133 adb: Improve test_adb a bit more
This change:

* uses unittest.main(), which allows for a subset of the tests to be
  selected.
* drops the requirement to have a device already connected since all the
  tests that need a device now spin their own mock device.
* Splits the monolithic test class into more granular classes.
* Makes this file be pylint-compliant.

Bug: None
Test: python system/core/adb/test_adb.py
Test: pylint system/core/adb/test_adb.py
Change-Id: I91c7ced520c3c69f855d639e0dbf7e57bb690e97
2018-05-16 15:20:48 -07:00
Luis Hector Chavez
454bc7c0be adb: Add a way to reconnect TCP transports
This change adds a reconnect handler that tracks all TCP transports that
were connected at some point, but became disconnected. It does so by
attempting to reconnect every 10s for up to a minute.

Bug: 74411879
Test: system/core/adb/test_adb.py
Test: adb connect chromebook:22  # This runs with sslh
Test: CtsBootStatsTestCases
Test: emulator -show-kernel ; adb -s emulator-5554 shell

Change-Id: I7b9f6d181b71ccf5c26ff96c45d36aaf6409b992
2018-05-16 15:20:48 -07:00
Jerry Zhang
d8c1ae910f adb: Move io_setup to usb_handle init
Remove some redundancy by moving io_setup
into aio_block_init. The io_contexts will
now live till the end of the program, similar
to the rest of usb_handle

Test: adb works
Bug: 78793464
Change-Id: I910a39d4395645f1ff231f265c285a72893a0ac6
2018-05-16 21:47:11 +00:00