diff options
author | Mike Lockwood <lockwood@android.com> | 2011-03-29 16:49:42 -0700 |
---|---|---|
committer | Mike Lockwood <lockwood@android.com> | 2011-03-29 23:05:59 -0700 |
commit | 8f2e3862bc4629bf152810aa147089bd066ded83 (patch) | |
tree | ae73ffb033b46b32981da8c834e5f5bdf69bf2c2 | |
parent | 87805ca3a477e165891baa18efe5239a70d11bc9 (diff) | |
download | base-8f2e3862bc4629bf152810aa147089bd066ded83.tar.gz |
DO NOT MERGE: UsbService: Make USB disconnect handling for accessory mode more robust
Handle the case where the kernel driver is in accessory mode but we failed
to initialize it at the framework level. On disconnnect, check to see if the
accessory kernel driver is enabled rather than checking mCurrentAccessory.
That way we will restore the USB state in the kernel even if mCurrentAccessory
is null.
Change-Id: I2c4f6edb34aae2064f4b62ec0461d1fdd8770541
Signed-off-by: Mike Lockwood <lockwood@android.com>
-rw-r--r-- | services/java/com/android/server/usb/UsbService.java | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/services/java/com/android/server/usb/UsbService.java b/services/java/com/android/server/usb/UsbService.java index f366e1095098..b4789e732629 100644 --- a/services/java/com/android/server/usb/UsbService.java +++ b/services/java/com/android/server/usb/UsbService.java @@ -387,11 +387,14 @@ public class UsbService extends IUsbManager.Stub { case MSG_UPDATE_STATE: if (mConnected != mLastConnected || mConfiguration != mLastConfiguration) { if (mConnected == 0) { - // make sure accessory mode is off, and restore default functions - if (mCurrentAccessory != null && UsbManager.setFunctionEnabled( - UsbManager.USB_FUNCTION_ACCESSORY, false)) { + if (UsbManager.isFunctionEnabled( + UsbManager.USB_FUNCTION_ACCESSORY)) { + // make sure accessory mode is off, and restore default functions Log.d(TAG, "exited USB accessory mode"); - + if (!UsbManager.setFunctionEnabled + (UsbManager.USB_FUNCTION_ACCESSORY, false)) { + Log.e(TAG, "could not disable accessory function"); + } int count = mDefaultFunctions.size(); for (int i = 0; i < count; i++) { String function = mDefaultFunctions.get(i); @@ -400,8 +403,10 @@ public class UsbService extends IUsbManager.Stub { } } - mDeviceManager.accessoryDetached(mCurrentAccessory); - mCurrentAccessory = null; + if (mCurrentAccessory != null) { + mDeviceManager.accessoryDetached(mCurrentAccessory); + mCurrentAccessory = null; + } } } |