Merge "Define @IntDef for setRestrictedUnderlyingNetworkTransports" am: f3298d7372

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2405131

Change-Id: I2800a860c41df41b3194e0d222bb71ebe357ddd0
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Yan Yan
2023-02-07 22:23:29 +00:00
committed by Automerger Merge Worker

View File

@@ -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<Integer> ALLOWED_TRANSPORTS = new ArraySet<>();
static {
@@ -164,7 +180,7 @@ public final class VcnConfig implements Parcelable {
* @see Builder#setRestrictedUnderlyingNetworkTransports(Set)
*/
@NonNull
public Set<Integer> 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
* <p>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<Integer> transports) {
public Builder setRestrictedUnderlyingNetworkTransports(
@NonNull Set<@VcnUnderlyingNetworkTransport Integer> transports) {
validateRestrictedTransportsOrThrow(transports);
mRestrictedTransports.clear();