[VCN15] expose addUnwantedCapability and related APIs
Test: m -j doc-comment-check-docs Bug: 175662146 Merged-In: I3f2e6a99e015f09cc4405f6804eac4ae33e3dcc7 Change-Id: I3f2e6a99e015f09cc4405f6804eac4ae33e3dcc7 (cherry-picked from ag/13929102)
This commit is contained in:
@@ -639,19 +639,31 @@ public final class NetworkCapabilities implements Parcelable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes (if found) the given capability from this {@code NetworkCapability} instance.
|
||||
* Removes (if found) the given capability from this {@code NetworkCapability}
|
||||
* instance that were added via addCapability(int) or setCapabilities(int[], int[]).
|
||||
*
|
||||
* @param capability the capability to be removed.
|
||||
* @return This NetworkCapabilities instance, to facilitate chaining.
|
||||
* @hide
|
||||
*/
|
||||
public @NonNull NetworkCapabilities removeCapability(@NetCapability int capability) {
|
||||
// Note that this method removes capabilities that were added via addCapability(int),
|
||||
// addUnwantedCapability(int) or setCapabilities(int[], int[]).
|
||||
checkValidCapability(capability);
|
||||
final long mask = ~(1 << capability);
|
||||
mNetworkCapabilities &= mask;
|
||||
mUnwantedNetworkCapabilities &= mask;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes (if found) the given unwanted capability from this {@code NetworkCapability}
|
||||
* instance that were added via addUnwantedCapability(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) {
|
||||
checkValidCapability(capability);
|
||||
mUnwantedNetworkCapabilities &= ~(1 << capability);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -723,6 +735,7 @@ public final class NetworkCapabilities implements Parcelable {
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
|
||||
public boolean hasUnwantedCapability(@NetCapability int capability) {
|
||||
return isValidCapability(capability)
|
||||
&& ((mUnwantedNetworkCapabilities & (1 << capability)) != 0);
|
||||
@@ -736,10 +749,16 @@ public final class NetworkCapabilities implements Parcelable {
|
||||
return ((mNetworkCapabilities & CONNECTIVITY_MANAGED_CAPABILITIES) != 0);
|
||||
}
|
||||
|
||||
/** Note this method may result in having the same capability in wanted and unwanted lists. */
|
||||
private void combineNetCapabilities(@NonNull NetworkCapabilities nc) {
|
||||
this.mNetworkCapabilities |= nc.mNetworkCapabilities;
|
||||
this.mUnwantedNetworkCapabilities |= nc.mUnwantedNetworkCapabilities;
|
||||
final long wantedCaps = this.mNetworkCapabilities | nc.mNetworkCapabilities;
|
||||
final long unwantedCaps =
|
||||
this.mUnwantedNetworkCapabilities | nc.mUnwantedNetworkCapabilities;
|
||||
if ((wantedCaps & unwantedCaps) != 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"Cannot have the same capability in wanted and unwanted lists.");
|
||||
}
|
||||
this.mNetworkCapabilities = wantedCaps;
|
||||
this.mUnwantedNetworkCapabilities = unwantedCaps;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -305,11 +305,30 @@ public class NetworkRequest implements Parcelable {
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@NonNull
|
||||
@SuppressLint("MissingGetterMatchingBuilder")
|
||||
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
|
||||
public Builder addUnwantedCapability(@NetworkCapabilities.NetCapability int capability) {
|
||||
mNetworkCapabilities.addUnwantedCapability(capability);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes (if found) the given unwanted capability from this builder instance.
|
||||
*
|
||||
* @param capability The unwanted capability to remove.
|
||||
* @return The builder to facilitate chaining.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@NonNull
|
||||
@SuppressLint("BuilderSetStyle")
|
||||
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
|
||||
public Builder removeUnwantedCapability(@NetworkCapabilities.NetCapability int capability) {
|
||||
mNetworkCapabilities.removeUnwantedCapability(capability);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Completely clears all the {@code NetworkCapabilities} from this builder instance,
|
||||
* removing even the capabilities that are set by default when the object is constructed.
|
||||
@@ -567,6 +586,7 @@ public class NetworkRequest implements Parcelable {
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
|
||||
public boolean hasUnwantedCapability(@NetCapability int capability) {
|
||||
return networkCapabilities.hasUnwantedCapability(capability);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user