diff --git a/usb/usb/Usb.cpp b/usb/usb/Usb.cpp index 4bdd5ed..d8afb80 100644 --- a/usb/usb/Usb.cpp +++ b/usb/usb/Usb.cpp @@ -672,6 +672,11 @@ ScopedAStatus Usb::switchRole(const string& in_portName, const PortRole& in_role fp = fopen(filename.c_str(), "w"); if (fp != NULL) { int ret = fputs(convertRoletoString(in_role).c_str(), fp); + if (ret == EAGAIN) { + ALOGI("role switch busy, retry in %d ms", ROLE_SWAP_RETRY_MS); + std::this_thread::sleep_for(std::chrono::milliseconds(ROLE_SWAP_RETRY_MS)); + ret = fputs(convertRoletoString(in_role).c_str(), fp); + } fclose(fp); if ((ret != EOF) && ReadFileToString(filename, &written)) { written = Trim(written); diff --git a/usb/usb/Usb.h b/usb/usb/Usb.h index 96af846..8f0c3a0 100644 --- a/usb/usb/Usb.h +++ b/usb/usb/Usb.h @@ -80,6 +80,7 @@ constexpr char kGadgetName[] = "11210000.dwc3"; #define DISPLAYPORT_IRQ_HPD_COUNT_CHECK 3 #define DISPLAYPORT_POLL_WAIT_MS 100 +#define ROLE_SWAP_RETRY_MS 700 #define SVID_DISPLAYPORT "ff01" #define SVID_THUNDERBOLT "8087"