Snap for 11973804 from c5a560160fd82e94870a2252037d394e1e1f9780 to 24Q3-release

Change-Id: Ibb3db4c1bf7c9dc3829ea2e720d6cb89b8485742
diff --git a/usb/usb/Usb.cpp b/usb/usb/Usb.cpp
index b8c5c8e..0736f4c 100644
--- a/usb/usb/Usb.cpp
+++ b/usb/usb/Usb.cpp
@@ -593,6 +593,11 @@
         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 facc328..15348af 100644
--- a/usb/usb/Usb.h
+++ b/usb/usb/Usb.h
@@ -55,6 +55,8 @@
 #define VBUS_PATH NEW_UDC_PATH "dwc3_exynos_otg_b_sess"
 #define USB_DATA_PATH NEW_UDC_PATH "usb_data_enabled"
 
+#define ROLE_SWAP_RETRY_MS 700
+
 struct Usb : public BnUsb {
     Usb();