Merge "Mark Restricted APN connections as restricted."
This commit is contained in:
@@ -18,7 +18,8 @@ package android.net;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -229,7 +230,8 @@ public final class NetworkCapabilities implements Parcelable {
|
||||
* Capabilities that suggest that a network is restricted.
|
||||
* {@see #maybeMarkCapabilitiesRestricted}.
|
||||
*/
|
||||
private static final long RESTRICTED_CAPABILITIES =
|
||||
@VisibleForTesting
|
||||
/* package */ static final long RESTRICTED_CAPABILITIES =
|
||||
(1 << NET_CAPABILITY_CBS) |
|
||||
(1 << NET_CAPABILITY_DUN) |
|
||||
(1 << NET_CAPABILITY_EIMS) |
|
||||
@@ -239,6 +241,17 @@ public final class NetworkCapabilities implements Parcelable {
|
||||
(1 << NET_CAPABILITY_RCS) |
|
||||
(1 << NET_CAPABILITY_XCAP);
|
||||
|
||||
/**
|
||||
* Capabilities that suggest that a network is unrestricted.
|
||||
* {@see #maybeMarkCapabilitiesRestricted}.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
/* package */ static final long UNRESTRICTED_CAPABILITIES =
|
||||
(1 << NET_CAPABILITY_INTERNET) |
|
||||
(1 << NET_CAPABILITY_MMS) |
|
||||
(1 << NET_CAPABILITY_SUPL) |
|
||||
(1 << NET_CAPABILITY_WIFI_P2P);
|
||||
|
||||
/**
|
||||
* Adds the given capability to this {@code NetworkCapability} instance.
|
||||
* Multiple capabilities may be applied sequentially. Note that when searching
|
||||
@@ -365,12 +378,16 @@ public final class NetworkCapabilities implements Parcelable {
|
||||
* @hide
|
||||
*/
|
||||
public void maybeMarkCapabilitiesRestricted() {
|
||||
// If all the capabilities are typically provided by restricted networks, conclude that this
|
||||
// network is restricted.
|
||||
if ((mNetworkCapabilities & ~(DEFAULT_CAPABILITIES | RESTRICTED_CAPABILITIES)) == 0 &&
|
||||
// Must have at least some restricted capabilities, otherwise a request for an
|
||||
// internet-less network will get marked restricted.
|
||||
(mNetworkCapabilities & RESTRICTED_CAPABILITIES) != 0) {
|
||||
// Verify there aren't any unrestricted capabilities. If there are we say
|
||||
// the whole thing is unrestricted.
|
||||
final boolean hasUnrestrictedCapabilities =
|
||||
((mNetworkCapabilities & UNRESTRICTED_CAPABILITIES) != 0);
|
||||
|
||||
// Must have at least some restricted capabilities.
|
||||
final boolean hasRestrictedCapabilities =
|
||||
((mNetworkCapabilities & RESTRICTED_CAPABILITIES) != 0);
|
||||
|
||||
if (hasRestrictedCapabilities && !hasUnrestrictedCapabilities) {
|
||||
removeCapability(NET_CAPABILITY_NOT_RESTRICTED);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user