summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Gao <jmgao@google.com>2017-12-06 15:06:14 -0800
committerJosh Gao <jmgao@google.com>2017-12-06 15:34:41 -0800
commit801048c6eac1b3929576689471fb7d965c90268e (patch)
treeec5ecd6888bdc93e9f966332474e0a4b3f9b78b2
parentcce381e307dd3b2a3b54463afae53b6a8a30cefc (diff)
downloadcore-801048c6eac1b3929576689471fb7d965c90268e.tar.gz
core-801048c6eac1b3929576689471fb7d965c90268e.tar.bz2
core-801048c6eac1b3929576689471fb7d965c90268e.zip
adb: disable USB packet overflow checking on OS X.
OS X appears to be misreporting the maximum packet size on some hardware. Disable this on OS X until we figure out what's going on. Bug: http://b/65063965 Bug: https://issuetracker.google.com/70244520 Test: python test_device.py on linux with CHECK_PACKET_OVERFLOW disabled Test: python test_device.py on darwin (but on hardware that wasn't reproducing this) Change-Id: I57e1adfa162e40ed79f71f97af552b3f0519324e
-rw-r--r--adb/client/usb_osx.cpp1
-rw-r--r--adb/transport_usb.cpp14
2 files changed, 15 insertions, 0 deletions
diff --git a/adb/client/usb_osx.cpp b/adb/client/usb_osx.cpp
index 2e999eef3..b15d28a27 100644
--- a/adb/client/usb_osx.cpp
+++ b/adb/client/usb_osx.cpp
@@ -305,6 +305,7 @@ AndroidInterfaceAdded(io_iterator_t iterator)
handle->devpath = devpath;
usb_handle* handle_p = handle.get();
VLOG(USB) << "Add usb device " << serial;
+ LOG(INFO) << "reported max packet size for " << serial << " is " << handle->max_packet_size;
AddDevice(std::move(handle));
register_usb_transport(reinterpret_cast<::usb_handle*>(handle_p), serial, devpath.c_str(),
1);
diff --git a/adb/transport_usb.cpp b/adb/transport_usb.cpp
index fdecccfc3..a00ed5e4d 100644
--- a/adb/transport_usb.cpp
+++ b/adb/transport_usb.cpp
@@ -27,11 +27,18 @@
#if ADB_HOST
+#if defined(__APPLE__)
+#define CHECK_PACKET_OVERFLOW 0
+#else
+#define CHECK_PACKET_OVERFLOW 1
+#endif
+
// Call usb_read using a buffer having a multiple of usb_get_max_packet_size() bytes
// to avoid overflow. See http://libusb.sourceforge.net/api-1.0/packetoverflow.html.
static int UsbReadMessage(usb_handle* h, amessage* msg) {
D("UsbReadMessage");
+#if CHECK_PACKET_OVERFLOW
size_t usb_packet_size = usb_get_max_packet_size(h);
CHECK_GE(usb_packet_size, sizeof(*msg));
CHECK_LT(usb_packet_size, 4096ULL);
@@ -44,6 +51,9 @@ static int UsbReadMessage(usb_handle* h, amessage* msg) {
}
memcpy(msg, buffer, sizeof(*msg));
return n;
+#else
+ return usb_read(h, msg, sizeof(*msg));
+#endif
}
// Call usb_read using a buffer having a multiple of usb_get_max_packet_size() bytes
@@ -51,6 +61,7 @@ static int UsbReadMessage(usb_handle* h, amessage* msg) {
static int UsbReadPayload(usb_handle* h, apacket* p) {
D("UsbReadPayload(%d)", p->msg.data_length);
+#if CHECK_PACKET_OVERFLOW
size_t usb_packet_size = usb_get_max_packet_size(h);
CHECK_EQ(0ULL, sizeof(p->data) % usb_packet_size);
@@ -64,6 +75,9 @@ static int UsbReadPayload(usb_handle* h, apacket* p) {
}
CHECK_LE(len, sizeof(p->data));
return usb_read(h, &p->data, len);
+#else
+ return usb_read(h, &p->data, p->msg.data_length);
+#endif
}
static int remote_read(apacket* p, atransport* t) {