Merge "Load ncm regexs config to tetherableUsbRegexs if isUsingNcm=true"

This commit is contained in:
Lorenzo Colitti
2021-07-06 03:39:31 +00:00
committed by Gerrit Code Review
3 changed files with 55 additions and 8 deletions

View File

@@ -170,8 +170,16 @@ public class TetheringConfiguration {
mUsbTetheringFunction = getUsbTetheringFunction(res);
tetherableUsbRegexs = getResourceStringArray(res, R.array.config_tether_usb_regexs);
tetherableNcmRegexs = getResourceStringArray(res, R.array.config_tether_ncm_regexs);
final String[] ncmRegexs = getResourceStringArray(res, R.array.config_tether_ncm_regexs);
// If usb tethering use NCM and config_tether_ncm_regexs is not empty, use
// config_tether_ncm_regexs for tetherableUsbRegexs.
if (isUsingNcm() && (ncmRegexs.length != 0)) {
tetherableUsbRegexs = ncmRegexs;
tetherableNcmRegexs = EMPTY_STRING_ARRAY;
} else {
tetherableUsbRegexs = getResourceStringArray(res, R.array.config_tether_usb_regexs);
tetherableNcmRegexs = ncmRegexs;
}
// TODO: Evaluate deleting this altogether now that Wi-Fi always passes
// us an interface name. Careful consideration needs to be given to
// implications for Settings and for provisioning checks.

View File

@@ -30,6 +30,7 @@ import static com.android.networkstack.tethering.TetheringConfiguration.TETHER_F
import static com.android.networkstack.tethering.TetheringConfiguration.TETHER_USB_NCM_FUNCTION;
import static com.android.networkstack.tethering.TetheringConfiguration.TETHER_USB_RNDIS_FUNCTION;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -600,4 +601,48 @@ public class TetheringConfigurationTest {
private void setTetherForceUsbFunctions(final int value) {
setTetherForceUsbFunctions(Integer.toString(value));
}
@Test
public void testNcmRegexs() throws Exception {
final String[] rndisRegexs = {"test_rndis\\d"};
final String[] ncmRegexs = {"test_ncm\\d"};
final String[] rndisNcmRegexs = {"test_rndis\\d", "test_ncm\\d"};
// cfg.isUsingNcm = false.
when(mResources.getInteger(R.integer.config_tether_usb_functions)).thenReturn(
TETHER_USB_RNDIS_FUNCTION);
setUsbAndNcmRegexs(rndisRegexs, ncmRegexs);
assertUsbAndNcmRegexs(rndisRegexs, ncmRegexs);
setUsbAndNcmRegexs(rndisNcmRegexs, new String[0]);
assertUsbAndNcmRegexs(rndisNcmRegexs, new String[0]);
// cfg.isUsingNcm = true.
when(mResources.getInteger(R.integer.config_tether_usb_functions)).thenReturn(
TETHER_USB_NCM_FUNCTION);
setUsbAndNcmRegexs(rndisRegexs, ncmRegexs);
assertUsbAndNcmRegexs(ncmRegexs, new String[0]);
setUsbAndNcmRegexs(rndisNcmRegexs, new String[0]);
assertUsbAndNcmRegexs(rndisNcmRegexs, new String[0]);
// Check USB regex is not overwritten by the NCM regex after force to use rndis from
// Settings.
setUsbAndNcmRegexs(rndisRegexs, ncmRegexs);
setTetherForceUsbFunctions(TETHER_USB_RNDIS_FUNCTION);
assertUsbAndNcmRegexs(rndisRegexs, ncmRegexs);
}
private void setUsbAndNcmRegexs(final String[] usbRegexs, final String[] ncmRegexs) {
when(mResources.getStringArray(R.array.config_tether_usb_regexs)).thenReturn(usbRegexs);
when(mResources.getStringArray(R.array.config_tether_ncm_regexs)).thenReturn(ncmRegexs);
}
private void assertUsbAndNcmRegexs(final String[] usbRegexs, final String[] ncmRegexs) {
final TetheringConfiguration cfg =
new TetheringConfiguration(mMockContext, mLog, INVALID_SUBSCRIPTION_ID);
assertArrayEquals(usbRegexs, cfg.tetherableUsbRegexs);
assertArrayEquals(ncmRegexs, cfg.tetherableNcmRegexs);
}
}

View File

@@ -2665,12 +2665,6 @@ public class TetheringTest {
forceUsbTetheringUse(TETHER_USB_NCM_FUNCTION);
verifyUsbTetheringStopDueToSettingChange(TEST_NCM_IFNAME);
// TODO: move this into setup after allowing configure TEST_NCM_REGEX into
// config_tether_usb_regexs and config_tether_ncm_regexs at the same time.
when(mResources.getStringArray(R.array.config_tether_usb_regexs))
.thenReturn(new String[] {TEST_RNDIS_REGEX, TEST_NCM_REGEX});
sendConfigurationChanged();
// If TETHERING_USB is forced to use ncm function, TETHERING_NCM would no longer be
// available.
final ResultListener ncmResult = new ResultListener(TETHER_ERROR_SERVICE_UNAVAIL);