diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2023-03-24 22:46:21 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2023-03-24 22:46:21 +0000 |
commit | ad14f7ddd84f48ebc1d65e3c25c6830c4fa24ddc (patch) | |
tree | 61425f25403e5d76592c4cf62d40e40bc92f03cb | |
parent | f94833370c1035b6f48a2995301f2674900e25bf (diff) | |
parent | c95a0ec620dd90b7d37f5ee67ce1d959b61975fa (diff) | |
download | adb-ad14f7ddd84f48ebc1d65e3c25c6830c4fa24ddc.tar.gz |
Merge "Revert "Revert "Flag(env) guarding clear endpoint (device) feature for OSX usb start.""" am: 2ae387b3c0 am: c95a0ec620
Original change: https://android-review.googlesource.com/c/platform/packages/modules/adb/+/2504219
Change-Id: I21cb683bf4f28f3c95ee8e7993e6ac14e99fa290
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. |