Hoisting ambiguous transport handling outside the loop.
This is a pre-cursory CL for https://android-review.git.corp.google.com/c/platform/packages/modules/adb/+/2724438
Bug: 290267160
Test: For these tests, we're constrained to using the hotspot
network (that will allow wireless adb debugging).
Alternatively, a non-corp wireless network (with less stringent
security config) would also work out (tested with both these setups).
Due to these limitations, an integrated test (e.g test_device.py)
does not apply because the test environment is too specialized for
the production environment. It is likely feasible to automate the
hotspot connection (using MH for e.g), however it does not seem
realistic at this time.
aosp-master-with-phones$adb kill-server
aosp-master-with-phones$adb tcpip 5555
restarting in TCP mode port: 5555
aosp-master-with-phones$adb connect 192.168.208.183:5555
connected to 192.168.208.183:5555
aosp-master-with-phones$adb devices
List of devices attached
6L4X895PYXTC7DR8 device
192.168.208.183:5555 device
Disconnect the USB (both point to the same device) and connect another Android device.
aosp-master-with-phones$adb devices
List of devices attached
17071FDEE0027Y device
192.168.208.183:5555 device
Test ambiguity:
aosp-master-with-phones$adb wait-for-disconnect
error: more than one device/emulator
List of devices attached
17071FDEE0027Y device
192.168.208.183:5555 device
aosp-master-with-phones$adb -s 17071FDEE0027Y wait-for-disconnect
Disconnect USB physically.
aosp-master-with-phones$adb devices
List of devices attached
192.168.208.183:5555 device
Reconnect USB:
aosp-master-with-phones$adb devices
List of devices attached
17071FDEE0027Y device
192.168.208.183:5555 device
Test disconnect of wireless transport (use a secondary terminal to disconnect):
aosp-master-with-phones$adb devices
List of devices attached
17071FDEE0027Y device
192.168.208.183:5555 device
aosp-master-with-phones$adb -s 192.168.208.183:5555 wait-for-disconnect
Run `adb disconnect 192.168.208.183:5555` from a secondary terminal.
aosp-master-with-phones$adb devices
List of devices attached
17071FDEE0027Y device
Change-Id: I3521d993a32962d72f59e8f8ac172f39bc2f02d8
diff --git a/services.cpp b/services.cpp
index 19a9030..43cacb3 100644
--- a/services.cpp
+++ b/services.cpp
@@ -201,6 +201,13 @@
acquire_one_transport(transport_type, !serial.empty() ? serial.c_str() : nullptr,
transport_id, &is_ambiguous, &error);
+ // If the target transport disconnect (to wait-for) is unclear, punt
+ // to the user for corrective action (e.g. specify `adb -s <>
+ // wait-for-disconnect`).
+ if (is_ambiguous) {
+ SendFail(fd, error);
+ return;
+ }
for (const auto& state : states) {
if (state == kCsOffline) {
// Special case for wait-for-disconnect:
@@ -221,11 +228,6 @@
}
}
- if (is_ambiguous) {
- SendFail(fd, error);
- return;
- }
-
// Sleep before retrying.
adb_pollfd pfd = {.fd = fd.get(), .events = POLLIN};
if (adb_poll(&pfd, 1, 100) != 0) {