[VCN07] Bypass VCN for non-internet app accessible cellular services
Deduce the NET_CAPABILITY_NOT_VCN_MANAGED capability from other
capabilities and user intention, which includes:
1. For the requests that don't have anything besides
VCN_SUPPORTED_CAPABILITIES, add the NOT_VCN_MANAGED to
allow the callers automatically utilize VCN networks
if available.
2. For the requests that explicitly add or remove
NOT_VCN_MANAGED, do not alter them to allow user fire
request that suits their need.
Test: atest NetworkRequestTest#testBypassingVcnForNonInternetRequest
Bug: 175662146
Change-Id: I2876264cee14b624c89ba3b380027a8b521ad8ea
(cherry-picked from aosp/1549817)
This commit is contained in:
@@ -16,6 +16,22 @@
|
||||
|
||||
package android.net;
|
||||
|
||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_CAPTIVE_PORTAL;
|
||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_DUN;
|
||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_FOREGROUND;
|
||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET;
|
||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_CONGESTED;
|
||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_METERED;
|
||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED;
|
||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_ROAMING;
|
||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_SUSPENDED;
|
||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_VCN_MANAGED;
|
||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_VPN;
|
||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_PARTIAL_CONNECTIVITY;
|
||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_TEMPORARILY_NOT_METERED;
|
||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_TRUSTED;
|
||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_VALIDATED;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.RequiresPermission;
|
||||
@@ -30,6 +46,8 @@ import android.os.Process;
|
||||
import android.text.TextUtils;
|
||||
import android.util.proto.ProtoOutputStream;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -154,8 +172,30 @@ public class NetworkRequest implements Parcelable {
|
||||
* needed in terms of {@link NetworkCapabilities} features
|
||||
*/
|
||||
public static class Builder {
|
||||
/**
|
||||
* Capabilities that are currently compatible with VCN networks.
|
||||
*/
|
||||
private static final List<Integer> VCN_SUPPORTED_CAPABILITIES = Arrays.asList(
|
||||
NET_CAPABILITY_CAPTIVE_PORTAL,
|
||||
NET_CAPABILITY_DUN,
|
||||
NET_CAPABILITY_FOREGROUND,
|
||||
NET_CAPABILITY_INTERNET,
|
||||
NET_CAPABILITY_NOT_CONGESTED,
|
||||
NET_CAPABILITY_NOT_METERED,
|
||||
NET_CAPABILITY_NOT_RESTRICTED,
|
||||
NET_CAPABILITY_NOT_ROAMING,
|
||||
NET_CAPABILITY_NOT_SUSPENDED,
|
||||
NET_CAPABILITY_NOT_VPN,
|
||||
NET_CAPABILITY_PARTIAL_CONNECTIVITY,
|
||||
NET_CAPABILITY_TEMPORARILY_NOT_METERED,
|
||||
NET_CAPABILITY_TRUSTED,
|
||||
NET_CAPABILITY_VALIDATED);
|
||||
|
||||
private final NetworkCapabilities mNetworkCapabilities;
|
||||
|
||||
// A boolean that represents the user modified NOT_VCN_MANAGED capability.
|
||||
private boolean mModifiedNotVcnManaged = false;
|
||||
|
||||
/**
|
||||
* Default constructor for Builder.
|
||||
*/
|
||||
@@ -177,6 +217,7 @@ public class NetworkRequest implements Parcelable {
|
||||
// maybeMarkCapabilitiesRestricted() doesn't add back.
|
||||
final NetworkCapabilities nc = new NetworkCapabilities(mNetworkCapabilities);
|
||||
nc.maybeMarkCapabilitiesRestricted();
|
||||
deduceNotVcnManagedCapability(nc);
|
||||
return new NetworkRequest(nc, ConnectivityManager.TYPE_NONE,
|
||||
ConnectivityManager.REQUEST_ID_UNSET, Type.NONE);
|
||||
}
|
||||
@@ -193,6 +234,9 @@ public class NetworkRequest implements Parcelable {
|
||||
*/
|
||||
public Builder addCapability(@NetworkCapabilities.NetCapability int capability) {
|
||||
mNetworkCapabilities.addCapability(capability);
|
||||
if (capability == NetworkCapabilities.NET_CAPABILITY_NOT_VCN_MANAGED) {
|
||||
mModifiedNotVcnManaged = true;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -204,6 +248,9 @@ public class NetworkRequest implements Parcelable {
|
||||
*/
|
||||
public Builder removeCapability(@NetworkCapabilities.NetCapability int capability) {
|
||||
mNetworkCapabilities.removeCapability(capability);
|
||||
if (capability == NetworkCapabilities.NET_CAPABILITY_NOT_VCN_MANAGED) {
|
||||
mModifiedNotVcnManaged = true;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -261,6 +308,9 @@ public class NetworkRequest implements Parcelable {
|
||||
@NonNull
|
||||
public Builder clearCapabilities() {
|
||||
mNetworkCapabilities.clearAll();
|
||||
// If the caller explicitly clear all capabilities, the NOT_VCN_MANAGED capabilities
|
||||
// should not be add back later.
|
||||
mModifiedNotVcnManaged = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -380,6 +430,25 @@ public class NetworkRequest implements Parcelable {
|
||||
mNetworkCapabilities.setSignalStrength(signalStrength);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deduce the NET_CAPABILITY_NOT_VCN_MANAGED capability from other capabilities
|
||||
* and user intention, which includes:
|
||||
* 1. For the requests that don't have anything besides
|
||||
* {@link #VCN_SUPPORTED_CAPABILITIES}, add the NET_CAPABILITY_NOT_VCN_MANAGED to
|
||||
* allow the callers automatically utilize VCN networks if available.
|
||||
* 2. For the requests that explicitly add or remove NET_CAPABILITY_NOT_VCN_MANAGED,
|
||||
* do not alter them to allow user fire request that suits their need.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
private void deduceNotVcnManagedCapability(final NetworkCapabilities nc) {
|
||||
if (mModifiedNotVcnManaged) return;
|
||||
for (final int cap : nc.getCapabilities()) {
|
||||
if (!VCN_SUPPORTED_CAPABILITIES.contains(cap)) return;
|
||||
}
|
||||
nc.addCapability(NET_CAPABILITY_NOT_VCN_MANAGED);
|
||||
}
|
||||
}
|
||||
|
||||
// implement the Parcelable interface
|
||||
|
||||
Reference in New Issue
Block a user