aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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.