Skip to content

Commit 234fb3b

Browse files
statik213Gerrit Code Review
authored andcommitted
usb: ensure accessory detached sent on re-attach
It's possible for USB state change events to get swallowed if the cable is reconnected quickly because state changes are de-bounced with a 1 second interval. As a result an accessory detached event will not be sent if it re-attaches quickly. However, UsbDeviceManager will send an attached event when the USB connection is configured. This causes apps to misbehave and attempt to open the accessory without closing the previous one. The call to openAccessory fails (with EBUSY) because the underlying /dev/usb_accessory chardev is already open exclusively by the first accessory. Fix this issue by sending a detached event before sending an attached event if the previous accessory was not cleaned up properly. This change fixes a failure in CTSVerifier's USB Accessory Test where the test fails if you reconnect the USB cable quickly. OPO-688, FEIJ-471 Change-Id: I49690553213e866d200da1fb22c83348c6eb3491
1 parent 507b3a7 commit 234fb3b

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

services/usb/java/com/android/server/usb/UsbDeviceManager.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,13 @@ private void updateCurrentAccessory() {
580580

581581
if (mConfigured && enteringAccessoryMode) {
582582
// successfully entered accessory mode
583-
583+
if (mCurrentAccessory != null) {
584+
Slog.w(TAG, "USB accessory re-attached, detach was not announced!");
585+
if (mBootCompleted) {
586+
getCurrentSettings().accessoryDetached(mCurrentAccessory);
587+
}
588+
mCurrentAccessory = null;
589+
}
584590
if (mAccessoryStrings != null) {
585591
mCurrentAccessory = new UsbAccessory(mAccessoryStrings);
586592
Slog.d(TAG, "entering USB accessory mode: " + mCurrentAccessory);

0 commit comments

Comments
 (0)