Add NetworkCapabilities#deduceRestrictedCapability

Support telephony mainline module usage.

Bug: 138306002
Test: atest FrameworksNetTests
      atest CtsNetTestCases --instant

Change-Id: Idbd9c547eff7227085c753461b901c7cdbe396fb
This commit is contained in:
paulhu
2020-01-09 17:08:11 +08:00
parent 9a00f5be3b
commit 9c7a0fa46a

View File

@@ -587,15 +587,14 @@ public final class NetworkCapabilities implements Parcelable {
}
/**
* Removes the NET_CAPABILITY_NOT_RESTRICTED capability if all the capabilities it provides are
* typically provided by restricted networks.
* Deduces that all the capabilities it provides are typically provided by restricted networks
* or not.
*
* TODO: consider:
* - Renaming it to guessRestrictedCapability and make it set the
* restricted capability bit in addition to clearing it.
* @return {@code true} if the network should be restricted.
* @hide
*/
public void maybeMarkCapabilitiesRestricted() {
@SystemApi
public boolean deduceRestrictedCapability() {
// Check if we have any capability that forces the network to be restricted.
final boolean forceRestrictedCapability =
(mNetworkCapabilities & FORCE_RESTRICTED_CAPABILITIES) != 0;
@@ -609,8 +608,17 @@ public final class NetworkCapabilities implements Parcelable {
final boolean hasRestrictedCapabilities =
(mNetworkCapabilities & RESTRICTED_CAPABILITIES) != 0;
if (forceRestrictedCapability
|| (hasRestrictedCapabilities && !hasUnrestrictedCapabilities)) {
return forceRestrictedCapability
|| (hasRestrictedCapabilities && !hasUnrestrictedCapabilities);
}
/**
* Removes the NET_CAPABILITY_NOT_RESTRICTED capability if deducing the network is restricted.
*
* @hide
*/
public void maybeMarkCapabilitiesRestricted() {
if (deduceRestrictedCapability()) {
removeCapability(NET_CAPABILITY_NOT_RESTRICTED);
}
}