Merge "Mark networks with OEM_PAID always restricted"

This commit is contained in:
Lorenzo Colitti
2018-03-30 07:00:54 +00:00
committed by Gerrit Code Review
2 changed files with 34 additions and 8 deletions

View File

@@ -273,14 +273,28 @@ public class NetworkCapabilitiesTest {
@Test
public void testOemPaid() {
NetworkCapabilities nc = new NetworkCapabilities();
nc.maybeMarkCapabilitiesRestricted();
// By default OEM_PAID is neither in the unwanted or required lists and the network is not
// restricted.
assertFalse(nc.hasUnwantedCapability(NET_CAPABILITY_OEM_PAID));
assertFalse(nc.hasCapability(NET_CAPABILITY_OEM_PAID));
nc.maybeMarkCapabilitiesRestricted();
assertTrue(nc.hasCapability(NET_CAPABILITY_NOT_RESTRICTED));
// Adding OEM_PAID to capability list should make network restricted.
nc.addCapability(NET_CAPABILITY_OEM_PAID);
nc.addCapability(NET_CAPABILITY_INTERNET); // Combine with unrestricted capability.
nc.maybeMarkCapabilitiesRestricted();
assertTrue(nc.hasCapability(NET_CAPABILITY_OEM_PAID));
assertFalse(nc.hasCapability(NET_CAPABILITY_NOT_RESTRICTED));
// Now let's make request for OEM_PAID network.
NetworkCapabilities nr = new NetworkCapabilities();
nr.addCapability(NET_CAPABILITY_OEM_PAID);
nr.maybeMarkCapabilitiesRestricted();
assertTrue(nr.satisfiedByNetworkCapabilities(nc));
// Request fails for network with the default capabilities.
assertFalse(nr.satisfiedByNetworkCapabilities(new NetworkCapabilities()));
}
@Test
@@ -295,7 +309,8 @@ public class NetworkCapabilitiesTest {
request.addUnwantedCapability(NET_CAPABILITY_WIFI_P2P);
request.addUnwantedCapability(NET_CAPABILITY_NOT_METERED);
assertTrue(request.satisfiedByNetworkCapabilities(network));
assertArrayEquals(new int[] {NET_CAPABILITY_WIFI_P2P, NET_CAPABILITY_NOT_METERED},
assertArrayEquals(new int[] {NET_CAPABILITY_WIFI_P2P,
NET_CAPABILITY_NOT_METERED},
request.getUnwantedCapabilities());
// This is a default capability, just want to make sure its there because we use it below.