Commit graph

155 commits

Author SHA1 Message Date
Josh Gao
afd3dfeeff Merge "Only set mdns_registered on success" 2019-01-09 20:41:17 +00:00
David Anderson
22a8462336 Merge "adbd: Automatically disable verity in adb remount." 2019-01-09 19:48:47 +00:00
Gustav Svensson
965286cba8 Only set mdns_registered on success
In setup_mdns_thread mdns_registered should only be set to true
if DNSServiceRegister was successful.

Test: N/A

Change-Id: I8a2798cced91b05b7d8bf5f0df4d16719c581dee
Signed-off-by: Gustav Svensson <gustav.svensson@volvo.corp-partner.google.com>
2019-01-09 08:46:50 +01:00
Alex Buynytskyy
640407d632 Adding Android Binder Bridge (abb) utility launched from adbd.
Once launched, abb will listen for incoming Binder cli requests.
Executing in-process provides 6x latency improvement (125ms vs 25ms on
PixelXL) for commands like 'package path'

Intended usage by Android Studio for fast deployment and patching of APKs.

Test: manual
BUG: 111621042

Change-Id: Ica84eb2ec9628efa441ecd627b119f3361feaf9f
2019-01-07 15:45:11 +00:00
Josh Gao
6bd16b1d22 adbd: strip nulls from all service strings.
Other services are checking for exact equality, like jdwp.

Test: adb jdwp
Change-Id: I1081904621b111b0143a275bd9337f903fe9c111
2018-12-27 11:19:44 -08:00
Josh Gao
e26154167c adb: switch daemon_service_to_fd to string_view.
Test: test_adb.py
Test: test_device.py
Test: $ANDROID_HOST_OUT/nativetest64/adb_test/adb_test
Test: adb shell /data/nativetest64/adbd_test/adbd_test
Change-Id: I298517b688650c9d94bf837284e0264ca0ac6702
2018-12-21 11:52:56 -08:00
Josh Gao
0f29cbc750 adb: switch unix_open to string_view.
Test: test_adb.py
Test: test_device.py
Test: $ANDROID_HOST_OUT/nativetest64/adb_test/adb_test
Test: adb shell /data/nativetest64/adbd_test/adbd_test
Change-Id: Ieecc9b1b7f2111f4da45d4bbd1b7703535fe7d4d
2018-12-21 01:43:31 -08:00
David Anderson
a5db1d72cf adbd: Automatically disable verity in adb remount.
Before overlayfs, we supported deduplicated filesystems by undoing
deduplication in recovery. This required an extra reboot cycle, so we
changed "adb remount" to disable verity and boot to recovery in one
command.

After overlayfs, adb remount is still trying to undo deduplication,
which leads to very confusing messages. This patch makes things a bit
clearer. "adb remount" will disable verity, which installs overlayfs.
"adb remount -R" will do the same except automatically reboot.

Bug: N/A
Test: adb remount on dynamic partitions device
Change-Id: Id72f6b9e2297c2f4d5722d5679f6264fe660e631
2018-12-17 13:15:05 -08:00
Josh Gao
78f94a39f2 Merge changes I042f25f8,I973f42c5,Icb4acea5
* changes:
  adbd: add source/sink services.
  adb: make `adb raw` bidirectional.
  adb: remove incorrect use of RTTI.
2018-12-13 01:26:49 +00:00
Josh Gao
6eb788298b adbd: add source/sink services.
Add some services that skip the service fd to see how much of a benefit
it'll be to eliminate it.

Test: adb raw source:$((300 * 1024 * 1024)) | pv > /dev/null
Test: dd if=/dev/zero bs=1M count=100 | pv | adb raw sink:$((100 * 1024 * 1024))
Change-Id: I042f25f85b16ae9869cb1f1e306d8671b024ed97
2018-12-12 12:54:28 -08:00
Treehugger Robot
fe3becb56b Merge "Fix performance-for-range-copy warnings" 2018-12-12 17:46:46 +00:00
Tom Cherry
23319ebebf Start using new C++ Fstab class widely
Bug: 62292478
Test: boot
Test: adb-remount-test.sh

Change-Id: Id4715af4c1f03e2cfc67de92d3ea58e933685e51
2018-12-12 17:08:09 +00:00
Chih-Hung Hsieh
1b7b7979af Fix performance-for-range-copy warnings
Bug: 30413223
Test: make with WITH_TIDY=1 DEFAULT_GLOBAL_TIDY_CHECKS=-*,performance*
Change-Id: I3ad102f2b0f971266d57488a3bd57d312f7ee3e6
2018-12-11 10:51:13 -08:00
Yifan Hong
0e0f818c8a logical -> dynamic partitions.
Reflect a name change.
Test: boots
Bug: 119286600

