Merge "Fix ConnectivityManagerTest initialization on Q"
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.TETHER_PRIVILEGED;
|
||||||
import static android.Manifest.permission.WRITE_SETTINGS;
|
import static android.Manifest.permission.WRITE_SETTINGS;
|
||||||
import static android.net.TetheringManager.TETHERING_WIFI;
|
import static android.net.TetheringManager.TETHERING_WIFI;
|
||||||
import static android.net.cts.util.CtsTetheringUtils.isWifiTetheringSupported;
|
|
||||||
import static android.provider.DeviceConfig.NAMESPACE_CONNECTIVITY;
|
import static android.provider.DeviceConfig.NAMESPACE_CONNECTIVITY;
|
||||||
|
|
||||||
import static com.android.testutils.TestNetworkTrackerKt.initTestNetwork;
|
import static com.android.testutils.TestNetworkTrackerKt.initTestNetwork;
|
||||||
@@ -102,8 +101,7 @@ public class TetheringModuleTest {
|
|||||||
|
|
||||||
TestNetworkTracker tnt = null;
|
TestNetworkTracker tnt = null;
|
||||||
try {
|
try {
|
||||||
tetherEventCallback.assumeTetheringSupported();
|
tetherEventCallback.assumeWifiTetheringSupported(mContext);
|
||||||
assumeTrue(isWifiTetheringSupported(mContext, tetherEventCallback));
|
|
||||||
tetherEventCallback.expectNoTetheringActive();
|
tetherEventCallback.expectNoTetheringActive();
|
||||||
|
|
||||||
final TetheringInterface tetheredIface =
|
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.NET_CAPABILITY_VALIDATED;
|
||||||
import static android.net.NetworkCapabilities.TRANSPORT_TEST;
|
import static android.net.NetworkCapabilities.TRANSPORT_TEST;
|
||||||
import static android.net.NetworkCapabilities.TRANSPORT_WIFI;
|
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.ConnectivityActionReceiver;
|
||||||
import static android.net.cts.util.CtsNetUtils.HTTP_PORT;
|
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.NETWORK_CALLBACK_ACTION;
|
||||||
import static android.net.cts.util.CtsNetUtils.TEST_HOST;
|
import static android.net.cts.util.CtsNetUtils.TEST_HOST;
|
||||||
import static android.net.cts.util.CtsNetUtils.TestNetworkCallback;
|
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.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_HTTPS_URL;
|
||||||
import static android.net.util.NetworkStackUtils.TEST_CAPTIVE_PORTAL_HTTP_URL;
|
import static android.net.util.NetworkStackUtils.TEST_CAPTIVE_PORTAL_HTTP_URL;
|
||||||
import static android.os.MessageQueue.OnFileDescriptorEventListener.EVENT_INPUT;
|
import static android.os.MessageQueue.OnFileDescriptorEventListener.EVENT_INPUT;
|
||||||
@@ -132,9 +128,9 @@ import android.net.SocketKeepalive;
|
|||||||
import android.net.TelephonyNetworkSpecifier;
|
import android.net.TelephonyNetworkSpecifier;
|
||||||
import android.net.TestNetworkInterface;
|
import android.net.TestNetworkInterface;
|
||||||
import android.net.TestNetworkManager;
|
import android.net.TestNetworkManager;
|
||||||
import android.net.TetheringManager;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.net.cts.util.CtsNetUtils;
|
import android.net.cts.util.CtsNetUtils;
|
||||||
|
import android.net.cts.util.CtsTetheringUtils;
|
||||||
import android.net.util.KeepaliveUtils;
|
import android.net.util.KeepaliveUtils;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
@@ -284,7 +280,6 @@ public class ConnectivityManagerTest {
|
|||||||
private final ArraySet<Integer> mNetworkTypes = new ArraySet<>();
|
private final ArraySet<Integer> mNetworkTypes = new ArraySet<>();
|
||||||
private UiAutomation mUiAutomation;
|
private UiAutomation mUiAutomation;
|
||||||
private CtsNetUtils mCtsNetUtils;
|
private CtsNetUtils mCtsNetUtils;
|
||||||
private TetheringManager mTm;
|
|
||||||
|
|
||||||
// Used for cleanup purposes.
|
// Used for cleanup purposes.
|
||||||
private final List<Range<Integer>> mVpnRequiredUidRanges = new ArrayList<>();
|
private final List<Range<Integer>> mVpnRequiredUidRanges = new ArrayList<>();
|
||||||
@@ -300,7 +295,6 @@ public class ConnectivityManagerTest {
|
|||||||
mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
|
mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
|
||||||
mPackageManager = mContext.getPackageManager();
|
mPackageManager = mContext.getPackageManager();
|
||||||
mCtsNetUtils = new CtsNetUtils(mContext);
|
mCtsNetUtils = new CtsNetUtils(mContext);
|
||||||
mTm = mContext.getSystemService(TetheringManager.class);
|
|
||||||
|
|
||||||
if (DevSdkIgnoreRuleKt.isDevSdkInRange(null /* minExclusive */,
|
if (DevSdkIgnoreRuleKt.isDevSdkInRange(null /* minExclusive */,
|
||||||
Build.VERSION_CODES.R /* maxInclusive */)) {
|
Build.VERSION_CODES.R /* maxInclusive */)) {
|
||||||
@@ -2231,14 +2225,15 @@ public class ConnectivityManagerTest {
|
|||||||
ConnectivitySettingsManager.getNetworkAvoidBadWifi(mContext);
|
ConnectivitySettingsManager.getNetworkAvoidBadWifi(mContext);
|
||||||
final int curPrivateDnsMode = ConnectivitySettingsManager.getPrivateDnsMode(mContext);
|
final int curPrivateDnsMode = ConnectivitySettingsManager.getPrivateDnsMode(mContext);
|
||||||
|
|
||||||
final TestTetheringEventCallback tetherEventCallback = new TestTetheringEventCallback();
|
TestTetheringEventCallback tetherEventCallback = null;
|
||||||
|
final CtsTetheringUtils tetherUtils = new CtsTetheringUtils(mContext);
|
||||||
try {
|
try {
|
||||||
mTm.registerTetheringEventCallback(c -> c.run() /* executor */, tetherEventCallback);
|
tetherEventCallback = tetherUtils.registerTetheringEventCallback();
|
||||||
// Adopt for NETWORK_SETTINGS permission.
|
// Adopt for NETWORK_SETTINGS permission.
|
||||||
mUiAutomation.adoptShellPermissionIdentity();
|
mUiAutomation.adoptShellPermissionIdentity();
|
||||||
// start tethering
|
// start tethering
|
||||||
tetherEventCallback.assumeWifiTetheringSupported(mContext);
|
tetherEventCallback.assumeWifiTetheringSupported(mContext);
|
||||||
startWifiTethering(tetherEventCallback);
|
tetherUtils.startWifiTethering(tetherEventCallback);
|
||||||
// Update setting to verify the behavior.
|
// Update setting to verify the behavior.
|
||||||
mCm.setAirplaneMode(true);
|
mCm.setAirplaneMode(true);
|
||||||
ConnectivitySettingsManager.setPrivateDnsMode(mContext,
|
ConnectivitySettingsManager.setPrivateDnsMode(mContext,
|
||||||
@@ -2259,8 +2254,10 @@ public class ConnectivityManagerTest {
|
|||||||
mCm.setAirplaneMode(false);
|
mCm.setAirplaneMode(false);
|
||||||
ConnectivitySettingsManager.setNetworkAvoidBadWifi(mContext, curAvoidBadWifi);
|
ConnectivitySettingsManager.setNetworkAvoidBadWifi(mContext, curAvoidBadWifi);
|
||||||
ConnectivitySettingsManager.setPrivateDnsMode(mContext, curPrivateDnsMode);
|
ConnectivitySettingsManager.setPrivateDnsMode(mContext, curPrivateDnsMode);
|
||||||
mTm.unregisterTetheringEventCallback(tetherEventCallback);
|
if (tetherEventCallback != null) {
|
||||||
mTm.stopAllTethering();
|
tetherUtils.unregisterTetheringEventCallback(tetherEventCallback);
|
||||||
|
}
|
||||||
|
tetherUtils.stopAllTethering();
|
||||||
mUiAutomation.dropShellPermissionIdentity();
|
mUiAutomation.dropShellPermissionIdentity();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2307,19 +2304,6 @@ public class ConnectivityManagerTest {
|
|||||||
ConnectivitySettingsManager.getNetworkAvoidBadWifi(mContext));
|
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.
|
* 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,
|
* For specified apps, validate networks are prioritized in order: unmetered, TEST transport,
|
||||||
|
|||||||
@@ -440,12 +440,6 @@ public final class CtsTetheringUtils {
|
|||||||
return callback.getTetheringInterfaceRegexps().getTetherableWifiRegexs();
|
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. */
|
/* Returns if wifi supports hotspot. */
|
||||||
private static boolean isPortableHotspotSupported(final Context ctx) throws Exception {
|
private static boolean isPortableHotspotSupported(final Context ctx) throws Exception {
|
||||||
final PackageManager pm = ctx.getPackageManager();
|
final PackageManager pm = ctx.getPackageManager();
|
||||||
@@ -522,4 +516,8 @@ public final class CtsTetheringUtils {
|
|||||||
callback.expectNoTetheringActive();
|
callback.expectNoTetheringActive();
|
||||||
callback.expectOneOfOffloadStatusChanged(TETHER_HARDWARE_OFFLOAD_STOPPED);
|
callback.expectOneOfOffloadStatusChanged(TETHER_HARDWARE_OFFLOAD_STOPPED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void stopAllTethering() {
|
||||||
|
mTm.stopAllTethering();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user