Add a local dynamic config for ConnectivityManagerTest to decouple the test config from test logic.
Test: local runs, abtd Bug: 317166695 Change-Id: I105650c4c9cb93e7da8cbe9aa68baa04d750a691
This commit is contained in:
parent
b26b437dea
commit
f4c16355dc
3 changed files with 55 additions and 3 deletions
|
|
@ -24,6 +24,11 @@
|
|||
<option name="config-descriptor:metadata" key="mainline-param" value="CaptivePortalLoginGoogle.apk+NetworkStackGoogle.apk" />
|
||||
<option name="config-descriptor:metadata" key="mainline-param" value="com.google.android.tethering.apex" />
|
||||
<option name="not-shardable" value="true" />
|
||||
<target_preparer class="com.android.compatibility.common.tradefed.targetprep.DynamicConfigPusher">
|
||||
<option name="target" value="device" />
|
||||
<option name="config-filename" value="{MODULE}" />
|
||||
<option name="version" value="1.0" />
|
||||
</target_preparer>
|
||||
<target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
|
||||
<option name="cleanup-apks" value="true" />
|
||||
<option name="test-file-name" value="{MODULE}.apk" />
|
||||
|
|
@ -38,6 +43,7 @@
|
|||
<option name="runtime-hint" value="9m4s" />
|
||||
<option name="hidden-api-checks" value="false" />
|
||||
<option name="isolated-storage" value="false" />
|
||||
<option name="instrumentation-arg" key="test-module-name" value="{MODULE}" />
|
||||
<!-- Test filter that allows test APKs to select which tests they want to run by annotating
|
||||
those tests with an annotation matching the name of the APK.
|
||||
|
||||
|
|
|
|||
24
tests/cts/net/DynamicConfig.xml
Normal file
24
tests/cts/net/DynamicConfig.xml
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<!--
|
||||
~ Copyright (C) 2024 The Android Open Source Project
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<dynamicConfig>
|
||||
<entry key="remote_config_required">
|
||||
<value>false</value>
|
||||
</entry>
|
||||
<entry key="IP_ADDRESS_ECHO_URL">
|
||||
<value>https://google-ipv6test.appspot.com/ip.js?fmt=text</value>
|
||||
</entry>
|
||||
</dynamicConfig>
|
||||
|
|
@ -174,6 +174,7 @@ import android.net.wifi.WifiInfo;
|
|||
import android.net.wifi.WifiManager;
|
||||
import android.os.Binder;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.MessageQueue;
|
||||
|
|
@ -192,10 +193,11 @@ import android.util.ArraySet;
|
|||
import android.util.Log;
|
||||
import android.util.Range;
|
||||
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.filters.RequiresDevice;
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.android.compatibility.common.util.DynamicConfigDeviceSide;
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
import com.android.modules.utils.build.SdkLevel;
|
||||
import com.android.net.module.util.CollectionUtils;
|
||||
|
|
@ -249,6 +251,7 @@ import java.net.URL;
|
|||
import java.net.UnknownHostException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
|
@ -335,6 +338,11 @@ public class ConnectivityManagerTest {
|
|||
private static final String TEST_HTTPS_URL_PATH = "/https_path";
|
||||
private static final String TEST_HTTP_URL_PATH = "/http_path";
|
||||
private static final String LOCALHOST_HOSTNAME = "localhost";
|
||||
private static final String TEST_MODULE_NAME_OPTION = "test-module-name";
|
||||
private static final String IP_ADDRESS_ECHO_URL_KEY = "IP_ADDRESS_ECHO_URL";
|
||||
private static final List<String> ALLOWED_IP_ADDRESS_ECHO_URLS = Arrays.asList(
|
||||
"https://google-ipv6test.appspot.com/ip.js?fmt=text",
|
||||
"https://ipv6test.googleapis-cn.com/ip.js?fmt=text");
|
||||
// Re-connecting to the AP, obtaining an IP address, revalidating can take a long time
|
||||
private static final long WIFI_CONNECT_TIMEOUT_MS = 60_000L;
|
||||
|
||||
|
|
@ -855,7 +863,7 @@ public class ConnectivityManagerTest {
|
|||
* Tests that connections can be opened on WiFi and cellphone networks,
|
||||
* and that they are made from different IP addresses.
|
||||
*/
|
||||
@AppModeFull(reason = "Cannot get WifiManager in instant app mode")
|
||||
@AppModeFull(reason = "Cannot get WifiManager or access the SD card in instant app mode")
|
||||
@Test
|
||||
@RequiresDevice // Virtual devices use a single internet connection for all networks
|
||||
public void testOpenConnection() throws Exception {
|
||||
|
|
@ -865,7 +873,8 @@ public class ConnectivityManagerTest {
|
|||
Network wifiNetwork = mCtsNetUtils.ensureWifiConnected();
|
||||
Network cellNetwork = networkCallbackRule.requestCell();
|
||||
// This server returns the requestor's IP address as the response body.
|
||||
URL url = new URL("http://google-ipv6test.appspot.com/ip.js?fmt=text");
|
||||
String ipAddressEchoUrl = getIpAddressEchoUrlFromConfig();
|
||||
URL url = new URL(ipAddressEchoUrl);
|
||||
String wifiAddressString = httpGet(wifiNetwork, url);
|
||||
String cellAddressString = httpGet(cellNetwork, url);
|
||||
|
||||
|
|
@ -881,6 +890,19 @@ public class ConnectivityManagerTest {
|
|||
assertFalse("Unexpectedly equal: " + wifiNetwork, wifiNetwork.equals(cellNetwork));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets IP address echo url from dynamic config.
|
||||
*/
|
||||
private static String getIpAddressEchoUrlFromConfig() throws Exception {
|
||||
Bundle instrumentationArgs = InstrumentationRegistry.getArguments();
|
||||
String testModuleName = instrumentationArgs.getString(TEST_MODULE_NAME_OPTION);
|
||||
// Get the DynamicConfig.xml contents and extract the ipv6 test URL.
|
||||
DynamicConfigDeviceSide dynamicConfig = new DynamicConfigDeviceSide(testModuleName);
|
||||
String ipAddressEchoUrl = dynamicConfig.getValue(IP_ADDRESS_ECHO_URL_KEY);
|
||||
assertContains(ALLOWED_IP_ADDRESS_ECHO_URLS, ipAddressEchoUrl);
|
||||
return ipAddressEchoUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a HTTP GET to the specified URL on the specified Network, and returns
|
||||
* the response body decoded as UTF-8.
|
||||
|
|
|
|||
Loading…
Reference in a new issue