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

Commit 4fe5acd4 authored by Badhri Jagan Sridharan's avatar Badhri Jagan Sridharan Committed by Android (Google) Code Review
Browse files

Merge "Do not debounce disconnect while resetUsbGadget"

parents 741c60f3 0b2be9a6
Loading
Loading
Loading
Loading
+33 −5
Original line number Original line Diff line number Diff line
@@ -536,7 +536,6 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser
        private boolean mInHostModeWithNoAccessoryConnected;
        private boolean mInHostModeWithNoAccessoryConnected;
        private boolean mSourcePower;
        private boolean mSourcePower;
        private boolean mSinkPower;
        private boolean mSinkPower;
        private boolean mConfigured;
        private boolean mAudioAccessoryConnected;
        private boolean mAudioAccessoryConnected;
        private boolean mAudioAccessorySupported;
        private boolean mAudioAccessorySupported;
        private boolean mConnectedToDataDisabledPort;
        private boolean mConnectedToDataDisabledPort;
@@ -571,7 +570,12 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser
        private final UsbPermissionManager mPermissionManager;
        private final UsbPermissionManager mPermissionManager;
        private NotificationManager mNotificationManager;
        private NotificationManager mNotificationManager;


        /**
         * Do not debounce for the first disconnect after resetUsbGadget.
         */
        protected boolean mResetUsbGadgetDisableDebounce;
        protected boolean mConnected;
        protected boolean mConnected;
        protected boolean mConfigured;
        protected long mScreenUnlockedFunctions;
        protected long mScreenUnlockedFunctions;
        protected boolean mBootCompleted;
        protected boolean mBootCompleted;
        protected boolean mCurrentFunctionsApplied;
        protected boolean mCurrentFunctionsApplied;
@@ -716,16 +720,30 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser
                Slog.e(TAG, "unknown state " + state);
                Slog.e(TAG, "unknown state " + state);
                return;
                return;
            }
            }
            if (configured == 0) removeMessages(MSG_UPDATE_STATE);
            if (connected == 1) removeMessages(MSG_FUNCTION_SWITCH_TIMEOUT);
            if (connected == 1) removeMessages(MSG_FUNCTION_SWITCH_TIMEOUT);
            Message msg = Message.obtain(this, MSG_UPDATE_STATE);
            Message msg = Message.obtain(this, MSG_UPDATE_STATE);
            msg.arg1 = connected;
            msg.arg1 = connected;
            msg.arg2 = configured;
            msg.arg2 = configured;
            // debounce disconnects to avoid problems bringing up USB tethering
            if (DEBUG) {
                Slog.i(TAG, "mResetUsbGadgetDisableDebounce:" + mResetUsbGadgetDisableDebounce
                       + " connected:" + connected + "configured:" + configured);
            }
            if (mResetUsbGadgetDisableDebounce) {
                // Do not debounce disconnect after resetUsbGadget.
                sendMessage(msg);
                if (connected == 1) mResetUsbGadgetDisableDebounce = false;
            } else {
                if (configured == 0) {
                    removeMessages(MSG_UPDATE_STATE);
                    if (DEBUG) Slog.i(TAG, "removeMessages MSG_UPDATE_STATE");
                }
                if (connected == 1) removeMessages(MSG_FUNCTION_SWITCH_TIMEOUT);
                // debounce disconnects to avoid problems bringing up USB tethering.
                sendMessageDelayed(msg,
                sendMessageDelayed(msg,
                    (connected == 0) ? (mScreenLocked ? DEVICE_STATE_UPDATE_DELAY
                    (connected == 0) ? (mScreenLocked ? DEVICE_STATE_UPDATE_DELAY
                                                      : DEVICE_STATE_UPDATE_DELAY_EXT) : 0);
                                                      : DEVICE_STATE_UPDATE_DELAY_EXT) : 0);
            }
            }
        }


        public void updateHostState(UsbPort port, UsbPortStatus status) {
        public void updateHostState(UsbPort port, UsbPortStatus status) {
            if (DEBUG) {
            if (DEBUG) {
@@ -974,7 +992,10 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser
                    int operationId = sUsbOperationCount.incrementAndGet();
                    int operationId = sUsbOperationCount.incrementAndGet();
                    mConnected = (msg.arg1 == 1);
                    mConnected = (msg.arg1 == 1);
                    mConfigured = (msg.arg2 == 1);
                    mConfigured = (msg.arg2 == 1);

                    if (DEBUG) {
                        Slog.i(TAG, "handleMessage MSG_UPDATE_STATE " + "mConnected:" + mConnected
                               + " mConfigured:" + mConfigured);
                    }
                    updateUsbNotification(false);
                    updateUsbNotification(false);
                    updateAdbNotification(false);
                    updateAdbNotification(false);
                    if (mBootCompleted) {
                    if (mBootCompleted) {
@@ -2132,9 +2153,16 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser
                        }
                        }


                        try {
                        try {
                            // MSG_ACCESSORY_MODE_ENTER_TIMEOUT has to be removed to allow exiting
                            // AOAP mode during resetUsbGadget.
                            removeMessages(MSG_ACCESSORY_MODE_ENTER_TIMEOUT);
                            if (mConfigured) {
                                mResetUsbGadgetDisableDebounce = true;
                            }
                            mUsbGadgetHal.reset();
                            mUsbGadgetHal.reset();
                        } catch (Exception e) {
                        } catch (Exception e) {
                            Slog.e(TAG, "reset Usb Gadget failed", e);
                            Slog.e(TAG, "reset Usb Gadget failed", e);
                            mResetUsbGadgetDisableDebounce = false;
                        }
                        }
                    }
                    }
                    break;
                    break;