Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4f0f3561 authored by Mike Lockwood's avatar Mike Lockwood
Browse files

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: I35d458f21a8b21611946da523d0f53723cab0540
Signed-off-by: default avatarMike Lockwood <lockwood@android.com>
parent 7661dd8d
Loading
Loading
Loading
Loading
+11 −6
Original line number Diff line number Diff line
@@ -561,11 +561,14 @@ public class UsbService extends IUsbManager.Stub {
                    case MSG_UPDATE_STATE:
                        if (mConnected != mLastConnected || mConfiguration != mLastConfiguration) {
                            if (mConnected == 0) {
                                if (UsbManager.isFunctionEnabled(
                                            UsbManager.USB_FUNCTION_ACCESSORY)) {
                                    // make sure accessory mode is off, and restore default functions
                                if (mCurrentAccessory != null && UsbManager.setFunctionEnabled(
                                        UsbManager.USB_FUNCTION_ACCESSORY, false)) {
                                    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);
@@ -574,10 +577,12 @@ public class UsbService extends IUsbManager.Stub {
                                        }
                                    }

                                    if (mCurrentAccessory != null) {
                                        mDeviceManager.accessoryDetached(mCurrentAccessory);
                                        mCurrentAccessory = null;
                                    }
                                }
                            }

                            final ContentResolver cr = mContext.getContentResolver();
                            if (Settings.Secure.getInt(cr,