diff options
| author | Badhri Jagan Sridharan <badhri@google.com> | 2018-06-22 12:06:42 -0700 |
|---|---|---|
| committer | Howard Yen <howardyen@google.com> | 2018-09-04 17:58:08 +0800 |
| commit | 408f25bf9503dea66c931f78a35b8c5eca0564a8 (patch) | |
| tree | 06e00088697ceea6ca1829f32c143e5298798bc9 /usb | |
| parent | 8abb329a427be1731863df28b5200df92051115f (diff) | |
usb gadget: Introduce a delay between ep up and pull up
adb root command fails occationally as the gadget gets pullep
up too soon right after the end points show up. Introduce a delay
to mitigate this.
Bug: 113775439
Test: while true; do fastboot reboot; adb wait-for-device; adb shell getprop ro.bootmode;
adb root; sleep 2; adb wait-for-device; adb reboot bootloader; done;
Not adb root failures were seen.
Change-Id: I3da6cac7c9d616da0c2fa88c8be998fe95a791a2
(cherry picked from commit 91d456d63cf3e2163f3cbbe0f36b4a6b60943475)
Signed-off-by: Howard Yen <howardyen@google.com>
Diffstat (limited to 'usb')
| -rw-r--r-- | usb/UsbGadget.cpp | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/usb/UsbGadget.cpp b/usb/UsbGadget.cpp index bc1756df..69c1adae 100644 --- a/usb/UsbGadget.cpp +++ b/usb/UsbGadget.cpp @@ -30,7 +30,8 @@ constexpr int BUFFER_SIZE = 512; constexpr int MAX_FILE_PATH_LENGTH = 256; constexpr int EPOLL_EVENTS = 10; constexpr bool DEBUG = false; -constexpr int DISCONNECT_WAIT_US = 10000; +constexpr int DISCONNECT_WAIT_US = 100000; +constexpr int PULL_UP_DELAY = 500000; #define BUILD_TYPE "ro.build.type" #define GADGET_PATH "/config/usb_gadget/g1/" @@ -113,6 +114,7 @@ static void *monitorFfs(void *param) { while (!stopMonitor) { int nrEvents = epoll_wait(usbGadget->mEpollFd, events, EPOLL_EVENTS, -1); + if (nrEvents <= 0) { ALOGE("epoll wait did not return descriptor number"); continue; @@ -144,15 +146,17 @@ static void *monitorFfs(void *param) { if (!descriptorPresent && !writeUdc) { if (DEBUG) ALOGI("endpoints not up"); writeUdc = true; - } else if (descriptorPresent && writeUdc && - !!WriteStringToFile(GADGET_NAME, PULLUP_PATH)) { - lock_guard<mutex> lock(usbGadget->mLock); - usbGadget->mCurrentUsbFunctionsApplied = true; - ALOGI("GADGET pulled up"); - writeUdc = false; - gadgetPullup = true; - // notify the main thread to signal userspace. - usbGadget->mCv.notify_all(); + } else if (descriptorPresent && writeUdc) { + usleep(PULL_UP_DELAY); + if(!!WriteStringToFile(GADGET_NAME, PULLUP_PATH)) { + lock_guard<mutex> lock(usbGadget->mLock); + usbGadget->mCurrentUsbFunctionsApplied = true; + ALOGI("GADGET pulled up"); + writeUdc = false; + gadgetPullup = true; + // notify the main thread to signal userspace. + usbGadget->mCv.notify_all(); + } } } } else { |
