summaryrefslogtreecommitdiffstats
path: root/mtp
diff options
context:
space:
mode:
authorEthan Yonker <dees_troy@teamw.in>2017-08-25 04:45:50 +0200
committerEthan Yonker <dees_troy@teamw.in>2017-08-25 04:45:50 +0200
commit95e8007578193422ef7fe2d098b80e8ba99fc48d (patch)
tree856f90d15b1f7c74d497503bd6ac6fd12b08b32d /mtp
parentMerge "Fix typos / inconsistencies in German language" into android-7.1 (diff)
downloadandroid_bootable_recovery-95e8007578193422ef7fe2d098b80e8ba99fc48d.tar
android_bootable_recovery-95e8007578193422ef7fe2d098b80e8ba99fc48d.tar.gz
android_bootable_recovery-95e8007578193422ef7fe2d098b80e8ba99fc48d.tar.bz2
android_bootable_recovery-95e8007578193422ef7fe2d098b80e8ba99fc48d.tar.lz
android_bootable_recovery-95e8007578193422ef7fe2d098b80e8ba99fc48d.tar.xz
android_bootable_recovery-95e8007578193422ef7fe2d098b80e8ba99fc48d.tar.zst
android_bootable_recovery-95e8007578193422ef7fe2d098b80e8ba99fc48d.zip
Diffstat (limited to 'mtp')
-rw-r--r--mtp/Android.mk3
-rw-r--r--mtp/MtpDataPacket.cpp4
-rw-r--r--mtp/MtpDevice.cpp18
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);