Merge "Update multiple validation result to ConnectivityService" am: 5af07137d7
am: a0e9af113c Change-Id: I243db4c406cca826e803c8035268bc0c6e6e01e2
This commit is contained in:
@@ -30,9 +30,12 @@ import static android.net.ConnectivityManager.TYPE_MOBILE_MMS;
|
||||
import static android.net.ConnectivityManager.TYPE_NONE;
|
||||
import static android.net.ConnectivityManager.TYPE_VPN;
|
||||
import static android.net.ConnectivityManager.TYPE_WIFI;
|
||||
import static android.net.INetworkMonitor.NETWORK_TEST_RESULT_INVALID;
|
||||
import static android.net.INetworkMonitor.NETWORK_TEST_RESULT_PARTIAL_CONNECTIVITY;
|
||||
import static android.net.INetworkMonitor.NETWORK_TEST_RESULT_VALID;
|
||||
import static android.net.INetworkMonitor.NETWORK_VALIDATION_PROBE_DNS;
|
||||
import static android.net.INetworkMonitor.NETWORK_VALIDATION_PROBE_FALLBACK;
|
||||
import static android.net.INetworkMonitor.NETWORK_VALIDATION_PROBE_HTTP;
|
||||
import static android.net.INetworkMonitor.NETWORK_VALIDATION_PROBE_HTTPS;
|
||||
import static android.net.INetworkMonitor.NETWORK_VALIDATION_RESULT_PARTIAL;
|
||||
import static android.net.INetworkMonitor.NETWORK_VALIDATION_RESULT_VALID;
|
||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_CAPTIVE_PORTAL;
|
||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_CBS;
|
||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_DUN;
|
||||
@@ -443,6 +446,16 @@ public class ConnectivityServiceTest {
|
||||
}
|
||||
|
||||
private class MockNetworkAgent {
|
||||
private static final int VALIDATION_RESULT_BASE = NETWORK_VALIDATION_PROBE_DNS
|
||||
| NETWORK_VALIDATION_PROBE_HTTP
|
||||
| NETWORK_VALIDATION_PROBE_HTTPS;
|
||||
private static final int VALIDATION_RESULT_VALID = VALIDATION_RESULT_BASE
|
||||
| NETWORK_VALIDATION_RESULT_VALID;
|
||||
private static final int VALIDATION_RESULT_PARTIAL = VALIDATION_RESULT_BASE
|
||||
| NETWORK_VALIDATION_PROBE_FALLBACK
|
||||
| NETWORK_VALIDATION_RESULT_PARTIAL;
|
||||
private static final int VALIDATION_RESULT_INVALID = 0;
|
||||
|
||||
private final INetworkMonitor mNetworkMonitor;
|
||||
private final NetworkInfo mNetworkInfo;
|
||||
private final NetworkCapabilities mNetworkCapabilities;
|
||||
@@ -460,17 +473,17 @@ public class ConnectivityServiceTest {
|
||||
private String mRedirectUrl;
|
||||
|
||||
private INetworkMonitorCallbacks mNmCallbacks;
|
||||
private int mNmValidationResult = NETWORK_TEST_RESULT_INVALID;
|
||||
private int mNmValidationResult = VALIDATION_RESULT_BASE;
|
||||
private String mNmValidationRedirectUrl = null;
|
||||
private boolean mNmProvNotificationRequested = false;
|
||||
|
||||
void setNetworkValid() {
|
||||
mNmValidationResult = NETWORK_TEST_RESULT_VALID;
|
||||
mNmValidationResult = VALIDATION_RESULT_VALID;
|
||||
mNmValidationRedirectUrl = null;
|
||||
}
|
||||
|
||||
void setNetworkInvalid() {
|
||||
mNmValidationResult = NETWORK_TEST_RESULT_INVALID;
|
||||
mNmValidationResult = VALIDATION_RESULT_INVALID;
|
||||
mNmValidationRedirectUrl = null;
|
||||
}
|
||||
|
||||
@@ -480,7 +493,12 @@ public class ConnectivityServiceTest {
|
||||
}
|
||||
|
||||
void setNetworkPartial() {
|
||||
mNmValidationResult = NETWORK_TEST_RESULT_PARTIAL_CONNECTIVITY;
|
||||
mNmValidationResult = VALIDATION_RESULT_PARTIAL;
|
||||
mNmValidationRedirectUrl = null;
|
||||
}
|
||||
|
||||
void setNetworkPartialValid() {
|
||||
mNmValidationResult = VALIDATION_RESULT_PARTIAL | VALIDATION_RESULT_VALID;
|
||||
mNmValidationRedirectUrl = null;
|
||||
}
|
||||
|
||||
@@ -597,7 +615,7 @@ public class ConnectivityServiceTest {
|
||||
private void onValidationRequested() {
|
||||
try {
|
||||
if (mNmProvNotificationRequested
|
||||
&& mNmValidationResult == NETWORK_TEST_RESULT_VALID) {
|
||||
&& mNmValidationResult == VALIDATION_RESULT_VALID) {
|
||||
mNmCallbacks.hideProvisioningNotification();
|
||||
mNmProvNotificationRequested = false;
|
||||
}
|
||||
@@ -2651,7 +2669,7 @@ public class ConnectivityServiceTest {
|
||||
|
||||
// With HTTPS probe disabled, NetworkMonitor should pass the network validation with http
|
||||
// probe.
|
||||
mWiFiNetworkAgent.setNetworkValid();
|
||||
mWiFiNetworkAgent.setNetworkPartialValid();
|
||||
// If the user chooses yes to use this partial connectivity wifi, switch the default
|
||||
// network to wifi and check if wifi becomes valid or not.
|
||||
mCm.setAcceptPartialConnectivity(mWiFiNetworkAgent.getNetwork(), true /* accept */,
|
||||
@@ -2748,6 +2766,54 @@ public class ConnectivityServiceTest {
|
||||
callback.expectCallback(CallbackState.LOST, mWiFiNetworkAgent);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCaptivePortalOnPartialConnectivity() throws RemoteException {
|
||||
final TestNetworkCallback captivePortalCallback = new TestNetworkCallback();
|
||||
final NetworkRequest captivePortalRequest = new NetworkRequest.Builder()
|
||||
.addCapability(NET_CAPABILITY_CAPTIVE_PORTAL).build();
|
||||
mCm.registerNetworkCallback(captivePortalRequest, captivePortalCallback);
|
||||
|
||||
final TestNetworkCallback validatedCallback = new TestNetworkCallback();
|
||||
final NetworkRequest validatedRequest = new NetworkRequest.Builder()
|
||||
.addCapability(NET_CAPABILITY_VALIDATED).build();
|
||||
mCm.registerNetworkCallback(validatedRequest, validatedCallback);
|
||||
|
||||
// Bring up a network with a captive portal.
|
||||
// Expect onAvailable callback of listen for NET_CAPABILITY_CAPTIVE_PORTAL.
|
||||
mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
|
||||
String firstRedirectUrl = "http://example.com/firstPath";
|
||||
mWiFiNetworkAgent.connectWithCaptivePortal(firstRedirectUrl);
|
||||
captivePortalCallback.expectAvailableCallbacksUnvalidated(mWiFiNetworkAgent);
|
||||
assertEquals(mWiFiNetworkAgent.waitForRedirectUrl(), firstRedirectUrl);
|
||||
|
||||
// Check that startCaptivePortalApp sends the expected command to NetworkMonitor.
|
||||
mCm.startCaptivePortalApp(mWiFiNetworkAgent.getNetwork());
|
||||
verify(mWiFiNetworkAgent.mNetworkMonitor, timeout(TIMEOUT_MS).times(1))
|
||||
.launchCaptivePortalApp();
|
||||
|
||||
// Report that the captive portal is dismissed with partial connectivity, and check that
|
||||
// callbacks are fired.
|
||||
mWiFiNetworkAgent.setNetworkPartial();
|
||||
mWiFiNetworkAgent.mNetworkMonitor.forceReevaluation(Process.myUid());
|
||||
waitForIdle();
|
||||
captivePortalCallback.expectCapabilitiesWith(NET_CAPABILITY_PARTIAL_CONNECTIVITY,
|
||||
mWiFiNetworkAgent);
|
||||
|
||||
// Report partial connectivity is accepted.
|
||||
mWiFiNetworkAgent.setNetworkPartialValid();
|
||||
mCm.setAcceptPartialConnectivity(mWiFiNetworkAgent.getNetwork(), true /* accept */,
|
||||
false /* always */);
|
||||
waitForIdle();
|
||||
mCm.reportNetworkConnectivity(mWiFiNetworkAgent.getNetwork(), true);
|
||||
validatedCallback.expectAvailableCallbacksValidated(mWiFiNetworkAgent);
|
||||
NetworkCapabilities nc =
|
||||
validatedCallback.expectCapabilitiesWith(NET_CAPABILITY_PARTIAL_CONNECTIVITY,
|
||||
mWiFiNetworkAgent);
|
||||
|
||||
mCm.unregisterNetworkCallback(captivePortalCallback);
|
||||
mCm.unregisterNetworkCallback(validatedCallback);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCaptivePortal() {
|
||||
final TestNetworkCallback captivePortalCallback = new TestNetworkCallback();
|
||||
|
||||
Reference in New Issue
Block a user