Exit accessory mode more aggressively
The debouncing of USB disconnects means that the disconnect caused
by resetting the connection without unplugging the device does not make
it to the handler, and thus doesn't exit accessory mode. Therefore we
must exit accessory mode even for connect events after we have left the
entering accessory mode state.
Test: Manual testing with desktop head unit
Change-Id: Ia028ff28783fa777a9f8bcd86b523d01f633a140
diff --git a/services/usb/java/com/android/server/usb/UsbDeviceManager.java b/services/usb/java/com/android/server/usb/UsbDeviceManager.java
index b86a85b..8fd0d04 100644
--- a/services/usb/java/com/android/server/usb/UsbDeviceManager.java
+++ b/services/usb/java/com/android/server/usb/UsbDeviceManager.java
@@ -599,8 +599,12 @@
} else {
Slog.e(TAG, "nativeGetAccessoryStrings failed");
}
- } else if (!mConnected && !enteringAccessoryMode) {
- notifyAccessoryModeExit();
+ } else {
+ if (!enteringAccessoryMode) {
+ notifyAccessoryModeExit();
+ } else if (DEBUG) {
+ Slog.v(TAG, "Debouncing accessory mode exit");
+ }
}
}
@@ -805,6 +809,9 @@
break;
}
case MSG_ACCESSORY_MODE_ENTER_TIMEOUT: {
+ if (DEBUG) {
+ Slog.v(TAG, "Accessory mode enter timeout: " + mConnected);
+ }
if (!mConnected) {
notifyAccessoryModeExit();
}