NetworkCapabilities: fix describeImmutableDifferences

This patch fixes the mask used in describeImmutableDifferences which did
not correctly turn NET_CAPABILITY_NOT_METERED into bit flag.

Bug: 63326103
Test: added unit tests, runtest frameworks-net
Change-Id: Ib6b390b1daef5912859302692af7dcd6cfd3e39a
This commit is contained in:
Hugo Benichi
2017-08-04 13:18:40 +09:00
parent 59e6fc6d27
commit 99806e5606
2 changed files with 46 additions and 1 deletions

View File

@@ -21,10 +21,14 @@ import static android.net.NetworkCapabilities.NET_CAPABILITY_EIMS;
import static android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET;
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_METERED;
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED;
import static android.net.NetworkCapabilities.NET_CAPABILITY_VALIDATED;
import static android.net.NetworkCapabilities.RESTRICTED_CAPABILITIES;
import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
import static android.net.NetworkCapabilities.TRANSPORT_WIFI;
import static android.net.NetworkCapabilities.UNRESTRICTED_CAPABILITIES;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
@@ -114,4 +118,45 @@ public class NetworkCapabilitiesTest {
assertFalse(netCap.hasCapability(NET_CAPABILITY_NOT_RESTRICTED));
}
@Test
public void testDescribeImmutableDifferences() {
NetworkCapabilities nc1;
NetworkCapabilities nc2;
// Transports changing
nc1 = new NetworkCapabilities().addTransportType(TRANSPORT_CELLULAR);
nc2 = new NetworkCapabilities().addTransportType(TRANSPORT_WIFI);
assertNotEquals("", nc1.describeImmutableDifferences(nc2));
assertEquals("", nc1.describeImmutableDifferences(nc1));
// Mutable capability changing
nc1 = new NetworkCapabilities().addCapability(NET_CAPABILITY_VALIDATED);
nc2 = new NetworkCapabilities();
assertEquals("", nc1.describeImmutableDifferences(nc2));
assertEquals("", nc1.describeImmutableDifferences(nc1));
// NOT_METERED changing (http://b/63326103)
nc1 = new NetworkCapabilities()
.addCapability(NET_CAPABILITY_NOT_METERED)
.addCapability(NET_CAPABILITY_INTERNET);
nc2 = new NetworkCapabilities().addCapability(NET_CAPABILITY_INTERNET);
assertEquals("", nc1.describeImmutableDifferences(nc2));
assertEquals("", nc1.describeImmutableDifferences(nc1));
// Immutable capability changing
nc1 = new NetworkCapabilities()
.addCapability(NET_CAPABILITY_INTERNET)
.removeCapability(NET_CAPABILITY_NOT_RESTRICTED);
nc2 = new NetworkCapabilities().addCapability(NET_CAPABILITY_INTERNET);
assertNotEquals("", nc1.describeImmutableDifferences(nc2));
assertEquals("", nc1.describeImmutableDifferences(nc1));
// Specifier changing
nc1 = new NetworkCapabilities().addTransportType(TRANSPORT_WIFI);
nc2 = new NetworkCapabilities()
.addTransportType(TRANSPORT_WIFI)
.setNetworkSpecifier(new StringNetworkSpecifier("specs"));
assertNotEquals("", nc1.describeImmutableDifferences(nc2));
assertEquals("", nc1.describeImmutableDifferences(nc1));
}
}