Loading adb/client/usb_libusb.cpp +7 −16 Original line number Original line Diff line number Diff line Loading @@ -180,10 +180,6 @@ static std::string get_device_dev_path(libusb_device* device) { if (port_count < 0) return ""; if (port_count < 0) return ""; return StringPrintf("/dev/bus/usb/%03u/%03u", libusb_get_bus_number(device), ports[0]); return StringPrintf("/dev/bus/usb/%03u/%03u", libusb_get_bus_number(device), ports[0]); } } static bool is_device_accessible(libusb_device* device) { return access(get_device_dev_path(device).c_str(), R_OK | W_OK) == 0; } #endif #endif static bool endpoint_is_output(uint8_t endpoint) { static bool endpoint_is_output(uint8_t endpoint) { Loading Loading @@ -377,9 +373,10 @@ static void process_device(libusb_device* device) { { { std::unique_lock<std::mutex> lock(usb_handles_mutex); std::unique_lock<std::mutex> lock(usb_handles_mutex); usb_handles[device_address] = std::move(result); usb_handles[device_address] = std::move(result); } register_usb_transport(usb_handle_raw, device_serial.c_str(), device_address.c_str(), writable); register_usb_transport(usb_handle_raw, device_serial.c_str(), device_address.c_str(), writable); } LOG(INFO) << "registered new usb device '" << device_serial << "'"; LOG(INFO) << "registered new usb device '" << device_serial << "'"; } } Loading @@ -388,18 +385,12 @@ static std::atomic<int> connecting_devices(0); static void device_connected(libusb_device* device) { static void device_connected(libusb_device* device) { #if defined(__linux__) #if defined(__linux__) // Android's host linux libusb uses netlink instead of udev for device hotplug notification, // Android's host linux libusb uses netlink instead of udev for device hotplug notification, // which means we can get hotplug notifications before udev has updated ownership/perms on // which means we can get hotplug notifications before udev has updated ownership/perms on the // the device. Since we're not going to be able to link against the system's libudev any // device. Since we're not going to be able to link against the system's libudev any time soon, // time soon, hack around this by checking for accessibility in a loop. // hack around this by inserting a sleep. auto thread = std::thread([device]() { auto thread = std::thread([device]() { std::string device_path = get_device_dev_path(device); std::string device_path = get_device_dev_path(device); auto start = std::chrono::steady_clock::now(); std::this_thread::sleep_for(1s); while (std::chrono::steady_clock::now() - start < 500ms) { if (is_device_accessible(device)) { break; } std::this_thread::sleep_for(10ms); } process_device(device); process_device(device); if (--connecting_devices == 0) { if (--connecting_devices == 0) { Loading Loading
adb/client/usb_libusb.cpp +7 −16 Original line number Original line Diff line number Diff line Loading @@ -180,10 +180,6 @@ static std::string get_device_dev_path(libusb_device* device) { if (port_count < 0) return ""; if (port_count < 0) return ""; return StringPrintf("/dev/bus/usb/%03u/%03u", libusb_get_bus_number(device), ports[0]); return StringPrintf("/dev/bus/usb/%03u/%03u", libusb_get_bus_number(device), ports[0]); } } static bool is_device_accessible(libusb_device* device) { return access(get_device_dev_path(device).c_str(), R_OK | W_OK) == 0; } #endif #endif static bool endpoint_is_output(uint8_t endpoint) { static bool endpoint_is_output(uint8_t endpoint) { Loading Loading @@ -377,9 +373,10 @@ static void process_device(libusb_device* device) { { { std::unique_lock<std::mutex> lock(usb_handles_mutex); std::unique_lock<std::mutex> lock(usb_handles_mutex); usb_handles[device_address] = std::move(result); usb_handles[device_address] = std::move(result); } register_usb_transport(usb_handle_raw, device_serial.c_str(), device_address.c_str(), writable); register_usb_transport(usb_handle_raw, device_serial.c_str(), device_address.c_str(), writable); } LOG(INFO) << "registered new usb device '" << device_serial << "'"; LOG(INFO) << "registered new usb device '" << device_serial << "'"; } } Loading @@ -388,18 +385,12 @@ static std::atomic<int> connecting_devices(0); static void device_connected(libusb_device* device) { static void device_connected(libusb_device* device) { #if defined(__linux__) #if defined(__linux__) // Android's host linux libusb uses netlink instead of udev for device hotplug notification, // Android's host linux libusb uses netlink instead of udev for device hotplug notification, // which means we can get hotplug notifications before udev has updated ownership/perms on // which means we can get hotplug notifications before udev has updated ownership/perms on the // the device. Since we're not going to be able to link against the system's libudev any // device. Since we're not going to be able to link against the system's libudev any time soon, // time soon, hack around this by checking for accessibility in a loop. // hack around this by inserting a sleep. auto thread = std::thread([device]() { auto thread = std::thread([device]() { std::string device_path = get_device_dev_path(device); std::string device_path = get_device_dev_path(device); auto start = std::chrono::steady_clock::now(); std::this_thread::sleep_for(1s); while (std::chrono::steady_clock::now() - start < 500ms) { if (is_device_accessible(device)) { break; } std::this_thread::sleep_for(10ms); } process_device(device); process_device(device); if (--connecting_devices == 0) { if (--connecting_devices == 0) { Loading