Merge "Add VcnContext, Vcn skeletons" am: ebc78a4cb5
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1495024
Change-Id: I70a3a2b4be86341c9aa2e20a0bd00b7b9d2e5e50
diff --git a/services/core/java/com/android/server/VcnManagementService.java b/services/core/java/com/android/server/VcnManagementService.java
index f376473..165b6a1 100644
--- a/services/core/java/com/android/server/VcnManagementService.java
+++ b/services/core/java/com/android/server/VcnManagementService.java
@@ -165,9 +165,13 @@
// TODO: Clear VCN configuration, trigger teardown as necessary
}
- @VisibleForTesting(visibility = Visibility.PRIVATE)
- class VcnNetworkProvider extends NetworkProvider {
- VcnNetworkProvider(@NonNull Context context, @NonNull Looper looper) {
+ /**
+ * Network provider for VCN networks.
+ *
+ * @hide
+ */
+ public class VcnNetworkProvider extends NetworkProvider {
+ VcnNetworkProvider(Context context, Looper looper) {
super(context, looper, VcnNetworkProvider.class.getSimpleName());
}
diff --git a/services/core/java/com/android/server/vcn/Vcn.java b/services/core/java/com/android/server/vcn/Vcn.java
new file mode 100644
index 0000000..2af4172
--- /dev/null
+++ b/services/core/java/com/android/server/vcn/Vcn.java
@@ -0,0 +1,95 @@
+/*
+ * 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.net.NetworkRequest;
+import android.net.vcn.VcnConfig;
+import android.os.Handler;
+import android.os.Message;
+import android.os.ParcelUuid;
+
+import java.util.Objects;
+
+/**
+ * Represents an single instance of a VCN.
+ *
+ * <p>Each Vcn instance manages all tunnels for a given subscription group, including per-capability
+ * networks, network selection, and multi-homing.
+ *
+ * @hide
+ */
+public class Vcn extends Handler {
+ private static final String TAG = Vcn.class.getSimpleName();
+
+ @NonNull private final VcnContext mVcnContext;
+ @NonNull private final ParcelUuid mSubscriptionGroup;
+ @NonNull private final Dependencies mDeps;
+
+ @NonNull private VcnConfig mConfig;
+
+ public Vcn(
+ @NonNull VcnContext vcnContext,
+ @NonNull ParcelUuid subscriptionGroup,
+ @NonNull VcnConfig config) {
+ this(vcnContext, subscriptionGroup, config, new Dependencies());
+ }
+
+ private Vcn(
+ @NonNull VcnContext vcnContext,
+ @NonNull ParcelUuid subscriptionGroup,
+ @NonNull VcnConfig config,
+ @NonNull Dependencies deps) {
+ super(Objects.requireNonNull(vcnContext, "Missing vcnContext").getLooper());
+ mVcnContext = vcnContext;
+ mSubscriptionGroup = Objects.requireNonNull(subscriptionGroup, "Missing subscriptionGroup");
+ mDeps = Objects.requireNonNull(deps, "Missing deps");
+
+ mConfig = Objects.requireNonNull(config, "Missing config");
+ }
+
+ /** Asynchronously updates the configuration and triggers a re-evaluation of Networks */
+ public void updateConfig(@NonNull VcnConfig config) {
+ Objects.requireNonNull(config, "Missing config");
+ // TODO: Proxy to handler, and make config there.
+ }
+
+ /** Asynchronously tears down this Vcn instance, along with all tunnels and Networks */
+ public void teardown() {
+ // TODO: Proxy to handler, and teardown there.
+ }
+
+ /** Notifies this Vcn instance of a new NetworkRequest */
+ public void onNetworkRequested(@NonNull NetworkRequest request, int score, int providerId) {
+ Objects.requireNonNull(request, "Missing request");
+
+ // TODO: Proxy to handler, and handle there.
+ }
+
+ @Override
+ public void handleMessage(@NonNull Message msg) {
+ // TODO: Do something
+ }
+
+ /** 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
+ return 52;
+ }
+
+ private static class Dependencies {}
+}
diff --git a/services/core/java/com/android/server/vcn/VcnContext.java b/services/core/java/com/android/server/vcn/VcnContext.java
new file mode 100644
index 0000000..8ab52931
--- /dev/null
+++ b/services/core/java/com/android/server/vcn/VcnContext.java
@@ -0,0 +1,60 @@
+/*
+ * 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.content.Context;
+import android.os.Looper;
+
+import com.android.server.VcnManagementService.VcnNetworkProvider;
+
+import java.util.Objects;
+
+/**
+ * A simple class to pass around context information.
+ *
+ * @hide
+ */
+public class VcnContext {
+ @NonNull private final Context mContext;
+ @NonNull private final Looper mLooper;
+ @NonNull private final VcnNetworkProvider mVcnNetworkProvider;
+
+ public VcnContext(
+ @NonNull Context context,
+ @NonNull Looper looper,
+ @NonNull VcnNetworkProvider vcnNetworkProvider) {
+ mContext = Objects.requireNonNull(context, "Missing context");
+ mLooper = Objects.requireNonNull(looper, "Missing looper");
+ mVcnNetworkProvider = Objects.requireNonNull(vcnNetworkProvider, "Missing networkProvider");
+ }
+
+ @NonNull
+ public Context getContext() {
+ return mContext;
+ }
+
+ @NonNull
+ public Looper getLooper() {
+ return mLooper;
+ }
+
+ @NonNull
+ public VcnNetworkProvider getVcnNetworkProvider() {
+ return mVcnNetworkProvider;
+ }
+}