Merge "Prep VCN files for exposing APIs"

This commit is contained in:
Benedict Wong
2021-01-27 02:34:09 +00:00
committed by Gerrit Code Review
4 changed files with 144 additions and 41 deletions

View File

@@ -96,7 +96,11 @@ public final class VcnConfig implements Parcelable {
return mPackageName;
}
/** Retrieves the set of configured tunnels. */
/**
* Retrieves the set of configured tunnels.
*
* @hide
*/
@NonNull
public Set<VcnGatewayConnectionConfig> getGatewayConnectionConfigs() {
return Collections.unmodifiableSet(mGatewayConnectionConfigs);
@@ -146,7 +150,7 @@ public final class VcnConfig implements Parcelable {
}
@Override
public void writeToParcel(Parcel out, int flags) {
public void writeToParcel(@NonNull Parcel out, int flags) {
out.writeParcelable(toPersistableBundle(), flags);
}
@@ -164,8 +168,12 @@ public final class VcnConfig implements Parcelable {
}
};
/** This class is used to incrementally build {@link VcnConfig} objects. */
public static class Builder {
/**
* This class is used to incrementally build {@link VcnConfig} objects.
*
* @hide
*/
public static final class Builder {
@NonNull private final String mPackageName;
@NonNull
@@ -182,6 +190,7 @@ public final class VcnConfig implements Parcelable {
*
* @param gatewayConnectionConfig the configuration for an individual gateway connection
* @return this {@link Builder} instance, for chaining
* @hide
*/
@NonNull
public Builder addGatewayConnectionConfig(
@@ -196,6 +205,7 @@ public final class VcnConfig implements Parcelable {
* Builds and validates the VcnConfig.
*
* @return an immutable VcnConfig instance
* @hide
*/
@NonNull
public VcnConfig build() {

View File

@@ -17,6 +17,7 @@ package android.net.vcn;
import static com.android.internal.annotations.VisibleForTesting.Visibility;
import android.annotation.IntDef;
import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -25,14 +26,19 @@ import android.os.PersistableBundle;
import android.util.ArraySet;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.Preconditions;
import com.android.server.vcn.util.PersistableBundleUtils;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Objects;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.concurrent.TimeUnit;
/**
@@ -97,6 +103,26 @@ public final class VcnGatewayConnectionConfig {
ALLOWED_CAPABILITIES = Collections.unmodifiableSet(allowedCaps);
}
/** @hide */
@Retention(RetentionPolicy.SOURCE)
@IntDef(
prefix = {"NET_CAPABILITY_"},
value = {
NetworkCapabilities.NET_CAPABILITY_MMS,
NetworkCapabilities.NET_CAPABILITY_SUPL,
NetworkCapabilities.NET_CAPABILITY_DUN,
NetworkCapabilities.NET_CAPABILITY_FOTA,
NetworkCapabilities.NET_CAPABILITY_IMS,
NetworkCapabilities.NET_CAPABILITY_CBS,
NetworkCapabilities.NET_CAPABILITY_IA,
NetworkCapabilities.NET_CAPABILITY_RCS,
NetworkCapabilities.NET_CAPABILITY_XCAP,
NetworkCapabilities.NET_CAPABILITY_EIMS,
NetworkCapabilities.NET_CAPABILITY_INTERNET,
NetworkCapabilities.NET_CAPABILITY_MCX,
})
public @interface VcnSupportedCapability {}
private static final int DEFAULT_MAX_MTU = 1500;
/**
@@ -128,10 +154,10 @@ public final class VcnGatewayConnectionConfig {
};
private static final String EXPOSED_CAPABILITIES_KEY = "mExposedCapabilities";
@NonNull private final Set<Integer> mExposedCapabilities;
@NonNull private final SortedSet<Integer> mExposedCapabilities;
private static final String UNDERLYING_CAPABILITIES_KEY = "mUnderlyingCapabilities";
@NonNull private final Set<Integer> mUnderlyingCapabilities;
@NonNull private final SortedSet<Integer> mUnderlyingCapabilities;
// TODO: Add Ike/ChildSessionParams as a subclass - maybe VcnIkeGatewayConnectionConfig
@@ -141,14 +167,14 @@ public final class VcnGatewayConnectionConfig {
private static final String RETRY_INTERVAL_MS_KEY = "mRetryIntervalsMs";
@NonNull private final long[] mRetryIntervalsMs;
@VisibleForTesting(visibility = Visibility.PRIVATE)
public VcnGatewayConnectionConfig(
/** Builds a VcnGatewayConnectionConfig with the specified parameters. */
private VcnGatewayConnectionConfig(
@NonNull Set<Integer> exposedCapabilities,
@NonNull Set<Integer> underlyingCapabilities,
@NonNull long[] retryIntervalsMs,
@IntRange(from = MIN_MTU_V6) int maxMtu) {
mExposedCapabilities = exposedCapabilities;
mUnderlyingCapabilities = underlyingCapabilities;
mExposedCapabilities = new TreeSet(exposedCapabilities);
mUnderlyingCapabilities = new TreeSet(underlyingCapabilities);
mRetryIntervalsMs = retryIntervalsMs;
mMaxMtu = maxMtu;
@@ -163,9 +189,9 @@ public final class VcnGatewayConnectionConfig {
final PersistableBundle underlyingCapsBundle =
in.getPersistableBundle(UNDERLYING_CAPABILITIES_KEY);
mExposedCapabilities = new ArraySet<>(PersistableBundleUtils.toList(
mExposedCapabilities = new TreeSet<>(PersistableBundleUtils.toList(
exposedCapsBundle, PersistableBundleUtils.INTEGER_DESERIALIZER));
mUnderlyingCapabilities = new ArraySet<>(PersistableBundleUtils.toList(
mUnderlyingCapabilities = new TreeSet<>(PersistableBundleUtils.toList(
underlyingCapsBundle, PersistableBundleUtils.INTEGER_DESERIALIZER));
mRetryIntervalsMs = in.getLongArray(RETRY_INTERVAL_MS_KEY);
mMaxMtu = in.getInt(MAX_MTU_KEY);
@@ -219,52 +245,93 @@ public final class VcnGatewayConnectionConfig {
/**
* Returns all exposed capabilities.
*
* <p>The returned integer-value capabilities will not contain duplicates, and will be sorted in
* ascending numerical order.
*
* @see Builder#addExposedCapability(int)
* @see Builder#clearExposedCapability(int)
* @hide
*/
@NonNull
public int[] getExposedCapabilities() {
// Sorted set guarantees ordering
return ArrayUtils.convertToIntArray(new ArrayList<>(mExposedCapabilities));
}
/**
* Returns all exposed capabilities.
*
* <p>Left to prevent the need to make major changes while changes are actively in flight.
*
* @deprecated use getExposedCapabilities() instead
* @hide
*/
@Deprecated
@NonNull
public Set<Integer> getAllExposedCapabilities() {
return Collections.unmodifiableSet(mExposedCapabilities);
}
/**
* Checks if this config is configured to support/expose a specific capability.
* Returns all capabilities required of underlying networks.
*
* @param capability the capability to check for
* <p>The returned integer-value capabilities will be sorted in ascending numerical order.
*
* @see Builder#addRequiredUnderlyingCapability(int)
* @see Builder#clearRequiredUnderlyingCapability(int)
* @hide
*/
public boolean hasExposedCapability(int capability) {
checkValidCapability(capability);
return mExposedCapabilities.contains(capability);
@NonNull
public int[] getRequiredUnderlyingCapabilities() {
// Sorted set guarantees ordering
return ArrayUtils.convertToIntArray(new ArrayList<>(mUnderlyingCapabilities));
}
/**
* Returns all capabilities required of underlying networks.
*
* <p>Left to prevent the need to make major changes while changes are actively in flight.
*
* @deprecated use getRequiredUnderlyingCapabilities() instead
* @hide
*/
@Deprecated
@NonNull
public Set<Integer> getAllUnderlyingCapabilities() {
return Collections.unmodifiableSet(mUnderlyingCapabilities);
}
/**
* Checks if this config requires an underlying network to have the specified capability.
* Retrieves the configured retry intervals.
*
* @param capability the capability to check for
* @see Builder#setRetryInterval(long[])
* @hide
*/
public boolean requiresUnderlyingCapability(int capability) {
checkValidCapability(capability);
return mUnderlyingCapabilities.contains(capability);
}
/** Retrieves the configured retry intervals. */
@NonNull
public long[] getRetryIntervalsMs() {
public long[] getRetryInterval() {
return Arrays.copyOf(mRetryIntervalsMs, mRetryIntervalsMs.length);
}
/** Retrieves the maximum MTU allowed for this Gateway Connection. */
/**
* Retrieves the configured retry intervals.
*
* <p>Left to prevent the need to make major changes while changes are actively in flight.
*
* @deprecated use getRequiredUnderlyingCapabilities() instead
* @hide
*/
@Deprecated
@NonNull
public long[] getRetryIntervalsMs() {
return getRetryInterval();
}
/**
* Retrieves the maximum MTU allowed for this Gateway Connection.
*
* @see Builder.setMaxMtu(int)
* @hide
*/
@IntRange(from = MIN_MTU_V6)
public int getMaxMtu() {
return mMaxMtu;
@@ -319,8 +386,12 @@ public final class VcnGatewayConnectionConfig {
&& mMaxMtu == rhs.mMaxMtu;
}
/** This class is used to incrementally build {@link VcnGatewayConnectionConfig} objects. */
public static class Builder {
/**
* This class is used to incrementally build {@link VcnGatewayConnectionConfig} objects.
*
* @hide
*/
public static final class Builder {
@NonNull private final Set<Integer> mExposedCapabilities = new ArraySet();
@NonNull private final Set<Integer> mUnderlyingCapabilities = new ArraySet();
@NonNull private long[] mRetryIntervalsMs = DEFAULT_RETRY_INTERVALS_MS;
@@ -338,8 +409,10 @@ public final class VcnGatewayConnectionConfig {
* @return this {@link Builder} instance, for chaining
* @see VcnGatewayConnectionConfig for a list of capabilities may be exposed by a Gateway
* Connection
* @hide
*/
public Builder addExposedCapability(int exposedCapability) {
@NonNull
public Builder addExposedCapability(@VcnSupportedCapability int exposedCapability) {
checkValidCapability(exposedCapability);
mExposedCapabilities.add(exposedCapability);
@@ -354,8 +427,10 @@ public final class VcnGatewayConnectionConfig {
* @return this {@link Builder} instance, for chaining
* @see VcnGatewayConnectionConfig for a list of capabilities may be exposed by a Gateway
* Connection
* @hide
*/
public Builder removeExposedCapability(int exposedCapability) {
@NonNull
public Builder clearExposedCapability(@VcnSupportedCapability int exposedCapability) {
checkValidCapability(exposedCapability);
mExposedCapabilities.remove(exposedCapability);
@@ -370,8 +445,11 @@ public final class VcnGatewayConnectionConfig {
* @return this {@link Builder} instance, for chaining
* @see VcnGatewayConnectionConfig for a list of capabilities may be required of underlying
* networks
* @hide
*/
public Builder addRequiredUnderlyingCapability(int underlyingCapability) {
@NonNull
public Builder addRequiredUnderlyingCapability(
@VcnSupportedCapability int underlyingCapability) {
checkValidCapability(underlyingCapability);
mUnderlyingCapabilities.add(underlyingCapability);
@@ -390,8 +468,11 @@ public final class VcnGatewayConnectionConfig {
* @return this {@link Builder} instance, for chaining
* @see VcnGatewayConnectionConfig for a list of capabilities may be required of underlying
* networks
* @hide
*/
public Builder removeRequiredUnderlyingCapability(int underlyingCapability) {
@NonNull
public Builder clearRequiredUnderlyingCapability(
@VcnSupportedCapability int underlyingCapability) {
checkValidCapability(underlyingCapability);
mUnderlyingCapabilities.remove(underlyingCapability);
@@ -420,6 +501,7 @@ public final class VcnGatewayConnectionConfig {
* 15m]}
* @return this {@link Builder} instance, for chaining
* @see VcnManager for additional discussion on fail-safe mode
* @hide
*/
@NonNull
public Builder setRetryInterval(@NonNull long[] retryIntervalsMs) {
@@ -441,6 +523,7 @@ public final class VcnGatewayConnectionConfig {
* @param maxMtu the maximum MTU allowed for this Gateway Connection. Must be greater than
* the IPv6 minimum MTU of 1280. Defaults to 1500.
* @return this {@link Builder} instance, for chaining
* @hide
*/
@NonNull
public Builder setMaxMtu(@IntRange(from = MIN_MTU_V6) int maxMtu) {
@@ -455,6 +538,7 @@ public final class VcnGatewayConnectionConfig {
* Builds and validates the VcnGatewayConnectionConfig.
*
* @return an immutable VcnGatewayConnectionConfig instance
* @hide
*/
@NonNull
public VcnGatewayConnectionConfig build() {

View File

@@ -65,6 +65,7 @@ import java.util.concurrent.Executor;
public final class VcnManager {
@NonNull private static final String TAG = VcnManager.class.getSimpleName();
/** @hide */
@VisibleForTesting
public static final Map<
VcnUnderlyingNetworkPolicyListener, VcnUnderlyingNetworkPolicyListenerBinder>

View File

@@ -28,6 +28,7 @@ import androidx.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
@RunWith(AndroidJUnit4.class)
@@ -39,6 +40,12 @@ public class VcnGatewayConnectionConfigTest {
NetworkCapabilities.NET_CAPABILITY_INTERNET, NetworkCapabilities.NET_CAPABILITY_MMS
};
public static final int[] UNDERLYING_CAPS = new int[] {NetworkCapabilities.NET_CAPABILITY_DUN};
static {
Arrays.sort(EXPOSED_CAPS);
Arrays.sort(UNDERLYING_CAPS);
}
public static final long[] RETRY_INTERVALS_MS =
new long[] {
TimeUnit.SECONDS.toMillis(5),
@@ -124,12 +131,13 @@ public class VcnGatewayConnectionConfigTest {
public void testBuilderAndGetters() {
final VcnGatewayConnectionConfig config = buildTestConfig();
for (int cap : EXPOSED_CAPS) {
config.hasExposedCapability(cap);
}
for (int cap : UNDERLYING_CAPS) {
config.requiresUnderlyingCapability(cap);
}
int[] exposedCaps = config.getExposedCapabilities();
Arrays.sort(exposedCaps);
assertArrayEquals(EXPOSED_CAPS, exposedCaps);
int[] underlyingCaps = config.getRequiredUnderlyingCapabilities();
Arrays.sort(underlyingCaps);
assertArrayEquals(UNDERLYING_CAPS, underlyingCaps);
assertArrayEquals(RETRY_INTERVALS_MS, config.getRetryIntervalsMs());
assertEquals(MAX_MTU, config.getMaxMtu());