From 8bdf0c9b146d083483bb41b47b44ccf9890ef01f Mon Sep 17 00:00:00 2001 From: Yan Yan Date: Fri, 27 Jan 2023 20:03:01 +0000 Subject: [PATCH] Define @IntDef for setRestrictedUnderlyingNetworkTransports This commit also improves the API doc to explain the result of a network being restricted. Bug: 262448368 Test: make Change-Id: Idb7fde0f925048b4abba55b6f6b74a27c0a37bd3 --- core/java/android/net/vcn/VcnConfig.java | 32 +++++++++++++++++++----- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/core/java/android/net/vcn/VcnConfig.java b/core/java/android/net/vcn/VcnConfig.java index dcf002613b80e..6f9c9dd918d1e 100644 --- a/core/java/android/net/vcn/VcnConfig.java +++ b/core/java/android/net/vcn/VcnConfig.java @@ -22,6 +22,7 @@ import static com.android.internal.annotations.VisibleForTesting.Visibility; import static com.android.server.vcn.util.PersistableBundleUtils.INTEGER_DESERIALIZER; import static com.android.server.vcn.util.PersistableBundleUtils.INTEGER_SERIALIZER; +import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.content.Context; @@ -37,6 +38,10 @@ import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.Preconditions; import com.android.server.vcn.util.PersistableBundleUtils; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; @@ -54,6 +59,17 @@ import java.util.Set; public final class VcnConfig implements Parcelable { @NonNull private static final String TAG = VcnConfig.class.getSimpleName(); + /** @hide */ + @Retention(RetentionPolicy.SOURCE) + @IntDef( + prefix = {"TRANSPORT_"}, + value = { + NetworkCapabilities.TRANSPORT_CELLULAR, + NetworkCapabilities.TRANSPORT_WIFI, + }) + @Target({ElementType.TYPE_USE}) + public @interface VcnUnderlyingNetworkTransport {} + private static final Set ALLOWED_TRANSPORTS = new ArraySet<>(); static { @@ -164,7 +180,7 @@ public final class VcnConfig implements Parcelable { * @see Builder#setRestrictedUnderlyingNetworkTransports(Set) */ @NonNull - public Set getRestrictedUnderlyingNetworkTransports() { + public Set<@VcnUnderlyingNetworkTransport Integer> getRestrictedUnderlyingNetworkTransports() { return Collections.unmodifiableSet(mRestrictedTransports); } @@ -308,16 +324,20 @@ public final class VcnConfig implements Parcelable { /** * Sets transports that will be restricted by the VCN. * - * @param transports transports that will be restricted by VCN. Networks that include any - * of the transports will be marked as restricted. Only {@link - * NetworkCapabilities#TRANSPORT_WIFI} and {@link - * NetworkCapabilities#TRANSPORT_CELLULAR} are allowed. {@link + *

In general, apps will not be able to bind to, or use a restricted network. In other + * words, unless the network type is marked restricted, any app can opt to use underlying + * networks, instead of through the VCN. + * + * @param transports transports that will be restricted by VCN. Networks that include any of + * the transports will be marked as restricted. {@link * NetworkCapabilities#TRANSPORT_WIFI} is marked restricted by default. * @return this {@link Builder} instance, for chaining * @throws IllegalArgumentException if the input contains unsupported transport types. + * @see NetworkCapabilities#NET_CAPABILITY_NOT_RESTRICTED */ @NonNull - public Builder setRestrictedUnderlyingNetworkTransports(@NonNull Set transports) { + public Builder setRestrictedUnderlyingNetworkTransports( + @NonNull Set<@VcnUnderlyingNetworkTransport Integer> transports) { validateRestrictedTransportsOrThrow(transports); mRestrictedTransports.clear();