TetheringConfiguration: force to select upstream automatically on U+
Simply the upstream selection since U+ device for tethering refactor.
Changes:
1. Support automatic mode only on U+ device.
2. Add two tethering tests to make sure that the resource config can't
control automatic mode anymore. Expect that always automatic mode
on U+ device. Also limit some existing tethering tests for R, S,
or T.
Changes of TetheringTest:
- testAutomaticUpstreamSelectionWithConfigDisabled (U+) [new]
- testLegacyUpstreamSelection (T-)
- testChooseDunUpstreamByLegacyMode (T-)
- testChooseDunUpstreamByAutomaticModeWithConfigDisabled (U+) [new]
3. Add two tethering configuration tests to make sure that automatic
mode is always enabled no mater what the resource config or flag
are on U+ device. Also limit some existing tethering tests for R,
S, or T.
Changes of TetheringConfiguration:
- testChooseUpstreamAutomatically (T-)
- testChooseUpstreamAutomaticallyAfterT (U+) [new]
- testChooseUpstreamAutomatically_FlagOverride (R)
- testChooseUpstreamAutomatically_FlagOverrideOnSAndT (S, T)
(Renamed from testChooseUpstreamAutomatically_FlagOverrideAfterR)
- testChooseUpstreamAutomatically_FlagOverrideAfterT (U+) [new]
Bug: 257941865
Bug: 257408654
Test: atest TetheringTest
Change-Id: I7ace317a1529177a84557741dc07d732b7f8cf89
diff --git a/Tethering/src/com/android/networkstack/tethering/TetheringConfiguration.java b/Tethering/src/com/android/networkstack/tethering/TetheringConfiguration.java
index 7ed4725..903de9d 100644
--- a/Tethering/src/com/android/networkstack/tethering/TetheringConfiguration.java
+++ b/Tethering/src/com/android/networkstack/tethering/TetheringConfiguration.java
@@ -194,8 +194,13 @@
isDunRequired = checkDunRequired(ctx);
- final boolean forceAutomaticUpstream = !SdkLevel.isAtLeastS()
- && isConnectivityFeatureEnabled(ctx, TETHER_FORCE_UPSTREAM_AUTOMATIC_VERSION);
+ // Here is how automatic mode enable/disable support on different Android version:
+ // - R : can be enabled/disabled by resource config_tether_upstream_automatic.
+ // but can be force-enabled by flag TETHER_FORCE_UPSTREAM_AUTOMATIC_VERSION.
+ // - S, T: can be enabled/disabled by resource config_tether_upstream_automatic.
+ // - U+ : automatic mode only.
+ final boolean forceAutomaticUpstream = SdkLevel.isAtLeastU() || (!SdkLevel.isAtLeastS()
+ && isConnectivityFeatureEnabled(ctx, TETHER_FORCE_UPSTREAM_AUTOMATIC_VERSION));
chooseUpstreamAutomatically = forceAutomaticUpstream || getResourceBoolean(
res, R.bool.config_tether_upstream_automatic, false /** defaultValue */);
preferredUpstreamIfaceTypes = getUpstreamIfaceTypes(res, isDunRequired);
diff --git a/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringConfigurationTest.java b/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringConfigurationTest.java
index 1a12125..f662c02 100644
--- a/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringConfigurationTest.java
+++ b/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringConfigurationTest.java
@@ -545,7 +545,8 @@
assertTrue(testCfg.shouldEnableWifiP2pDedicatedIp());
}
- @Test
+ // The config only works on T-
+ @Test @IgnoreAfter(Build.VERSION_CODES.TIRAMISU)
public void testChooseUpstreamAutomatically() throws Exception {
when(mResources.getBoolean(R.bool.config_tether_upstream_automatic))
.thenReturn(true);
@@ -556,6 +557,20 @@
assertChooseUpstreamAutomaticallyIs(false);
}
+ // The automatic mode is always enabled on U+
+ @Test @IgnoreUpTo(Build.VERSION_CODES.TIRAMISU)
+ public void testChooseUpstreamAutomaticallyAfterT() throws Exception {
+ // Expect that automatic mode is always enabled no matter what
+ // config_tether_upstream_automatic is.
+ when(mResources.getBoolean(R.bool.config_tether_upstream_automatic))
+ .thenReturn(true);
+ assertChooseUpstreamAutomaticallyIs(true);
+
+ when(mResources.getBoolean(R.bool.config_tether_upstream_automatic))
+ .thenReturn(false);
+ assertChooseUpstreamAutomaticallyIs(true);
+ }
+
// The flag override only works on R-
@Test @IgnoreAfter(Build.VERSION_CODES.R)
public void testChooseUpstreamAutomatically_FlagOverride() throws Exception {
@@ -574,14 +589,34 @@
assertChooseUpstreamAutomaticallyIs(false);
}
- @Test @IgnoreUpTo(Build.VERSION_CODES.R)
- public void testChooseUpstreamAutomatically_FlagOverrideAfterR() throws Exception {
+ @Test @IgnoreUpTo(Build.VERSION_CODES.R) @IgnoreAfter(Build.VERSION_CODES.TIRAMISU)
+ public void testChooseUpstreamAutomatically_FlagOverrideOnSAndT() throws Exception {
when(mResources.getBoolean(R.bool.config_tether_upstream_automatic))
.thenReturn(false);
setTetherForceUpstreamAutomaticFlagVersion(TEST_PACKAGE_VERSION - 1);
assertChooseUpstreamAutomaticallyIs(false);
}
+ // The automatic mode is always enabled on U+
+ @Test @IgnoreUpTo(Build.VERSION_CODES.TIRAMISU)
+ public void testChooseUpstreamAutomatically_FlagOverrideAfterT() throws Exception {
+ // Expect that automatic mode is always enabled no matter what
+ // TETHER_FORCE_UPSTREAM_AUTOMATIC_VERSION is.
+ when(mResources.getBoolean(R.bool.config_tether_upstream_automatic))
+ .thenReturn(false);
+ setTetherForceUpstreamAutomaticFlagVersion(TEST_PACKAGE_VERSION - 1);
+ assertTrue(DeviceConfigUtils.isFeatureEnabled(mMockContext, NAMESPACE_CONNECTIVITY,
+ TetheringConfiguration.TETHER_FORCE_UPSTREAM_AUTOMATIC_VERSION, APEX_NAME, false));
+
+ assertChooseUpstreamAutomaticallyIs(true);
+
+ setTetherForceUpstreamAutomaticFlagVersion(0L);
+ assertChooseUpstreamAutomaticallyIs(true);
+
+ setTetherForceUpstreamAutomaticFlagVersion(Long.MAX_VALUE);
+ assertChooseUpstreamAutomaticallyIs(true);
+ }
+
private void setTetherForceUpstreamAutomaticFlagVersion(Long version) {
doReturn(version == null ? null : Long.toString(version)).when(
() -> DeviceConfig.getProperty(eq(NAMESPACE_CONNECTIVITY),
diff --git a/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringTest.java b/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringTest.java
index 9337b1a..a8d886b 100644
--- a/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringTest.java
+++ b/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringTest.java
@@ -196,6 +196,7 @@
import com.android.networkstack.tethering.TestConnectivityManager.TestNetworkAgent;
import com.android.networkstack.tethering.metrics.TetheringMetrics;
import com.android.testutils.DevSdkIgnoreRule;
+import com.android.testutils.DevSdkIgnoreRule.IgnoreAfter;
import com.android.testutils.DevSdkIgnoreRule.IgnoreUpTo;
import com.android.testutils.MiscAsserts;
@@ -1212,13 +1213,12 @@
inOrder.verify(mUpstreamNetworkMonitor).setCurrentUpstream(wifi.networkId);
}
- @Test
- public void testAutomaticUpstreamSelection() throws Exception {
+ private void verifyAutomaticUpstreamSelection(boolean configAutomatic) throws Exception {
TestNetworkAgent mobile = new TestNetworkAgent(mCm, buildMobileDualStackUpstreamState());
TestNetworkAgent wifi = new TestNetworkAgent(mCm, buildWifiUpstreamState());
InOrder inOrder = inOrder(mCm, mUpstreamNetworkMonitor);
// Enable automatic upstream selection.
- upstreamSelectionTestCommon(true, inOrder, mobile, wifi);
+ upstreamSelectionTestCommon(configAutomatic, inOrder, mobile, wifi);
// This code has historically been racy, so test different orderings of CONNECTIVITY_ACTION
// broadcasts and callbacks, and add mLooper.dispatchAll() calls between the two.
@@ -1298,6 +1298,20 @@
}
@Test
+ public void testAutomaticUpstreamSelection() throws Exception {
+ verifyAutomaticUpstreamSelection(true /* configAutomatic */);
+ }
+
+ @Test
+ @IgnoreUpTo(Build.VERSION_CODES.TIRAMISU)
+ public void testAutomaticUpstreamSelectionWithConfigDisabled() throws Exception {
+ // Expect that automatic config can't disable the automatic mode because automatic mode
+ // is always enabled on U+ device.
+ verifyAutomaticUpstreamSelection(false /* configAutomatic */);
+ }
+
+ @Test
+ @IgnoreAfter(Build.VERSION_CODES.TIRAMISU)
public void testLegacyUpstreamSelection() throws Exception {
TestNetworkAgent mobile = new TestNetworkAgent(mCm, buildMobileDualStackUpstreamState());
TestNetworkAgent wifi = new TestNetworkAgent(mCm, buildWifiUpstreamState());
@@ -1323,14 +1337,13 @@
verifyDisableTryCellWhenTetheringStop(inOrder);
}
- @Test
- public void testChooseDunUpstreamByAutomaticMode() throws Exception {
+ private void verifyChooseDunUpstreamByAutomaticMode(boolean configAutomatic) throws Exception {
// Enable automatic upstream selection.
TestNetworkAgent mobile = new TestNetworkAgent(mCm, buildMobileDualStackUpstreamState());
TestNetworkAgent wifi = new TestNetworkAgent(mCm, buildWifiUpstreamState());
TestNetworkAgent dun = new TestNetworkAgent(mCm, buildDunUpstreamState());
InOrder inOrder = inOrder(mCm, mUpstreamNetworkMonitor);
- chooseDunUpstreamTestCommon(true, inOrder, mobile, wifi, dun);
+ chooseDunUpstreamTestCommon(configAutomatic, inOrder, mobile, wifi, dun);
// When default network switch to mobile and wifi is connected (may have low signal),
// automatic mode would request dun again and choose it as upstream.
@@ -1359,6 +1372,18 @@
}
@Test
+ public void testChooseDunUpstreamByAutomaticMode() throws Exception {
+ verifyChooseDunUpstreamByAutomaticMode(true /* configAutomatic */);
+ }
+
+ @Test
+ @IgnoreUpTo(Build.VERSION_CODES.TIRAMISU)
+ public void testChooseDunUpstreamByAutomaticModeWithConfigDisabled() throws Exception {
+ verifyChooseDunUpstreamByAutomaticMode(false /* configAutomatic */);
+ }
+
+ @Test
+ @IgnoreAfter(Build.VERSION_CODES.TIRAMISU)
public void testChooseDunUpstreamByLegacyMode() throws Exception {
// Enable Legacy upstream selection.
TestNetworkAgent mobile = new TestNetworkAgent(mCm, buildMobileDualStackUpstreamState());