Fix can't select the [USB Tethering] item in [Developer Options]

- This CL is using 'USB_CONFIGURED' to check whether the USB enumeration
  is completed from the intent. If 'USB_CONFIGURED' is true then update
  the UI.

Bug: 229200265
Test: make -j65 RunSettingsRoboTests
Change-Id: Icab05e37ae3fcc9f1bf404a610fc97c368c453f5
This commit is contained in:
Hugh Chen
2022-04-29 08:40:21 +00:00
parent aadc44ae26
commit ec0c171735
7 changed files with 92 additions and 37 deletions

View File

@@ -55,7 +55,7 @@ public class ConnectedUsbDeviceUpdater {
@VisibleForTesting
UsbConnectionBroadcastReceiver.UsbConnectionListener mUsbConnectionListener =
(connected, functions, powerRole, dataRole) -> {
(connected, functions, powerRole, dataRole, isUsbConfigured) -> {
if (connected) {
mUsbPreference.setSummary(getSummary(dataRole == DATA_ROLE_DEVICE
? functions : UsbManager.FUNCTION_NONE, powerRole));

View File

@@ -61,6 +61,8 @@ public class UsbConnectionBroadcastReceiver extends BroadcastReceiver implements
if (DEBUG) {
Log.d(TAG, "onReceive() action : " + intent.getAction());
}
boolean isUsbConfigured = intent.getExtras() != null
? intent.getExtras().getBoolean(UsbManager.USB_CONFIGURED) : false;
if (UsbManager.ACTION_USB_STATE.equals(intent.getAction())) {
mConnected = intent.getExtras().getBoolean(UsbManager.USB_CONNECTED)
|| intent.getExtras().getBoolean(UsbManager.USB_HOST_CONNECTED);
@@ -98,7 +100,7 @@ public class UsbConnectionBroadcastReceiver extends BroadcastReceiver implements
}
if (mUsbConnectionListener != null) {
mUsbConnectionListener.onUsbConnectionChanged(mConnected, mFunctions, mPowerRole,
mDataRole);
mDataRole, isUsbConfigured);
}
}
@@ -142,6 +144,7 @@ public class UsbConnectionBroadcastReceiver extends BroadcastReceiver implements
* Interface definition for a callback to be invoked when usb connection is changed.
*/
interface UsbConnectionListener {
void onUsbConnectionChanged(boolean connected, long functions, int powerRole, int dataRole);
void onUsbConnectionChanged(boolean connected, long functions, int powerRole, int dataRole,
boolean isUsbConfigured);
}
}

View File

@@ -69,22 +69,23 @@ public class UsbDefaultFragment extends RadioButtonPickerFragment {
@VisibleForTesting
UsbConnectionBroadcastReceiver.UsbConnectionListener mUsbConnectionListener =
(connected, functions, powerRole, dataRole) -> {
(connected, functions, powerRole, dataRole, isUsbConfigured) -> {
final long defaultFunctions = mUsbBackend.getDefaultUsbFunctions();
Log.d(TAG, "UsbConnectionListener() connected : " + connected + ", functions : "
+ functions + ", defaultFunctions : " + defaultFunctions
+ ", mIsStartTethering : " + mIsStartTethering);
if (connected && !mIsConnected && (defaultFunctions == UsbManager.FUNCTION_RNDIS
+ ", mIsStartTethering : " + mIsStartTethering
+ ", isUsbConfigured : " + isUsbConfigured);
if (connected && !mIsConnected && ((defaultFunctions == UsbManager.FUNCTION_RNDIS
|| defaultFunctions == UsbManager.FUNCTION_NCM)
&& defaultFunctions == functions)
&& !mIsStartTethering) {
mCurrentFunctions = defaultFunctions;
startTethering();
}
if (mIsStartTethering && connected) {
if ((mIsStartTethering || isUsbConfigured) && connected) {
mCurrentFunctions = functions;
refresh(functions);
mUsbBackend.setDefaultUsbFunctions(functions);
mIsStartTethering = false;
}
mIsConnected = connected;

View File

@@ -50,7 +50,7 @@ public class UsbDetailsFragment extends DashboardFragment {
UsbConnectionBroadcastReceiver mUsbReceiver;
private UsbConnectionBroadcastReceiver.UsbConnectionListener mUsbConnectionListener =
(connected, functions, powerRole, dataRole) -> {
(connected, functions, powerRole, dataRole, isUsbFigured) -> {
for (UsbDetailsController controller : mControllers) {
controller.refresh(connected, functions, powerRole, dataRole);
}