Merge "Fix ConnectivityManagerTest initialization on Q" am: 72f59b3019
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1740779 Change-Id: Iea8a7bbe63a16efc10733dd94cccc77560a7a058
This commit is contained in:
@@ -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 =
|
||||
|
||||
@@ -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<Integer> mNetworkTypes = new ArraySet<>();
|
||||
private UiAutomation mUiAutomation;
|
||||
private CtsNetUtils mCtsNetUtils;
|
||||
private TetheringManager mTm;
|
||||
|
||||
// Used for cleanup purposes.
|
||||
private final List<Range<Integer>> 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<String> 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,
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user