aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2023-03-25 00:20:10 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2023-03-25 00:20:10 +0000
commitdcb6436d1aaa72cb8ed8a37e5107203c8040d782 (patch)
tree61425f25403e5d76592c4cf62d40e40bc92f03cb
parent77ad2356e5e67673f16e3d653eb35ce9652a936f (diff)
parent1362634c77ff80e53a433864b9da7540039832b1 (diff)
downloadadb-dcb6436d1aaa72cb8ed8a37e5107203c8040d782.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: I2e86534065ab4ccb5b8346e197d7968016fcd1ae Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--client/usb_osx.cpp30
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.