diff options
4 files changed, 272 insertions, 1 deletions
diff --git a/core/java/android/net/vcn/VcnGatewayConnectionConfig.java b/core/java/android/net/vcn/VcnGatewayConnectionConfig.java new file mode 100644 index 000000000000..8160edc87440 --- /dev/null +++ b/core/java/android/net/vcn/VcnGatewayConnectionConfig.java @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.net.vcn; + +import android.annotation.NonNull; + +/** + * This class represents a configuration for a connection to a Virtual Carrier Network gateway. + * + * <p>Each VcnGatewayConnectionConfig represents a single logical connection to a carrier gateway, + * and may provide one or more telephony services (as represented by network capabilities). Each + * gateway is expected to provide mobility for a given session as the device roams across {@link + * Network}s. + * + * <p>A VCN connection based on this configuration will be brought up dynamically based on device + * settings, and filed NetworkRequests. Underlying networks will be selected based on the services + * required by this configuration (as represented by network capabilities), and must be part of the + * subscription group under which this configuration is registered (see {@link + * VcnManager#setVcnConfig}). + * + * <p>Services that can be provided by a VCN network, or required for underlying networks are + * limited to services provided by cellular networks: + * + * <ul> + * <li>{@link android.net.NetworkCapabilities.NET_CAPABILITY_MMS} + * <li>{@link android.net.NetworkCapabilities.NET_CAPABILITY_SUPL} + * <li>{@link android.net.NetworkCapabilities.NET_CAPABILITY_DUN} + * <li>{@link android.net.NetworkCapabilities.NET_CAPABILITY_FOTA} + * <li>{@link android.net.NetworkCapabilities.NET_CAPABILITY_IMS} + * <li>{@link android.net.NetworkCapabilities.NET_CAPABILITY_CBS} + * <li>{@link android.net.NetworkCapabilities.NET_CAPABILITY_IA} + * <li>{@link android.net.NetworkCapabilities.NET_CAPABILITY_RCS} + * <li>{@link android.net.NetworkCapabilities.NET_CAPABILITY_XCAP} + * <li>{@link android.net.NetworkCapabilities.NET_CAPABILITY_EIMS} + * <li>{@link android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET} + * <li>{@link android.net.NetworkCapabilities.NET_CAPABILITY_MCX} + * </ul> + * + * @hide + */ +public final class VcnGatewayConnectionConfig { + private VcnGatewayConnectionConfig() { + validate(); + } + + // TODO: Implement getters, validators, etc + + /** + * Validates this configuration + * + * @hide + */ + private void validate() { + // TODO: implement validation logic + } + + // Parcelable methods + + /** This class is used to incrementally build {@link VcnGatewayConnectionConfig} objects */ + public static class Builder { + // TODO: Implement this builder + + /** + * Builds and validates the VcnGatewayConnectionConfig + * + * @return an immutable VcnGatewayConnectionConfig instance + */ + @NonNull + public VcnGatewayConnectionConfig build() { + return new VcnGatewayConnectionConfig(); + } + } +} diff --git a/services/core/java/com/android/server/vcn/UnderlyingNetworkTracker.java b/services/core/java/com/android/server/vcn/UnderlyingNetworkTracker.java new file mode 100644 index 000000000000..e1feb5aab869 --- /dev/null +++ b/services/core/java/com/android/server/vcn/UnderlyingNetworkTracker.java @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.server.vcn; + +import android.annotation.NonNull; +import android.annotation.Nullable; +import android.net.LinkProperties; +import android.net.Network; +import android.net.NetworkCapabilities; +import android.os.Handler; +import android.os.ParcelUuid; + +import java.util.Objects; + +/** + * Tracks a set of Networks underpinning a VcnGatewayConnection. + * + * <p>A single UnderlyingNetworkTracker is built to serve a SINGLE VCN Gateway Connection, and MUST + * be torn down with the VcnGatewayConnection in order to ensure underlying networks are allowed to + * be reaped. + * + * @hide + */ +public class UnderlyingNetworkTracker extends Handler { + @NonNull private static final String TAG = UnderlyingNetworkTracker.class.getSimpleName(); + + @NonNull private final VcnContext mVcnContext; + @NonNull private final ParcelUuid mSubscriptionGroup; + @NonNull private final UnderlyingNetworkTrackerCallback mCb; + @NonNull private final Dependencies mDeps; + + public UnderlyingNetworkTracker( + @NonNull VcnContext vcnContext, + @NonNull ParcelUuid subscriptionGroup, + @NonNull UnderlyingNetworkTrackerCallback cb) { + this(vcnContext, subscriptionGroup, cb, new Dependencies()); + } + + private UnderlyingNetworkTracker( + @NonNull VcnContext vcnContext, + @NonNull ParcelUuid subscriptionGroup, + @NonNull UnderlyingNetworkTrackerCallback cb, + @NonNull Dependencies deps) { + super(Objects.requireNonNull(vcnContext, "Missing vcnContext").getLooper()); + mVcnContext = vcnContext; + mSubscriptionGroup = Objects.requireNonNull(subscriptionGroup, "Missing subscriptionGroup"); + mCb = Objects.requireNonNull(cb, "Missing cb"); + mDeps = Objects.requireNonNull(deps, "Missing deps"); + } + + /** Tears down this Tracker, and releases all underlying network requests. */ + public void teardown() {} + + /** An record of a single underlying network, caching relevant fields. */ + public static class UnderlyingNetworkRecord { + @NonNull public final Network network; + @NonNull public final NetworkCapabilities networkCapabilities; + @NonNull public final LinkProperties linkProperties; + public final boolean blocked; + + private UnderlyingNetworkRecord( + @NonNull Network network, + @NonNull NetworkCapabilities networkCapabilities, + @NonNull LinkProperties linkProperties, + boolean blocked) { + this.network = network; + this.networkCapabilities = networkCapabilities; + this.linkProperties = linkProperties; + this.blocked = blocked; + } + } + + /** Callbacks for being notified of the changes in, or to the selected underlying network. */ + public interface UnderlyingNetworkTrackerCallback { + /** + * Fired when a new underlying network is selected, or properties have changed. + * + * <p>This callback does NOT signal a mobility event. + * + * @param underlying The details of the new underlying network + */ + void onSelectedUnderlyingNetworkChanged(@Nullable UnderlyingNetworkRecord underlying); + } + + private static class Dependencies {} +} diff --git a/services/core/java/com/android/server/vcn/Vcn.java b/services/core/java/com/android/server/vcn/Vcn.java index 2af41726caab..d51d16b1b4df 100644 --- a/services/core/java/com/android/server/vcn/Vcn.java +++ b/services/core/java/com/android/server/vcn/Vcn.java @@ -87,7 +87,8 @@ public class Vcn extends Handler { /** Retrieves the network score for a VCN Network */ private int getNetworkScore() { - // TODO: STOPSHIP: Make this use new NetworkSelection, or some magic "max in subGrp" value + // TODO: STOPSHIP (b/173549607): Make this use new NetworkSelection, or some magic "max in + // subGrp" value return 52; } diff --git a/services/core/java/com/android/server/vcn/VcnGatewayConnection.java b/services/core/java/com/android/server/vcn/VcnGatewayConnection.java new file mode 100644 index 000000000000..49c9b3297c77 --- /dev/null +++ b/services/core/java/com/android/server/vcn/VcnGatewayConnection.java @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.server.vcn; + +import android.annotation.NonNull; +import android.annotation.Nullable; +import android.net.vcn.VcnGatewayConnectionConfig; +import android.os.Handler; +import android.os.ParcelUuid; + +import com.android.server.vcn.UnderlyingNetworkTracker.UnderlyingNetworkRecord; +import com.android.server.vcn.UnderlyingNetworkTracker.UnderlyingNetworkTrackerCallback; + +import java.util.Objects; + +/** + * A single VCN Gateway Connection, providing a single public-facing VCN network. + * + * <p>This class handles mobility events, performs retries, and tracks safe-mode conditions. + * + * @hide + */ +public class VcnGatewayConnection extends Handler implements UnderlyingNetworkTrackerCallback { + private static final String TAG = VcnGatewayConnection.class.getSimpleName(); + + @NonNull private final VcnContext mVcnContext; + @NonNull private final ParcelUuid mSubscriptionGroup; + @NonNull private final UnderlyingNetworkTracker mUnderlyingNetworkTracker; + @NonNull private final VcnGatewayConnectionConfig mConnectionConfig; + @NonNull private final Dependencies mDeps; + + public VcnGatewayConnection( + @NonNull VcnContext vcnContext, + @NonNull ParcelUuid subscriptionGroup, + @NonNull VcnGatewayConnectionConfig connectionConfig) { + this(vcnContext, subscriptionGroup, connectionConfig, new Dependencies()); + } + + private VcnGatewayConnection( + @NonNull VcnContext vcnContext, + @NonNull ParcelUuid subscriptionGroup, + @NonNull VcnGatewayConnectionConfig connectionConfig, + @NonNull Dependencies deps) { + super(Objects.requireNonNull(vcnContext, "Missing vcnContext").getLooper()); + mVcnContext = vcnContext; + mSubscriptionGroup = Objects.requireNonNull(subscriptionGroup, "Missing subscriptionGroup"); + mConnectionConfig = Objects.requireNonNull(connectionConfig, "Missing connectionConfig"); + mDeps = Objects.requireNonNull(deps, "Missing deps"); + + mUnderlyingNetworkTracker = + mDeps.newUnderlyingNetworkTracker(mVcnContext, subscriptionGroup, this); + } + + /** Tears down this GatewayConnection, and any resources used */ + public void teardown() { + mUnderlyingNetworkTracker.teardown(); + } + + private static class Dependencies { + public UnderlyingNetworkTracker newUnderlyingNetworkTracker( + VcnContext vcnContext, + ParcelUuid subscriptionGroup, + UnderlyingNetworkTrackerCallback callback) { + return new UnderlyingNetworkTracker(vcnContext, subscriptionGroup, callback); + } + } + + @Override + public void onSelectedUnderlyingNetworkChanged(@Nullable UnderlyingNetworkRecord underlying) {} +} |