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