Commit 7307c009 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 7799923 from f90e9055 to mainline-os-statsd-release

Change-Id: I9ffd22483e774ce1729155e2065e9b3552dc8a7f
parents 3b3123ab f90e9055
......@@ -40,8 +40,7 @@
// We must specify at least one module here or the tests won't run. Use the same set as CTS
// so in theory the infra would not need to reinstall/reboot devices to run both.
{
// TODO: add back tethering when it is updatable in this branch
"name": "NetworkStackTests[CaptivePortalLoginGoogle.apk+NetworkStackGoogle.apk+com.google.android.resolv.apex]"
"name": "NetworkStackTests[CaptivePortalLoginGoogle.apk+NetworkStackGoogle.apk+com.google.android.resolv.apex+com.google.android.tethering.apex]"
}
],
"mainline-postsubmit": [
......
......@@ -83,10 +83,6 @@ public class NetworkMonitorUtils {
return true;
}
// TODO: once TRANSPORT_TEST is @SystemApi in S and S SDK is stable (so constant shims can
// be replaced with the SDK constant that will be inlined), replace isTestNetwork with
// hasTransport(TRANSPORT_TEST)
// Test networks that also have one of the major transport types are attempting to replicate
// that transport on a test interface (for example, test ethernet networks with
// EthernetManager#setIncludeTestInterfaces). Run validation on them for realistic tests.
......
......@@ -121,7 +121,7 @@ aidl_interface {
enabled: false,
},
},
imports: ["ipmemorystore-aidl-interfaces"],
imports: ["ipmemorystore-aidl-interfaces-V10"],
versions: [
"1",
"2",
......
......@@ -19,7 +19,7 @@
<string name="notification_channel_name_connected" msgid="1795068343200033922">"Godkendelse til loginportal"</string>
<string name="notification_channel_description_connected" msgid="7239184168268014518">"De notifikationer, der vises, når enheden er blevet godkendt til et netværk via en loginportal"</string>
<string name="notification_channel_name_network_venue_info" msgid="6526543187249265733">"Oplysninger om netværksplacering"</string>
<string name="notification_channel_description_network_venue_info" msgid="5131499595382733605">"Notifikationer, der vises for at indikere, at netværket har en side med oplysninger om placeringen"</string>
<string name="notification_channel_description_network_venue_info" msgid="5131499595382733605">"Notifikationer, der vises for at indikere, at netværket har en side med oplysninger om lokationen"</string>
<string name="connected" msgid="4563643884927480998">"Der er oprettet forbindelse"</string>
<string name="tap_for_info" msgid="6849746325626883711">"Der er oprettet forbindelse/tryk for at se website"</string>
<string name="application_label" msgid="1322847171305285454">"Netværksadministrator"</string>
......
......@@ -715,7 +715,7 @@ public class IpClient extends StateMachine {
(ifaceUp) -> sendMessage(EVENT_NETLINK_LINKPROPERTIES_CHANGED, ifaceUp
? ARG_LINKPROP_CHANGED_LINKSTATE_UP
: ARG_LINKPROP_CHANGED_LINKSTATE_DOWN),
config, mLog) {
config, mLog, mDependencies) {
@Override
public void onInterfaceAdded(String iface) {
super.onInterfaceAdded(iface);
......@@ -906,6 +906,7 @@ public class IpClient extends StateMachine {
private void stopStateMachineUpdaters() {
mObserverRegistry.unregisterObserver(mLinkObserver);
mLinkObserver.clearInterfaceParams();
mLinkObserver.shutdown();
}
......@@ -1969,7 +1970,6 @@ public class IpClient extends StateMachine {
mHasDisabledIpv6OrAcceptRaOnProvLoss = false;
mGratuitousNaTargetAddresses.clear();
mLinkObserver.clearInterfaceParams();
resetLinkProperties();
if (mStartTimeMillis > 0) {
// Completed a life-cycle; send a final empty LinkProperties
......
......@@ -16,6 +16,7 @@
package android.net.ip;
import static android.net.util.NetworkStackUtils.IPCLIENT_PARSE_NETLINK_EVENTS_VERSION;
import static android.system.OsConstants.AF_INET6;
import static com.android.net.module.util.NetworkStackConstants.ICMPV6_ROUTER_ADVERTISEMENT;
......@@ -37,6 +38,7 @@ import com.android.net.module.util.netlink.NduseroptMessage;
import com.android.net.module.util.netlink.NetlinkConstants;
import com.android.net.module.util.netlink.NetlinkMessage;
import com.android.net.module.util.netlink.StructNdOptPref64;
import com.android.net.module.util.netlink.StructNdOptRdnss;
import com.android.networkstack.apishim.NetworkInformationShimImpl;
import com.android.networkstack.apishim.common.NetworkInformationShim;
import com.android.server.NetworkObserver;
......@@ -107,6 +109,7 @@ public class IpClientLinkObserver implements NetworkObserver {
}
}
private final Context mContext;
private final String mInterfaceName;
private final Callback mCallback;
private final LinkProperties mLinkProperties;
......@@ -115,13 +118,15 @@ public class IpClientLinkObserver implements NetworkObserver {
private final AlarmManager mAlarmManager;
private final Configuration mConfig;
private final Handler mHandler;
private final IpClient.Dependencies mDependencies;
private final MyNetlinkMonitor mNetlinkMonitor;
private static final boolean DBG = false;
public IpClientLinkObserver(Context context, Handler h, String iface, Callback callback,
Configuration config, SharedLog log) {
Configuration config, SharedLog log, IpClient.Dependencies deps) {
mContext = context;
mInterfaceName = iface;
mTag = "NetlinkTracker/" + mInterfaceName;
mCallback = callback;
......@@ -134,6 +139,7 @@ public class IpClientLinkObserver implements NetworkObserver {
mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
mNetlinkMonitor = new MyNetlinkMonitor(h, log, mTag);
mHandler.post(mNetlinkMonitor::start);
mDependencies = deps;
}
public void shutdown() {
......@@ -153,6 +159,11 @@ public class IpClientLinkObserver implements NetworkObserver {
}
}
private boolean isNetlinkEventParsingEnabled() {
return mDependencies.isFeatureEnabled(mContext, IPCLIENT_PARSE_NETLINK_EVENTS_VERSION,
false /* default value */);
}
@Override
public void onInterfaceRemoved(String iface) {
maybeLog("interfaceRemoved", iface);
......@@ -246,17 +257,21 @@ public class IpClientLinkObserver implements NetworkObserver {
@Override
public void onInterfaceDnsServerInfo(String iface, long lifetime, String[] addresses) {
if (mInterfaceName.equals(iface)) {
maybeLog("interfaceDnsServerInfo", Arrays.toString(addresses));
final boolean changed = mDnsServerRepository.addServers(lifetime, addresses);
final boolean linkState;
if (changed) {
synchronized (this) {
mDnsServerRepository.setDnsServersOn(mLinkProperties);
linkState = getInterfaceLinkStateLocked();
}
mCallback.update(linkState);
if (isNetlinkEventParsingEnabled()) return;
if (!mInterfaceName.equals(iface)) return;
maybeLog("interfaceDnsServerInfo", Arrays.toString(addresses));
updateInterfaceDnsServerInfo(lifetime, addresses);
}
private void updateInterfaceDnsServerInfo(long lifetime, final String[] addresses) {
final boolean changed = mDnsServerRepository.addServers(lifetime, addresses);
final boolean linkState;
if (changed) {
synchronized (this) {
mDnsServerRepository.setDnsServersOn(mLinkProperties);
linkState = getInterfaceLinkStateLocked();
}
mCallback.update(linkState);
}
}
......@@ -408,6 +423,15 @@ public class IpClientLinkObserver implements NetworkObserver {
updatePref64(opt.prefix, now, expiry);
}
private void processRdnssOption(StructNdOptRdnss opt) {
if (!isNetlinkEventParsingEnabled()) return;
final String[] addresses = new String[opt.servers.length];
for (int i = 0; i < opt.servers.length; i++) {
addresses[i] = opt.servers[i].getHostAddress();
}
updateInterfaceDnsServerInfo(opt.header.lifetime, addresses);
}
private void processNduseroptMessage(NduseroptMessage msg, final long whenMs) {
if (msg.family != AF_INET6 || msg.option == null || msg.ifindex != mIfindex) return;
if (msg.icmp_type != (byte) ICMPV6_ROUTER_ADVERTISEMENT) return;
......@@ -417,8 +441,12 @@ public class IpClientLinkObserver implements NetworkObserver {
processPref64Option((StructNdOptPref64) msg.option, whenMs);
break;
case StructNdOptRdnss.TYPE:
processRdnssOption((StructNdOptRdnss) msg.option);
break;
default:
// TODO: implement RDNSS and DNSSL.
// TODO: implement DNSSL.
break;
}
}
......
......@@ -249,6 +249,13 @@ public class NetworkStackUtils {
public static final String IPCLIENT_GARP_NA_ROAMING_VERSION =
"ipclient_garp_na_roaming_version";
/**
* Experiment flag to enable parsing netlink events from kernel directly instead from netd aidl
* interface.
*/
public static final String IPCLIENT_PARSE_NETLINK_EVENTS_VERSION =
"ipclient_parse_netlink_events_version";
/**
* Experiment flag to disable accept_ra parameter when IPv6 provisioning loss happens due to
* the default route has gone.
......
......@@ -146,7 +146,6 @@ import android.system.Os;
import androidx.annotation.NonNull;
import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
import com.android.internal.util.HexDump;
import com.android.internal.util.StateMachine;
......@@ -181,6 +180,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.Mock;
......@@ -224,7 +224,7 @@ import kotlin.LazyKt;
*
* Tests in this class can either be run with signature permissions, or with root access.
*/
@RunWith(AndroidJUnit4.class)
@RunWith(Parameterized.class)
@SmallTest
public abstract class IpClientIntegrationTestCommon {
private static final int DATA_BUFFER_LEN = 4096;
......@@ -247,6 +247,17 @@ public abstract class IpClientIntegrationTestCommon {
@Rule
public final TestName mTestNameRule = new TestName();
// Indicate whether the flag of parsing netlink event is enabled or not. If it's disabled,
// integration test still covers the old codepath(i.e. using NetworkObserver), otherwise,
// test goes through the new codepath(i.e. processRtNetlinkxxx).
@Parameterized.Parameter(0)
public boolean mIsNetlinkEventParseEnabled;
@Parameterized.Parameters
public static Iterable<? extends Object> data() {
return Arrays.asList(Boolean.valueOf("false"), Boolean.valueOf("true"));
}
/**
* Indicates that a test requires signature permissions to run.
*
......@@ -553,8 +564,14 @@ public abstract class IpClientIntegrationTestCommon {
@Before
public void setUp() throws Exception {
final Method testMethod = IpClientIntegrationTestCommon.class.getMethod(
mTestNameRule.getMethodName());
// Suffix "[0]" or "[1]" is added to the end of test method name after running with
// Parameterized.class, that's intended behavior, to iterate each test method with the
// parameterize value. However, Class#getMethod() throws NoSuchMethodException when
// searching the target test method name due to this change. Just keep the original test
// method name to fix NoSuchMethodException, and find the correct annotation associated
// to test method.
final String testMethodName = mTestNameRule.getMethodName().split("\\[")[0];
final Method testMethod = IpClientIntegrationTestCommon.class.getMethod(testMethodName);
mIsSignatureRequiredTest = testMethod.getAnnotation(SignatureRequiredTest.class) != null;
assumeFalse(testSkipped());
......@@ -567,6 +584,12 @@ public abstract class IpClientIntegrationTestCommon {
}
mIIpClient = makeIIpClient(mIfaceName, mCb);
// Depend on the parameterized value to enable/disable netlink message refactor flag.
// Make sure both of the old codepath(rely on the INetdUnsolicitedEventListener aidl)
// and new codepath(parse netlink event from kernel) will be executed.
setFeatureEnabled(NetworkStackUtils.IPCLIENT_PARSE_NETLINK_EVENTS_VERSION,
mIsNetlinkEventParseEnabled /* default value */);
}
protected void setUpMocks() throws Exception {
......
......@@ -56,10 +56,7 @@ android_test {
min_sdk_version: "29",
srcs: [], // TODO: tests that only apply to the current, non-stable API can be added here
test_suites: ["general-tests"],
test_mainline_modules: [
"CaptivePortalLoginGoogle.apk+NetworkStackGoogle.apk+com.google.android.resolv.apex",
"CaptivePortalLoginGoogle.apk+NetworkStackGoogle.apk+com.google.android.resolv.apex+com.google.android.tethering.apex"
],
test_mainline_modules: ["CaptivePortalLoginGoogle.apk+NetworkStackGoogle.apk+com.google.android.resolv.apex+com.google.android.tethering.apex"],
defaults: ["NetworkStackTestsDefaults"],
static_libs: ["NetworkStackApiCurrentLib"],
compile_multilib: "both", // Workaround for b/147785146 for mainline-presubmit
......@@ -86,10 +83,7 @@ android_test {
min_sdk_version: "29",
target_sdk_version: "30",
test_suites: ["general-tests", "mts"],
test_mainline_modules: [
"CaptivePortalLoginGoogle.apk+NetworkStackGoogle.apk+com.google.android.resolv.apex",
"CaptivePortalLoginGoogle.apk+NetworkStackGoogle.apk+com.google.android.resolv.apex+com.google.android.tethering.apex"
],
test_mainline_modules: ["CaptivePortalLoginGoogle.apk+NetworkStackGoogle.apk+com.google.android.resolv.apex+com.google.android.tethering.apex"],
defaults: ["NetworkStackTestsDefaults"],
static_libs: ["NetworkStackApiStableLib"],
compile_multilib: "both",
......
......@@ -16,6 +16,7 @@
package com.android.server.connectivity;
import static android.content.Intent.ACTION_CONFIGURATION_CHANGED;
import static android.net.CaptivePortal.APP_RETURN_DISMISSED;
import static android.net.CaptivePortal.APP_RETURN_WANTED_AS_IS;
import static android.net.DnsResolver.TYPE_A;
......@@ -637,6 +638,7 @@ public class NetworkMonitorTest {
@Override
protected void onQuitting() {
super.onQuitting();
assertTrue(mCreatedNetworkMonitors.remove(this));
mQuitCv.open();
}
......@@ -863,7 +865,6 @@ public class NetworkMonitorTest {
@Test
public void testGetHttpProbeUrl() {
final WrappedNetworkMonitor wnm = makeCellNotMeteredNetworkMonitor();
// If config_captive_portal_http_url is set and the global setting is set, the config is
// used.
doReturn(TEST_HTTP_URL).when(mResources).getString(R.string.config_captive_portal_http_url);
......@@ -871,16 +872,21 @@ public class NetworkMonitorTest {
R.string.default_captive_portal_http_url);
when(mDependencies.getSetting(any(), eq(Settings.Global.CAPTIVE_PORTAL_HTTP_URL), any()))
.thenReturn(TEST_HTTP_OTHER_URL1);
assertEquals(TEST_HTTP_URL, wnm.getCaptivePortalServerHttpUrl());
final WrappedNetworkMonitor wnm = makeCellNotMeteredNetworkMonitor();
assertEquals(TEST_HTTP_URL, wnm.getCaptivePortalServerHttpUrl(mContext));
// If config_captive_portal_http_url is unset and the global setting is set, the global
// setting is used.
doReturn(null).when(mResources).getString(R.string.config_captive_portal_http_url);
assertEquals(TEST_HTTP_OTHER_URL1, wnm.getCaptivePortalServerHttpUrl());
assertEquals(TEST_HTTP_OTHER_URL1, wnm.getCaptivePortalServerHttpUrl(mContext));
// If both config_captive_portal_http_url and global setting are unset,
// default_captive_portal_http_url is used.
// default_captive_portal_http_url is used. But the global setting will only be read in the
// constructor.
when(mDependencies.getSetting(any(), eq(Settings.Global.CAPTIVE_PORTAL_HTTP_URL), any()))
.thenReturn(null);
assertEquals(TEST_HTTP_OTHER_URL2, wnm.getCaptivePortalServerHttpUrl());
assertEquals(TEST_HTTP_OTHER_URL1, wnm.getCaptivePortalServerHttpUrl(mContext));
// default_captive_portal_http_url is used when the configuration is applied in new NM.
final WrappedNetworkMonitor wnm2 = makeCellNotMeteredNetworkMonitor();
assertEquals(TEST_HTTP_OTHER_URL2, wnm2.getCaptivePortalServerHttpUrl(mContext));
}
@Test
......@@ -937,6 +943,57 @@ public class NetworkMonitorTest {
}
}
@Test
public void testConfigurationChange_BeforeNMConnected() throws Exception {
final WrappedNetworkMonitor nm = new WrappedNetworkMonitor();
final ArgumentCaptor<BroadcastReceiver> receiverCaptor =
ArgumentCaptor.forClass(BroadcastReceiver.class);
// Verify configuration change receiver is registered after start().
verify(mContext, never()).registerReceiver(receiverCaptor.capture(),
argThat(receiver -> ACTION_CONFIGURATION_CHANGED.equals(receiver.getAction(0))));
nm.start();
mCreatedNetworkMonitors.add(nm);
HandlerUtils.waitForIdle(nm.getHandler(), HANDLER_TIMEOUT_MS);
verify(mContext, times(1)).registerReceiver(receiverCaptor.capture(),
argThat(receiver -> ACTION_CONFIGURATION_CHANGED.equals(receiver.getAction(0))));
// Update a new URL and send a configuration change
doReturn(TEST_HTTPS_OTHER_URL1).when(mResources).getString(
R.string.config_captive_portal_https_url);
receiverCaptor.getValue().onReceive(mContext, new Intent(ACTION_CONFIGURATION_CHANGED));
HandlerUtils.waitForIdle(nm.getHandler(), HANDLER_TIMEOUT_MS);
// Should stay in default state before receiving CMD_NETWORK_CONNECTED
verify(mOtherHttpsConnection1, never()).getResponseCode();
}
@Test
public void testIsCaptivePortal_ConfigurationChange_RenewUrls() throws Exception {
setStatus(mHttpsConnection, 204);
final NetworkMonitor nm = runValidatedNetworkTest();
final ArgumentCaptor<BroadcastReceiver> receiverCaptor =
ArgumentCaptor.forClass(BroadcastReceiver.class);
verify(mContext, times(1)).registerReceiver(receiverCaptor.capture(),
argThat(receiver -> ACTION_CONFIGURATION_CHANGED.equals(receiver.getAction(0))));
resetCallbacks();
// New URLs with partial connectivity
doReturn(TEST_HTTPS_OTHER_URL1).when(mResources).getString(
R.string.config_captive_portal_https_url);
doReturn(TEST_HTTP_OTHER_URL1).when(mResources).getString(
R.string.config_captive_portal_http_url);
setStatus(mOtherHttpsConnection1, 500);
setStatus(mOtherHttpConnection1, 204);
// Receive configuration. Expect a reevaluation triggered.
receiverCaptor.getValue().onReceive(mContext, new Intent(ACTION_CONFIGURATION_CHANGED));
HandlerUtils.waitForIdle(nm.getHandler(), HANDLER_TIMEOUT_MS);
verifyNetworkTested(NETWORK_VALIDATION_RESULT_PARTIAL,
NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_HTTP);
verify(mOtherHttpsConnection1, times(1)).getResponseCode();
verify(mOtherHttpConnection1, times(1)).getResponseCode();
}
private CellInfoGsm makeTestCellInfoGsm(String mcc) throws Exception {
final CellInfoGsm info = new CellInfoGsm();
final CellIdentityGsm ci = makeCellIdentityGsm(0, 0, 0, 0, mcc, "01", "", "");
......@@ -967,7 +1024,7 @@ public class NetworkMonitorTest {
public void testMakeFallbackUrls() throws Exception {
final WrappedNetworkMonitor wnm = makeCellNotMeteredNetworkMonitor();
// Value exist in setting provider.
URL[] urls = wnm.makeCaptivePortalFallbackUrls();
URL[] urls = wnm.makeCaptivePortalFallbackUrls(mContext);
assertEquals(urls[0].toString(), TEST_FALLBACK_URL);
// Clear setting provider value. Verify it to get configuration from resource instead.
......@@ -975,13 +1032,13 @@ public class NetworkMonitorTest {
// Verify that getting resource with exception.
when(mResources.getStringArray(R.array.config_captive_portal_fallback_urls))
.thenThrow(Resources.NotFoundException.class);
urls = wnm.makeCaptivePortalFallbackUrls();
urls = wnm.makeCaptivePortalFallbackUrls(mContext);
assertEquals(urls.length, 0);
// Verify resource return 2 different URLs.
doReturn(new String[] {"http://testUrl1.com", "http://testUrl2.com"}).when(mResources)
.getStringArray(R.array.config_captive_portal_fallback_urls);
urls = wnm.makeCaptivePortalFallbackUrls();
urls = wnm.makeCaptivePortalFallbackUrls(mContext);
assertEquals(urls.length, 2);
assertEquals("http://testUrl1.com", urls[0].toString());
assertEquals("http://testUrl2.com", urls[1].toString());
......@@ -992,7 +1049,7 @@ public class NetworkMonitorTest {
setupNoSimCardNeighborMcc();
doReturn(new String[] {"http://testUrl3.com"}).when(mMccResource)
.getStringArray(R.array.config_captive_portal_fallback_urls);
urls = wnm.makeCaptivePortalFallbackUrls();
urls = wnm.makeCaptivePortalFallbackUrls(mContext);
assertEquals(urls.length, 2);
assertEquals("http://testUrl1.com", urls[0].toString());
assertEquals("http://testUrl2.com", urls[1].toString());
......@@ -1005,7 +1062,7 @@ public class NetworkMonitorTest {
doReturn(new String[] {"http://testUrl.com"}).when(mMccResource)
.getStringArray(R.array.config_captive_portal_fallback_urls);
final WrappedNetworkMonitor wnm = makeCellNotMeteredNetworkMonitor();
final URL[] urls = wnm.makeCaptivePortalFallbackUrls();
final URL[] urls = wnm.makeCaptivePortalFallbackUrls(mMccContext);
assertEquals(urls.length, 1);
assertEquals("http://testUrl.com", urls[0].toString());
}
......@@ -1894,7 +1951,7 @@ public class NetworkMonitorTest {
verify(mCallbacks, timeout(HANDLER_TIMEOUT_MS).times(1))
.showProvisioningNotification(any(), any());
assertEquals(1, mRegisteredReceivers.size());
assertCaptivePortalAppReceiverRegistered(true /* isPortal */);
// Check that startCaptivePortalApp sends the expected intent.
nm.launchCaptivePortalApp();
......@@ -1932,7 +1989,7 @@ public class NetworkMonitorTest {
.notifyNetworkTestedWithExtras(matchNetworkTestResultParcelable(
NETWORK_VALIDATION_RESULT_VALID,
NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_HTTP));
assertEquals(0, mRegisteredReceivers.size());
assertCaptivePortalAppReceiverRegistered(false /* isPortal */);
}
@Test
......@@ -2518,7 +2575,7 @@ public class NetworkMonitorTest {
verify(mCallbacks, timeout(HANDLER_TIMEOUT_MS).times(1))
.showProvisioningNotification(any(), any());
assertEquals(1, mRegisteredReceivers.size());
assertCaptivePortalAppReceiverRegistered(true /* isPortal */);
// Check that startCaptivePortalApp sends the expected intent.
nm.launchCaptivePortalApp();
......@@ -2740,7 +2797,7 @@ public class NetworkMonitorTest {
monitor.notifyNetworkConnected(linkProperties, networkCapabilities);
verify(mCallbacks, timeout(HANDLER_TIMEOUT_MS).times(1))
.showProvisioningNotification(any(), any());
assertEquals(1, mRegisteredReceivers.size());
assertCaptivePortalAppReceiverRegistered(true /* isPortal */);
verifyNetworkTested(VALIDATION_RESULT_PORTAL, 0 /* probesSucceeded */, TEST_LOGIN_URL);
// Force reevaluation and confirm that the network is still captive
......@@ -2903,21 +2960,21 @@ public class NetworkMonitorTest {
private NetworkMonitor runPortalNetworkTest() throws RemoteException {
final NetworkMonitor nm = runNetworkTest(VALIDATION_RESULT_PORTAL,
0 /* probesSucceeded */, TEST_LOGIN_URL);
assertEquals(1, mRegisteredReceivers.size());
assertCaptivePortalAppReceiverRegistered(true /* isPortal */);
return nm;
}
private NetworkMonitor runNoValidationNetworkTest() throws RemoteException {
final NetworkMonitor nm = runNetworkTest(NETWORK_VALIDATION_RESULT_VALID,
0 /* probesSucceeded */, null /* redirectUrl */);
assertEquals(0, mRegisteredReceivers.size());
assertCaptivePortalAppReceiverRegistered(false /* isPortal */);
return nm;
}
private NetworkMonitor runFailedNetworkTest() throws RemoteException {
final NetworkMonitor nm = runNetworkTest(
VALIDATION_RESULT_INVALID, 0 /* probesSucceeded */, null /* redirectUrl */);
assertEquals(0, mRegisteredReceivers.size());
assertCaptivePortalAppReceiverRegistered(false /* isPortal */);
return nm;
}
......@@ -2925,7 +2982,7 @@ public class NetworkMonitorTest {
throws RemoteException {
final NetworkMonitor nm = runNetworkTest(NETWORK_VALIDATION_RESULT_PARTIAL,
probesSucceeded, null /* redirectUrl */);
assertEquals(0, mRegisteredReceivers.size());
assertCaptivePortalAppReceiverRegistered(false /* isPortal */);
return nm;
}
......@@ -3057,5 +3114,13 @@ public class NetworkMonitorTest {
private DataStallReportParcelable matchTcpDataStallParcelable() {
return argThat(p -> (p.detectionMethod & ConstantsShim.DETECTION_METHOD_TCP_METRICS) != 0);
}
private void assertCaptivePortalAppReceiverRegistered(boolean isPortal) {
// There will be configuration change receiver registered after NetworkMonitor being
// started. If captive portal app receiver is registered, then the size of the registered
// receivers will be 2. Otherwise, mRegisteredReceivers should only contain 1 configuration
// change receiver.
assertEquals(isPortal ? 2 : 1, mRegisteredReceivers.size());
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment