diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2023-03-24 22:00:40 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2023-03-24 22:00:40 +0000 |
commit | c95a0ec620dd90b7d37f5ee67ce1d959b61975fa (patch) | |
tree | 61425f25403e5d76592c4cf62d40e40bc92f03cb | |
parent | 2486378ba3ff3e231866716e91b042ae239f72ff (diff) | |
parent | 2ae387b3c0d631a3c5cdb51d6658320e6ed52ceb (diff) | |
download | adb-c95a0ec620dd90b7d37f5ee67ce1d959b61975fa.tar.gz |
Merge "Revert "Revert "Flag(env) guarding clear endpoint (device) feature for OSX usb start.""" am: 2ae387b3c0
Original change: https://android-review.googlesource.com/c/platform/packages/modules/adb/+/2504219
Change-Id: Ib20f2253985d5fb6f8a2740c44b779b8aa97d001
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | client/usb_osx.cpp | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/client/usb_osx.cpp b/client/usb_osx.cpp index e1541ec1..99857e26 100644 --- a/client/usb_osx.cpp +++ b/client/usb_osx.cpp @@ -110,6 +110,16 @@ static void AndroidInterfaceAdded(io_iterator_t iterator); static std::unique_ptr<usb_handle> CheckInterface(IOUSBInterfaceInterface550** iface, UInt16 vendor, UInt16 product); +// Flag-guarded (using host env variable) feature that turns on +// the ability to clear the device-side endpoint also before +// starting. See public bug https://issuetracker.google.com/issues/37055927 +// for historical context. +static bool clear_endpoints() { + static const char* env(getenv("ADB_OSX_USB_CLEAR_ENDPOINTS")); + static bool result = env && strcmp("1", env) == 0; + return result; +} + static bool FindUSBDevices() { // Create the matching dictionary to find the Android device's adb interface. CFMutableDictionaryRef matchingDict = IOServiceMatching(kIOUSBInterfaceClassName); @@ -322,7 +332,17 @@ AndroidInterfaceAdded(io_iterator_t iterator) // Used to clear both the endpoints before starting. // When adb quits, we might clear the host endpoint but not the device. // So we make sure both sides are clear before starting up. +// Returns true if: +// - the feature is disabled (OSX/host only) +// - the feature is enabled and successfully clears both endpoints +// Returns false otherwise (if an error is encountered) static bool ClearPipeStallBothEnds(IOUSBInterfaceInterface550** interface, UInt8 bulkEp) { + // If feature-disabled, (silently) bypass clearing both + // endpoints (including device-side). + if (!clear_endpoints()) { + return true; + } + IOReturn rc = (*interface)->ClearPipeStallBothEnds(interface, bulkEp); if (rc != kIOReturnSuccess) { LOG(ERROR) << "Could not clear pipe stall both ends: " << std::hex << rc; @@ -415,12 +435,18 @@ static std::unique_ptr<usb_handle> CheckInterface(IOUSBInterfaceInterface550** i if (kUSBIn == direction) { handle->bulkIn = endpoint; - if (!ClearPipeStallBothEnds(interface, handle->bulkIn)) goto err_get_pipe_props; + + if (!ClearPipeStallBothEnds(interface, handle->bulkIn)) { + goto err_get_pipe_props; + } } if (kUSBOut == direction) { handle->bulkOut = endpoint; - if (!ClearPipeStallBothEnds(interface, handle->bulkOut)) goto err_get_pipe_props; + + if (!ClearPipeStallBothEnds(interface, handle->bulkOut)) { + goto err_get_pipe_props; + } } // Compute the packet-size, in case the system did not return the correct value. |