adb: fix old host transport selection.
We regressed handling of the old host transport selection syntax, which
broke users that reimplement adb themselves (e.g. Studio via ddmlib).
Bug: https://issuetracker.google.com/140369526
Test: adb raw "host-serial:822X0028S:forward:tcp:42929;localabstract:/com.example.ndktest-0/platform-1568299082100.sock"
Test: ./test_device.py
Change-Id: Iaaec8fde952316fe9bf2a6f6c6c4a3bc9f74bf72
diff --git a/adb/adb.cpp b/adb/adb.cpp
index ba6df7a..1ec145b 100644
--- a/adb/adb.cpp
+++ b/adb/adb.cpp
@@ -1131,7 +1131,9 @@
if (service == "features") {
std::string error;
- atransport* t = acquire_one_transport(type, serial, transport_id, nullptr, &error);
+ atransport* t =
+ s->transport ? s->transport
+ : acquire_one_transport(type, serial, transport_id, nullptr, &error);
if (t != nullptr) {
SendOkay(reply_fd, FeatureSetToString(t->features()));
} else {
@@ -1190,7 +1192,9 @@
// These always report "unknown" rather than the actual error, for scripts.
if (service == "get-serialno") {
std::string error;
- atransport* t = acquire_one_transport(type, serial, transport_id, nullptr, &error);
+ atransport* t =
+ s->transport ? s->transport
+ : acquire_one_transport(type, serial, transport_id, nullptr, &error);
if (t) {
SendOkay(reply_fd, !t->serial.empty() ? t->serial : "unknown");
} else {
@@ -1200,7 +1204,9 @@
}
if (service == "get-devpath") {
std::string error;
- atransport* t = acquire_one_transport(type, serial, transport_id, nullptr, &error);
+ atransport* t =
+ s->transport ? s->transport
+ : acquire_one_transport(type, serial, transport_id, nullptr, &error);
if (t) {
SendOkay(reply_fd, !t->devpath.empty() ? t->devpath : "unknown");
} else {
@@ -1210,7 +1216,9 @@
}
if (service == "get-state") {
std::string error;
- atransport* t = acquire_one_transport(type, serial, transport_id, nullptr, &error);
+ atransport* t =
+ s->transport ? s->transport
+ : acquire_one_transport(type, serial, transport_id, nullptr, &error);
if (t) {
SendOkay(reply_fd, t->connection_state_name());
} else {
@@ -1234,7 +1242,9 @@
if (service == "reconnect") {
std::string response;
- atransport* t = acquire_one_transport(type, serial, transport_id, nullptr, &response, true);
+ atransport* t = s->transport ? s->transport
+ : acquire_one_transport(type, serial, transport_id, nullptr,
+ &response, true);
if (t != nullptr) {
kick_transport(t, true);
response =
@@ -1246,8 +1256,15 @@
// TODO: Switch handle_forward_request to string_view.
std::string service_str(service);
- if (handle_forward_request(
- service_str.c_str(), [=](std::string* error) { return s->transport; }, reply_fd)) {
+ auto transport_acquirer = [=](std::string* error) {
+ if (s->transport) {
+ return s->transport;
+ } else {
+ std::string error;
+ return acquire_one_transport(type, serial, transport_id, nullptr, &error);
+ }
+ };
+ if (handle_forward_request(service_str.c_str(), transport_acquirer, reply_fd)) {
return HostRequestResult::Handled;
}