Loading core/java/android/net/NetworkCapabilities.java +1 −1 Original line number Diff line number Diff line Loading @@ -775,7 +775,7 @@ public final class NetworkCapabilities implements Parcelable { // TODO: consider only enforcing that capabilities are not removed, allowing addition. // Ignore NOT_METERED being added or removed as it is effectively dynamic. http://b/63326103 // TODO: properly support NOT_METERED as a mutable and requestable capability. final long mask = ~MUTABLE_CAPABILITIES & ~NET_CAPABILITY_NOT_METERED; final long mask = ~MUTABLE_CAPABILITIES & ~(1 << NET_CAPABILITY_NOT_METERED); long oldImmutableCapabilities = this.mNetworkCapabilities & mask; long newImmutableCapabilities = that.mNetworkCapabilities & mask; if (oldImmutableCapabilities != newImmutableCapabilities) { Loading tests/net/java/android/net/NetworkCapabilitiesTest.java +45 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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)); } } Loading
core/java/android/net/NetworkCapabilities.java +1 −1 Original line number Diff line number Diff line Loading @@ -775,7 +775,7 @@ public final class NetworkCapabilities implements Parcelable { // TODO: consider only enforcing that capabilities are not removed, allowing addition. // Ignore NOT_METERED being added or removed as it is effectively dynamic. http://b/63326103 // TODO: properly support NOT_METERED as a mutable and requestable capability. final long mask = ~MUTABLE_CAPABILITIES & ~NET_CAPABILITY_NOT_METERED; final long mask = ~MUTABLE_CAPABILITIES & ~(1 << NET_CAPABILITY_NOT_METERED); long oldImmutableCapabilities = this.mNetworkCapabilities & mask; long newImmutableCapabilities = that.mNetworkCapabilities & mask; if (oldImmutableCapabilities != newImmutableCapabilities) { Loading
tests/net/java/android/net/NetworkCapabilitiesTest.java +45 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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)); } }