diff --git a/Tethering/tests/mts/src/android/tethering/mts/TetheringModuleTest.java b/Tethering/tests/mts/src/android/tethering/mts/TetheringModuleTest.java index 07aab6378f..ef254ff7e3 100644 --- a/Tethering/tests/mts/src/android/tethering/mts/TetheringModuleTest.java +++ b/Tethering/tests/mts/src/android/tethering/mts/TetheringModuleTest.java @@ -22,7 +22,6 @@ import static android.Manifest.permission.READ_DEVICE_CONFIG; import static android.Manifest.permission.TETHER_PRIVILEGED; import static android.Manifest.permission.WRITE_SETTINGS; import static android.net.TetheringManager.TETHERING_WIFI; -import static android.net.cts.util.CtsTetheringUtils.isWifiTetheringSupported; import static android.provider.DeviceConfig.NAMESPACE_CONNECTIVITY; import static com.android.testutils.TestNetworkTrackerKt.initTestNetwork; @@ -102,8 +101,7 @@ public class TetheringModuleTest { TestNetworkTracker tnt = null; try { - tetherEventCallback.assumeTetheringSupported(); - assumeTrue(isWifiTetheringSupported(mContext, tetherEventCallback)); + tetherEventCallback.assumeWifiTetheringSupported(mContext); tetherEventCallback.expectNoTetheringActive(); final TetheringInterface tetheredIface = diff --git a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java index f50687473f..8f471c1b1f 100644 --- a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java +++ b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java @@ -55,16 +55,12 @@ import static android.net.NetworkCapabilities.NET_CAPABILITY_PARTIAL_CONNECTIVIT import static android.net.NetworkCapabilities.NET_CAPABILITY_VALIDATED; import static android.net.NetworkCapabilities.TRANSPORT_TEST; import static android.net.NetworkCapabilities.TRANSPORT_WIFI; -import static android.net.TetheringManager.TETHERING_WIFI; -import static android.net.TetheringManager.TetheringRequest; import static android.net.cts.util.CtsNetUtils.ConnectivityActionReceiver; import static android.net.cts.util.CtsNetUtils.HTTP_PORT; import static android.net.cts.util.CtsNetUtils.NETWORK_CALLBACK_ACTION; import static android.net.cts.util.CtsNetUtils.TEST_HOST; import static android.net.cts.util.CtsNetUtils.TestNetworkCallback; -import static android.net.cts.util.CtsTetheringUtils.StartTetheringCallback; import static android.net.cts.util.CtsTetheringUtils.TestTetheringEventCallback; -import static android.net.cts.util.CtsTetheringUtils.isWifiTetheringSupported; import static android.net.util.NetworkStackUtils.TEST_CAPTIVE_PORTAL_HTTPS_URL; import static android.net.util.NetworkStackUtils.TEST_CAPTIVE_PORTAL_HTTP_URL; import static android.os.MessageQueue.OnFileDescriptorEventListener.EVENT_INPUT; @@ -132,9 +128,9 @@ import android.net.SocketKeepalive; import android.net.TelephonyNetworkSpecifier; import android.net.TestNetworkInterface; import android.net.TestNetworkManager; -import android.net.TetheringManager; import android.net.Uri; import android.net.cts.util.CtsNetUtils; +import android.net.cts.util.CtsTetheringUtils; import android.net.util.KeepaliveUtils; import android.net.wifi.WifiManager; import android.os.Binder; @@ -284,7 +280,6 @@ public class ConnectivityManagerTest { private final ArraySet mNetworkTypes = new ArraySet<>(); private UiAutomation mUiAutomation; private CtsNetUtils mCtsNetUtils; - private TetheringManager mTm; // Used for cleanup purposes. private final List> mVpnRequiredUidRanges = new ArrayList<>(); @@ -300,7 +295,6 @@ public class ConnectivityManagerTest { mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); mPackageManager = mContext.getPackageManager(); mCtsNetUtils = new CtsNetUtils(mContext); - mTm = mContext.getSystemService(TetheringManager.class); if (DevSdkIgnoreRuleKt.isDevSdkInRange(null /* minExclusive */, Build.VERSION_CODES.R /* maxInclusive */)) { @@ -2231,14 +2225,15 @@ public class ConnectivityManagerTest { ConnectivitySettingsManager.getNetworkAvoidBadWifi(mContext); final int curPrivateDnsMode = ConnectivitySettingsManager.getPrivateDnsMode(mContext); - final TestTetheringEventCallback tetherEventCallback = new TestTetheringEventCallback(); + TestTetheringEventCallback tetherEventCallback = null; + final CtsTetheringUtils tetherUtils = new CtsTetheringUtils(mContext); try { - mTm.registerTetheringEventCallback(c -> c.run() /* executor */, tetherEventCallback); + tetherEventCallback = tetherUtils.registerTetheringEventCallback(); // Adopt for NETWORK_SETTINGS permission. mUiAutomation.adoptShellPermissionIdentity(); // start tethering tetherEventCallback.assumeWifiTetheringSupported(mContext); - startWifiTethering(tetherEventCallback); + tetherUtils.startWifiTethering(tetherEventCallback); // Update setting to verify the behavior. mCm.setAirplaneMode(true); ConnectivitySettingsManager.setPrivateDnsMode(mContext, @@ -2259,8 +2254,10 @@ public class ConnectivityManagerTest { mCm.setAirplaneMode(false); ConnectivitySettingsManager.setNetworkAvoidBadWifi(mContext, curAvoidBadWifi); ConnectivitySettingsManager.setPrivateDnsMode(mContext, curPrivateDnsMode); - mTm.unregisterTetheringEventCallback(tetherEventCallback); - mTm.stopAllTethering(); + if (tetherEventCallback != null) { + tetherUtils.unregisterTetheringEventCallback(tetherEventCallback); + } + tetherUtils.stopAllTethering(); mUiAutomation.dropShellPermissionIdentity(); } } @@ -2307,19 +2304,6 @@ public class ConnectivityManagerTest { ConnectivitySettingsManager.getNetworkAvoidBadWifi(mContext)); } - private void startWifiTethering(final TestTetheringEventCallback callback) throws Exception { - if (!isWifiTetheringSupported(mContext, callback)) return; - - final List wifiRegexs = - callback.getTetheringInterfaceRegexps().getTetherableWifiRegexs(); - final StartTetheringCallback startTetheringCallback = new StartTetheringCallback(); - final TetheringRequest request = new TetheringRequest.Builder(TETHERING_WIFI) - .setShouldShowEntitlementUi(false).build(); - mTm.startTethering(request, c -> c.run() /* executor */, startTetheringCallback); - startTetheringCallback.verifyTetheringStarted(); - callback.expectTetheredInterfacesChanged(wifiRegexs, TETHERING_WIFI); - } - /** * Verify that per-app OEM network preference functions as expected for network preference TEST. * For specified apps, validate networks are prioritized in order: unmetered, TEST transport, diff --git a/tests/cts/net/util/java/android/net/cts/util/CtsTetheringUtils.java b/tests/cts/net/util/java/android/net/cts/util/CtsTetheringUtils.java index c220326145..8c5372d5ee 100644 --- a/tests/cts/net/util/java/android/net/cts/util/CtsTetheringUtils.java +++ b/tests/cts/net/util/java/android/net/cts/util/CtsTetheringUtils.java @@ -440,12 +440,6 @@ public final class CtsTetheringUtils { return callback.getTetheringInterfaceRegexps().getTetherableWifiRegexs(); } - public static boolean isWifiTetheringSupported(final Context ctx, - final TestTetheringEventCallback callback) throws Exception { - return !getWifiTetherableInterfaceRegexps(callback).isEmpty() - && isPortableHotspotSupported(ctx); - } - /* Returns if wifi supports hotspot. */ private static boolean isPortableHotspotSupported(final Context ctx) throws Exception { final PackageManager pm = ctx.getPackageManager(); @@ -522,4 +516,8 @@ public final class CtsTetheringUtils { callback.expectNoTetheringActive(); callback.expectOneOfOffloadStatusChanged(TETHER_HARDWARE_OFFLOAD_STOPPED); } + + public void stopAllTethering() { + mTm.stopAllTethering(); + } }