Merge "TetheringConfiguration: force to select upstream automatically on U+"
This commit is contained in:
@@ -194,8 +194,13 @@ public class TetheringConfiguration {
|
||||
|
||||
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);
|
||||
|
||||
@@ -545,7 +545,8 @@ public class TetheringConfigurationTest {
|
||||
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 @@ public class TetheringConfigurationTest {
|
||||
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 @@ public class TetheringConfigurationTest {
|
||||
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),
|
||||
|
||||
@@ -196,6 +196,7 @@ import com.android.networkstack.apishim.common.UnsupportedApiLevelException;
|
||||
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 @@ public class TetheringTest {
|
||||
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 @@ public class TetheringTest {
|
||||
}
|
||||
|
||||
@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 @@ public class TetheringTest {
|
||||
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 @@ public class TetheringTest {
|
||||
}
|
||||
|
||||
@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());
|
||||
|
||||
Reference in New Issue
Block a user