Change-Id: I076071be18be521eeee4ebae10491b9f3e8ef857
2018-11-16 12:53:18 -08:00
Mark Salyzyn
beb4cb8e43 adb: overlayfs failed to remount /system
Regression introduced commit bb1efbd1c6

By not first checking if overlayfs mount on /system is in /proc/mounts
remount fails to discover the override and take the selected action.

Test: adb-remount-test.sh
Bug: 109821005
Change-Id: I1f0bae22caae1bca84fc1e33b508b54d98f4ed5c
2018-11-06 09:49:10 -08:00
David Anderson
bb1efbd1c6 adbd: Fix adb remount when switching roots during first-stage init.
This patch addresses two issues with adb remount.

First, the blk_device field in fstab_rec will be incorrect if referring
to a device-mapper node (fs_mgr_update_logical_partition must be
called).

Second, devices that are not system-as-root now move their mount point
and chroot to "/" during first-stage init. However, the fstab entry will
have "/system" as its mount point. The new logic now reflects this.

Bug: N/A
Test: adb remount on hikey or device with dynamic partitions
Change-Id: I48b379db49d2def555ea49888c4994fbcf501672
2018-10-26 13:51:32 -07:00
Treehugger Robot
33eb652783 Merge "adb: don't use <error.h>." 2018-10-23 03:53:50 +00:00
Elliott Hughes
d2aaede610 adb: don't use <error.h>.
This should fix the bloody Mac build, which doesn't have <error.h>. Since
we weren't entirely happy with error(3) anyway, switch to the toybox
style of error_exit and perror_exit, which are slightly briefer and quite
a bit more intention-revealing.

Bug: N/A
Test: builds
Change-Id: Ic8e411906c363af51657da5ce947b25a0b6bb1f3
2018-10-22 17:04:32 -07:00
Josh Gao
95a3916ef9 Merge changes I9b77c105,I0b369d16,I59602c20,Iae4f3d55
* changes:
  adbd: implement a nonblocking USB Connection.
  adbd: rename daemon/usb.cpp to daemon/usb_legacy.cpp.
  adbd: open functionfs ep0 as O_RDWR.
  adbd: extract functionfs fd creation.
2018-10-22 19:45:33 +00:00
Josh Gao
c51726cbec adbd: implement a nonblocking USB Connection.
Implement a Connection that implements a nonblocking interface to
functionfs, to replace the existing implementation that uses two
threads that loop and call read and write respectively. The existing
implementation is vulnerable to a race condition that can occur when a
connection is terminated, where one thread can notice failure and
complete reinitialization of the USB endpoints before the other thread
noticed anything went wrong, resulting in either the first packet
coming from the other end disappearing in to the void, or the other end
getting a packet of garbage.

As a side benefit, this improves performance on walleye from:

    push 100MiB: 10 runs: median 49.48 MiB/s, mean 50.00 MiB/s, stddev: 2.77 MiB/s
    pull 100MiB: 10 runs: median 75.82 MiB/s, mean 76.18 MiB/s, stddev: 6.60 MiB/s

to:

    push 100MiB: 10 runs: median 73.90 MiB/s, mean 73.51 MiB/s, stddev: 5.26 MiB/s
    pull 100MiB: 10 runs: median 105.90 MiB/s, mean 107.19 MiB/s, stddev: 6.10 MiB/s

Test: python test_device.py
Change-Id: I9b77c1057965edfef739ed9736e5d76613adf60a
2018-10-19 17:53:18 -07:00
Elliott Hughes
4679a39610 adb: rationalize fatal/error logging.
Let's use LOG(FATAL)/PLOG(FATAL) for actual fatal stuff.

Add a Windows error(3) and move folks who didn't really mean "abort"
fatal over to it. Also get rid of syntax_error which wasn't adding a
lot of value, and most of the places it was adding "usage: " didn't seem
entirely appropriate anyway.

In particular, we seemed to have confused fastdeploy.cpp into aborting
in most user error cases, and none of the reviewers noticed. Clearly
we'd all lost track of far too many options.

