DO NOT MERGE Android 8.0 stuff

Change-Id: I8c8a9734adbf36c33463123844fa6e078934ae34
diff --git a/mtp/Android.mk b/mtp/Android.mk
index c6a7fb7..32518d3 100644
--- a/mtp/Android.mk
+++ b/mtp/Android.mk
@@ -40,6 +40,9 @@
 ifneq ($(TW_MTP_DEVICE),)
 	LOCAL_CFLAGS += -DUSB_MTP_DEVICE=$(TW_MTP_DEVICE)
 endif
+ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 25; echo $$?),0)
+    LOCAL_CFLAGS += -DHAS_USBHOST_TIMEOUT
+endif
 
 include $(BUILD_SHARED_LIBRARY)
 
diff --git a/mtp/MtpDataPacket.cpp b/mtp/MtpDataPacket.cpp
index 2c51725..845db96 100644
--- a/mtp/MtpDataPacket.cpp
+++ b/mtp/MtpDataPacket.cpp
@@ -427,7 +427,11 @@
 
 // Wait for result of readDataAsync
 int MtpDataPacket::readDataWait(struct usb_device *device) {
+#ifdef HAS_USBHOST_TIMEOUT
+	struct usb_request *req = usb_request_wait(device, 200);
+#else
 	struct usb_request *req = usb_request_wait(device);
+#endif
 	return (req ? req->actual_length : -1);
 }
 
diff --git a/mtp/MtpDevice.cpp b/mtp/MtpDevice.cpp
index 53f8b2e..089fc22 100644
--- a/mtp/MtpDevice.cpp
+++ b/mtp/MtpDevice.cpp
@@ -50,6 +50,10 @@
 }
 #endif
 
+#ifdef HAS_USBHOST_TIMEOUT
+static const int USB_CONTROL_TRANSFER_TIMEOUT_MS = 200;
+#endif
+
 MtpDevice* MtpDevice::open(const char* deviceName, int fd) {
 	struct usb_device *device = usb_device_new(deviceName, fd);
 	if (!device) {
@@ -70,15 +74,24 @@
 				interface->bInterfaceSubClass == 1 && // Still Image Capture
 				interface->bInterfaceProtocol == 1)	 // Picture Transfer Protocol (PIMA 15470)
 			{
+#ifdef HAS_USBHOST_TIMEOUT
+				char* manufacturerName = usb_device_get_manufacturer_name(device, USB_CONTROL_TRANSFER_TIMEOUT_MS);
+				char* productName = usb_device_get_product_name(device, USB_CONTROL_TRANSFER_TIMEOUT_MS);
+#else
 				char* manufacturerName = usb_device_get_manufacturer_name(device);
 				char* productName = usb_device_get_product_name(device);
+#endif
 				MTPD("Found camera: \"%s\" \"%s\"\n", manufacturerName, productName);
 				free(manufacturerName);
 				free(productName);
 			} else if (interface->bInterfaceClass == 0xFF &&
 					interface->bInterfaceSubClass == 0xFF &&
 					interface->bInterfaceProtocol == 0) {
+#ifdef HAS_USBHOST_TIMEOUT
+				char* interfaceName = usb_device_get_string(device, interface->iInterface, USB_CONTROL_TRANSFER_TIMEOUT_MS);
+#else
 				char* interfaceName = usb_device_get_string(device, interface->iInterface);
+#endif
 				if (!interfaceName) {
 					continue;
 				} else if (strcmp(interfaceName, "MTP")) {
@@ -88,8 +101,13 @@
 				free(interfaceName);
 
 				// Looks like an android style MTP device
+#ifdef HAS_USBHOST_TIMEOUT
+				char* manufacturerName = usb_device_get_manufacturer_name(device, USB_CONTROL_TRANSFER_TIMEOUT_MS);
+				char* productName = usb_device_get_product_name(device, USB_CONTROL_TRANSFER_TIMEOUT_MS);
+#else
 				char* manufacturerName = usb_device_get_manufacturer_name(device);
 				char* productName = usb_device_get_product_name(device);
+#endif
 				MTPI("Found MTP device: \"%s\" \"%s\"\n", manufacturerName, productName);
 				free(manufacturerName);
 				free(productName);