Rename unwanted capabilities to forbidden capabilities.
Addresses API council feedback.
Bug: 184890428
Test: atest FrameworksNetTests CtsNetTestCases
Test: atest CtsNetTestCasesLatestSdk:NetworkCapabilitiesTest on R device
Change-Id: Id7c68fbf56ee08fcad8e8e3aacf037fa1885936b
diff --git a/apex/jobscheduler/service/java/com/android/server/job/JobStore.java b/apex/jobscheduler/service/java/com/android/server/job/JobStore.java
index 9cd3a8f..f741596 100644
--- a/apex/jobscheduler/service/java/com/android/server/job/JobStore.java
+++ b/apex/jobscheduler/service/java/com/android/server/job/JobStore.java
@@ -554,7 +554,7 @@
out.attribute(null, "net-capabilities", Long.toString(
BitUtils.packBits(network.getCapabilities())));
out.attribute(null, "net-unwanted-capabilities", Long.toString(
- BitUtils.packBits(network.getUnwantedCapabilities())));
+ BitUtils.packBits(network.getForbiddenCapabilities())));
out.attribute(null, "net-transport-types", Long.toString(
BitUtils.packBits(network.getTransportTypes())));
@@ -977,22 +977,22 @@
String val;
final String netCapabilities = parser.getAttributeValue(null, "net-capabilities");
- final String netUnwantedCapabilities = parser.getAttributeValue(
+ final String netforbiddenCapabilities = parser.getAttributeValue(
null, "net-unwanted-capabilities");
final String netTransportTypes = parser.getAttributeValue(null, "net-transport-types");
if (netCapabilities != null && netTransportTypes != null) {
final NetworkRequest.Builder builder = new NetworkRequest.Builder()
.clearCapabilities();
- final long unwantedCapabilities = netUnwantedCapabilities != null
- ? Long.parseLong(netUnwantedCapabilities)
- : BitUtils.packBits(builder.build().getUnwantedCapabilities());
+ final long forbiddenCapabilities = netforbiddenCapabilities != null
+ ? Long.parseLong(netforbiddenCapabilities)
+ : BitUtils.packBits(builder.build().getForbiddenCapabilities());
// We're okay throwing NFE here; caught by caller
for (int capability : BitUtils.unpackBits(Long.parseLong(netCapabilities))) {
builder.addCapability(capability);
}
- for (int unwantedCapability : BitUtils.unpackBits(
- Long.parseLong(netUnwantedCapabilities))) {
- builder.addUnwantedCapability(unwantedCapability);
+ for (int forbiddenCapability : BitUtils.unpackBits(
+ Long.parseLong(netforbiddenCapabilities))) {
+ builder.addForbiddenCapability(forbiddenCapability);
}
for (int transport : BitUtils.unpackBits(Long.parseLong(netTransportTypes))) {
builder.addTransportType(transport);
diff --git a/packages/Connectivity/framework/api/module-lib-current.txt b/packages/Connectivity/framework/api/module-lib-current.txt
index 90580fa..78dff21 100644
--- a/packages/Connectivity/framework/api/module-lib-current.txt
+++ b/packages/Connectivity/framework/api/module-lib-current.txt
@@ -109,7 +109,7 @@
public final class NetworkCapabilities implements android.os.Parcelable {
method @Nullable public java.util.Set<android.util.Range<java.lang.Integer>> getUids();
- method public boolean hasUnwantedCapability(int);
+ method public boolean hasForbiddenCapability(int);
field public static final long REDACT_ALL = -1L; // 0xffffffffffffffffL
field public static final long REDACT_FOR_ACCESS_FINE_LOCATION = 1L; // 0x1L
field public static final long REDACT_FOR_LOCAL_MAC_ADDRESS = 2L; // 0x2L
@@ -123,13 +123,13 @@
}
public class NetworkRequest implements android.os.Parcelable {
- method @NonNull public int[] getUnwantedCapabilities();
- method public boolean hasUnwantedCapability(int);
+ method @NonNull public int[] getForbiddenCapabilities();
+ method public boolean hasForbiddenCapability(int);
}
public static class NetworkRequest.Builder {
- method @NonNull public android.net.NetworkRequest.Builder addUnwantedCapability(int);
- method @NonNull public android.net.NetworkRequest.Builder removeUnwantedCapability(int);
+ method @NonNull public android.net.NetworkRequest.Builder addForbiddenCapability(int);
+ method @NonNull public android.net.NetworkRequest.Builder removeForbiddenCapability(int);
method @NonNull public android.net.NetworkRequest.Builder setUids(@Nullable java.util.Set<android.util.Range<java.lang.Integer>>);
}
diff --git a/packages/Connectivity/framework/src/android/net/NetworkCapabilities.java b/packages/Connectivity/framework/src/android/net/NetworkCapabilities.java
index 775c88f..0bafd5b 100644
--- a/packages/Connectivity/framework/src/android/net/NetworkCapabilities.java
+++ b/packages/Connectivity/framework/src/android/net/NetworkCapabilities.java
@@ -183,7 +183,7 @@
throw new UnsupportedOperationException(
"Cannot clear NetworkCapabilities when mRedactions is set");
}
- mNetworkCapabilities = mTransportTypes = mUnwantedNetworkCapabilities = 0;
+ mNetworkCapabilities = mTransportTypes = mForbiddenNetworkCapabilities = 0;
mLinkUpBandwidthKbps = mLinkDownBandwidthKbps = LINK_BANDWIDTH_UNSPECIFIED;
mNetworkSpecifier = null;
mTransportInfo = null;
@@ -219,7 +219,7 @@
mUids = (nc.mUids == null) ? null : new ArraySet<>(nc.mUids);
setAdministratorUids(nc.getAdministratorUids());
mOwnerUid = nc.mOwnerUid;
- mUnwantedNetworkCapabilities = nc.mUnwantedNetworkCapabilities;
+ mForbiddenNetworkCapabilities = nc.mForbiddenNetworkCapabilities;
mSSID = nc.mSSID;
mPrivateDnsBroken = nc.mPrivateDnsBroken;
mRequestorUid = nc.mRequestorUid;
@@ -237,7 +237,7 @@
/**
* If any capabilities specified here they must not exist in the matching Network.
*/
- private long mUnwantedNetworkCapabilities;
+ private long mForbiddenNetworkCapabilities;
/** @hide */
@Retention(RetentionPolicy.SOURCE)
@@ -595,21 +595,21 @@
* @hide
*/
public @NonNull NetworkCapabilities addCapability(@NetCapability int capability) {
- // If the given capability was previously added to the list of unwanted capabilities
- // then the capability will also be removed from the list of unwanted capabilities.
- // TODO: Consider adding unwanted capabilities to the public API and mention this
+ // If the given capability was previously added to the list of forbidden capabilities
+ // then the capability will also be removed from the list of forbidden capabilities.
+ // TODO: Consider adding forbidden capabilities to the public API and mention this
// in the documentation.
checkValidCapability(capability);
mNetworkCapabilities |= 1L << capability;
- // remove from unwanted capability list
- mUnwantedNetworkCapabilities &= ~(1L << capability);
+ // remove from forbidden capability list
+ mForbiddenNetworkCapabilities &= ~(1L << capability);
return this;
}
/**
- * Adds the given capability to the list of unwanted capabilities of this
+ * Adds the given capability to the list of forbidden capabilities of this
* {@code NetworkCapability} instance. Note that when searching for a network to
- * satisfy a request, the network must not contain any capability from unwanted capability
+ * satisfy a request, the network must not contain any capability from forbidden capability
* list.
* <p>
* If the capability was previously added to the list of required capabilities (for
@@ -619,9 +619,9 @@
* @see #addCapability(int)
* @hide
*/
- public void addUnwantedCapability(@NetCapability int capability) {
+ public void addForbiddenCapability(@NetCapability int capability) {
checkValidCapability(capability);
- mUnwantedNetworkCapabilities |= 1L << capability;
+ mForbiddenNetworkCapabilities |= 1L << capability;
mNetworkCapabilities &= ~(1L << capability); // remove from requested capabilities
}
@@ -641,16 +641,16 @@
}
/**
- * Removes (if found) the given unwanted capability from this {@code NetworkCapability}
- * instance that were added via addUnwantedCapability(int) or setCapabilities(int[], int[]).
+ * Removes (if found) the given forbidden capability from this {@code NetworkCapability}
+ * instance that were added via addForbiddenCapability(int) or setCapabilities(int[], int[]).
*
* @param capability the capability to be removed.
* @return This NetworkCapabilities instance, to facilitate chaining.
* @hide
*/
- public @NonNull NetworkCapabilities removeUnwantedCapability(@NetCapability int capability) {
+ public @NonNull NetworkCapabilities removeForbiddenCapability(@NetCapability int capability) {
checkValidCapability(capability);
- mUnwantedNetworkCapabilities &= ~(1L << capability);
+ mForbiddenNetworkCapabilities &= ~(1L << capability);
return this;
}
@@ -679,13 +679,13 @@
}
/**
- * Gets all the unwanted capabilities set on this {@code NetworkCapability} instance.
+ * Gets all the forbidden capabilities set on this {@code NetworkCapability} instance.
*
- * @return an array of unwanted capability values for this instance.
+ * @return an array of forbidden capability values for this instance.
* @hide
*/
- public @NetCapability int[] getUnwantedCapabilities() {
- return NetworkCapabilitiesUtils.unpackBits(mUnwantedNetworkCapabilities);
+ public @NetCapability int[] getForbiddenCapabilities() {
+ return NetworkCapabilitiesUtils.unpackBits(mForbiddenNetworkCapabilities);
}
@@ -696,9 +696,9 @@
* @hide
*/
public void setCapabilities(@NetCapability int[] capabilities,
- @NetCapability int[] unwantedCapabilities) {
+ @NetCapability int[] forbiddenCapabilities) {
mNetworkCapabilities = NetworkCapabilitiesUtils.packBits(capabilities);
- mUnwantedNetworkCapabilities = NetworkCapabilitiesUtils.packBits(unwantedCapabilities);
+ mForbiddenNetworkCapabilities = NetworkCapabilitiesUtils.packBits(forbiddenCapabilities);
}
/**
@@ -723,9 +723,9 @@
/** @hide */
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
- public boolean hasUnwantedCapability(@NetCapability int capability) {
+ public boolean hasForbiddenCapability(@NetCapability int capability) {
return isValidCapability(capability)
- && ((mUnwantedNetworkCapabilities & (1L << capability)) != 0);
+ && ((mForbiddenNetworkCapabilities & (1L << capability)) != 0);
}
/**
@@ -755,14 +755,14 @@
private void combineNetCapabilities(@NonNull NetworkCapabilities nc) {
final long wantedCaps = this.mNetworkCapabilities | nc.mNetworkCapabilities;
- final long unwantedCaps =
- this.mUnwantedNetworkCapabilities | nc.mUnwantedNetworkCapabilities;
- if ((wantedCaps & unwantedCaps) != 0) {
+ final long forbiddenCaps =
+ this.mForbiddenNetworkCapabilities | nc.mForbiddenNetworkCapabilities;
+ if ((wantedCaps & forbiddenCaps) != 0) {
throw new IllegalArgumentException(
- "Cannot have the same capability in wanted and unwanted lists.");
+ "Cannot have the same capability in wanted and forbidden lists.");
}
this.mNetworkCapabilities = wantedCaps;
- this.mUnwantedNetworkCapabilities = unwantedCaps;
+ this.mForbiddenNetworkCapabilities = forbiddenCaps;
}
/**
@@ -773,7 +773,7 @@
* @hide
*/
public @Nullable String describeFirstNonRequestableCapability() {
- final long nonRequestable = (mNetworkCapabilities | mUnwantedNetworkCapabilities)
+ final long nonRequestable = (mNetworkCapabilities | mForbiddenNetworkCapabilities)
& NON_REQUESTABLE_CAPABILITIES;
if (nonRequestable != 0) {
@@ -790,28 +790,28 @@
private boolean satisfiedByNetCapabilities(@NonNull NetworkCapabilities nc,
boolean onlyImmutable) {
long requestedCapabilities = mNetworkCapabilities;
- long requestedUnwantedCapabilities = mUnwantedNetworkCapabilities;
+ long requestedForbiddenCapabilities = mForbiddenNetworkCapabilities;
long providedCapabilities = nc.mNetworkCapabilities;
if (onlyImmutable) {
requestedCapabilities &= ~MUTABLE_CAPABILITIES;
- requestedUnwantedCapabilities &= ~MUTABLE_CAPABILITIES;
+ requestedForbiddenCapabilities &= ~MUTABLE_CAPABILITIES;
}
return ((providedCapabilities & requestedCapabilities) == requestedCapabilities)
- && ((requestedUnwantedCapabilities & providedCapabilities) == 0);
+ && ((requestedForbiddenCapabilities & providedCapabilities) == 0);
}
/** @hide */
public boolean equalsNetCapabilities(@NonNull NetworkCapabilities nc) {
return (nc.mNetworkCapabilities == this.mNetworkCapabilities)
- && (nc.mUnwantedNetworkCapabilities == this.mUnwantedNetworkCapabilities);
+ && (nc.mForbiddenNetworkCapabilities == this.mForbiddenNetworkCapabilities);
}
private boolean equalsNetCapabilitiesRequestable(@NonNull NetworkCapabilities that) {
- return ((this.mNetworkCapabilities & ~NON_REQUESTABLE_CAPABILITIES) ==
- (that.mNetworkCapabilities & ~NON_REQUESTABLE_CAPABILITIES))
- && ((this.mUnwantedNetworkCapabilities & ~NON_REQUESTABLE_CAPABILITIES) ==
- (that.mUnwantedNetworkCapabilities & ~NON_REQUESTABLE_CAPABILITIES));
+ return ((this.mNetworkCapabilities & ~NON_REQUESTABLE_CAPABILITIES)
+ == (that.mNetworkCapabilities & ~NON_REQUESTABLE_CAPABILITIES))
+ && ((this.mForbiddenNetworkCapabilities & ~NON_REQUESTABLE_CAPABILITIES)
+ == (that.mForbiddenNetworkCapabilities & ~NON_REQUESTABLE_CAPABILITIES));
}
/**
@@ -1734,7 +1734,7 @@
* Combine a set of Capabilities to this one. Useful for coming up with the complete set.
* <p>
* Note that this method may break an invariant of having a particular capability in either
- * wanted or unwanted lists but never in both. Requests that have the same capability in
+ * wanted or forbidden lists but never in both. Requests that have the same capability in
* both lists will never be satisfied.
* @hide
*/
@@ -1875,8 +1875,8 @@
public int hashCode() {
return (int) (mNetworkCapabilities & 0xFFFFFFFF)
+ ((int) (mNetworkCapabilities >> 32) * 3)
- + ((int) (mUnwantedNetworkCapabilities & 0xFFFFFFFF) * 5)
- + ((int) (mUnwantedNetworkCapabilities >> 32) * 7)
+ + ((int) (mForbiddenNetworkCapabilities & 0xFFFFFFFF) * 5)
+ + ((int) (mForbiddenNetworkCapabilities >> 32) * 7)
+ ((int) (mTransportTypes & 0xFFFFFFFF) * 11)
+ ((int) (mTransportTypes >> 32) * 13)
+ mLinkUpBandwidthKbps * 17
@@ -1911,7 +1911,7 @@
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(mNetworkCapabilities);
- dest.writeLong(mUnwantedNetworkCapabilities);
+ dest.writeLong(mForbiddenNetworkCapabilities);
dest.writeLong(mTransportTypes);
dest.writeInt(mLinkUpBandwidthKbps);
dest.writeInt(mLinkDownBandwidthKbps);
@@ -1935,7 +1935,7 @@
NetworkCapabilities netCap = new NetworkCapabilities();
netCap.mNetworkCapabilities = in.readLong();
- netCap.mUnwantedNetworkCapabilities = in.readLong();
+ netCap.mForbiddenNetworkCapabilities = in.readLong();
netCap.mTransportTypes = in.readLong();
netCap.mLinkUpBandwidthKbps = in.readInt();
netCap.mLinkDownBandwidthKbps = in.readInt();
@@ -1989,9 +1989,9 @@
appendStringRepresentationOfBitMaskToStringBuilder(sb, mNetworkCapabilities,
NetworkCapabilities::capabilityNameOf, "&");
}
- if (0 != mUnwantedNetworkCapabilities) {
- sb.append(" Unwanted: ");
- appendStringRepresentationOfBitMaskToStringBuilder(sb, mUnwantedNetworkCapabilities,
+ if (0 != mForbiddenNetworkCapabilities) {
+ sb.append(" Forbidden: ");
+ appendStringRepresentationOfBitMaskToStringBuilder(sb, mForbiddenNetworkCapabilities,
NetworkCapabilities::capabilityNameOf, "&");
}
if (mLinkUpBandwidthKbps > 0) {
diff --git a/packages/Connectivity/framework/src/android/net/NetworkRequest.java b/packages/Connectivity/framework/src/android/net/NetworkRequest.java
index 194b8ff..a384109 100644
--- a/packages/Connectivity/framework/src/android/net/NetworkRequest.java
+++ b/packages/Connectivity/framework/src/android/net/NetworkRequest.java
@@ -311,7 +311,7 @@
*
* @see #addCapability(int)
*
- * @param capability The capability to add to unwanted capability list.
+ * @param capability The capability to add to forbidden capability list.
* @return The builder to facilitate chaining.
*
* @hide
@@ -319,15 +319,15 @@
@NonNull
@SuppressLint("MissingGetterMatchingBuilder")
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
- public Builder addUnwantedCapability(@NetworkCapabilities.NetCapability int capability) {
- mNetworkCapabilities.addUnwantedCapability(capability);
+ public Builder addForbiddenCapability(@NetworkCapabilities.NetCapability int capability) {
+ mNetworkCapabilities.addForbiddenCapability(capability);
return this;
}
/**
- * Removes (if found) the given unwanted capability from this builder instance.
+ * Removes (if found) the given forbidden capability from this builder instance.
*
- * @param capability The unwanted capability to remove.
+ * @param capability The forbidden capability to remove.
* @return The builder to facilitate chaining.
*
* @hide
@@ -335,8 +335,9 @@
@NonNull
@SuppressLint("BuilderSetStyle")
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
- public Builder removeUnwantedCapability(@NetworkCapabilities.NetCapability int capability) {
- mNetworkCapabilities.removeUnwantedCapability(capability);
+ public Builder removeForbiddenCapability(
+ @NetworkCapabilities.NetCapability int capability) {
+ mNetworkCapabilities.removeForbiddenCapability(capability);
return this;
}
@@ -598,13 +599,13 @@
}
/**
- * @see Builder#addUnwantedCapability(int)
+ * @see Builder#addForbiddenCapability(int)
*
* @hide
*/
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
- public boolean hasUnwantedCapability(@NetCapability int capability) {
- return networkCapabilities.hasUnwantedCapability(capability);
+ public boolean hasForbiddenCapability(@NetCapability int capability) {
+ return networkCapabilities.hasForbiddenCapability(capability);
}
/**
@@ -690,18 +691,18 @@
}
/**
- * Gets all the unwanted capabilities set on this {@code NetworkRequest} instance.
+ * Gets all the forbidden capabilities set on this {@code NetworkRequest} instance.
*
- * @return an array of unwanted capability values for this instance.
+ * @return an array of forbidden capability values for this instance.
*
* @hide
*/
@NonNull
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
- public @NetCapability int[] getUnwantedCapabilities() {
- // No need to make a defensive copy here as NC#getUnwantedCapabilities() already returns
+ public @NetCapability int[] getForbiddenCapabilities() {
+ // No need to make a defensive copy here as NC#getForbiddenCapabilities() already returns
// a new array.
- return networkCapabilities.getUnwantedCapabilities();
+ return networkCapabilities.getForbiddenCapabilities();
}
/**
diff --git a/services/tests/servicestests/src/com/android/server/job/JobStoreTest.java b/services/tests/servicestests/src/com/android/server/job/JobStoreTest.java
index 8b35af8..2efebbf 100644
--- a/services/tests/servicestests/src/com/android/server/job/JobStoreTest.java
+++ b/services/tests/servicestests/src/com/android/server/job/JobStoreTest.java
@@ -374,7 +374,7 @@
.setPersisted(true)
.setRequiredNetwork(new NetworkRequest.Builder()
.addCapability(NET_CAPABILITY_IMS)
- .addUnwantedCapability(NET_CAPABILITY_OEM_PAID)
+ .addForbiddenCapability(NET_CAPABILITY_OEM_PAID)
.build())
.build());
}
diff --git a/tests/net/common/java/android/net/NetworkCapabilitiesTest.java b/tests/net/common/java/android/net/NetworkCapabilitiesTest.java
index 9b74583..1c8a1bf 100644
--- a/tests/net/common/java/android/net/NetworkCapabilitiesTest.java
+++ b/tests/net/common/java/android/net/NetworkCapabilitiesTest.java
@@ -391,9 +391,11 @@
@Test
public void testOemPaid() {
NetworkCapabilities nc = new NetworkCapabilities();
- // By default OEM_PAID is neither in the unwanted or required lists and the network is not
+ // By default OEM_PAID is neither in the required or forbidden lists and the network is not
// restricted.
- assertFalse(nc.hasUnwantedCapability(NET_CAPABILITY_OEM_PAID));
+ if (isAtLeastS()) {
+ assertFalse(nc.hasForbiddenCapability(NET_CAPABILITY_OEM_PAID));
+ }
assertFalse(nc.hasCapability(NET_CAPABILITY_OEM_PAID));
nc.maybeMarkCapabilitiesRestricted();
assertTrue(nc.hasCapability(NET_CAPABILITY_NOT_RESTRICTED));
@@ -418,9 +420,9 @@
@Test @IgnoreUpTo(Build.VERSION_CODES.R)
public void testOemPrivate() {
NetworkCapabilities nc = new NetworkCapabilities();
- // By default OEM_PRIVATE is neither in the unwanted or required lists and the network is
+ // By default OEM_PRIVATE is neither in the required or forbidden lists and the network is
// not restricted.
- assertFalse(nc.hasUnwantedCapability(NET_CAPABILITY_OEM_PRIVATE));
+ assertFalse(nc.hasForbiddenCapability(NET_CAPABILITY_OEM_PRIVATE));
assertFalse(nc.hasCapability(NET_CAPABILITY_OEM_PRIVATE));
nc.maybeMarkCapabilitiesRestricted();
assertTrue(nc.hasCapability(NET_CAPABILITY_NOT_RESTRICTED));
@@ -442,8 +444,8 @@
assertFalse(nr.satisfiedByNetworkCapabilities(new NetworkCapabilities()));
}
- @Test
- public void testUnwantedCapabilities() {
+ @Test @IgnoreUpTo(Build.VERSION_CODES.R)
+ public void testForbiddenCapabilities() {
NetworkCapabilities network = new NetworkCapabilities();
NetworkCapabilities request = new NetworkCapabilities();
@@ -451,19 +453,19 @@
request.satisfiedByNetworkCapabilities(network));
// Requesting absence of capabilities that network doesn't have. Request should satisfy.
- request.addUnwantedCapability(NET_CAPABILITY_WIFI_P2P);
- request.addUnwantedCapability(NET_CAPABILITY_NOT_METERED);
+ request.addForbiddenCapability(NET_CAPABILITY_WIFI_P2P);
+ request.addForbiddenCapability(NET_CAPABILITY_NOT_METERED);
assertTrue(request.satisfiedByNetworkCapabilities(network));
- assertArrayEquals(new int[] {NET_CAPABILITY_WIFI_P2P,
+ assertArrayEquals(new int[]{NET_CAPABILITY_WIFI_P2P,
NET_CAPABILITY_NOT_METERED},
- request.getUnwantedCapabilities());
+ request.getForbiddenCapabilities());
// This is a default capability, just want to make sure its there because we use it below.
assertTrue(network.hasCapability(NET_CAPABILITY_NOT_RESTRICTED));
- // Verify that adding unwanted capability will effectively remove it from capability list.
- request.addUnwantedCapability(NET_CAPABILITY_NOT_RESTRICTED);
- assertTrue(request.hasUnwantedCapability(NET_CAPABILITY_NOT_RESTRICTED));
+ // Verify that adding forbidden capability will effectively remove it from capability list.
+ request.addForbiddenCapability(NET_CAPABILITY_NOT_RESTRICTED);
+ assertTrue(request.hasForbiddenCapability(NET_CAPABILITY_NOT_RESTRICTED));
assertFalse(request.hasCapability(NET_CAPABILITY_NOT_RESTRICTED));
// Now this request won't be satisfied because network contains NOT_RESTRICTED.
@@ -471,10 +473,10 @@
network.removeCapability(NET_CAPABILITY_NOT_RESTRICTED);
assertTrue(request.satisfiedByNetworkCapabilities(network));
- // Verify that adding capability will effectively remove it from unwanted list
+ // Verify that adding capability will effectively remove it from forbidden list
request.addCapability(NET_CAPABILITY_NOT_RESTRICTED);
assertTrue(request.hasCapability(NET_CAPABILITY_NOT_RESTRICTED));
- assertFalse(request.hasUnwantedCapability(NET_CAPABILITY_NOT_RESTRICTED));
+ assertFalse(request.hasForbiddenCapability(NET_CAPABILITY_NOT_RESTRICTED));
assertFalse(request.satisfiedByNetworkCapabilities(network));
network.addCapability(NET_CAPABILITY_NOT_RESTRICTED);
@@ -513,24 +515,20 @@
assertTrue(nc1.equalsNetCapabilities(nc2));
assertEquals(nc1, nc2);
- nc1.addUnwantedCapability(NET_CAPABILITY_INTERNET);
- assertFalse(nc1.equalsNetCapabilities(nc2));
- nc2.addUnwantedCapability(NET_CAPABILITY_INTERNET);
- assertTrue(nc1.equalsNetCapabilities(nc2));
if (isAtLeastS()) {
- // Remove a required capability doesn't affect unwanted capabilities.
- // This is a behaviour change from S.
+ nc1.addForbiddenCapability(NET_CAPABILITY_INTERNET);
+ assertFalse(nc1.equalsNetCapabilities(nc2));
+ nc2.addForbiddenCapability(NET_CAPABILITY_INTERNET);
+ assertTrue(nc1.equalsNetCapabilities(nc2));
+
+ // Remove a required capability doesn't affect forbidden capabilities.
+ // This is a behaviour change from R to S.
nc1.removeCapability(NET_CAPABILITY_INTERNET);
assertTrue(nc1.equalsNetCapabilities(nc2));
- nc1.removeUnwantedCapability(NET_CAPABILITY_INTERNET);
+ nc1.removeForbiddenCapability(NET_CAPABILITY_INTERNET);
assertFalse(nc1.equalsNetCapabilities(nc2));
- nc2.removeUnwantedCapability(NET_CAPABILITY_INTERNET);
- assertTrue(nc1.equalsNetCapabilities(nc2));
- } else {
- nc1.removeCapability(NET_CAPABILITY_INTERNET);
- assertFalse(nc1.equalsNetCapabilities(nc2));
- nc2.removeCapability(NET_CAPABILITY_INTERNET);
+ nc2.removeForbiddenCapability(NET_CAPABILITY_INTERNET);
assertTrue(nc1.equalsNetCapabilities(nc2));
}
}
@@ -582,31 +580,25 @@
NetworkCapabilities nc1 = new NetworkCapabilities();
NetworkCapabilities nc2 = new NetworkCapabilities();
- nc1.addUnwantedCapability(NET_CAPABILITY_CAPTIVE_PORTAL);
+ if (isAtLeastS()) {
+ nc1.addForbiddenCapability(NET_CAPABILITY_CAPTIVE_PORTAL);
+ }
nc1.addCapability(NET_CAPABILITY_NOT_ROAMING);
assertNotEquals(nc1, nc2);
nc2.combineCapabilities(nc1);
assertEquals(nc1, nc2);
assertTrue(nc2.hasCapability(NET_CAPABILITY_NOT_ROAMING));
- assertTrue(nc2.hasUnwantedCapability(NET_CAPABILITY_CAPTIVE_PORTAL));
-
- // This will effectively move NOT_ROAMING capability from required to unwanted for nc1.
- nc1.addUnwantedCapability(NET_CAPABILITY_NOT_ROAMING);
+ if (isAtLeastS()) {
+ assertTrue(nc2.hasForbiddenCapability(NET_CAPABILITY_CAPTIVE_PORTAL));
+ }
if (isAtLeastS()) {
- // From S, it is not allowed to have the same capability in both wanted and
- // unwanted list.
+ // This will effectively move NOT_ROAMING capability from required to forbidden for nc1.
+ nc1.addForbiddenCapability(NET_CAPABILITY_NOT_ROAMING);
+ // It is not allowed to have the same capability in both wanted and forbidden list.
assertThrows(IllegalArgumentException.class, () -> nc2.combineCapabilities(nc1));
- // Remove unwanted capability to continue other tests.
- nc1.removeUnwantedCapability(NET_CAPABILITY_NOT_ROAMING);
- } else {
- nc2.combineCapabilities(nc1);
- // We will get this capability in both requested and unwanted lists thus this request
- // will never be satisfied.
- assertTrue(nc2.hasCapability(NET_CAPABILITY_NOT_ROAMING));
- assertTrue(nc2.hasUnwantedCapability(NET_CAPABILITY_NOT_ROAMING));
- // For R or below, remove unwanted capability via removeCapability.
- nc1.removeCapability(NET_CAPABILITY_NOT_ROAMING);
+ // Remove forbidden capability to continue other tests.
+ nc1.removeForbiddenCapability(NET_CAPABILITY_NOT_ROAMING);
}
nc1.setSSID(TEST_SSID);
@@ -684,14 +676,11 @@
public void testSetCapabilities() {
final int[] REQUIRED_CAPABILITIES = new int[] {
NET_CAPABILITY_INTERNET, NET_CAPABILITY_NOT_VPN };
- final int[] UNWANTED_CAPABILITIES = new int[] {
- NET_CAPABILITY_NOT_RESTRICTED, NET_CAPABILITY_NOT_METERED
- };
NetworkCapabilities nc1 = new NetworkCapabilities();
NetworkCapabilities nc2 = new NetworkCapabilities();
- nc1.setCapabilities(REQUIRED_CAPABILITIES, UNWANTED_CAPABILITIES);
+ nc1.setCapabilities(REQUIRED_CAPABILITIES);
assertArrayEquals(REQUIRED_CAPABILITIES, nc1.getCapabilities());
// Verify that setting and adding capabilities leads to the same object state.
@@ -699,10 +688,25 @@
for (int cap : REQUIRED_CAPABILITIES) {
nc2.addCapability(cap);
}
- for (int cap : UNWANTED_CAPABILITIES) {
- nc2.addUnwantedCapability(cap);
- }
assertEquals(nc1, nc2);
+
+ if (isAtLeastS()) {
+ final int[] forbiddenCapabilities = new int[]{
+ NET_CAPABILITY_NOT_METERED, NET_CAPABILITY_NOT_RESTRICTED };
+
+ nc1.setCapabilities(REQUIRED_CAPABILITIES, forbiddenCapabilities);
+ assertArrayEquals(REQUIRED_CAPABILITIES, nc1.getCapabilities());
+ assertArrayEquals(forbiddenCapabilities, nc1.getForbiddenCapabilities());
+
+ nc2.clearAll();
+ for (int cap : REQUIRED_CAPABILITIES) {
+ nc2.addCapability(cap);
+ }
+ for (int cap : forbiddenCapabilities) {
+ nc2.addForbiddenCapability(cap);
+ }
+ assertEquals(nc1, nc2);
+ }
}
@Test
@@ -770,23 +774,32 @@
NetworkCapabilities nc1 = new NetworkCapabilities();
NetworkCapabilities nc2 = new NetworkCapabilities();
- nc1.addUnwantedCapability(NET_CAPABILITY_CAPTIVE_PORTAL);
+ if (isAtLeastS()) {
+ nc1.addForbiddenCapability(NET_CAPABILITY_CAPTIVE_PORTAL);
+ }
nc1.addCapability(NET_CAPABILITY_NOT_ROAMING);
assertNotEquals(nc1, nc2);
nc2.set(nc1);
assertEquals(nc1, nc2);
assertTrue(nc2.hasCapability(NET_CAPABILITY_NOT_ROAMING));
- assertTrue(nc2.hasUnwantedCapability(NET_CAPABILITY_CAPTIVE_PORTAL));
+ if (isAtLeastS()) {
+ assertTrue(nc2.hasForbiddenCapability(NET_CAPABILITY_CAPTIVE_PORTAL));
+ }
- // This will effectively move NOT_ROAMING capability from required to unwanted for nc1.
- nc1.addUnwantedCapability(NET_CAPABILITY_NOT_ROAMING);
+ if (isAtLeastS()) {
+ // This will effectively move NOT_ROAMING capability from required to forbidden for nc1.
+ nc1.addForbiddenCapability(NET_CAPABILITY_NOT_ROAMING);
+ }
nc1.setSSID(TEST_SSID);
nc2.set(nc1);
assertEquals(nc1, nc2);
- // Contrary to combineCapabilities, set() will have removed the NOT_ROAMING capability
- // from nc2.
- assertFalse(nc2.hasCapability(NET_CAPABILITY_NOT_ROAMING));
- assertTrue(nc2.hasUnwantedCapability(NET_CAPABILITY_NOT_ROAMING));
+ if (isAtLeastS()) {
+ // Contrary to combineCapabilities, set() will have removed the NOT_ROAMING capability
+ // from nc2.
+ assertFalse(nc2.hasCapability(NET_CAPABILITY_NOT_ROAMING));
+ assertTrue(nc2.hasForbiddenCapability(NET_CAPABILITY_NOT_ROAMING));
+ }
+
if (isAtLeastR()) {
assertTrue(TEST_SSID.equals(nc2.getSsid()));
}