Replace isTetheringWithSoftApConfig flag with B SDK check am: a10437f133

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/3543708

Change-Id: I8a5d2f468313e465b7db5ed236e55f88065c9bda
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Quang Anh Luong 2025-03-17 00:21:09 -07:00 • committed by Automerger Merge Worker
commit d2d93b35cb
4 changed files with 28 additions and 35 deletions

View file

@ -148,7 +148,6 @@ import com.android.internal.util.MessageUtils;
import com.android.internal.util.State; import com.android.internal.util.State;
import com.android.internal.util.StateMachine; import com.android.internal.util.StateMachine;
import com.android.modules.utils.build.SdkLevel; import com.android.modules.utils.build.SdkLevel;
import com.android.net.flags.Flags;
import com.android.net.module.util.BaseNetdUnsolicitedEventListener; import com.android.net.module.util.BaseNetdUnsolicitedEventListener;
import com.android.net.module.util.CollectionUtils; import com.android.net.module.util.CollectionUtils;
import com.android.net.module.util.HandlerUtils; import com.android.net.module.util.HandlerUtils;
@ -463,9 +462,8 @@ public class Tethering {
return mSettingsObserver; return mSettingsObserver;
} }
// TODO: Replace with SdkLevel.isAtLeastB() once the feature is fully implemented.
boolean isTetheringWithSoftApConfigEnabled() { boolean isTetheringWithSoftApConfigEnabled() {
return SdkLevel.isAtLeastB() && Flags.tetheringWithSoftApConfig(); return mDeps.isTetheringWithSoftApConfigEnabled();
} }
/** /**

View file

@ -37,7 +37,6 @@ import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import com.android.modules.utils.build.SdkLevel; import com.android.modules.utils.build.SdkLevel;
import com.android.net.flags.Flags;
import com.android.net.module.util.RoutingCoordinatorManager; import com.android.net.module.util.RoutingCoordinatorManager;
import com.android.net.module.util.RoutingCoordinatorService; import com.android.net.module.util.RoutingCoordinatorService;
import com.android.net.module.util.SharedLog; import com.android.net.module.util.SharedLog;
@ -211,9 +210,9 @@ public abstract class TetheringDependencies {
} }
/** /**
* Wrapper for tethering_with_soft_ap_config feature flag. * Returns true if the tethering with soft ap config feature is enabled.
*/ */
public boolean isTetheringWithSoftApConfigEnabled() { public boolean isTetheringWithSoftApConfigEnabled() {
return SdkLevel.isAtLeastB() && Flags.tetheringWithSoftApConfig(); return SdkLevel.isAtLeastB();
} }
} }

View file

