From 91ed63124cee163e4e72154f374de91aa8a8e2fb Mon Sep 17 00:00:00 2001 From: Hugh Chen Date: Mon, 14 Sep 2020 15:55:57 +0800 Subject: [PATCH] Fix the usb menu didn't switch to "File Transfer/Android Auto" right after connecting to the car unit. - Before this CL, the usb receivers didn't check the extra information of the accessory. It causes the usb menu not to be aware that the usb port is switched to accessory mode. In this CL, the receivers will check whether the intent has an accessory extra. If the usb port is switched to accessory mode the usb menu will switch to "File Transfer/Android Auto". Bug: 162451162 Test: make -j42 RunSettingsRoboTests Change-Id: I0eca89a23670c674b74753fc526256cc1d52e759 Merged-In: I0eca89a23670c674b74753fc526256cc1d52e759 (cherry picked from commit af0a45bb7a8f2317965dbda41c570ad684c08d52) --- .../usb/UsbConnectionBroadcastReceiver.java | 3 +++ .../usb/UsbDetailsFunctionsController.java | 6 +++++- .../usb/UsbDetailsFunctionsControllerTest.java | 13 +++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/com/android/settings/connecteddevice/usb/UsbConnectionBroadcastReceiver.java b/src/com/android/settings/connecteddevice/usb/UsbConnectionBroadcastReceiver.java index e557847d06e..a203534dded 100644 --- a/src/com/android/settings/connecteddevice/usb/UsbConnectionBroadcastReceiver.java +++ b/src/com/android/settings/connecteddevice/usb/UsbConnectionBroadcastReceiver.java @@ -72,6 +72,9 @@ public class UsbConnectionBroadcastReceiver extends BroadcastReceiver implements if (intent.getExtras().getBoolean(UsbManager.USB_FUNCTION_RNDIS)) { functions |= UsbManager.FUNCTION_RNDIS; } + if (intent.getExtras().getBoolean(UsbManager.USB_FUNCTION_ACCESSORY)) { + functions |= UsbManager.FUNCTION_ACCESSORY; + } mFunctions = functions; mDataRole = mUsbBackend.getDataRole(); mPowerRole = mUsbBackend.getPowerRole(); diff --git a/src/com/android/settings/connecteddevice/usb/UsbDetailsFunctionsController.java b/src/com/android/settings/connecteddevice/usb/UsbDetailsFunctionsController.java index 31bca1241ec..ded1294c94c 100644 --- a/src/com/android/settings/connecteddevice/usb/UsbDetailsFunctionsController.java +++ b/src/com/android/settings/connecteddevice/usb/UsbDetailsFunctionsController.java @@ -100,7 +100,11 @@ public class UsbDetailsFunctionsController extends UsbDetailsController pref = getProfilePreference(UsbBackend.usbFunctionsToString(option), title); // Only show supported options if (mUsbBackend.areFunctionsSupported(option)) { - pref.setChecked(functions == option); + if (functions == UsbManager.FUNCTION_ACCESSORY) { + pref.setChecked(UsbManager.FUNCTION_MTP == option); + } else { + pref.setChecked(functions == option); + } } else { mProfilesContainer.removePreference(pref); } diff --git a/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDetailsFunctionsControllerTest.java b/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDetailsFunctionsControllerTest.java index 3a6eec0fd89..149df6ef33e 100644 --- a/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDetailsFunctionsControllerTest.java +++ b/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDetailsFunctionsControllerTest.java @@ -153,6 +153,19 @@ public class UsbDetailsFunctionsControllerTest { assertThat(prefs.get(0).isChecked()).isTrue(); } + @Test + public void displayRefresh_accessoryEnabled_shouldCheckSwitches() { + when(mUsbBackend.areFunctionsSupported(anyLong())).thenReturn(true); + + mDetailsFunctionsController.refresh(true, UsbManager.FUNCTION_ACCESSORY, POWER_ROLE_SINK, + DATA_ROLE_DEVICE); + List prefs = getRadioPreferences(); + + assertThat(prefs.get(0).getKey()) + .isEqualTo(UsbBackend.usbFunctionsToString(UsbManager.FUNCTION_MTP)); + assertThat(prefs.get(0).isChecked()).isTrue(); + } + @Test public void onClickMtp_noneEnabled_shouldEnableMtp() { when(mUsbBackend.areFunctionsSupported(anyLong())).thenReturn(true);