Merge "Remove TunnelConnectionParams interface" am: b8f67d1bd7 am: b1578de55a am: 92154c7465

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

Change-Id: I546b7eecca41d2a745b65f67961a2634be29609f
diff --git a/core/api/current.txt b/core/api/current.txt
index b40604e..974c5a5 100644
--- a/core/api/current.txt
+++ b/core/api/current.txt
@@ -26547,9 +26547,6 @@
     field public static final int UNSUPPORTED = -1; // 0xffffffff
   }
 
-  public interface TunnelConnectionParams {
-  }
-
   public abstract class Uri implements java.lang.Comparable<android.net.Uri> android.os.Parcelable {
     method public abstract android.net.Uri.Builder buildUpon();
     method public int compareTo(android.net.Uri);
@@ -27118,7 +27115,7 @@
   }
 
   public static final class VcnGatewayConnectionConfig.Builder {
-    ctor public VcnGatewayConnectionConfig.Builder(@NonNull String, @NonNull android.net.TunnelConnectionParams);
+    ctor public VcnGatewayConnectionConfig.Builder(@NonNull String, @NonNull android.net.ipsec.ike.IkeTunnelConnectionParams);
     method @NonNull public android.net.vcn.VcnGatewayConnectionConfig.Builder addExposedCapability(int);
     method @NonNull public android.net.vcn.VcnGatewayConnectionConfig build();
     method @NonNull public android.net.vcn.VcnGatewayConnectionConfig.Builder removeExposedCapability(int);
diff --git a/core/java/android/net/TunnelConnectionParams.java b/core/java/android/net/TunnelConnectionParams.java
deleted file mode 100644
index f5b3539..0000000
--- a/core/java/android/net/TunnelConnectionParams.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (C) 2021 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;
-
-/**
- * TunnelConnectionParams represents a configuration to set up a tunnel connection.
- *
- * <p>Concrete implementations for a control plane protocol should implement this interface.
- * Subclasses should be immutable data classes containing connection, authentication and
- * authorization parameters required to establish a tunnel connection.
- *
- * @see android.net.ipsec.ike.IkeTunnelConnectionParams
- */
-// TODO:b/186071626 Remove TunnelConnectionParams when non-updatable API stub can resolve
-// IkeTunnelConnectionParams
-public interface TunnelConnectionParams {}
diff --git a/core/java/android/net/vcn/VcnGatewayConnectionConfig.java b/core/java/android/net/vcn/VcnGatewayConnectionConfig.java
index 3c02cf0..eedeeb5 100644
--- a/core/java/android/net/vcn/VcnGatewayConnectionConfig.java
+++ b/core/java/android/net/vcn/VcnGatewayConnectionConfig.java
@@ -24,7 +24,7 @@
 import android.annotation.SuppressLint;
 import android.net.Network;
 import android.net.NetworkCapabilities;
-import android.net.TunnelConnectionParams;
+import android.net.ipsec.ike.IkeTunnelConnectionParams;
 import android.net.vcn.persistablebundleutils.TunnelConnectionParamsUtils;
 import android.os.PersistableBundle;
 import android.util.ArraySet;
@@ -159,7 +159,7 @@
     @NonNull private final String mGatewayConnectionName;
 
     private static final String TUNNEL_CONNECTION_PARAMS_KEY = "mTunnelConnectionParams";
-    @NonNull private TunnelConnectionParams mTunnelConnectionParams;
+    @NonNull private IkeTunnelConnectionParams mTunnelConnectionParams;
 
     private static final String EXPOSED_CAPABILITIES_KEY = "mExposedCapabilities";
     @NonNull private final SortedSet<Integer> mExposedCapabilities;
@@ -176,7 +176,7 @@
     /** Builds a VcnGatewayConnectionConfig with the specified parameters. */
     private VcnGatewayConnectionConfig(
             @NonNull String gatewayConnectionName,
-            @NonNull TunnelConnectionParams tunnelConnectionParams,
+            @NonNull IkeTunnelConnectionParams tunnelConnectionParams,
             @NonNull Set<Integer> exposedCapabilities,
             @NonNull Set<Integer> underlyingCapabilities,
             @NonNull long[] retryIntervalsMs,
@@ -276,7 +276,7 @@
      * @hide
      */
     @NonNull
-    public TunnelConnectionParams getTunnelConnectionParams() {
+    public IkeTunnelConnectionParams getTunnelConnectionParams() {
         return mTunnelConnectionParams;
     }
 
@@ -419,7 +419,7 @@
      */
     public static final class Builder {
         @NonNull private final String mGatewayConnectionName;
-        @NonNull private final TunnelConnectionParams mTunnelConnectionParams;
+        @NonNull private final IkeTunnelConnectionParams mTunnelConnectionParams;
         @NonNull private final Set<Integer> mExposedCapabilities = new ArraySet();
         @NonNull private final Set<Integer> mUnderlyingCapabilities = new ArraySet();
         @NonNull private long[] mRetryIntervalsMs = DEFAULT_RETRY_INTERVALS_MS;
@@ -437,13 +437,13 @@
          *     VcnConfig} must be given a unique name. This name is used by the caller to
          *     distinguish between VcnGatewayConnectionConfigs configured on a single {@link
          *     VcnConfig}. This will be used as the identifier in VcnStatusCallback invocations.
-         * @param tunnelConnectionParams the tunnel connection configuration
-         * @see TunnelConnectionParams
+         * @param tunnelConnectionParams the IKE tunnel connection configuration
+         * @see IkeTunnelConnectionParams
          * @see VcnManager.VcnStatusCallback#onGatewayConnectionError
          */
         public Builder(
                 @NonNull String gatewayConnectionName,
-                @NonNull TunnelConnectionParams tunnelConnectionParams) {
+                @NonNull IkeTunnelConnectionParams tunnelConnectionParams) {
             Objects.requireNonNull(gatewayConnectionName, "gatewayConnectionName was null");
             Objects.requireNonNull(tunnelConnectionParams, "tunnelConnectionParams was null");
 
diff --git a/core/java/android/net/vcn/persistablebundleutils/TunnelConnectionParamsUtils.java b/core/java/android/net/vcn/persistablebundleutils/TunnelConnectionParamsUtils.java
index 690e4e7..4bc5b49 100644
--- a/core/java/android/net/vcn/persistablebundleutils/TunnelConnectionParamsUtils.java
+++ b/core/java/android/net/vcn/persistablebundleutils/TunnelConnectionParamsUtils.java
@@ -16,7 +16,6 @@
 package android.net.vcn.persistablebundleutils;
 
 import android.annotation.NonNull;
-import android.net.TunnelConnectionParams;
 import android.net.ipsec.ike.IkeSessionParams;
 import android.net.ipsec.ike.IkeTunnelConnectionParams;
 import android.net.ipsec.ike.TunnelModeChildSessionParams;
@@ -25,7 +24,7 @@
 import java.util.Objects;
 
 /**
- * Utility class to convert TunnelConnectionParams to/from PersistableBundle
+ * Utility class to convert Tunnel Connection Params to/from PersistableBundle
  *
  * @hide
  */
@@ -34,30 +33,28 @@
 
     private static final String PARAMS_TYPE_IKE = "IKE";
 
-    /** Serializes an TunnelConnectionParams to a PersistableBundle. */
+    /** Serializes an IkeTunnelConnectionParams to a PersistableBundle. */
     @NonNull
-    public static PersistableBundle toPersistableBundle(@NonNull TunnelConnectionParams params) {
+    public static PersistableBundle toPersistableBundle(@NonNull IkeTunnelConnectionParams params) {
         final PersistableBundle result = new PersistableBundle();
 
-        if (params instanceof IkeTunnelConnectionParams) {
-            result.putPersistableBundle(
-                    PARAMS_TYPE_IKE,
-                    IkeTunnelConnectionParamsUtils.serializeIkeParams(
-                            (IkeTunnelConnectionParams) params));
-            return result;
-        } else {
-            throw new UnsupportedOperationException("Invalid TunnelConnectionParams type");
-        }
+        result.putPersistableBundle(
+                PARAMS_TYPE_IKE,
+                IkeTunnelConnectionParamsUtils.serializeIkeParams(
+                        (IkeTunnelConnectionParams) params));
+        return result;
     }
 
-    /** Constructs an TunnelConnectionParams by deserializing a PersistableBundle. */
+    /** Constructs an IkeTunnelConnectionParams by deserializing a PersistableBundle. */
     @NonNull
-    public static TunnelConnectionParams fromPersistableBundle(@NonNull PersistableBundle in) {
+    public static IkeTunnelConnectionParams fromPersistableBundle(@NonNull PersistableBundle in) {
         Objects.requireNonNull(in, "PersistableBundle was null");
 
         if (in.keySet().size() != EXPECTED_BUNDLE_KEY_CNT) {
             throw new IllegalArgumentException(
-                    "Expect PersistableBundle to have one element but found: " + in.keySet());
+                    String.format(
+                            "Expect PersistableBundle to have %d element but found: %d",
+                            EXPECTED_BUNDLE_KEY_CNT, in.keySet()));
         }
 
         if (in.get(PARAMS_TYPE_IKE) != null) {
@@ -66,7 +63,7 @@
         }
 
         throw new IllegalArgumentException(
-                "Invalid TunnelConnectionParams type " + in.keySet().iterator().next());
+                "Invalid Tunnel Connection Params type " + in.keySet().iterator().next());
     }
 
     private static final class IkeTunnelConnectionParamsUtils {
diff --git a/services/core/java/com/android/server/vcn/VcnGatewayConnection.java b/services/core/java/com/android/server/vcn/VcnGatewayConnection.java
index 6ca3c4b..8f60b09 100644
--- a/services/core/java/com/android/server/vcn/VcnGatewayConnection.java
+++ b/services/core/java/com/android/server/vcn/VcnGatewayConnection.java
@@ -52,7 +52,6 @@
 import android.net.NetworkScore;
 import android.net.RouteInfo;
 import android.net.TelephonyNetworkSpecifier;
-import android.net.TunnelConnectionParams;
 import android.net.Uri;
 import android.net.annotations.PolicyDirection;
 import android.net.ipsec.ike.ChildSessionCallback;
@@ -1924,14 +1923,8 @@
             @NonNull IpSecTunnelInterface tunnelIface,
             @NonNull VcnChildSessionConfiguration childConfig,
             @Nullable UnderlyingNetworkRecord underlying) {
-        final TunnelConnectionParams tunnelParams =
+        final IkeTunnelConnectionParams ikeTunnelParams =
                 gatewayConnectionConfig.getTunnelConnectionParams();
-        if (!(tunnelParams instanceof IkeTunnelConnectionParams)) {
-            throw new IllegalStateException(
-                    "TunnelConnectionParams is not IkeTunnelConnectionParams");
-        }
-
-        final IkeTunnelConnectionParams ikeTunnelParams = (IkeTunnelConnectionParams) tunnelParams;
         final LinkProperties lp = new LinkProperties();
 
         lp.setInterfaceName(tunnelIface.getInterfaceName());
@@ -2138,32 +2131,16 @@
     }
 
     private IkeSessionParams buildIkeParams(@NonNull Network network) {
-        final TunnelConnectionParams tunnelConnectionParams =
+        final IkeTunnelConnectionParams ikeTunnelConnectionParams =
                 mConnectionConfig.getTunnelConnectionParams();
-
-        if (tunnelConnectionParams instanceof IkeTunnelConnectionParams) {
-            final IkeTunnelConnectionParams ikeTunnelConnectionParams =
-                    (IkeTunnelConnectionParams) tunnelConnectionParams;
-            final IkeSessionParams.Builder builder =
-                    new IkeSessionParams.Builder(ikeTunnelConnectionParams.getIkeSessionParams());
-            builder.setNetwork(network);
-
-            return builder.build();
-        }
-
-        throw new IllegalStateException("TunnelConnectionParams is not IkeTunnelConnectionParams");
+        final IkeSessionParams.Builder builder =
+                new IkeSessionParams.Builder(ikeTunnelConnectionParams.getIkeSessionParams());
+        builder.setNetwork(network);
+        return builder.build();
     }
 
     private ChildSessionParams buildChildParams() {
-        final TunnelConnectionParams tunnelConnectionParams =
-                mConnectionConfig.getTunnelConnectionParams();
-
-        if (tunnelConnectionParams instanceof IkeTunnelConnectionParams) {
-            return ((IkeTunnelConnectionParams) tunnelConnectionParams)
-                    .getTunnelModeChildSessionParams();
-        }
-
-        throw new IllegalStateException("TunnelConnectionParams is not IkeTunnelConnectionParams");
+        return mConnectionConfig.getTunnelConnectionParams().getTunnelModeChildSessionParams();
     }
 
     @VisibleForTesting(visibility = Visibility.PRIVATE)
diff --git a/tests/vcn/java/android/net/vcn/VcnGatewayConnectionConfigTest.java b/tests/vcn/java/android/net/vcn/VcnGatewayConnectionConfigTest.java
index 0d3fd3f..7cfd275 100644
--- a/tests/vcn/java/android/net/vcn/VcnGatewayConnectionConfigTest.java
+++ b/tests/vcn/java/android/net/vcn/VcnGatewayConnectionConfigTest.java
@@ -22,7 +22,7 @@
 import static org.junit.Assert.fail;
 
 import android.net.NetworkCapabilities;
-import android.net.TunnelConnectionParams;
+import android.net.ipsec.ike.IkeTunnelConnectionParams;
 import android.net.vcn.persistablebundleutils.TunnelConnectionParamsUtilsTest;
 
 import androidx.test.filters.SmallTest;
@@ -60,7 +60,7 @@
             };
     public static final int MAX_MTU = 1360;
 
-    public static final TunnelConnectionParams TUNNEL_CONNECTION_PARAMS =
+    public static final IkeTunnelConnectionParams TUNNEL_CONNECTION_PARAMS =
             TunnelConnectionParamsUtilsTest.buildTestParams();
 
     public static final String GATEWAY_CONNECTION_NAME_PREFIX = "gatewayConnectionName-";
diff --git a/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionConnectedStateTest.java b/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionConnectedStateTest.java
index 530e636..90ee738 100644
--- a/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionConnectedStateTest.java
+++ b/tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionConnectedStateTest.java
@@ -51,7 +51,6 @@
 import android.net.NetworkAgent;
 import android.net.NetworkCapabilities;
 import android.net.ipsec.ike.ChildSaProposal;
-import android.net.ipsec.ike.IkeTunnelConnectionParams;
 import android.net.ipsec.ike.exceptions.IkeException;
 import android.net.ipsec.ike.exceptions.IkeInternalException;
 import android.net.ipsec.ike.exceptions.IkeProtocolException;
@@ -181,7 +180,7 @@
         assertEquals(mGatewayConnection.mConnectedState, mGatewayConnection.getCurrentState());
 
         final List<ChildSaProposal> saProposals =
-                ((IkeTunnelConnectionParams) mConfig.getTunnelConnectionParams())
+                mConfig.getTunnelConnectionParams()
                         .getTunnelModeChildSessionParams()
                         .getSaProposals();
         final int expectedMtu =