Do not debounce disconnect while resetUsbGadget

When resetUsbGadget is requested, do not debounce disconnect to allow
falling back to the the default configuration. Also remove
accessory mode enter timeout messages to prevent leaving AOAP
enabled when resetUsbGadget is requested.

Bug: 260145166
Change-Id: I538f405312049846839297dc3835ec2ff7d75084
Merged-in: I538f405312049846839297dc3835ec2ff7d75084
(cherry picked from commit 0b2be9a6fb)
This commit is contained in:
Badhri Jagan Sridharan
2023-01-12 08:34:01 +00:00
parent f804faaf95
commit f81a09f4ca

View File

@@ -535,7 +535,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;
@@ -568,7 +567,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;
@@ -713,15 +717,29 @@ 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) {
sendMessageDelayed(msg, 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,
(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) {
@@ -971,7 +989,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) {
@@ -2116,9 +2137,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;