Replace isTetheringWithSoftApConfig flag with B SDK check

isTetheringWithSoftApConfig flag is finalized, replace it with a simple
SdkLevel.isAtLeastB() check. This also fixes any issues with reading the
flag during boot.

Bug: 216524590
Test: covered by existing tests
Change-Id: I6c2717a68fa4f3c664c9948ec19b246db5afdb8b
diff --git a/Tethering/src/com/android/networkstack/tethering/Tethering.java b/Tethering/src/com/android/networkstack/tethering/Tethering.java
index 59f05ed..c7ae353 100644
--- a/Tethering/src/com/android/networkstack/tethering/Tethering.java
+++ b/Tethering/src/com/android/networkstack/tethering/Tethering.java
@@ -148,7 +148,6 @@
 import com.android.internal.util.State;
 import com.android.internal.util.StateMachine;
 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.CollectionUtils;
 import com.android.net.module.util.HandlerUtils;
@@ -463,9 +462,8 @@
         return mSettingsObserver;
     }
 
-    // TODO: Replace with SdkLevel.isAtLeastB() once the feature is fully implemented.
     boolean isTetheringWithSoftApConfigEnabled() {
-        return SdkLevel.isAtLeastB() && Flags.tetheringWithSoftApConfig();
+        return mDeps.isTetheringWithSoftApConfigEnabled();
     }
 
     /**
diff --git a/Tethering/src/com/android/networkstack/tethering/TetheringDependencies.java b/Tethering/src/com/android/networkstack/tethering/TetheringDependencies.java
index bd35cf2..00a7f09 100644
--- a/Tethering/src/com/android/networkstack/tethering/TetheringDependencies.java
+++ b/Tethering/src/com/android/networkstack/tethering/TetheringDependencies.java
@@ -37,7 +37,6 @@
 import androidx.annotation.RequiresApi;
 
 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.RoutingCoordinatorService;
 import com.android.net.module.util.SharedLog;
@@ -211,9 +210,9 @@
     }
 
     /**
-     * Wrapper for tethering_with_soft_ap_config feature flag.
+     * Returns true if the tethering with soft ap config feature is enabled.
      */
     public boolean isTetheringWithSoftApConfigEnabled() {
-        return SdkLevel.isAtLeastB() && Flags.tetheringWithSoftApConfig();
+        return SdkLevel.isAtLeastB();
     }
 }
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 103d273..096fee1 100644
--- a/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringTest.java
+++ b/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringTest.java
@@ -96,7 +96,6 @@
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
-import static org.junit.Assume.assumeFalse;
 import static org.junit.Assume.assumeTrue;
 import static org.mockito.ArgumentMatchers.argThat;
 import static org.mockito.ArgumentMatchers.notNull;
@@ -201,7 +200,6 @@
 import com.android.internal.util.test.BroadcastInterceptingContext;
 import com.android.internal.util.test.FakeSettingsProvider;
 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.InterfaceParams;
 import com.android.net.module.util.PrivateAddressCoordinator;
@@ -344,6 +342,7 @@
     private TestConnectivityManager mCm;
     private boolean mForceEthernetServiceUnavailable = false;
     private int mBinderCallingUid = TEST_CALLER_UID;
+    private boolean mTetheringWithSoftApConfigEnabled = SdkLevel.isAtLeastB();
 
     private class TestContext extends BroadcastInterceptingContext {
         TestContext(Context base) {
@@ -584,6 +583,11 @@
         public int getBinderCallingUid() {
             return mBinderCallingUid;
         }
+
+        @Override
+        public boolean isTetheringWithSoftApConfigEnabled() {
+            return mTetheringWithSoftApConfigEnabled;
+        }
     }
 
     private static LinkProperties buildUpstreamLinkProperties(String interfaceName,
@@ -720,6 +724,7 @@
         when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_WIFI)).thenReturn(true);
         when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_WIFI_DIRECT)).thenReturn(true);
         mIpServerDependencies = spy(new MockIpServerDependencies());
+        mTetheringWithSoftApConfigEnabled = SdkLevel.isAtLeastB();
     }
 
     // In order to interact with syncSM from the test, tethering must be created in test thread.
@@ -2437,7 +2442,7 @@
 
     @Test
     public void testSoftApConfigInTetheringEventCallback() throws Exception {
-        assumeTrue(isTetheringWithSoftApConfigEnabled());
+        assumeTrue(mTetheringDependencies.isTetheringWithSoftApConfigEnabled());
         when(mContext.checkCallingOrSelfPermission(NETWORK_SETTINGS))
                 .thenReturn(PERMISSION_DENIED);
         when(mContext.checkCallingOrSelfPermission(NETWORK_STACK))
@@ -2533,13 +2538,9 @@
         callback.assertNoCallback();
     }
 
