adbd: Check USB disabled property after opening FFS
When a device with a DWC3 controller switches from host mode
back to peripheral mode, the USB HAL can set the sys.usb.adb.disabled
property to 0 to allow resumption of the usb_ffs_open_thread.
However when the kernel DWC3 driver switches modes it does the host
mode exit followed immediately by the gadget mode re-init in one fell
swoop. Furthermore, the re-adding of the gadget "UDC" device attempts
to immediately rebind the ConfigFS driver which is dependent on the
FunctionFS instance being ready to go, otherwise the operation fails.
Thus by the time USB HAL informs ADBD via the property change, there is
a race condition since the daemon must again open the FunctionFS
endpoints and reinitialize the descriptors before the kernel tries
to bind to the DWC3 gadget.
This can be avoided by moving the property check to after the
open_functionfs() call. This ensures ADBD will have prepared the
FFS descriptors and keeps the EP files open before pausing the thread
loop when in host mode. When leaving host mode the thread can pick
up from there and directly proceed to starting the monitor thread,
which satisfies the conditions needed for the gadget re-bind.
Bug: http://b/189256322
Change-Id: I57b0eede1ed14592d66065659d689285cae4102d
diff --git a/daemon/usb.cpp b/daemon/usb.cpp
index ad6f818..4366ea9 100644
--- a/daemon/usb.cpp
+++ b/daemon/usb.cpp
@@ -741,12 +741,6 @@
});
while (true) {
- if (android::base::GetBoolProperty(kPropertyUsbDisabled, false)) {
- LOG(INFO) << "pausing USB due to " << kPropertyUsbDisabled;
- prop_mon.Run();
- LOG(INFO) << "resuming USB";
- }
-
unique_fd control;
unique_fd bulk_out;
unique_fd bulk_in;
@@ -755,6 +749,12 @@
continue;
}
+ if (android::base::GetBoolProperty(kPropertyUsbDisabled, false)) {
+ LOG(INFO) << "pausing USB due to " << kPropertyUsbDisabled;
+ prop_mon.Run();
+ LOG(INFO) << "resuming USB";
+ }
+
atransport* transport = new atransport();
transport->serial = "UsbFfs";
std::promise<void> destruction_notifier;