diff options
-rw-r--r-- | OWNERS | 1 | ||||
-rw-r--r-- | SERVICES.TXT | 2 | ||||
-rw-r--r-- | adb_listeners.cpp | 22 | ||||
-rw-r--r-- | adb_listeners.h | 2 | ||||
-rw-r--r-- | adb_mdns.cpp | 1 | ||||
-rw-r--r-- | client/adb_wifi.cpp | 2 | ||||
-rw-r--r-- | client/auth.cpp | 2 | ||||
-rw-r--r-- | client/main.cpp | 3 | ||||
-rw-r--r-- | client/openscreen/platform/udp_socket.cpp | 14 | ||||
-rw-r--r-- | client/transport_usb.cpp | 6 | ||||
-rw-r--r-- | client/usb_libusb.cpp | 3 | ||||
-rw-r--r-- | daemon/abb_service.cpp | 7 | ||||
-rw-r--r-- | docs/user/adb.1.md | 8 | ||||
-rw-r--r-- | proto/devices.proto | 1 | ||||
-rw-r--r-- | sockets.cpp | 6 | ||||
-rw-r--r-- | sysdeps_win32.cpp | 4 | ||||
-rwxr-xr-x | test_device.py | 1 | ||||
-rw-r--r-- | transport.cpp | 3 |
18 files changed, 55 insertions, 33 deletions
@@ -1,3 +1,4 @@ +# Bug component: 1352 shaju@google.com enh@google.com diff --git a/SERVICES.TXT b/SERVICES.TXT index 380f2cf0..7beaef1b 100644 --- a/SERVICES.TXT +++ b/SERVICES.TXT @@ -254,7 +254,7 @@ track-app: a new messeage is sent (this service never stops). Each message features a hex4 length prefix followed by a - human-readable protocol buffer. e.g.: + binary protocol buffer. e.g.: process { pid: 18595 diff --git a/adb_listeners.cpp b/adb_listeners.cpp index 124e2d8d..c24016fb 100644 --- a/adb_listeners.cpp +++ b/adb_listeners.cpp @@ -33,15 +33,18 @@ #include "transport.h" // A listener is an entity which binds to a local port and, upon receiving a connection on that -// port, creates an asocket to connect the new local connection to a specific remote service. +// port, creates an asocket to connect the new local connection to a specific remote service. They +// are mostly used to implement forward and reverse-forward. // -// TODO: some listeners read from the new connection to determine what exact service to connect to -// on the far side. +// Some listeners, called "smartsockets" read from the new connection to determine what exact +// service to connect to on the far side. This is implemented with a different fdevent handler. class alistener { public: alistener(const std::string& _local_name, const std::string& _connect_to); ~alistener(); + bool isSmartSocket() { return connect_to == kSmartSocketConnectTo; } + fdevent* fde = nullptr; int fd = -1; @@ -127,8 +130,7 @@ std::string format_listeners() EXCLUDES(listener_list_mutex) { std::lock_guard<std::mutex> lock(listener_list_mutex); std::string result; for (auto& l : listener_list) { - // Ignore special listeners like those for *smartsocket* - if (l->connect_to[0] == '*') { + if (l->isSmartSocket()) { continue; } // <device-serial> " " <local-name> " " <remote-name> "\n" @@ -166,20 +168,20 @@ void remove_all_listeners() EXCLUDES(listener_list_mutex) { } } +#if ADB_HOST void enable_server_sockets() EXCLUDES(listener_list_mutex) { std::lock_guard<std::mutex> lock(listener_list_mutex); for (auto& l : listener_list) { - if (l->connect_to == "*smartsocket*") { + if (l->isSmartSocket()) { fdevent_set(l->fde, FDE_READ); } } } -#if ADB_HOST void close_smartsockets() EXCLUDES(listener_list_mutex) { std::lock_guard<std::mutex> lock(listener_list_mutex); auto pred = [](const std::unique_ptr<alistener>& listener) { - return listener->local_name == "*smartsocket*"; + return listener->isSmartSocket(); }; listener_list.remove_if(pred); } @@ -192,7 +194,7 @@ InstallStatus install_listener(const std::string& local_name, const char* connec for (auto& l : listener_list) { if (local_name == l->local_name) { // Can't repurpose a smartsocket. - if (l->connect_to[0] == '*') { + if (l->isSmartSocket()) { *error = "cannot repurpose smartsocket"; return INSTALL_STATUS_INTERNAL_ERROR; } @@ -230,7 +232,7 @@ InstallStatus install_listener(const std::string& local_name, const char* connec } close_on_exec(listener->fd); - if (listener->connect_to == "*smartsocket*") { + if (listener->isSmartSocket()) { #if ADB_HOST listener->fde = fdevent_create(listener->fd, ss_listener_event_func, listener.get()); #else diff --git a/adb_listeners.h b/adb_listeners.h index 0aa774a7..7fd46f02 100644 --- a/adb_listeners.h +++ b/adb_listeners.h @@ -22,6 +22,8 @@ #include <android-base/macros.h> +inline constexpr const char* kSmartSocketConnectTo = "*smartsocket*"; + // error/status codes for install_listener. enum InstallStatus { INSTALL_STATUS_OK = 0, diff --git a/adb_mdns.cpp b/adb_mdns.cpp index 087a9ab9..73230ea6 100644 --- a/adb_mdns.cpp +++ b/adb_mdns.cpp @@ -18,6 +18,7 @@ #include "adb_mdns.h" +#include <algorithm> #include <set> #include <android-base/stringprintf.h> diff --git a/client/adb_wifi.cpp b/client/adb_wifi.cpp index 50ea2e95..d79cbffe 100644 --- a/client/adb_wifi.cpp +++ b/client/adb_wifi.cpp @@ -58,8 +58,6 @@ struct PairingResultWaiter { } }; // PairingResultWaiter -void adb_wifi_init() {} - static std::vector<uint8_t> stringToUint8(const std::string& str) { auto* p8 = reinterpret_cast<const uint8_t*>(str.data()); return std::vector<uint8_t>(p8, p8 + str.length()); diff --git a/client/auth.cpp b/client/auth.cpp index 10b835e5..f90c334b 100644 --- a/client/auth.cpp +++ b/client/auth.cpp @@ -260,7 +260,7 @@ std::deque<std::shared_ptr<RSA>> adb_auth_get_private_keys() { static std::string adb_auth_sign(RSA* key, const char* token, size_t token_size) { if (token_size != TOKEN_SIZE) { D("Unexpected token size %zd", token_size); - return nullptr; + return std::string(); } std::string result; diff --git a/client/main.cpp b/client/main.cpp index bdd99e83..818d305a 100644 --- a/client/main.cpp +++ b/client/main.cpp @@ -132,7 +132,6 @@ int adb_server_main(int is_daemon, const std::string& socket_spec, const char* o init_reconnect_handler(); - adb_wifi_init(); if (!getenv("ADB_MDNS") || strcmp(getenv("ADB_MDNS"), "0") != 0) { init_mdns_transport_discovery(); } @@ -158,7 +157,7 @@ int adb_server_main(int is_daemon, const std::string& socket_spec, const char* o // If we told a previous adb server to quit because of version mismatch, we can get to this // point before it's finished exiting. Retry for a while to give it some time. Don't actually // accept any connections until adb_wait_for_device_initialization finishes below. - while (install_listener(socket_spec, "*smartsocket*", nullptr, INSTALL_LISTENER_DISABLED, + while (install_listener(socket_spec, kSmartSocketConnectTo, nullptr, INSTALL_LISTENER_DISABLED, nullptr, &error) != INSTALL_STATUS_OK) { if (std::chrono::steady_clock::now() - start > 0.5s) { LOG(FATAL) << "could not install *smartsocket* listener: " << error; diff --git a/client/openscreen/platform/udp_socket.cpp b/client/openscreen/platform/udp_socket.cpp index 32520782..9b9e4998 100644 --- a/client/openscreen/platform/udp_socket.cpp +++ b/client/openscreen/platform/udp_socket.cpp @@ -493,13 +493,23 @@ class AdbUdpSocket : public UdpSocket { // This is effectively a boolean passed to setsockopt() to allow a future // bind() on the same socket to succeed, even if the address is already in // use. This is pretty much universally the desired behavior. - const int reuse_addr = 1; - if (adb_setsockopt(fd_, SOL_SOCKET, SO_REUSEADDR, &reuse_addr, sizeof(reuse_addr)) == -1) { + const int reuse = 1; + if (adb_setsockopt(fd_, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)) == -1) { OnError(Error::Code::kSocketOptionSettingFailure); LOG(WARNING) << "Failed to set SO_REUSEADDR"; return; } +#if defined(__APPLE__) + // On Mac, SO_REUSEADDR is not enough to allow a bind() on a reusable multicast socket. + // We need to also set the option SO_REUSEPORT. + if (adb_setsockopt(fd_, SOL_SOCKET, SO_REUSEPORT, &reuse, sizeof(reuse)) == -1) { + OnError(Error::Code::kSocketOptionSettingFailure); + LOG(WARNING) << "Failed to set SO_REUSEPORT"; + return; + } +#endif + switch (local_endpoint_.address.version()) { case UdpSocket::Version::kV4: { struct sockaddr_in address = {}; diff --git a/client/transport_usb.cpp b/client/transport_usb.cpp index 35f406ad..998f73c9 100644 --- a/client/transport_usb.cpp +++ b/client/transport_usb.cpp @@ -178,9 +178,9 @@ bool is_adb_interface(int usb_class, int usb_subclass, int usb_protocol) { } bool should_use_libusb() { - bool enable = false; -#if defined(__APPLE__) - enable = true; + bool enable = true; +#if defined(_WIN32) + enable = false; #endif char* env = getenv("ADB_LIBUSB"); if (env) { diff --git a/client/usb_libusb.cpp b/client/usb_libusb.cpp index 4244225c..6133e7c8 100644 --- a/client/usb_libusb.cpp +++ b/client/usb_libusb.cpp @@ -1029,7 +1029,8 @@ void usb_init() { VLOG(USB) << "initializing libusb..."; int rc = libusb_init(nullptr); if (rc != 0) { - LOG(FATAL) << "failed to initialize libusb: " << libusb_error_name(rc); + LOG(WARNING) << "failed to initialize libusb: " << libusb_error_name(rc); + return; } // Register the hotplug callback. diff --git a/daemon/abb_service.cpp b/daemon/abb_service.cpp index e1df4a59..9725f5ce 100644 --- a/daemon/abb_service.cpp +++ b/daemon/abb_service.cpp @@ -24,9 +24,6 @@ namespace { -struct AbbProcess; -static auto& abbp = *new std::unique_ptr<AbbProcess>(std::make_unique<AbbProcess>()); - struct AbbProcess { unique_fd sendCommand(std::string_view command); @@ -83,8 +80,10 @@ unique_fd AbbProcess::startAbbProcess(unique_fd* error_fd) { kErrorProtocol, error_fd); } +static auto& abbp = *new AbbProcess; + } // namespace unique_fd execute_abb_command(std::string_view command) { - return abbp->sendCommand(command); + return abbp.sendCommand(command); } diff --git a/docs/user/adb.1.md b/docs/user/adb.1.md index e220786e..8e826899 100644 --- a/docs/user/adb.1.md +++ b/docs/user/adb.1.md @@ -356,6 +356,14 @@ detach **SERIAL** Detach from a USB device identified by its **SERIAL** to allow use by other processes. +# Features: + +host-features + list features supported by adb server. + +features + list features supported by both adb server and device. + # ENVIRONMENT VARIABLES $ADB_TRACE diff --git a/proto/devices.proto b/proto/devices.proto index 48ebadf8..6f65babb 100644 --- a/proto/devices.proto +++ b/proto/devices.proto @@ -54,6 +54,7 @@ message Device { ConnectionType connection_type = 7; int64 negotiated_speed = 8; int64 max_speed = 9; + int64 transport_id = 10; } message Devices { diff --git a/sockets.cpp b/sockets.cpp index e10f710e..a33157b8 100644 --- a/sockets.cpp +++ b/sockets.cpp @@ -149,9 +149,9 @@ static SocketFlushResult local_socket_flush_incoming(asocket* s) { // Deferred acks are available. send_ready(s->id, s->peer->id, s->transport, bytes_flushed); } else { - // Deferred acks aren't available, we should ask for more data as long as we've made any - // progress. - if (bytes_flushed != 0) { + // Deferred acks aren't available, we should ask for more data as long as we have less + // than a full packet left in our queue. + if (bytes_flushed != 0 && s->packet_queue.size() < MAX_PAYLOAD) { send_ready(s->id, s->peer->id, s->transport, 0); } } diff --git a/sysdeps_win32.cpp b/sysdeps_win32.cpp index bbf3ee5f..2c87dc19 100644 --- a/sysdeps_win32.cpp +++ b/sysdeps_win32.cpp @@ -3089,13 +3089,11 @@ Process adb_launch_process(std::string_view executable, std::vector<std::string> } // The SetThreadDescription API was brought in version 1607 of Windows 10. -typedef HRESULT(WINAPI* SetThreadDescription)(HANDLE hThread, PCWSTR lpThreadDescription); - // Based on PlatformThread::SetName() from // https://cs.chromium.org/chromium/src/base/threading/platform_thread_win.cc int adb_thread_setname(const std::string& name) { // The SetThreadDescription API works even if no debugger is attached. - auto set_thread_description_func = reinterpret_cast<SetThreadDescription>( + auto set_thread_description_func = reinterpret_cast<HRESULT(WINAPI *)(HANDLE, PCWSTR)>( ::GetProcAddress(::GetModuleHandleW(L"Kernel32.dll"), "SetThreadDescription")); if (set_thread_description_func) { std::wstring name_wide; diff --git a/test_device.py b/test_device.py index 20cd98da..e2e0f744 100755 --- a/test_device.py +++ b/test_device.py @@ -1847,6 +1847,7 @@ class DevicesListing(DeviceTest): self.assertFalse(device.device == "") self.assertTrue(device.negotiated_speed == int(device.negotiated_speed)) self.assertTrue(device.max_speed == int(device.max_speed)) + self.assertTrue(device.transport_id == int(device.transport_id)) def main(): random.seed(0) diff --git a/transport.cpp b/transport.cpp index 71756d36..d17ead76 100644 --- a/transport.cpp +++ b/transport.cpp @@ -1364,8 +1364,9 @@ static std::string transportListToProto(const std::list<atransport*>& sorted_tra device->set_product(sanitize(t->product, false)); device->set_model(sanitize(t->model, true)); device->set_device(sanitize(t->device, false)); - device->set_max_speed(t->connection()->MaxSpeedMbps()); device->set_negotiated_speed(t->connection()->NegotiatedSpeedMbps()); + device->set_max_speed(t->connection()->MaxSpeedMbps()); + device->set_transport_id(t->id); } std::string proto; |