Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6e08d93a authored by Vitalii Tomkiv's avatar Vitalii Tomkiv
Browse files

Add timeout to usb_device_get_string to prevent usb stuck state for bad

behaving devices.

Bug: 31923641
Test: manual run and test with bad devices.
Change-Id: I50e65733fff19f16c7d16bfd805ae930f30171b3
parent fa92ed03
Loading
Loading
Loading
Loading
+16 −5
Original line number Diff line number Diff line
@@ -39,6 +39,12 @@

namespace android {

namespace {

static constexpr int USB_CONTROL_TRANSFER_TIMEOUT_MS = 200;

}  // namespace

#if 0
static bool isMtpDevice(uint16_t vendor, uint16_t product) {
    // Sandisk Sansa Fuze
@@ -84,15 +90,18 @@ MtpDevice* MtpDevice::open(const char* deviceName, int fd) {
                interface->bInterfaceSubClass == 1 && // Still Image Capture
                interface->bInterfaceProtocol == 1)     // Picture Transfer Protocol (PIMA 15470)
            {
                char* manufacturerName = usb_device_get_manufacturer_name(device);
                char* productName = usb_device_get_product_name(device);
                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);
                ALOGD("Found camera: \"%s\" \"%s\"\n", manufacturerName, productName);
                free(manufacturerName);
                free(productName);
            } else if (interface->bInterfaceClass == 0xFF &&
                    interface->bInterfaceSubClass == 0xFF &&
                    interface->bInterfaceProtocol == 0) {
                char* interfaceName = usb_device_get_string(device, interface->iInterface);
                char* interfaceName = usb_device_get_string(device, interface->iInterface,
                        USB_CONTROL_TRANSFER_TIMEOUT_MS);
                if (!interfaceName) {
                    continue;
                } else if (strcmp(interfaceName, "MTP")) {
@@ -102,8 +111,10 @@ MtpDevice* MtpDevice::open(const char* deviceName, int fd) {
                free(interfaceName);

                // Looks like an android style MTP device
                char* manufacturerName = usb_device_get_manufacturer_name(device);
                char* productName = usb_device_get_product_name(device);
                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);
                ALOGD("Found MTP device: \"%s\" \"%s\"\n", manufacturerName, productName);
                free(manufacturerName);
                free(productName);