Merge "Simplify Exception expressions in CSTest"
This commit is contained in:
@@ -71,6 +71,7 @@ import static android.net.RouteInfo.RTN_UNREACHABLE;
|
|||||||
|
|
||||||
import static com.android.testutils.ConcurrentUtilsKt.await;
|
import static com.android.testutils.ConcurrentUtilsKt.await;
|
||||||
import static com.android.testutils.ConcurrentUtilsKt.durationOf;
|
import static com.android.testutils.ConcurrentUtilsKt.durationOf;
|
||||||
|
import static com.android.testutils.ExceptionUtils.ignoreExceptions;
|
||||||
import static com.android.testutils.HandlerUtilsKt.waitForIdleSerialExecutor;
|
import static com.android.testutils.HandlerUtilsKt.waitForIdleSerialExecutor;
|
||||||
import static com.android.testutils.MiscAssertsKt.assertContainsExactly;
|
import static com.android.testutils.MiscAssertsKt.assertContainsExactly;
|
||||||
import static com.android.testutils.MiscAssertsKt.assertEmpty;
|
import static com.android.testutils.MiscAssertsKt.assertEmpty;
|
||||||
@@ -206,8 +207,8 @@ import com.android.server.connectivity.Vpn;
|
|||||||
import com.android.server.net.NetworkPinner;
|
import com.android.server.net.NetworkPinner;
|
||||||
import com.android.server.net.NetworkPolicyManagerInternal;
|
import com.android.server.net.NetworkPolicyManagerInternal;
|
||||||
import com.android.server.net.NetworkStatsFactory;
|
import com.android.server.net.NetworkStatsFactory;
|
||||||
|
import com.android.testutils.ExceptionUtils;
|
||||||
import com.android.testutils.HandlerUtilsKt;
|
import com.android.testutils.HandlerUtilsKt;
|
||||||
import com.android.testutils.ThrowingConsumer;
|
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -228,7 +229,6 @@ import java.net.Inet6Address;
|
|||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -345,15 +345,6 @@ public class ConnectivityServiceTest {
|
|||||||
mStartedActivities.offer(intent);
|
mStartedActivities.offer(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Intent expectStartActivityIntent(int timeoutMs) {
|
|
||||||
Intent intent = null;
|
|
||||||
try {
|
|
||||||
intent = mStartedActivities.poll(timeoutMs, TimeUnit.MILLISECONDS);
|
|
||||||
} catch (InterruptedException e) {}
|
|
||||||
assertNotNull("Did not receive sign-in intent after " + timeoutMs + "ms", intent);
|
|
||||||
return intent;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void expectNoStartActivityIntent(int timeoutMs) {
|
public void expectNoStartActivityIntent(int timeoutMs) {
|
||||||
try {
|
try {
|
||||||
assertNull("Received unexpected Intent to start activity",
|
assertNull("Received unexpected Intent to start activity",
|
||||||
@@ -418,7 +409,7 @@ public class ConnectivityServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWaitForIdle() {
|
public void testWaitForIdle() throws Exception {
|
||||||
final int attempts = 50; // Causes the test to take about 200ms on bullhead-eng.
|
final int attempts = 50; // Causes the test to take about 200ms on bullhead-eng.
|
||||||
|
|
||||||
// Tests that waitForIdle returns immediately if the service is already idle.
|
// Tests that waitForIdle returns immediately if the service is already idle.
|
||||||
@@ -445,7 +436,7 @@ public class ConnectivityServiceTest {
|
|||||||
// This test has an inherent race condition in it, and cannot be enabled for continuous testing
|
// This test has an inherent race condition in it, and cannot be enabled for continuous testing
|
||||||
// or presubmit tests. It is kept for manual runs and documentation purposes.
|
// or presubmit tests. It is kept for manual runs and documentation purposes.
|
||||||
@Ignore
|
@Ignore
|
||||||
public void verifyThatNotWaitingForIdleCausesRaceConditions() {
|
public void verifyThatNotWaitingForIdleCausesRaceConditions() throws Exception {
|
||||||
// Bring up a network that we can use to send messages to ConnectivityService.
|
// Bring up a network that we can use to send messages to ConnectivityService.
|
||||||
ConditionVariable cv = waitForConnectivityBroadcasts(1);
|
ConditionVariable cv = waitForConnectivityBroadcasts(1);
|
||||||
mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
|
mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
|
||||||
@@ -525,11 +516,11 @@ public class ConnectivityServiceTest {
|
|||||||
mNmValidationRedirectUrl = null;
|
mNmValidationRedirectUrl = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
MockNetworkAgent(int transport) {
|
MockNetworkAgent(int transport) throws Exception {
|
||||||
this(transport, new LinkProperties());
|
this(transport, new LinkProperties());
|
||||||
}
|
}
|
||||||
|
|
||||||
MockNetworkAgent(int transport, LinkProperties linkProperties) {
|
MockNetworkAgent(int transport, LinkProperties linkProperties) throws Exception {
|
||||||
final int type = transportToLegacyType(transport);
|
final int type = transportToLegacyType(transport);
|
||||||
final String typeName = ConnectivityManager.getNetworkTypeName(type);
|
final String typeName = ConnectivityManager.getNetworkTypeName(type);
|
||||||
mNetworkInfo = new NetworkInfo(type, 0, typeName, "Mock");
|
mNetworkInfo = new NetworkInfo(type, 0, typeName, "Mock");
|
||||||
@@ -560,16 +551,12 @@ public class ConnectivityServiceTest {
|
|||||||
|
|
||||||
mNetworkMonitor = mock(INetworkMonitor.class);
|
mNetworkMonitor = mock(INetworkMonitor.class);
|
||||||
final Answer validateAnswer = inv -> {
|
final Answer validateAnswer = inv -> {
|
||||||
new Thread(this::onValidationRequested).start();
|
new Thread(ignoreExceptions(this::onValidationRequested)).start();
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
doAnswer(validateAnswer).when(mNetworkMonitor).notifyNetworkConnected(any(), any());
|
||||||
doAnswer(validateAnswer).when(mNetworkMonitor).notifyNetworkConnected(any(), any());
|
doAnswer(validateAnswer).when(mNetworkMonitor).forceReevaluation(anyInt());
|
||||||
doAnswer(validateAnswer).when(mNetworkMonitor).forceReevaluation(anyInt());
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
fail(e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
final ArgumentCaptor<Network> nmNetworkCaptor = ArgumentCaptor.forClass(Network.class);
|
final ArgumentCaptor<Network> nmNetworkCaptor = ArgumentCaptor.forClass(Network.class);
|
||||||
final ArgumentCaptor<INetworkMonitorCallbacks> nmCbCaptor =
|
final ArgumentCaptor<INetworkMonitorCallbacks> nmCbCaptor =
|
||||||
@@ -624,35 +611,27 @@ public class ConnectivityServiceTest {
|
|||||||
assertEquals(mNetworkAgent.netId, nmNetworkCaptor.getValue().netId);
|
assertEquals(mNetworkAgent.netId, nmNetworkCaptor.getValue().netId);
|
||||||
mNmCallbacks = nmCbCaptor.getValue();
|
mNmCallbacks = nmCbCaptor.getValue();
|
||||||
|
|
||||||
try {
|
mNmCallbacks.onNetworkMonitorCreated(mNetworkMonitor);
|
||||||
mNmCallbacks.onNetworkMonitorCreated(mNetworkMonitor);
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
fail(e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Waits for the NetworkAgent to be registered, which includes the creation of the
|
// Waits for the NetworkAgent to be registered, which includes the creation of the
|
||||||
// NetworkMonitor.
|
// NetworkMonitor.
|
||||||
waitForIdle();
|
waitForIdle();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onValidationRequested() {
|
private void onValidationRequested() throws Exception {
|
||||||
try {
|
if (mNmProvNotificationRequested
|
||||||
if (mNmProvNotificationRequested
|
&& ((mNmValidationResult & NETWORK_VALIDATION_RESULT_VALID) != 0)) {
|
||||||
&& ((mNmValidationResult & NETWORK_VALIDATION_RESULT_VALID) != 0)) {
|
mNmCallbacks.hideProvisioningNotification();
|
||||||
mNmCallbacks.hideProvisioningNotification();
|
mNmProvNotificationRequested = false;
|
||||||
mNmProvNotificationRequested = false;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
mNmCallbacks.notifyNetworkTested(
|
mNmCallbacks.notifyNetworkTested(
|
||||||
mNmValidationResult, mNmValidationRedirectUrl);
|
mNmValidationResult, mNmValidationRedirectUrl);
|
||||||
|
|
||||||
if (mNmValidationRedirectUrl != null) {
|
if (mNmValidationRedirectUrl != null) {
|
||||||
mNmCallbacks.showProvisioningNotification(
|
mNmCallbacks.showProvisioningNotification(
|
||||||
"test_provisioning_notif_action", "com.android.test.package");
|
"test_provisioning_notif_action", "com.android.test.package");
|
||||||
mNmProvNotificationRequested = true;
|
mNmProvNotificationRequested = true;
|
||||||
}
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
fail(e.getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1250,18 +1229,13 @@ public class ConnectivityServiceTest {
|
|||||||
waitForIdle(TIMEOUT_MS);
|
waitForIdle(TIMEOUT_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUidRulesChanged(int uidRules) {
|
public void setUidRulesChanged(int uidRules) throws RemoteException {
|
||||||
try {
|
mPolicyListener.onUidRulesChanged(Process.myUid(), uidRules);
|
||||||
mPolicyListener.onUidRulesChanged(Process.myUid(), uidRules);
|
|
||||||
} catch (RemoteException ignored) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRestrictBackgroundChanged(boolean restrictBackground) {
|
public void setRestrictBackgroundChanged(boolean restrictBackground)
|
||||||
try {
|
throws RemoteException {
|
||||||
mPolicyListener.onRestrictBackgroundChanged(restrictBackground);
|
mPolicyListener.onRestrictBackgroundChanged(restrictBackground);
|
||||||
} catch (RemoteException ignored) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1816,12 +1790,9 @@ public class ConnectivityServiceTest {
|
|||||||
return mLastAvailableNetwork;
|
return mLastAvailableNetwork;
|
||||||
}
|
}
|
||||||
|
|
||||||
CallbackInfo nextCallback(int timeoutMs) {
|
CallbackInfo nextCallback(int timeoutMs) throws InterruptedException {
|
||||||
CallbackInfo cb = null;
|
CallbackInfo cb = null;
|
||||||
try {
|
cb = mCallbacks.poll(timeoutMs, TimeUnit.MILLISECONDS);
|
||||||
cb = mCallbacks.poll(timeoutMs, TimeUnit.MILLISECONDS);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
}
|
|
||||||
if (cb == null) {
|
if (cb == null) {
|
||||||
// LinkedBlockingQueue.poll() returns null if it timeouts.
|
// LinkedBlockingQueue.poll() returns null if it timeouts.
|
||||||
fail("Did not receive callback after " + timeoutMs + "ms");
|
fail("Did not receive callback after " + timeoutMs + "ms");
|
||||||
@@ -1829,7 +1800,8 @@ public class ConnectivityServiceTest {
|
|||||||
return cb;
|
return cb;
|
||||||
}
|
}
|
||||||
|
|
||||||
CallbackInfo expectCallback(CallbackState state, MockNetworkAgent agent, int timeoutMs) {
|
CallbackInfo expectCallback(CallbackState state, MockNetworkAgent agent, int timeoutMs)
|
||||||
|
throws Exception {
|
||||||
final Network expectedNetwork = (agent != null) ? agent.getNetwork() : null;
|
final Network expectedNetwork = (agent != null) ? agent.getNetwork() : null;
|
||||||
CallbackInfo expected = new CallbackInfo(state, expectedNetwork, 0);
|
CallbackInfo expected = new CallbackInfo(state, expectedNetwork, 0);
|
||||||
CallbackInfo actual = nextCallback(timeoutMs);
|
CallbackInfo actual = nextCallback(timeoutMs);
|
||||||
@@ -1846,15 +1818,16 @@ public class ConnectivityServiceTest {
|
|||||||
return actual;
|
return actual;
|
||||||
}
|
}
|
||||||
|
|
||||||
CallbackInfo expectCallback(CallbackState state, MockNetworkAgent agent) {
|
CallbackInfo expectCallback(CallbackState state, MockNetworkAgent agent) throws Exception {
|
||||||
return expectCallback(state, agent, TEST_CALLBACK_TIMEOUT_MS);
|
return expectCallback(state, agent, TEST_CALLBACK_TIMEOUT_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
CallbackInfo expectCallbackLike(Predicate<CallbackInfo> fn) {
|
CallbackInfo expectCallbackLike(Predicate<CallbackInfo> fn) throws Exception {
|
||||||
return expectCallbackLike(fn, TEST_CALLBACK_TIMEOUT_MS);
|
return expectCallbackLike(fn, TEST_CALLBACK_TIMEOUT_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
CallbackInfo expectCallbackLike(Predicate<CallbackInfo> fn, int timeoutMs) {
|
CallbackInfo expectCallbackLike(Predicate<CallbackInfo> fn, int timeoutMs)
|
||||||
|
throws Exception {
|
||||||
int timeLeft = timeoutMs;
|
int timeLeft = timeoutMs;
|
||||||
while (timeLeft > 0) {
|
while (timeLeft > 0) {
|
||||||
long start = SystemClock.elapsedRealtime();
|
long start = SystemClock.elapsedRealtime();
|
||||||
@@ -1880,7 +1853,7 @@ public class ConnectivityServiceTest {
|
|||||||
// onCapabilitiesChanged callback.
|
// onCapabilitiesChanged callback.
|
||||||
// @param timeoutMs how long to wait for the callbacks.
|
// @param timeoutMs how long to wait for the callbacks.
|
||||||
void expectAvailableCallbacks(MockNetworkAgent agent, boolean expectSuspended,
|
void expectAvailableCallbacks(MockNetworkAgent agent, boolean expectSuspended,
|
||||||
boolean expectValidated, boolean expectBlocked, int timeoutMs) {
|
boolean expectValidated, boolean expectBlocked, int timeoutMs) throws Exception {
|
||||||
expectCallback(CallbackState.AVAILABLE, agent, timeoutMs);
|
expectCallback(CallbackState.AVAILABLE, agent, timeoutMs);
|
||||||
if (expectSuspended) {
|
if (expectSuspended) {
|
||||||
expectCallback(CallbackState.SUSPENDED, agent, timeoutMs);
|
expectCallback(CallbackState.SUSPENDED, agent, timeoutMs);
|
||||||
@@ -1895,23 +1868,26 @@ public class ConnectivityServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Expects the available callbacks (validated), plus onSuspended.
|
// Expects the available callbacks (validated), plus onSuspended.
|
||||||
void expectAvailableAndSuspendedCallbacks(MockNetworkAgent agent, boolean expectValidated) {
|
void expectAvailableAndSuspendedCallbacks(MockNetworkAgent agent, boolean expectValidated)
|
||||||
|
throws Exception {
|
||||||
expectAvailableCallbacks(agent, true, expectValidated, false, TEST_CALLBACK_TIMEOUT_MS);
|
expectAvailableCallbacks(agent, true, expectValidated, false, TEST_CALLBACK_TIMEOUT_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
void expectAvailableCallbacksValidated(MockNetworkAgent agent) {
|
void expectAvailableCallbacksValidated(MockNetworkAgent agent)
|
||||||
|
throws Exception {
|
||||||
expectAvailableCallbacks(agent, false, true, false, TEST_CALLBACK_TIMEOUT_MS);
|
expectAvailableCallbacks(agent, false, true, false, TEST_CALLBACK_TIMEOUT_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
void expectAvailableCallbacksValidatedAndBlocked(MockNetworkAgent agent) {
|
void expectAvailableCallbacksValidatedAndBlocked(MockNetworkAgent agent) throws Exception {
|
||||||
expectAvailableCallbacks(agent, false, true, true, TEST_CALLBACK_TIMEOUT_MS);
|
expectAvailableCallbacks(agent, false, true, true, TEST_CALLBACK_TIMEOUT_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
void expectAvailableCallbacksUnvalidated(MockNetworkAgent agent) {
|
void expectAvailableCallbacksUnvalidated(MockNetworkAgent agent) throws Exception {
|
||||||
expectAvailableCallbacks(agent, false, false, false, TEST_CALLBACK_TIMEOUT_MS);
|
expectAvailableCallbacks(agent, false, false, false, TEST_CALLBACK_TIMEOUT_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
void expectAvailableCallbacksUnvalidatedAndBlocked(MockNetworkAgent agent) {
|
void expectAvailableCallbacksUnvalidatedAndBlocked(MockNetworkAgent agent)
|
||||||
|
throws Exception {
|
||||||
expectAvailableCallbacks(agent, false, false, true, TEST_CALLBACK_TIMEOUT_MS);
|
expectAvailableCallbacks(agent, false, false, true, TEST_CALLBACK_TIMEOUT_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1919,7 +1895,7 @@ public class ConnectivityServiceTest {
|
|||||||
// VALIDATED capability), plus another onCapabilitiesChanged which is identical to the
|
// VALIDATED capability), plus another onCapabilitiesChanged which is identical to the
|
||||||
// one we just sent.
|
// one we just sent.
|
||||||
// TODO: this is likely a bug. Fix it and remove this method.
|
// TODO: this is likely a bug. Fix it and remove this method.
|
||||||
void expectAvailableDoubleValidatedCallbacks(MockNetworkAgent agent) {
|
void expectAvailableDoubleValidatedCallbacks(MockNetworkAgent agent) throws Exception {
|
||||||
expectCallback(CallbackState.AVAILABLE, agent, TEST_CALLBACK_TIMEOUT_MS);
|
expectCallback(CallbackState.AVAILABLE, agent, TEST_CALLBACK_TIMEOUT_MS);
|
||||||
NetworkCapabilities nc1 = expectCapabilitiesWith(NET_CAPABILITY_VALIDATED, agent);
|
NetworkCapabilities nc1 = expectCapabilitiesWith(NET_CAPABILITY_VALIDATED, agent);
|
||||||
expectCallback(CallbackState.LINK_PROPERTIES, agent, TEST_CALLBACK_TIMEOUT_MS);
|
expectCallback(CallbackState.LINK_PROPERTIES, agent, TEST_CALLBACK_TIMEOUT_MS);
|
||||||
@@ -1933,48 +1909,53 @@ public class ConnectivityServiceTest {
|
|||||||
// Expects the available callbacks where the onCapabilitiesChanged must not have validated,
|
// Expects the available callbacks where the onCapabilitiesChanged must not have validated,
|
||||||
// then expects another onCapabilitiesChanged that has the validated bit set. This is used
|
// then expects another onCapabilitiesChanged that has the validated bit set. This is used
|
||||||
// when a network connects and satisfies a callback, and then immediately validates.
|
// when a network connects and satisfies a callback, and then immediately validates.
|
||||||
void expectAvailableThenValidatedCallbacks(MockNetworkAgent agent) {
|
void expectAvailableThenValidatedCallbacks(MockNetworkAgent agent) throws Exception {
|
||||||
expectAvailableCallbacksUnvalidated(agent);
|
expectAvailableCallbacksUnvalidated(agent);
|
||||||
expectCapabilitiesWith(NET_CAPABILITY_VALIDATED, agent);
|
expectCapabilitiesWith(NET_CAPABILITY_VALIDATED, agent);
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkCapabilities expectCapabilitiesWith(int capability, MockNetworkAgent agent) {
|
NetworkCapabilities expectCapabilitiesWith(int capability, MockNetworkAgent agent)
|
||||||
|
throws Exception {
|
||||||
return expectCapabilitiesWith(capability, agent, TEST_CALLBACK_TIMEOUT_MS);
|
return expectCapabilitiesWith(capability, agent, TEST_CALLBACK_TIMEOUT_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkCapabilities expectCapabilitiesWith(int capability, MockNetworkAgent agent,
|
NetworkCapabilities expectCapabilitiesWith(int capability, MockNetworkAgent agent,
|
||||||
int timeoutMs) {
|
int timeoutMs) throws Exception {
|
||||||
CallbackInfo cbi = expectCallback(CallbackState.NETWORK_CAPABILITIES, agent, timeoutMs);
|
CallbackInfo cbi = expectCallback(CallbackState.NETWORK_CAPABILITIES, agent, timeoutMs);
|
||||||
NetworkCapabilities nc = (NetworkCapabilities) cbi.arg;
|
NetworkCapabilities nc = (NetworkCapabilities) cbi.arg;
|
||||||
assertTrue(nc.hasCapability(capability));
|
assertTrue(nc.hasCapability(capability));
|
||||||
return nc;
|
return nc;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkCapabilities expectCapabilitiesWithout(int capability, MockNetworkAgent agent) {
|
NetworkCapabilities expectCapabilitiesWithout(int capability, MockNetworkAgent agent)
|
||||||
|
throws Exception {
|
||||||
return expectCapabilitiesWithout(capability, agent, TEST_CALLBACK_TIMEOUT_MS);
|
return expectCapabilitiesWithout(capability, agent, TEST_CALLBACK_TIMEOUT_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkCapabilities expectCapabilitiesWithout(int capability, MockNetworkAgent agent,
|
NetworkCapabilities expectCapabilitiesWithout(int capability, MockNetworkAgent agent,
|
||||||
int timeoutMs) {
|
int timeoutMs) throws Exception {
|
||||||
CallbackInfo cbi = expectCallback(CallbackState.NETWORK_CAPABILITIES, agent, timeoutMs);
|
CallbackInfo cbi = expectCallback(CallbackState.NETWORK_CAPABILITIES, agent, timeoutMs);
|
||||||
NetworkCapabilities nc = (NetworkCapabilities) cbi.arg;
|
NetworkCapabilities nc = (NetworkCapabilities) cbi.arg;
|
||||||
assertFalse(nc.hasCapability(capability));
|
assertFalse(nc.hasCapability(capability));
|
||||||
return nc;
|
return nc;
|
||||||
}
|
}
|
||||||
|
|
||||||
void expectCapabilitiesLike(Predicate<NetworkCapabilities> fn, MockNetworkAgent agent) {
|
void expectCapabilitiesLike(Predicate<NetworkCapabilities> fn, MockNetworkAgent agent)
|
||||||
|
throws Exception {
|
||||||
CallbackInfo cbi = expectCallback(CallbackState.NETWORK_CAPABILITIES, agent);
|
CallbackInfo cbi = expectCallback(CallbackState.NETWORK_CAPABILITIES, agent);
|
||||||
assertTrue("Received capabilities don't match expectations : " + cbi.arg,
|
assertTrue("Received capabilities don't match expectations : " + cbi.arg,
|
||||||
fn.test((NetworkCapabilities) cbi.arg));
|
fn.test((NetworkCapabilities) cbi.arg));
|
||||||
}
|
}
|
||||||
|
|
||||||
void expectLinkPropertiesLike(Predicate<LinkProperties> fn, MockNetworkAgent agent) {
|
void expectLinkPropertiesLike(Predicate<LinkProperties> fn, MockNetworkAgent agent)
|
||||||
|
throws Exception {
|
||||||
CallbackInfo cbi = expectCallback(CallbackState.LINK_PROPERTIES, agent);
|
CallbackInfo cbi = expectCallback(CallbackState.LINK_PROPERTIES, agent);
|
||||||
assertTrue("Received LinkProperties don't match expectations : " + cbi.arg,
|
assertTrue("Received LinkProperties don't match expectations : " + cbi.arg,
|
||||||
fn.test((LinkProperties) cbi.arg));
|
fn.test((LinkProperties) cbi.arg));
|
||||||
}
|
}
|
||||||
|
|
||||||
void expectBlockedStatusCallback(boolean expectBlocked, MockNetworkAgent agent) {
|
void expectBlockedStatusCallback(boolean expectBlocked, MockNetworkAgent agent)
|
||||||
|
throws Exception {
|
||||||
CallbackInfo cbi = expectCallback(CallbackState.BLOCKED_STATUS, agent);
|
CallbackInfo cbi = expectCallback(CallbackState.BLOCKED_STATUS, agent);
|
||||||
boolean actualBlocked = (boolean) cbi.arg;
|
boolean actualBlocked = (boolean) cbi.arg;
|
||||||
assertEquals(expectBlocked, actualBlocked);
|
assertEquals(expectBlocked, actualBlocked);
|
||||||
@@ -2086,7 +2067,7 @@ public class ConnectivityServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMultipleLingering() {
|
public void testMultipleLingering() throws Exception {
|
||||||
// This test would be flaky with the default 120ms timer: that is short enough that
|
// This test would be flaky with the default 120ms timer: that is short enough that
|
||||||
// lingered networks are torn down before assertions can be run. We don't want to mock the
|
// lingered networks are torn down before assertions can be run. We don't want to mock the
|
||||||
// lingering timer to keep the WakeupMessage logic realistic: this has already proven useful
|
// lingering timer to keep the WakeupMessage logic realistic: this has already proven useful
|
||||||
@@ -2341,7 +2322,7 @@ public class ConnectivityServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNetworkGoesIntoBackgroundAfterLinger() {
|
public void testNetworkGoesIntoBackgroundAfterLinger() throws Exception {
|
||||||
setAlwaysOnNetworks(true);
|
setAlwaysOnNetworks(true);
|
||||||
NetworkRequest request = new NetworkRequest.Builder()
|
NetworkRequest request = new NetworkRequest.Builder()
|
||||||
.clearCapabilities()
|
.clearCapabilities()
|
||||||
@@ -2386,7 +2367,7 @@ public class ConnectivityServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExplicitlySelected() {
|
public void testExplicitlySelected() throws Exception {
|
||||||
NetworkRequest request = new NetworkRequest.Builder()
|
NetworkRequest request = new NetworkRequest.Builder()
|
||||||
.clearCapabilities().addCapability(NET_CAPABILITY_INTERNET)
|
.clearCapabilities().addCapability(NET_CAPABILITY_INTERNET)
|
||||||
.build();
|
.build();
|
||||||
@@ -2667,7 +2648,7 @@ public class ConnectivityServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPartialConnectivity() {
|
public void testPartialConnectivity() throws Exception {
|
||||||
// Register network callback.
|
// Register network callback.
|
||||||
NetworkRequest request = new NetworkRequest.Builder()
|
NetworkRequest request = new NetworkRequest.Builder()
|
||||||
.clearCapabilities().addCapability(NET_CAPABILITY_INTERNET)
|
.clearCapabilities().addCapability(NET_CAPABILITY_INTERNET)
|
||||||
@@ -2700,11 +2681,7 @@ public class ConnectivityServiceTest {
|
|||||||
// If user accepts partial connectivity network,
|
// If user accepts partial connectivity network,
|
||||||
// NetworkMonitor#setAcceptPartialConnectivity() should be called too.
|
// NetworkMonitor#setAcceptPartialConnectivity() should be called too.
|
||||||
waitForIdle();
|
waitForIdle();
|
||||||
try {
|
verify(mWiFiNetworkAgent.mNetworkMonitor, times(1)).setAcceptPartialConnectivity();
|
||||||
verify(mWiFiNetworkAgent.mNetworkMonitor, times(1)).setAcceptPartialConnectivity();
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
fail(e.getMessage());
|
|
||||||
}
|
|
||||||
// Need a trigger point to let NetworkMonitor tell ConnectivityService that network is
|
// Need a trigger point to let NetworkMonitor tell ConnectivityService that network is
|
||||||
// validated.
|
// validated.
|
||||||
mCm.reportNetworkConnectivity(mWiFiNetworkAgent.getNetwork(), true);
|
mCm.reportNetworkConnectivity(mWiFiNetworkAgent.getNetwork(), true);
|
||||||
@@ -2741,11 +2718,7 @@ public class ConnectivityServiceTest {
|
|||||||
// NetworkMonitor#setAcceptPartialConnectivity() will be called in
|
// NetworkMonitor#setAcceptPartialConnectivity() will be called in
|
||||||
// ConnectivityService#updateNetworkInfo().
|
// ConnectivityService#updateNetworkInfo().
|
||||||
waitForIdle();
|
waitForIdle();
|
||||||
try {
|
verify(mWiFiNetworkAgent.mNetworkMonitor, times(1)).setAcceptPartialConnectivity();
|
||||||
verify(mWiFiNetworkAgent.mNetworkMonitor, times(1)).setAcceptPartialConnectivity();
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
fail(e.getMessage());
|
|
||||||
}
|
|
||||||
callback.expectAvailableCallbacksUnvalidated(mWiFiNetworkAgent);
|
callback.expectAvailableCallbacksUnvalidated(mWiFiNetworkAgent);
|
||||||
callback.expectCallback(CallbackState.LOSING, mCellNetworkAgent);
|
callback.expectCallback(CallbackState.LOSING, mCellNetworkAgent);
|
||||||
nc = callback.expectCapabilitiesWith(NET_CAPABILITY_VALIDATED, mWiFiNetworkAgent);
|
nc = callback.expectCapabilitiesWith(NET_CAPABILITY_VALIDATED, mWiFiNetworkAgent);
|
||||||
@@ -2769,11 +2742,7 @@ public class ConnectivityServiceTest {
|
|||||||
// NetworkMonitor#setAcceptPartialConnectivity() will be called in
|
// NetworkMonitor#setAcceptPartialConnectivity() will be called in
|
||||||
// ConnectivityService#updateNetworkInfo().
|
// ConnectivityService#updateNetworkInfo().
|
||||||
waitForIdle();
|
waitForIdle();
|
||||||
try {
|
verify(mWiFiNetworkAgent.mNetworkMonitor, times(1)).setAcceptPartialConnectivity();
|
||||||
verify(mWiFiNetworkAgent.mNetworkMonitor, times(1)).setAcceptPartialConnectivity();
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
fail(e.getMessage());
|
|
||||||
}
|
|
||||||
callback.expectAvailableCallbacksUnvalidated(mWiFiNetworkAgent);
|
callback.expectAvailableCallbacksUnvalidated(mWiFiNetworkAgent);
|
||||||
callback.expectCallback(CallbackState.LOSING, mCellNetworkAgent);
|
callback.expectCallback(CallbackState.LOSING, mCellNetworkAgent);
|
||||||
// TODO: If the user accepted partial connectivity, we shouldn't switch to wifi until
|
// TODO: If the user accepted partial connectivity, we shouldn't switch to wifi until
|
||||||
@@ -2790,7 +2759,7 @@ public class ConnectivityServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCaptivePortalOnPartialConnectivity() throws RemoteException {
|
public void testCaptivePortalOnPartialConnectivity() throws Exception {
|
||||||
final TestNetworkCallback captivePortalCallback = new TestNetworkCallback();
|
final TestNetworkCallback captivePortalCallback = new TestNetworkCallback();
|
||||||
final NetworkRequest captivePortalRequest = new NetworkRequest.Builder()
|
final NetworkRequest captivePortalRequest = new NetworkRequest.Builder()
|
||||||
.addCapability(NET_CAPABILITY_CAPTIVE_PORTAL).build();
|
.addCapability(NET_CAPABILITY_CAPTIVE_PORTAL).build();
|
||||||
@@ -2839,7 +2808,7 @@ public class ConnectivityServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCaptivePortal() {
|
public void testCaptivePortal() throws Exception {
|
||||||
final TestNetworkCallback captivePortalCallback = new TestNetworkCallback();
|
final TestNetworkCallback captivePortalCallback = new TestNetworkCallback();
|
||||||
final NetworkRequest captivePortalRequest = new NetworkRequest.Builder()
|
final NetworkRequest captivePortalRequest = new NetworkRequest.Builder()
|
||||||
.addCapability(NET_CAPABILITY_CAPTIVE_PORTAL).build();
|
.addCapability(NET_CAPABILITY_CAPTIVE_PORTAL).build();
|
||||||
@@ -2891,7 +2860,7 @@ public class ConnectivityServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCaptivePortalApp() throws RemoteException {
|
public void testCaptivePortalApp() throws Exception {
|
||||||
final TestNetworkCallback captivePortalCallback = new TestNetworkCallback();
|
final TestNetworkCallback captivePortalCallback = new TestNetworkCallback();
|
||||||
final NetworkRequest captivePortalRequest = new NetworkRequest.Builder()
|
final NetworkRequest captivePortalRequest = new NetworkRequest.Builder()
|
||||||
.addCapability(NET_CAPABILITY_CAPTIVE_PORTAL).build();
|
.addCapability(NET_CAPABILITY_CAPTIVE_PORTAL).build();
|
||||||
@@ -2949,7 +2918,7 @@ public class ConnectivityServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAvoidOrIgnoreCaptivePortals() {
|
public void testAvoidOrIgnoreCaptivePortals() throws Exception {
|
||||||
final TestNetworkCallback captivePortalCallback = new TestNetworkCallback();
|
final TestNetworkCallback captivePortalCallback = new TestNetworkCallback();
|
||||||
final NetworkRequest captivePortalRequest = new NetworkRequest.Builder()
|
final NetworkRequest captivePortalRequest = new NetworkRequest.Builder()
|
||||||
.addCapability(NET_CAPABILITY_CAPTIVE_PORTAL).build();
|
.addCapability(NET_CAPABILITY_CAPTIVE_PORTAL).build();
|
||||||
@@ -2989,7 +2958,7 @@ public class ConnectivityServiceTest {
|
|||||||
* does work.
|
* does work.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testNetworkSpecifier() {
|
public void testNetworkSpecifier() throws Exception {
|
||||||
// A NetworkSpecifier subclass that matches all networks but must not be visible to apps.
|
// A NetworkSpecifier subclass that matches all networks but must not be visible to apps.
|
||||||
class ConfidentialMatchAllNetworkSpecifier extends NetworkSpecifier implements
|
class ConfidentialMatchAllNetworkSpecifier extends NetworkSpecifier implements
|
||||||
Parcelable {
|
Parcelable {
|
||||||
@@ -3178,7 +3147,7 @@ public class ConnectivityServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNetworkSpecifierUidSpoofSecurityException() {
|
public void testNetworkSpecifierUidSpoofSecurityException() throws Exception {
|
||||||
class UidAwareNetworkSpecifier extends NetworkSpecifier implements Parcelable {
|
class UidAwareNetworkSpecifier extends NetworkSpecifier implements Parcelable {
|
||||||
@Override
|
@Override
|
||||||
public boolean satisfiedBy(NetworkSpecifier other) {
|
public boolean satisfiedBy(NetworkSpecifier other) {
|
||||||
@@ -3791,7 +3760,7 @@ public class ConnectivityServiceTest {
|
|||||||
* time-out period expires.
|
* time-out period expires.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testSatisfiedNetworkRequestDoesNotTriggerOnUnavailable() {
|
public void testSatisfiedNetworkRequestDoesNotTriggerOnUnavailable() throws Exception {
|
||||||
NetworkRequest nr = new NetworkRequest.Builder().addTransportType(
|
NetworkRequest nr = new NetworkRequest.Builder().addTransportType(
|
||||||
NetworkCapabilities.TRANSPORT_WIFI).build();
|
NetworkCapabilities.TRANSPORT_WIFI).build();
|
||||||
final TestNetworkCallback networkCallback = new TestNetworkCallback();
|
final TestNetworkCallback networkCallback = new TestNetworkCallback();
|
||||||
@@ -3811,7 +3780,7 @@ public class ConnectivityServiceTest {
|
|||||||
* not trigger onUnavailable() once the time-out period expires.
|
* not trigger onUnavailable() once the time-out period expires.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testSatisfiedThenLostNetworkRequestDoesNotTriggerOnUnavailable() {
|
public void testSatisfiedThenLostNetworkRequestDoesNotTriggerOnUnavailable() throws Exception {
|
||||||
NetworkRequest nr = new NetworkRequest.Builder().addTransportType(
|
NetworkRequest nr = new NetworkRequest.Builder().addTransportType(
|
||||||
NetworkCapabilities.TRANSPORT_WIFI).build();
|
NetworkCapabilities.TRANSPORT_WIFI).build();
|
||||||
final TestNetworkCallback networkCallback = new TestNetworkCallback();
|
final TestNetworkCallback networkCallback = new TestNetworkCallback();
|
||||||
@@ -3834,7 +3803,7 @@ public class ConnectivityServiceTest {
|
|||||||
* (somehow) satisfied - the callback isn't called later.
|
* (somehow) satisfied - the callback isn't called later.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testTimedoutNetworkRequest() {
|
public void testTimedoutNetworkRequest() throws Exception {
|
||||||
NetworkRequest nr = new NetworkRequest.Builder().addTransportType(
|
NetworkRequest nr = new NetworkRequest.Builder().addTransportType(
|
||||||
NetworkCapabilities.TRANSPORT_WIFI).build();
|
NetworkCapabilities.TRANSPORT_WIFI).build();
|
||||||
final TestNetworkCallback networkCallback = new TestNetworkCallback();
|
final TestNetworkCallback networkCallback = new TestNetworkCallback();
|
||||||
@@ -3855,7 +3824,7 @@ public class ConnectivityServiceTest {
|
|||||||
* trigger the callback.
|
* trigger the callback.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testNoCallbackAfterUnregisteredNetworkRequest() {
|
public void testNoCallbackAfterUnregisteredNetworkRequest() throws Exception {
|
||||||
NetworkRequest nr = new NetworkRequest.Builder().addTransportType(
|
NetworkRequest nr = new NetworkRequest.Builder().addTransportType(
|
||||||
NetworkCapabilities.TRANSPORT_WIFI).build();
|
NetworkCapabilities.TRANSPORT_WIFI).build();
|
||||||
final TestNetworkCallback networkCallback = new TestNetworkCallback();
|
final TestNetworkCallback networkCallback = new TestNetworkCallback();
|
||||||
@@ -3947,7 +3916,7 @@ public class ConnectivityServiceTest {
|
|||||||
|
|
||||||
private static class TestKeepaliveCallback extends PacketKeepaliveCallback {
|
private static class TestKeepaliveCallback extends PacketKeepaliveCallback {
|
||||||
|
|
||||||
public static enum CallbackType { ON_STARTED, ON_STOPPED, ON_ERROR };
|
public enum CallbackType { ON_STARTED, ON_STOPPED, ON_ERROR }
|
||||||
|
|
||||||
private class CallbackValue {
|
private class CallbackValue {
|
||||||
public CallbackType callbackType;
|
public CallbackType callbackType;
|
||||||
@@ -3995,25 +3964,19 @@ public class ConnectivityServiceTest {
|
|||||||
mCallbacks.add(new CallbackValue(CallbackType.ON_ERROR, error));
|
mCallbacks.add(new CallbackValue(CallbackType.ON_ERROR, error));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void expectCallback(CallbackValue callbackValue) {
|
private void expectCallback(CallbackValue callbackValue) throws InterruptedException {
|
||||||
try {
|
assertEquals(callbackValue, mCallbacks.poll(TIMEOUT_MS, TimeUnit.MILLISECONDS));
|
||||||
assertEquals(
|
|
||||||
callbackValue,
|
|
||||||
mCallbacks.poll(TIMEOUT_MS, TimeUnit.MILLISECONDS));
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
fail(callbackValue.callbackType + " callback not seen after " + TIMEOUT_MS + " ms");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void expectStarted() {
|
public void expectStarted() throws Exception {
|
||||||
expectCallback(new CallbackValue(CallbackType.ON_STARTED));
|
expectCallback(new CallbackValue(CallbackType.ON_STARTED));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void expectStopped() {
|
public void expectStopped() throws Exception {
|
||||||
expectCallback(new CallbackValue(CallbackType.ON_STOPPED));
|
expectCallback(new CallbackValue(CallbackType.ON_STOPPED));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void expectError(int error) {
|
public void expectError(int error) throws Exception {
|
||||||
expectCallback(new CallbackValue(CallbackType.ON_ERROR, error));
|
expectCallback(new CallbackValue(CallbackType.ON_ERROR, error));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4074,25 +4037,20 @@ public class ConnectivityServiceTest {
|
|||||||
mCallbacks.add(new CallbackValue(CallbackType.ON_ERROR, error));
|
mCallbacks.add(new CallbackValue(CallbackType.ON_ERROR, error));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void expectCallback(CallbackValue callbackValue) {
|
private void expectCallback(CallbackValue callbackValue) throws InterruptedException {
|
||||||
try {
|
assertEquals(callbackValue, mCallbacks.poll(TIMEOUT_MS, TimeUnit.MILLISECONDS));
|
||||||
assertEquals(
|
|
||||||
callbackValue,
|
|
||||||
mCallbacks.poll(TIMEOUT_MS, TimeUnit.MILLISECONDS));
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
fail(callbackValue.callbackType + " callback not seen after " + TIMEOUT_MS + " ms");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void expectStarted() {
|
public void expectStarted() throws InterruptedException {
|
||||||
expectCallback(new CallbackValue(CallbackType.ON_STARTED));
|
expectCallback(new CallbackValue(CallbackType.ON_STARTED));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void expectStopped() {
|
public void expectStopped() throws InterruptedException {
|
||||||
expectCallback(new CallbackValue(CallbackType.ON_STOPPED));
|
expectCallback(new CallbackValue(CallbackType.ON_STOPPED));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void expectError(int error) {
|
public void expectError(int error) throws InterruptedException {
|
||||||
expectCallback(new CallbackValue(CallbackType.ON_ERROR, error));
|
expectCallback(new CallbackValue(CallbackType.ON_ERROR, error));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4103,7 +4061,7 @@ public class ConnectivityServiceTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Network connectKeepaliveNetwork(LinkProperties lp) {
|
private Network connectKeepaliveNetwork(LinkProperties lp) throws Exception {
|
||||||
// Ensure the network is disconnected before we do anything.
|
// Ensure the network is disconnected before we do anything.
|
||||||
if (mWiFiNetworkAgent != null) {
|
if (mWiFiNetworkAgent != null) {
|
||||||
assertNull(mCm.getNetworkCapabilities(mWiFiNetworkAgent.getNetwork()));
|
assertNull(mCm.getNetworkCapabilities(mWiFiNetworkAgent.getNetwork()));
|
||||||
@@ -4237,7 +4195,8 @@ public class ConnectivityServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Helper method to prepare the executor and run test
|
// Helper method to prepare the executor and run test
|
||||||
private void runTestWithSerialExecutors(ThrowingConsumer<Executor> functor) throws Exception {
|
private void runTestWithSerialExecutors(ExceptionUtils.ThrowingConsumer<Executor> functor)
|
||||||
|
throws Exception {
|
||||||
final ExecutorService executorSingleThread = Executors.newSingleThreadExecutor();
|
final ExecutorService executorSingleThread = Executors.newSingleThreadExecutor();
|
||||||
final Executor executorInline = (Runnable r) -> r.run();
|
final Executor executorInline = (Runnable r) -> r.run();
|
||||||
functor.accept(executorSingleThread);
|
functor.accept(executorSingleThread);
|
||||||
@@ -4555,7 +4514,7 @@ public class ConnectivityServiceTest {
|
|||||||
private static boolean isUdpPortInUse(int port) {
|
private static boolean isUdpPortInUse(int port) {
|
||||||
try (DatagramSocket ignored = new DatagramSocket(port)) {
|
try (DatagramSocket ignored = new DatagramSocket(port)) {
|
||||||
return false;
|
return false;
|
||||||
} catch (IOException ignored) {
|
} catch (IOException alreadyInUse) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4567,23 +4526,19 @@ public class ConnectivityServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static class TestNetworkPinner extends NetworkPinner {
|
private static class TestNetworkPinner extends NetworkPinner {
|
||||||
public static boolean awaitPin(int timeoutMs) {
|
public static boolean awaitPin(int timeoutMs) throws InterruptedException {
|
||||||
synchronized(sLock) {
|
synchronized(sLock) {
|
||||||
if (sNetwork == null) {
|
if (sNetwork == null) {
|
||||||
try {
|
sLock.wait(timeoutMs);
|
||||||
sLock.wait(timeoutMs);
|
|
||||||
} catch (InterruptedException e) {}
|
|
||||||
}
|
}
|
||||||
return sNetwork != null;
|
return sNetwork != null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean awaitUnpin(int timeoutMs) {
|
public static boolean awaitUnpin(int timeoutMs) throws InterruptedException {
|
||||||
synchronized(sLock) {
|
synchronized(sLock) {
|
||||||
if (sNetwork != null) {
|
if (sNetwork != null) {
|
||||||
try {
|
sLock.wait(timeoutMs);
|
||||||
sLock.wait(timeoutMs);
|
|
||||||
} catch (InterruptedException e) {}
|
|
||||||
}
|
}
|
||||||
return sNetwork == null;
|
return sNetwork == null;
|
||||||
}
|
}
|
||||||
@@ -4606,7 +4561,7 @@ public class ConnectivityServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNetworkPinner() {
|
public void testNetworkPinner() throws Exception {
|
||||||
NetworkRequest wifiRequest = new NetworkRequest.Builder()
|
NetworkRequest wifiRequest = new NetworkRequest.Builder()
|
||||||
.addTransportType(TRANSPORT_WIFI)
|
.addTransportType(TRANSPORT_WIFI)
|
||||||
.build();
|
.build();
|
||||||
@@ -4758,7 +4713,7 @@ public class ConnectivityServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNetworkInfoOfTypeNone() {
|
public void testNetworkInfoOfTypeNone() throws Exception {
|
||||||
ConditionVariable broadcastCV = waitForConnectivityBroadcasts(1);
|
ConditionVariable broadcastCV = waitForConnectivityBroadcasts(1);
|
||||||
|
|
||||||
verifyNoNetwork();
|
verifyNoNetwork();
|
||||||
@@ -4819,7 +4774,7 @@ public class ConnectivityServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLinkPropertiesEnsuresDirectlyConnectedRoutes() {
|
public void testLinkPropertiesEnsuresDirectlyConnectedRoutes() throws Exception {
|
||||||
final NetworkRequest networkRequest = new NetworkRequest.Builder()
|
final NetworkRequest networkRequest = new NetworkRequest.Builder()
|
||||||
.addTransportType(TRANSPORT_WIFI).build();
|
.addTransportType(TRANSPORT_WIFI).build();
|
||||||
final TestNetworkCallback networkCallback = new TestNetworkCallback();
|
final TestNetworkCallback networkCallback = new TestNetworkCallback();
|
||||||
@@ -5248,7 +5203,7 @@ public class ConnectivityServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVpnNetworkActive() {
|
public void testVpnNetworkActive() throws Exception {
|
||||||
final int uid = Process.myUid();
|
final int uid = Process.myUid();
|
||||||
|
|
||||||
final TestNetworkCallback genericNetworkCallback = new TestNetworkCallback();
|
final TestNetworkCallback genericNetworkCallback = new TestNetworkCallback();
|
||||||
@@ -5360,7 +5315,7 @@ public class ConnectivityServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVpnWithoutInternet() {
|
public void testVpnWithoutInternet() throws Exception {
|
||||||
final int uid = Process.myUid();
|
final int uid = Process.myUid();
|
||||||
|
|
||||||
final TestNetworkCallback defaultCallback = new TestNetworkCallback();
|
final TestNetworkCallback defaultCallback = new TestNetworkCallback();
|
||||||
@@ -5390,7 +5345,7 @@ public class ConnectivityServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVpnWithInternet() {
|
public void testVpnWithInternet() throws Exception {
|
||||||
final int uid = Process.myUid();
|
final int uid = Process.myUid();
|
||||||
|
|
||||||
final TestNetworkCallback defaultCallback = new TestNetworkCallback();
|
final TestNetworkCallback defaultCallback = new TestNetworkCallback();
|
||||||
@@ -5473,7 +5428,7 @@ public class ConnectivityServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVpnSetUnderlyingNetworks() {
|
public void testVpnSetUnderlyingNetworks() throws Exception {
|
||||||
final int uid = Process.myUid();
|
final int uid = Process.myUid();
|
||||||
|
|
||||||
final TestNetworkCallback vpnNetworkCallback = new TestNetworkCallback();
|
final TestNetworkCallback vpnNetworkCallback = new TestNetworkCallback();
|
||||||
@@ -5571,7 +5526,7 @@ public class ConnectivityServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNullUnderlyingNetworks() {
|
public void testNullUnderlyingNetworks() throws Exception {
|
||||||
final int uid = Process.myUid();
|
final int uid = Process.myUid();
|
||||||
|
|
||||||
final TestNetworkCallback vpnNetworkCallback = new TestNetworkCallback();
|
final TestNetworkCallback vpnNetworkCallback = new TestNetworkCallback();
|
||||||
@@ -5635,7 +5590,7 @@ public class ConnectivityServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsActiveNetworkMeteredOverWifi() {
|
public void testIsActiveNetworkMeteredOverWifi() throws Exception {
|
||||||
// Returns true by default when no network is available.
|
// Returns true by default when no network is available.
|
||||||
assertTrue(mCm.isActiveNetworkMetered());
|
assertTrue(mCm.isActiveNetworkMetered());
|
||||||
mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
|
mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
|
||||||
@@ -5647,7 +5602,7 @@ public class ConnectivityServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsActiveNetworkMeteredOverCell() {
|
public void testIsActiveNetworkMeteredOverCell() throws Exception {
|
||||||
// Returns true by default when no network is available.
|
// Returns true by default when no network is available.
|
||||||
assertTrue(mCm.isActiveNetworkMetered());
|
assertTrue(mCm.isActiveNetworkMetered());
|
||||||
mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
|
mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
|
||||||
@@ -5659,7 +5614,7 @@ public class ConnectivityServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsActiveNetworkMeteredOverVpnTrackingPlatformDefault() {
|
public void testIsActiveNetworkMeteredOverVpnTrackingPlatformDefault() throws Exception {
|
||||||
// Returns true by default when no network is available.
|
// Returns true by default when no network is available.
|
||||||
assertTrue(mCm.isActiveNetworkMetered());
|
assertTrue(mCm.isActiveNetworkMetered());
|
||||||
mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
|
mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
|
||||||
@@ -5713,7 +5668,7 @@ public class ConnectivityServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsActiveNetworkMeteredOverVpnSpecifyingUnderlyingNetworks() {
|
public void testIsActiveNetworkMeteredOverVpnSpecifyingUnderlyingNetworks() throws Exception {
|
||||||
// Returns true by default when no network is available.
|
// Returns true by default when no network is available.
|
||||||
assertTrue(mCm.isActiveNetworkMetered());
|
assertTrue(mCm.isActiveNetworkMetered());
|
||||||
mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
|
mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
|
||||||
@@ -5784,7 +5739,7 @@ public class ConnectivityServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsActiveNetworkMeteredOverAlwaysMeteredVpn() {
|
public void testIsActiveNetworkMeteredOverAlwaysMeteredVpn() throws Exception {
|
||||||
// Returns true by default when no network is available.
|
// Returns true by default when no network is available.
|
||||||
assertTrue(mCm.isActiveNetworkMetered());
|
assertTrue(mCm.isActiveNetworkMetered());
|
||||||
mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
|
mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
|
||||||
@@ -5831,7 +5786,7 @@ public class ConnectivityServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNetworkBlockedStatus() {
|
public void testNetworkBlockedStatus() throws Exception {
|
||||||
final TestNetworkCallback cellNetworkCallback = new TestNetworkCallback();
|
final TestNetworkCallback cellNetworkCallback = new TestNetworkCallback();
|
||||||
final NetworkRequest cellRequest = new NetworkRequest.Builder()
|
final NetworkRequest cellRequest = new NetworkRequest.Builder()
|
||||||
.addTransportType(TRANSPORT_CELLULAR)
|
.addTransportType(TRANSPORT_CELLULAR)
|
||||||
@@ -5882,7 +5837,7 @@ public class ConnectivityServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNetworkBlockedStatusBeforeAndAfterConnect() {
|
public void testNetworkBlockedStatusBeforeAndAfterConnect() throws Exception {
|
||||||
final TestNetworkCallback defaultCallback = new TestNetworkCallback();
|
final TestNetworkCallback defaultCallback = new TestNetworkCallback();
|
||||||
mCm.registerDefaultNetworkCallback(defaultCallback);
|
mCm.registerDefaultNetworkCallback(defaultCallback);
|
||||||
|
|
||||||
@@ -5951,7 +5906,7 @@ public class ConnectivityServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStackedLinkProperties() throws UnknownHostException, RemoteException {
|
public void testStackedLinkProperties() throws Exception {
|
||||||
final LinkAddress myIpv4 = new LinkAddress("1.2.3.4/24");
|
final LinkAddress myIpv4 = new LinkAddress("1.2.3.4/24");
|
||||||
final LinkAddress myIpv6 = new LinkAddress("2001:db8:1::1/64");
|
final LinkAddress myIpv6 = new LinkAddress("2001:db8:1::1/64");
|
||||||
final String kNat64PrefixString = "2001:db8:64:64:64:64::";
|
final String kNat64PrefixString = "2001:db8:64:64:64:64::";
|
||||||
@@ -6114,7 +6069,7 @@ public class ConnectivityServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDataActivityTracking() throws RemoteException {
|
public void testDataActivityTracking() throws Exception {
|
||||||
final TestNetworkCallback networkCallback = new TestNetworkCallback();
|
final TestNetworkCallback networkCallback = new TestNetworkCallback();
|
||||||
final NetworkRequest networkRequest = new NetworkRequest.Builder()
|
final NetworkRequest networkRequest = new NetworkRequest.Builder()
|
||||||
.addCapability(NET_CAPABILITY_INTERNET)
|
.addCapability(NET_CAPABILITY_INTERNET)
|
||||||
@@ -6189,21 +6144,17 @@ public class ConnectivityServiceTest {
|
|||||||
mCm.unregisterNetworkCallback(networkCallback);
|
mCm.unregisterNetworkCallback(networkCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void verifyTcpBufferSizeChange(String tcpBufferSizes) {
|
private void verifyTcpBufferSizeChange(String tcpBufferSizes) throws Exception {
|
||||||
String[] values = tcpBufferSizes.split(",");
|
String[] values = tcpBufferSizes.split(",");
|
||||||
String rmemValues = String.join(" ", values[0], values[1], values[2]);
|
String rmemValues = String.join(" ", values[0], values[1], values[2]);
|
||||||
String wmemValues = String.join(" ", values[3], values[4], values[5]);
|
String wmemValues = String.join(" ", values[3], values[4], values[5]);
|
||||||
waitForIdle();
|
waitForIdle();
|
||||||
try {
|
verify(mMockNetd, atLeastOnce()).setTcpRWmemorySize(rmemValues, wmemValues);
|
||||||
verify(mMockNetd, atLeastOnce()).setTcpRWmemorySize(rmemValues, wmemValues);
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
fail("mMockNetd should never throw RemoteException");
|
|
||||||
}
|
|
||||||
reset(mMockNetd);
|
reset(mMockNetd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTcpBufferReset() {
|
public void testTcpBufferReset() throws Exception {
|
||||||
final String testTcpBufferSizes = "1,2,3,4,5,6";
|
final String testTcpBufferSizes = "1,2,3,4,5,6";
|
||||||
|
|
||||||
mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
|
mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
|
||||||
@@ -6220,7 +6171,7 @@ public class ConnectivityServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetGlobalProxyForNetwork() {
|
public void testGetGlobalProxyForNetwork() throws Exception {
|
||||||
final ProxyInfo testProxyInfo = ProxyInfo.buildDirectProxy("test", 8888);
|
final ProxyInfo testProxyInfo = ProxyInfo.buildDirectProxy("test", 8888);
|
||||||
mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
|
mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
|
||||||
final Network wifiNetwork = mWiFiNetworkAgent.getNetwork();
|
final Network wifiNetwork = mWiFiNetworkAgent.getNetwork();
|
||||||
@@ -6229,7 +6180,7 @@ public class ConnectivityServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetProxyForActiveNetwork() {
|
public void testGetProxyForActiveNetwork() throws Exception {
|
||||||
final ProxyInfo testProxyInfo = ProxyInfo.buildDirectProxy("test", 8888);
|
final ProxyInfo testProxyInfo = ProxyInfo.buildDirectProxy("test", 8888);
|
||||||
mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
|
mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
|
||||||
mWiFiNetworkAgent.connect(true);
|
mWiFiNetworkAgent.connect(true);
|
||||||
@@ -6246,7 +6197,7 @@ public class ConnectivityServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetProxyForVPN() {
|
public void testGetProxyForVPN() throws Exception {
|
||||||
final ProxyInfo testProxyInfo = ProxyInfo.buildDirectProxy("test", 8888);
|
final ProxyInfo testProxyInfo = ProxyInfo.buildDirectProxy("test", 8888);
|
||||||
|
|
||||||
// Set up a WiFi network with no proxy
|
// Set up a WiFi network with no proxy
|
||||||
@@ -6432,7 +6383,7 @@ public class ConnectivityServiceTest {
|
|||||||
|
|
||||||
|
|
||||||
private MockNetworkAgent establishVpn(LinkProperties lp, int establishingUid,
|
private MockNetworkAgent establishVpn(LinkProperties lp, int establishingUid,
|
||||||
Set<UidRange> vpnRange) {
|
Set<UidRange> vpnRange) throws Exception {
|
||||||
final MockNetworkAgent vpnNetworkAgent = new MockNetworkAgent(TRANSPORT_VPN, lp);
|
final MockNetworkAgent vpnNetworkAgent = new MockNetworkAgent(TRANSPORT_VPN, lp);
|
||||||
vpnNetworkAgent.getNetworkCapabilities().setEstablishingVpnAppUid(establishingUid);
|
vpnNetworkAgent.getNetworkCapabilities().setEstablishingVpnAppUid(establishingUid);
|
||||||
mMockVpn.setNetworkAgent(vpnNetworkAgent);
|
mMockVpn.setNetworkAgent(vpnNetworkAgent);
|
||||||
|
|||||||
Reference in New Issue
Block a user