Fix USB tethering is not turned on with a single tap
Before this CL, the USB default settings will set default usb functions
to RNDIS when tethering is started. Because in some devices, the NCM
is used instead of RNDIS to start tethering. If RNDIS is set in the
device that uses NCM to start tethering, it will cause start
tethering failed.
This CL will use the current functions to set default usb functions
to fix this issue.
Bug: 195068679
Test: make -j42 RunSettingsRoboTests
Change-Id: Ic9353c5ac76c0cd517318a4304fa214d6b2201d2
diff --git a/src/com/android/settings/connecteddevice/usb/UsbDefaultFragment.java b/src/com/android/settings/connecteddevice/usb/UsbDefaultFragment.java
index d9bd4b2..ea1ccc0 100644
--- a/src/com/android/settings/connecteddevice/usb/UsbDefaultFragment.java
+++ b/src/com/android/settings/connecteddevice/usb/UsbDefaultFragment.java
@@ -198,8 +198,9 @@
@Override
public void onTetheringStarted() {
- Log.d(TAG, "onTetheringStarted()");
// Set default usb functions again to make internal data persistent
+ mCurrentFunctions = mUsbBackend.getCurrentFunctions();
+ Log.d(TAG, "onTetheringStarted() : mCurrentFunctions " + mCurrentFunctions);
mUsbBackend.setDefaultUsbFunctions(mCurrentFunctions);
}
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDefaultFragmentTest.java b/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDefaultFragmentTest.java
index eee6398..2317c97 100644
--- a/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDefaultFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDefaultFragmentTest.java
@@ -183,7 +183,7 @@
@Test
public void onTetheringStarted_currentFunctionsIsRndis_setsRndisAsDefaultUsbFunctions() {
- mFragment.mCurrentFunctions = UsbManager.FUNCTION_RNDIS;
+ when(mUsbBackend.getCurrentFunctions()).thenReturn(UsbManager.FUNCTION_RNDIS);
mFragment.mOnStartTetheringCallback.onTetheringStarted();
@@ -192,7 +192,7 @@
@Test
public void onTetheringStarted_currentFunctionsIsNcm_setsNcmAsDefaultUsbFunctions() {
- mFragment.mCurrentFunctions = UsbManager.FUNCTION_NCM;
+ when(mUsbBackend.getCurrentFunctions()).thenReturn(UsbManager.FUNCTION_NCM);
mFragment.mOnStartTetheringCallback.onTetheringStarted();