From 8f3b8873b01459c00dfd563a24f6c7f317faab29 Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Wed, 4 Oct 2017 15:05:40 -0700 Subject: [PATCH] adb: cleanup some portions of client usb interfaces Cleanup to remove open coded functions. Test: build Bug: 63736262 Bug: 38446744 Bug: 66912053 Change-Id: I3e6e5a22542934837b6a03523987141dc2776d48 --- adb/client/usb_linux.cpp | 2 +- adb/client/usb_osx.cpp | 2 +- adb/client/usb_windows.cpp | 32 +++++++++++++++----------------- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/adb/client/usb_linux.cpp b/adb/client/usb_linux.cpp index a7df0ed51..1f376a4c9 100644 --- a/adb/client/usb_linux.cpp +++ b/adb/client/usb_linux.cpp @@ -253,7 +253,7 @@ static void find_usb_device(const std::string& base, continue; } /* aproto 01 needs 0 termination */ - if (interface->bInterfaceProtocol == 0x01) { + if (interface->bInterfaceProtocol == ADB_PROTOCOL) { max_packet_size = ep1->wMaxPacketSize; zero_mask = ep1->wMaxPacketSize - 1; } diff --git a/adb/client/usb_osx.cpp b/adb/client/usb_osx.cpp index 4e1480f7b..2e999eef3 100644 --- a/adb/client/usb_osx.cpp +++ b/adb/client/usb_osx.cpp @@ -174,7 +174,7 @@ AndroidInterfaceAdded(io_iterator_t iterator) kr = (*iface)->GetInterfaceClass(iface, &if_class); kr = (*iface)->GetInterfaceSubClass(iface, &subclass); kr = (*iface)->GetInterfaceProtocol(iface, &protocol); - if(if_class != ADB_CLASS || subclass != ADB_SUBCLASS || protocol != ADB_PROTOCOL) { + if (!is_adb_interface(if_class, subclass, protocol)) { // Ignore non-ADB devices. LOG(DEBUG) << "Ignoring interface with incorrect class/subclass/protocol - " << if_class << ", " << subclass << ", " << protocol; diff --git a/adb/client/usb_windows.cpp b/adb/client/usb_windows.cpp index aff52299e..61981b179 100644 --- a/adb/client/usb_windows.cpp +++ b/adb/client/usb_windows.cpp @@ -531,25 +531,23 @@ int recognized_device(usb_handle* handle) { return 0; } - if (is_adb_interface(interf_desc.bInterfaceClass, interf_desc.bInterfaceSubClass, - interf_desc.bInterfaceProtocol)) { - if (interf_desc.bInterfaceProtocol == 0x01) { - AdbEndpointInformation endpoint_info; - // assuming zero is a valid bulk endpoint ID - if (AdbGetEndpointInformation(handle->adb_interface, 0, &endpoint_info)) { - handle->max_packet_size = endpoint_info.max_packet_size; - handle->zero_mask = endpoint_info.max_packet_size - 1; - D("device zero_mask: 0x%x", handle->zero_mask); - } else { - D("AdbGetEndpointInformation failed: %s", - android::base::SystemErrorCodeToString(GetLastError()).c_str()); - } - } - - return 1; + if (!is_adb_interface(interf_desc.bInterfaceClass, interf_desc.bInterfaceSubClass, + interf_desc.bInterfaceProtocol)) { + return 0; } - return 0; + AdbEndpointInformation endpoint_info; + // assuming zero is a valid bulk endpoint ID + if (AdbGetEndpointInformation(handle->adb_interface, 0, &endpoint_info)) { + handle->max_packet_size = endpoint_info.max_packet_size; + handle->zero_mask = endpoint_info.max_packet_size - 1; + D("device zero_mask: 0x%x", handle->zero_mask); + } else { + D("AdbGetEndpointInformation failed: %s", + android::base::SystemErrorCodeToString(GetLastError()).c_str()); + } + + return 1; } void find_devices() {