(I've also cleaned up a few random instances of fprintf(3) + exit(2).)

Bug: N/A
Test: manual
Change-Id: I3e8440848a24e30d928de9eded505916bc324786
2018-10-19 14:04:24 -07:00
Josh Gao
61e9e39b7e adbd: rename daemon/usb.cpp to daemon/usb_legacy.cpp.
Change-Id: I0b369d1653220f7d9b542ad06998c5c2c3e129a2
Test: mma
2018-10-18 13:58:06 -07:00
Josh Gao
d506dac0a0 adbd: open functionfs ep0 as O_RDWR.
We need to read from ep0 to poll for events.

Test: test_device.py
Change-Id: I59602c20f5dfdb17bfbab13d3033e9333a51caf3
2018-10-18 13:58:06 -07:00
Josh Gao
613cbb42e6 adbd: extract functionfs fd creation.
Extract common functionality that will be useful for implementing a
nonblocking Connection for functionfs.

Test: mma
Change-Id: Iae4f3d55b2f56568d4a5138db9a2af5622eb83ad
2018-10-18 13:58:06 -07:00
Treehugger Robot
3614b39bb9 Merge "adb: identical symlink, do not update" 2018-10-08 19:52:20 +00:00
Mark Salyzyn
376e3cbb50 adb: identical symlink, do not update
Inefficient to always update the symlinks to overlayfs, can
also lead to

    failed to copy 'xxx' to 'yyy': remote symlink failed: File exists

on older variants of overlayfs that do not effectively mark them
deleted.

Test: manual
Bug: 109821005
Change-Id: If1286d76f45ce14087cdb515fe8d2fed198fd9d8
2018-10-08 10:37:10 -07:00
Josh Gao
15dcc62c72 adbd: clean up jdwp service a bit.
Change-Id: Ia42447576b047dfa9ddc0b73b87adc8114e3f20f
Test: ./test_device.py
2018-10-05 17:23:44 -07:00
Josh Gao
39c1f4bca5 Revert "Revert "adb: detect some spin loops and abort.""
This reverts commit 04b9ca8c31.

The original incarnation of this patch was falsely triggering when our
poll would block with no activity happening for an extended amount of
time. When the poll returned, we would immediately flag that as a spin
loop. Solve this by tracking the last time we looped, to detect this.

While we're at it, switch from CLOCK_MONOTONIC to CLOCK_BOOTTIME, for
the same reason.

Change-Id: Ibcdf69d93f7b6012142cafd72066f39494c1f84b
Test: ./test_device.py
2018-10-05 17:23:44 -07:00
Treehugger Robot
4eb864bf7d Merge "allow adb to remount symlink mount points" 2018-10-02 23:41:40 +00:00
Bowgo Tsai
41649b871a allow adb to remount symlink mount points
Currently `adb remount` won't remount symlink mount points.
In Android Generic System Image, there is a symlink
/product -> /system/product for devices with and without a physical
/product partition to work, respectively:

  - Mount product partition under /system/product via
    'mount /product' OR

  - Keep using /product -> /system/product symlink,
    when no product partition

Currently find_proc_mount() is seeking "/product" under /proc/mounts.
But the actual mount path is "/system/product" when GSI is used
on a device with product partition.

Bug: 111539442
Test: adb remount && touch /product/abc on both GSI and non-GSI

Change-Id: I8f15a67109d0a3f4ee18596ef7eb4280c5631b11
2018-09-28 12:47:27 +08:00
Treehugger Robot
c105f4b63a Merge "adb: remount for /system as root" 2018-09-25 20:38:01 +00:00
Treehugger Robot
37d8bbdf9c Merge "fs_mgr: init: adb: add fstab argument to fs_mgr_overlayfs_mount_all" 2018-09-25 20:37:15 +00:00
Treehugger Robot
6544056d54 Merge "Support 'adb reboot fastboot' command conditionally." 2018-09-25 17:17:08 +00:00
Mark Salyzyn
04aa426c5f adb: remount for /system as root
We can not mount overlayfs on root / as it will intercept all file
transactions.  Thus must remount /system instead.

Test: manual
Bug: 109821005
Bug: 115751838
Change-Id: Idf646b8c1ca8a0d006bf64e23a76a7e909f9162a
2018-09-25 07:30:57 -07:00
Mark Salyzyn
f35db9b11b fs_mgr: init: adb: add fstab argument to fs_mgr_overlayfs_mount_all
Add an fstab argument for fs_mgr_overlayfs_mount_all so that it can
leverage the locally and timely acquired fstab entries.  Affects all
callers, adb and init.

Test: manual
Bug: 109821005
Bug: 115751838
Change-Id: I96e2045d88525a6ce39bef63327a0fcf0704e9bc
2018-09-25 07:30:55 -07:00
Hridya Valsaraju
542582689d Support 'adb reboot fastboot' command conditionally.
Devices not supporting logical partitions do not require the command.

Bug: 78793464
Test: 'adb reboot fastboot' reboots to bootloader for a device
not supporting logical partitions.

Change-Id: I0a7b6d4335040e24efbf461e2dd2d56ab1985b7f
2018-09-25 03:52:12 +00:00
Josh Gao
96d445d846 adbd: fix remount on non-system-as-root devices.
The system image is now a root image, even on devices that don't use
system-as-root. Fix remount to always remount /, to account for this.

Bug: http://b/115751838
Test: `adb remount; adb shell mount | grep " / "`
Change-Id: I2d89a795bd0bc53af33fe69c9d049bbb64d26f3b
2018-09-14 14:32:27 -07:00
Anton Hansson
7f3c01c1d4 Make sync and remount support product_services.
Test: adb remount; touch /product_services/x
Test: adb sync
Bug: 80741439
Bug: 113657113
Change-Id: I8d85964428e5c43811bb5e807b523a0175dd3f5b
2018-08-31 16:18:03 +01:00
Mark Salyzyn
7c2020bf64 adb: use fs_mgr_has_shared_blocks
Use fs_mgr_has_shared_blocks in fs_mgr for adb.

Test: compile
Bug: 109821005
Change-Id: Idccaa252c7630375e49f58727a014e61b50a96d6
2018-08-27 16:29:58 +00:00
Josh Gao
860cc5ae39 adbd: use unique_fd for the usb file descriptors.
Test: adb shell
Change-Id: I8b5e31377bbda9b02e522e3a4b75ac908197912f
2018-08-22 15:33:08 -07:00
Treehugger Robot
3231be66ce Merge "Add sideload, fastboot as reboot targets in init" 2018-08-14 21:25:50 +00:00
Mark Salyzyn
c60153f742 adb: add overlayfs handling for readonly system filesystems
adb verity-on setup overlayfs directories, do not skip if verity
feature not configured for device.

adb verity-off teardown overlayfs directories, do not skip if verity
feature not configured for device.

adb remount setup overlayfs directories and mount if possible, and
do so without a reboot if possible.

Test: compile
Bug: 109821005
Bug: 110985612
Change-Id: I28c4c23fea44b886c5523f0286a523f0b0485df0
2018-08-08 15:42:44 -07:00
Hridya Valsaraju
71fb82a271 Add sideload, fastboot as reboot targets in init
Rebooting to these targets requires writing bootloader
messages and thus root. Moving them into init means that
adb, reboot don't need root to use these targets.

Test: try rebooting to these targets
Bug: 78793464
Change-Id: Ia002d1e3b1cb0c0616f60435fb9af4dce162cf84
2018-08-03 10:03:41 -07:00
Josh Gao
6fb9461103 adbd: when rebooting, don't close socket before pausing.
An accidental side-effect of the change to unique_fd was that we
started closing the reboot service socket before pausing and waiting
for our death. This results in the client immediately returning, which
means they might get a chance to run other commands before we actually
manage to reboot.

Bug: http://b/112104037
Test: adb reboot; adb devices
Change-Id: Id61321da0c08ebd1ab57f1ce926bafd9109dd9c2
2018-08-02 12:52:26 -07:00
Josh Gao
1906243017 adb: move list-forward, kill-forward back into handle_forward_request.
The daemon-side reverse functions depended on handle_forward_request:
move them back instead of duplicating the logic we had in
handle_host_request. Accomplish what we originally wanted to do in this
change by changing the transport argument of handle_forward_request to a
std::function that acquires a transport, either via
acquire_one_transport or immediately returning a value that we already
have.

As a side effect, fix a bug where we would emit spurious errors for host
service requests.

Bug: http://b/112009742
Test: echo "001chost:connect:127.0.0.1:5555" | nc localhost 5037
Test: python test_device.py
Test: python test_adb.py
Change-Id: Iccc555575df6dbd7de10382854c4ea2c6f4beeaa
2018-07-31 15:36:55 -07:00
David Anderson
6dc508671b adb: Correctly detect deduplicated ext4 partitions.
The fs_has_shared_blocks function had two problems. One, it called
statfs() on the mount point, which will return information about the
file system the mount point is on, rather than the filesystem mounted at
that location. Second, the check for EXT4_SUPER_MAGIC was inverted.

Bug: N/A
Test: adb remount -R works on an ext4 deduplicated device
Change-Id: I2e5ef895ea274cb7cc3c35295120da90a026d0d2
2018-07-30 16:08:29 -07:00
Treehugger Robot
d81c4f07fb Merge "adbd: fix check of remount -R." 2018-07-28 01:00:36 +00:00
Josh Gao
1ba2e6a27f Merge "adb: split daemon services out of service_to_fd." 2018-07-27 23:17:18 +00:00
Josh Gao
2712192e12 adbd: fix check of remount -R.
The check was accidentally flipped when refactoring from strcmp to
std::string::operator==, inverting the behavior of `remount -R`.

Test: `adb remount` with verity enabled
Change-Id: Ib43889f1f4cc2f8fe1fd5d6e17e47d538dbe91bd
2018-07-27 16:08:56 -07:00
Mark Salyzyn
c29bf192b5 adb: use WriteFdExactly when no format
Minor cleanup

Test: compile
Bug: 109821005
Bug: 110985612
Change-Id: I15e33a9136675afe7a9498516301ad4960ad2a82
2018-07-27 10:53:54 -07:00