Merge "Add NetworkCapabilities#deduceRestrictedCapability" am: 0e82d1c50d am: 2d976e6c9e am: 02ee974ee1
Change-Id: I9d593d245287362aad82d70ac5fed4d6339f82d7
This commit is contained in:
@@ -587,15 +587,14 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the NET_CAPABILITY_NOT_RESTRICTED capability if all the capabilities it provides are
|
* Deduces that all the capabilities it provides are typically provided by restricted networks
|
||||||
* typically provided by restricted networks.
|
* or not.
|
||||||
*
|
*
|
||||||
* TODO: consider:
|
* @return {@code true} if the network should be restricted.
|
||||||
* - Renaming it to guessRestrictedCapability and make it set the
|
|
||||||
* restricted capability bit in addition to clearing it.
|
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public void maybeMarkCapabilitiesRestricted() {
|
@SystemApi
|
||||||
|
public boolean deduceRestrictedCapability() {
|
||||||
// Check if we have any capability that forces the network to be restricted.
|
// Check if we have any capability that forces the network to be restricted.
|
||||||
final boolean forceRestrictedCapability =
|
final boolean forceRestrictedCapability =
|
||||||
(mNetworkCapabilities & FORCE_RESTRICTED_CAPABILITIES) != 0;
|
(mNetworkCapabilities & FORCE_RESTRICTED_CAPABILITIES) != 0;
|
||||||
@@ -609,8 +608,17 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
final boolean hasRestrictedCapabilities =
|
final boolean hasRestrictedCapabilities =
|
||||||
(mNetworkCapabilities & RESTRICTED_CAPABILITIES) != 0;
|
(mNetworkCapabilities & RESTRICTED_CAPABILITIES) != 0;
|
||||||
|
|
||||||
if (forceRestrictedCapability
|
return forceRestrictedCapability
|
||||||
|| (hasRestrictedCapabilities && !hasUnrestrictedCapabilities)) {
|
|| (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);
|
removeCapability(NET_CAPABILITY_NOT_RESTRICTED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user