Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3b788acd authored by Yan Yan's avatar Yan Yan Committed by Automerger Merge Worker
Browse files

Merge "Define @IntDef for setRestrictedUnderlyingNetworkTransports" am: f3298d73

parents 1a37b41f f3298d73
Loading
Loading
Loading
Loading
+26 −6
Original line number Diff line number Diff line
@@ -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();