-    private boolean isTetheringWithSoftApConfigEnabled() {
-        return SdkLevel.isAtLeastB() && Flags.tetheringWithSoftApConfig();
-    }
-
     @Test
     public void testFuzzyMatchedWifiCannotBeAdded() throws Exception {
-        assumeTrue(isTetheringWithSoftApConfigEnabled());
+        assumeTrue(mTetheringDependencies.isTetheringWithSoftApConfigEnabled());
         initTetheringOnTestThread();
         TestTetheringEventCallback callback = new TestTetheringEventCallback();
         SoftApConfiguration softApConfig = new SoftApConfiguration.Builder().setWifiSsid(
@@ -2623,7 +2624,7 @@
 
     @Test
     public void testFuzzyMatchedWifiCanBeAddedAfterIpServerStopped() throws Exception {
-        assumeTrue(isTetheringWithSoftApConfigEnabled());
+        assumeTrue(mTetheringDependencies.isTetheringWithSoftApConfigEnabled());
         when(mWifiManager.startTetheredHotspot(null)).thenReturn(true);
         initTetheringOnTestThread();
 
@@ -2656,7 +2657,7 @@
 
     @Test
     public void testFuzzyMatchedWifiCanBeAddedAfterIpServerUnwanted() throws Exception {
-        assumeTrue(isTetheringWithSoftApConfigEnabled());
+        assumeTrue(mTetheringDependencies.isTetheringWithSoftApConfigEnabled());
         when(mWifiManager.startTetheredHotspot(null)).thenReturn(true);
         initTetheringOnTestThread();
 
@@ -2689,7 +2690,7 @@
 
     @Test
     public void testFuzzyMatchedWifiCanBeAddedAfterIpServerError() throws Exception {
-        assumeTrue(isTetheringWithSoftApConfigEnabled());
+        assumeTrue(mTetheringDependencies.isTetheringWithSoftApConfigEnabled());
         when(mWifiManager.startTetheredHotspot(null)).thenReturn(true);
         initTetheringOnTestThread();
 
@@ -2717,7 +2718,7 @@
 
     @Test
     public void testFuzzyMatchedWifiCanBeAddedAfterStoppingPendingRequest() throws Exception {
-        assumeTrue(isTetheringWithSoftApConfigEnabled());
+        assumeTrue(mTetheringDependencies.isTetheringWithSoftApConfigEnabled());
         when(mWifiManager.startTetheredHotspot(null)).thenReturn(true);
         initTetheringOnTestThread();
 
@@ -2749,7 +2750,7 @@
 
     @Test
     public void testFuzzyMatchedWifiCanBeAddedAfterStoppingServingRequest() throws Exception {
-        assumeTrue(isTetheringWithSoftApConfigEnabled());
+        assumeTrue(mTetheringDependencies.isTetheringWithSoftApConfigEnabled());
         when(mWifiManager.startTetheredHotspot(null)).thenReturn(true);
         initTetheringOnTestThread();
 
@@ -2782,7 +2783,7 @@
 
     @Test
     public void testStopTetheringWithMatchingRequest() throws Exception {
-        assumeTrue(isTetheringWithSoftApConfigEnabled());
+        assumeTrue(mTetheringDependencies.isTetheringWithSoftApConfigEnabled());
         when(mContext.checkCallingOrSelfPermission(NETWORK_SETTINGS)).thenReturn(PERMISSION_DENIED);
         initTetheringOnTestThread();
         UpstreamNetworkState upstreamState = buildMobileDualStackUpstreamState();
@@ -2830,7 +2831,7 @@
 
     @Test
     public void testStopTetheringWithSettingsPermission() throws Exception {
-        assumeTrue(isTetheringWithSoftApConfigEnabled());
+        assumeTrue(mTetheringDependencies.isTetheringWithSoftApConfigEnabled());
         initTetheringOnTestThread();
         UpstreamNetworkState upstreamState = buildMobileDualStackUpstreamState();
         initTetheringUpstream(upstreamState);
@@ -3126,7 +3127,7 @@
 
     @Test
     public void testMultipleStartTetheringLegacy() throws Exception {
-        assumeFalse(isTetheringWithSoftApConfigEnabled());
+        mTetheringWithSoftApConfigEnabled = false;
         initTetheringOnTestThread();
         final LinkAddress serverLinkAddr = new LinkAddress("192.168.20.1/24");
         final LinkAddress clientLinkAddr = new LinkAddress("192.168.20.42/24");
@@ -3907,7 +3908,7 @@
     @Test
     public void testStartBluetoothTetheringFailsWhenTheresAnExistingRequestWaitingForPanService()
             throws Exception {
-        assumeFalse(isTetheringWithSoftApConfigEnabled());
+        mTetheringWithSoftApConfigEnabled = false;
         initTetheringOnTestThread();
 
         mockBluetoothSettings(true /* bluetoothOn */, true /* tetheringOn */);
diff --git a/tests/cts/tethering/src/android/tethering/cts/TetheringManagerTest.java b/tests/cts/tethering/src/android/tethering/cts/TetheringManagerTest.java
index ed6107b..7d6a213 100644
--- a/tests/cts/tethering/src/android/tethering/cts/TetheringManagerTest.java
+++ b/tests/cts/tethering/src/android/tethering/cts/TetheringManagerTest.java
@@ -86,7 +86,6 @@
 import androidx.test.runner.AndroidJUnit4;
 
 import com.android.modules.utils.build.SdkLevel;
-import com.android.net.flags.Flags;
 import com.android.testutils.ParcelUtils;
 import com.android.testutils.com.android.testutils.CarrierConfigRule;
 
@@ -237,7 +236,7 @@
 
     @Test
     public void testStartTetheringDuplicateRequestRejected() throws Exception {
-        assumeTrue(isTetheringWithSoftApConfigEnabled());
+        assumeTrue(SdkLevel.isAtLeastB());
         final TestTetheringEventCallback tetherEventCallback =
                 mCtsTetheringUtils.registerTetheringEventCallback();
         try {
@@ -405,13 +404,13 @@
             tetherEventCallback.assumeWifiTetheringSupported(mContext);
             tetherEventCallback.expectNoTetheringActive();
 
-            SoftApConfiguration softApConfig = isTetheringWithSoftApConfigEnabled()
+            SoftApConfiguration softApConfig = SdkLevel.isAtLeastB()
                     ? createSoftApConfiguration("SSID") : null;
             final TetheringInterface tetheredIface =
                     mCtsTetheringUtils.startWifiTethering(tetherEventCallback, softApConfig);
 
             assertNotNull(tetheredIface);
-            if  (isTetheringWithSoftApConfigEnabled()) {
+            if  (SdkLevel.isAtLeastB()) {
                 assertEquals(softApConfig, tetheredIface.getSoftApConfiguration());
             }
 
@@ -484,7 +483,7 @@
 
     @Test
     public void testStopTetheringRequestNoMatchFailure() throws Exception {
-        assumeTrue(isTetheringWithSoftApConfigEnabled());
+        assumeTrue(SdkLevel.isAtLeastB());
         final TestTetheringEventCallback tetherEventCallback =
                 mCtsTetheringUtils.registerTetheringEventCallback();
         try {
@@ -504,7 +503,7 @@
 
     @Test
     public void testStopTetheringRequestMatchSuccess() throws Exception {
-        assumeTrue(isTetheringWithSoftApConfigEnabled());
+        assumeTrue(SdkLevel.isAtLeastB());
         final TestTetheringEventCallback tetherEventCallback =
                 mCtsTetheringUtils.registerTetheringEventCallback();
         try {
@@ -528,7 +527,7 @@
 
     @Test
     public void testStopTetheringRequestFuzzyMatchSuccess() throws Exception {
-        assumeTrue(isTetheringWithSoftApConfigEnabled());
+        assumeTrue(SdkLevel.isAtLeastB());
         final TestTetheringEventCallback tetherEventCallback =
                 mCtsTetheringUtils.registerTetheringEventCallback();
         try {
@@ -554,10 +553,6 @@
         }
     }
 
-    private boolean isTetheringWithSoftApConfigEnabled() {
-        return SdkLevel.isAtLeastB() && Flags.tetheringWithSoftApConfig();
-    }
-
     @Test
     public void testStartTetheringNoPermission() throws Exception {
         final StartTetheringCallback startTetheringCallback = new StartTetheringCallback();
@@ -568,7 +563,7 @@
         startTetheringCallback.expectTetheringFailed(TETHER_ERROR_NO_CHANGE_TETHERING_PERMISSION);
 
         // WRITE_SETTINGS not sufficient
-        if (isTetheringWithSoftApConfigEnabled()) {
+        if (SdkLevel.isAtLeastB()) {
             runAsShell(WRITE_SETTINGS, () -> {
                 mTM.startTethering(new TetheringRequest.Builder(TETHERING_WIFI).build(),
                         c -> c.run() /* executor */, startTetheringCallback);