@ -96,7 +96,6 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue; import static org.junit.Assume.assumeTrue;
import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.notNull; import static org.mockito.ArgumentMatchers.notNull;
@ -201,7 +200,6 @@ import androidx.test.runner.AndroidJUnit4;
import com.android.internal.util.test.BroadcastInterceptingContext; import com.android.internal.util.test.BroadcastInterceptingContext;
import com.android.internal.util.test.FakeSettingsProvider; import com.android.internal.util.test.FakeSettingsProvider;
import com.android.modules.utils.build.SdkLevel; import com.android.modules.utils.build.SdkLevel;
import com.android.net.flags.Flags;
import com.android.net.module.util.CollectionUtils; import com.android.net.module.util.CollectionUtils;
import com.android.net.module.util.InterfaceParams; import com.android.net.module.util.InterfaceParams;
import com.android.net.module.util.PrivateAddressCoordinator; import com.android.net.module.util.PrivateAddressCoordinator;
@ -344,6 +342,7 @@ public class TetheringTest {
private TestConnectivityManager mCm; private TestConnectivityManager mCm;
private boolean mForceEthernetServiceUnavailable = false; private boolean mForceEthernetServiceUnavailable = false;
private int mBinderCallingUid = TEST_CALLER_UID; private int mBinderCallingUid = TEST_CALLER_UID;
private boolean mTetheringWithSoftApConfigEnabled = SdkLevel.isAtLeastB();
private class TestContext extends BroadcastInterceptingContext { private class TestContext extends BroadcastInterceptingContext {
TestContext(Context base) { TestContext(Context base) {
@ -584,6 +583,11 @@ public class TetheringTest {
public int getBinderCallingUid() { public int getBinderCallingUid() {
return mBinderCallingUid; return mBinderCallingUid;
} }
@Override
public boolean isTetheringWithSoftApConfigEnabled() {
return mTetheringWithSoftApConfigEnabled;
}
} }
private static LinkProperties buildUpstreamLinkProperties(String interfaceName, private static LinkProperties buildUpstreamLinkProperties(String interfaceName,
@ -720,6 +724,7 @@ public class TetheringTest {
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_WIFI)).thenReturn(true); when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_WIFI)).thenReturn(true);
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_WIFI_DIRECT)).thenReturn(true); when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_WIFI_DIRECT)).thenReturn(true);
mIpServerDependencies = spy(new MockIpServerDependencies()); mIpServerDependencies = spy(new MockIpServerDependencies());
mTetheringWithSoftApConfigEnabled = SdkLevel.isAtLeastB();
} }
// In order to interact with syncSM from the test, tethering must be created in test thread. // In order to interact with syncSM from the test, tethering must be created in test thread.
@ -2437,7 +2442,7 @@ public class TetheringTest {
@Test @Test
public void testSoftApConfigInTetheringEventCallback() throws Exception { public void testSoftApConfigInTetheringEventCallback() throws Exception {
assumeTrue(isTetheringWithSoftApConfigEnabled()); assumeTrue(mTetheringDependencies.isTetheringWithSoftApConfigEnabled());
when(mContext.checkCallingOrSelfPermission(NETWORK_SETTINGS)) when(mContext.checkCallingOrSelfPermission(NETWORK_SETTINGS))
.thenReturn(PERMISSION_DENIED); .thenReturn(PERMISSION_DENIED);
when(mContext.checkCallingOrSelfPermission(NETWORK_STACK)) when(mContext.checkCallingOrSelfPermission(NETWORK_STACK))
@ -2533,13 +2538,9 @@ public class TetheringTest {
callback.assertNoCallback(); callback.assertNoCallback();
} }
private boolean isTetheringWithSoftApConfigEnabled() {
return SdkLevel.isAtLeastB() && Flags.tetheringWithSoftApConfig();
}
@Test @Test
public void testFuzzyMatchedWifiCannotBeAdded() throws Exception { public void testFuzzyMatchedWifiCannotBeAdded() throws Exception {
assumeTrue(isTetheringWithSoftApConfigEnabled()); assumeTrue(mTetheringDependencies.isTetheringWithSoftApConfigEnabled());
initTetheringOnTestThread(); initTetheringOnTestThread();
TestTetheringEventCallback callback = new TestTetheringEventCallback(); TestTetheringEventCallback callback = new TestTetheringEventCallback();
SoftApConfiguration softApConfig = new SoftApConfiguration.Builder().setWifiSsid( SoftApConfiguration softApConfig = new SoftApConfiguration.Builder().setWifiSsid(
@ -2623,7 +2624,7 @@ public class TetheringTest {
@Test @Test
public void testFuzzyMatchedWifiCanBeAddedAfterIpServerStopped() throws Exception { public void testFuzzyMatchedWifiCanBeAddedAfterIpServerStopped() throws Exception {
assumeTrue(isTetheringWithSoftApConfigEnabled()); assumeTrue(mTetheringDependencies.isTetheringWithSoftApConfigEnabled());
when(mWifiManager.startTetheredHotspot(null)).thenReturn(true); when(mWifiManager.startTetheredHotspot(null)).thenReturn(true);
initTetheringOnTestThread(); initTetheringOnTestThread();
@ -2656,7 +2657,7 @@ public class TetheringTest {
@Test @Test
public void testFuzzyMatchedWifiCanBeAddedAfterIpServerUnwanted() throws Exception { public void testFuzzyMatchedWifiCanBeAddedAfterIpServerUnwanted() throws Exception {
assumeTrue(isTetheringWithSoftApConfigEnabled()); assumeTrue(mTetheringDependencies.isTetheringWithSoftApConfigEnabled());
when(mWifiManager.startTetheredHotspot(null)).thenReturn(true); when(mWifiManager.startTetheredHotspot(null)).thenReturn(true);
initTetheringOnTestThread(); initTetheringOnTestThread();
@ -2689,7 +2690,7 @@ public class TetheringTest {
@Test @Test
public void testFuzzyMatchedWifiCanBeAddedAfterIpServerError() throws Exception { public void testFuzzyMatchedWifiCanBeAddedAfterIpServerError() throws Exception {
assumeTrue(isTetheringWithSoftApConfigEnabled()); assumeTrue(mTetheringDependencies.isTetheringWithSoftApConfigEnabled());
when(mWifiManager.startTetheredHotspot(null)).thenReturn(true); when(mWifiManager.startTetheredHotspot(null)).thenReturn(true);
initTetheringOnTestThread(); initTetheringOnTestThread();
@ -2717,7 +2718,7 @@ public class TetheringTest {
@Test @Test
public void testFuzzyMatchedWifiCanBeAddedAfterStoppingPendingRequest() throws Exception { public void testFuzzyMatchedWifiCanBeAddedAfterStoppingPendingRequest() throws Exception {
assumeTrue(isTetheringWithSoftApConfigEnabled()); assumeTrue(mTetheringDependencies.isTetheringWithSoftApConfigEnabled());
when(mWifiManager.startTetheredHotspot(null)).thenReturn(true); when(mWifiManager.startTetheredHotspot(null)).thenReturn(true);
initTetheringOnTestThread(); initTetheringOnTestThread();
@ -2749,7 +2750,7 @@ public class TetheringTest {
@Test @Test
public void testFuzzyMatchedWifiCanBeAddedAfterStoppingServingRequest() throws Exception { public void testFuzzyMatchedWifiCanBeAddedAfterStoppingServingRequest() throws Exception {
assumeTrue(isTetheringWithSoftApConfigEnabled()); assumeTrue(mTetheringDependencies.isTetheringWithSoftApConfigEnabled());
when(mWifiManager.startTetheredHotspot(null)).thenReturn(true); when(mWifiManager.startTetheredHotspot(null)).thenReturn(true);
initTetheringOnTestThread(); initTetheringOnTestThread();
@ -2782,7 +2783,7 @@ public class TetheringTest {
@Test @Test
public void testStopTetheringWithMatchingRequest() throws Exception { public void testStopTetheringWithMatchingRequest() throws Exception {
assumeTrue(isTetheringWithSoftApConfigEnabled()); assumeTrue(mTetheringDependencies.isTetheringWithSoftApConfigEnabled());
when(mContext.checkCallingOrSelfPermission(NETWORK_SETTINGS)).thenReturn(PERMISSION_DENIED); when(mContext.checkCallingOrSelfPermission(NETWORK_SETTINGS)).thenReturn(PERMISSION_DENIED);
initTetheringOnTestThread(); initTetheringOnTestThread();
UpstreamNetworkState upstreamState = buildMobileDualStackUpstreamState(); UpstreamNetworkState upstreamState = buildMobileDualStackUpstreamState();
@ -2830,7 +2831,7 @@ public class TetheringTest {
@Test @Test
public void testStopTetheringWithSettingsPermission() throws Exception { public void testStopTetheringWithSettingsPermission() throws Exception {
assumeTrue(isTetheringWithSoftApConfigEnabled()); assumeTrue(mTetheringDependencies.isTetheringWithSoftApConfigEnabled());
initTetheringOnTestThread(); initTetheringOnTestThread();
UpstreamNetworkState upstreamState = buildMobileDualStackUpstreamState(); UpstreamNetworkState upstreamState = buildMobileDualStackUpstreamState();
initTetheringUpstream(upstreamState); initTetheringUpstream(upstreamState);
@ -3126,7 +3127,7 @@ public class TetheringTest {
@Test @Test
public void testMultipleStartTetheringLegacy() throws Exception { public void testMultipleStartTetheringLegacy() throws Exception {
assumeFalse(isTetheringWithSoftApConfigEnabled()); mTetheringWithSoftApConfigEnabled = false;
initTetheringOnTestThread(); initTetheringOnTestThread();
final LinkAddress serverLinkAddr = new LinkAddress("192.168.20.1/24"); final LinkAddress serverLinkAddr = new LinkAddress("192.168.20.1/24");
final LinkAddress clientLinkAddr = new LinkAddress("192.168.20.42/24"); final LinkAddress clientLinkAddr = new LinkAddress("192.168.20.42/24");
@ -3907,7 +3908,7 @@ public class TetheringTest {
@Test @Test
public void testStartBluetoothTetheringFailsWhenTheresAnExistingRequestWaitingForPanService() public void testStartBluetoothTetheringFailsWhenTheresAnExistingRequestWaitingForPanService()
throws Exception { throws Exception {
assumeFalse(isTetheringWithSoftApConfigEnabled()); mTetheringWithSoftApConfigEnabled = false;
initTetheringOnTestThread(); initTetheringOnTestThread();
mockBluetoothSettings(true /* bluetoothOn */, true /* tetheringOn */); mockBluetoothSettings(true /* bluetoothOn */, true /* tetheringOn */);

View file

@ -86,7 +86,6 @@ import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4; import androidx.test.runner.AndroidJUnit4;
import com.android.modules.utils.build.SdkLevel; import com.android.modules.utils.build.SdkLevel;
import com.android.net.flags.Flags;
import com.android.testutils.ParcelUtils; import com.android.testutils.ParcelUtils;
import com.android.testutils.com.android.testutils.CarrierConfigRule; import com.android.testutils.com.android.testutils.CarrierConfigRule;
@ -237,7 +236,7 @@ public class TetheringManagerTest {
@Test @Test
public void testStartTetheringDuplicateRequestRejected() throws Exception { public void testStartTetheringDuplicateRequestRejected() throws Exception {
assumeTrue(isTetheringWithSoftApConfigEnabled()); assumeTrue(SdkLevel.isAtLeastB());
final TestTetheringEventCallback tetherEventCallback = final TestTetheringEventCallback tetherEventCallback =
mCtsTetheringUtils.registerTetheringEventCallback(); mCtsTetheringUtils.registerTetheringEventCallback();
try { try {
@ -405,13 +404,13 @@ public class TetheringManagerTest {
tetherEventCallback.assumeWifiTetheringSupported(mContext); tetherEventCallback.assumeWifiTetheringSupported(mContext);
tetherEventCallback.expectNoTetheringActive(); tetherEventCallback.expectNoTetheringActive();
SoftApConfiguration softApConfig = isTetheringWithSoftApConfigEnabled() SoftApConfiguration softApConfig = SdkLevel.isAtLeastB()
? createSoftApConfiguration("SSID") : null; ? createSoftApConfiguration("SSID") : null;
final TetheringInterface tetheredIface = final TetheringInterface tetheredIface =
mCtsTetheringUtils.startWifiTethering(tetherEventCallback, softApConfig); mCtsTetheringUtils.startWifiTethering(tetherEventCallback, softApConfig);
assertNotNull(tetheredIface); assertNotNull(tetheredIface);
if (isTetheringWithSoftApConfigEnabled()) { if (SdkLevel.isAtLeastB()) {
assertEquals(softApConfig, tetheredIface.getSoftApConfiguration()); assertEquals(softApConfig, tetheredIface.getSoftApConfiguration());
} }
@ -484,7 +483,7 @@ public class TetheringManagerTest {
@Test @Test
public void testStopTetheringRequestNoMatchFailure() throws Exception { public void testStopTetheringRequestNoMatchFailure() throws Exception {
assumeTrue(isTetheringWithSoftApConfigEnabled()); assumeTrue(SdkLevel.isAtLeastB());
final TestTetheringEventCallback tetherEventCallback = final TestTetheringEventCallback tetherEventCallback =
mCtsTetheringUtils.registerTetheringEventCallback(); mCtsTetheringUtils.registerTetheringEventCallback();
try { try {
@ -504,7 +503,7 @@ public class TetheringManagerTest {
@Test @Test
public void testStopTetheringRequestMatchSuccess() throws Exception { public void testStopTetheringRequestMatchSuccess() throws Exception {
assumeTrue(isTetheringWithSoftApConfigEnabled()); assumeTrue(SdkLevel.isAtLeastB());
final TestTetheringEventCallback tetherEventCallback = final TestTetheringEventCallback tetherEventCallback =
mCtsTetheringUtils.registerTetheringEventCallback(); mCtsTetheringUtils.registerTetheringEventCallback();
try { try {
@ -528,7 +527,7 @@ public class TetheringManagerTest {
@Test @Test
public void testStopTetheringRequestFuzzyMatchSuccess() throws Exception { public void testStopTetheringRequestFuzzyMatchSuccess() throws Exception {
assumeTrue(isTetheringWithSoftApConfigEnabled()); assumeTrue(SdkLevel.isAtLeastB());
final TestTetheringEventCallback tetherEventCallback = final TestTetheringEventCallback tetherEventCallback =
mCtsTetheringUtils.registerTetheringEventCallback(); mCtsTetheringUtils.registerTetheringEventCallback();
try { try {
@ -554,10 +553,6 @@ public class TetheringManagerTest {
} }
} }
private boolean isTetheringWithSoftApConfigEnabled() {
return SdkLevel.isAtLeastB() && Flags.tetheringWithSoftApConfig();
}
@Test @Test
public void testStartTetheringNoPermission() throws Exception { public void testStartTetheringNoPermission() throws Exception {
final StartTetheringCallback startTetheringCallback = new StartTetheringCallback(); final StartTetheringCallback startTetheringCallback = new StartTetheringCallback();
@ -568,7 +563,7 @@ public class TetheringManagerTest {
startTetheringCallback.expectTetheringFailed(TETHER_ERROR_NO_CHANGE_TETHERING_PERMISSION); startTetheringCallback.expectTetheringFailed(TETHER_ERROR_NO_CHANGE_TETHERING_PERMISSION);
// WRITE_SETTINGS not sufficient // WRITE_SETTINGS not sufficient
if (isTetheringWithSoftApConfigEnabled()) { if (SdkLevel.isAtLeastB()) {
runAsShell(WRITE_SETTINGS, () -> { runAsShell(WRITE_SETTINGS, () -> {
mTM.startTethering(new TetheringRequest.Builder(TETHERING_WIFI).build(), mTM.startTethering(new TetheringRequest.Builder(TETHERING_WIFI).build(),
c -> c.run() /* executor */, startTetheringCallback); c -> c.run() /* executor */, startTetheringCallback);