diff options
Diffstat (limited to 'mtp')
-rw-r--r-- | mtp/Android.mk | 3 | ||||
-rw-r--r-- | mtp/MtpDataPacket.cpp | 4 | ||||
-rw-r--r-- | mtp/MtpDevice.cpp | 18 |
3 files changed, 25 insertions, 0 deletions
diff --git a/mtp/Android.mk b/mtp/Android.mk index c6a7fb7db..32518d3fa 100644 --- a/mtp/Android.mk +++ b/mtp/Android.mk @@ -40,6 +40,9 @@ LOCAL_SHARED_LIBRARIES += libz libc libusbhost libstdc++ libdl libcutils libutil 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 2c517252a..845db968e 100644 --- a/mtp/MtpDataPacket.cpp +++ b/mtp/MtpDataPacket.cpp @@ -427,7 +427,11 @@ int MtpDataPacket::readDataAsync(struct usb_request *req) { // 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 53f8b2e9f..089fc2272 100644 --- a/mtp/MtpDevice.cpp +++ b/mtp/MtpDevice.cpp @@ -50,6 +50,10 @@ static bool isMtpDevice(uint16_t vendor, uint16_t product) { } #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 @@ MtpDevice* MtpDevice::open(const char* deviceName, int fd) { 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 @@ MtpDevice* MtpDevice::open(const char* deviceName, int fd) { 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); |