summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
authorYan Yan <evitayan@google.com>2021-04-22 08:39:20 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2021-04-22 08:39:20 +0000
commitbc545c8a8a26d749fc0ed0f5f2e521517147c28a (patch)
treee763b3ea998fe6e97db0ee8bc3e835a52100ad86 /core/java/android
parent2984d87873692e3b2ae286afc4aaa9bd428d6c20 (diff)
parent4eaa894d849f2a14e04e14fb47cff38cb7015c1a (diff)
Merge changes from topics "encrypted-tunnel-interface", "iketunnelparams", "vcn-encrypted-tunnel"
* changes: Replace VcnControlPlaneConfig with TunnelConnectionParams Convert TunnelConnectionParams to/from PersistableBundle Create TunnelConnectionParams interface
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/net/TunnelConnectionParams.java29
-rw-r--r--core/java/android/net/vcn/VcnControlPlaneConfig.java112
-rw-r--r--core/java/android/net/vcn/VcnControlPlaneIkeConfig.java158
-rw-r--r--core/java/android/net/vcn/VcnGatewayConnectionConfig.java47
-rw-r--r--core/java/android/net/vcn/persistablebundleutils/TunnelConnectionParamsUtils.java106
5 files changed, 161 insertions, 291 deletions
diff --git a/core/java/android/net/TunnelConnectionParams.java b/core/java/android/net/TunnelConnectionParams.java
new file mode 100644
index 000000000000..f5b35395b0bf
--- /dev/null
+++ b/core/java/android/net/TunnelConnectionParams.java
@@ -0,0 +1,29 @@
+/*
+ * 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/VcnControlPlaneConfig.java b/core/java/android/net/vcn/VcnControlPlaneConfig.java
deleted file mode 100644
index 92f6c4440377..000000000000
--- a/core/java/android/net/vcn/VcnControlPlaneConfig.java
+++ /dev/null
@@ -1,112 +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.vcn;
-
-import android.annotation.IntDef;
-import android.annotation.NonNull;
-import android.os.PersistableBundle;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.util.Objects;
-
-/**
- * This class represents a control plane configuration for a Virtual Carrier Network connection.
- *
- * <p>Each {@link VcnGatewayConnectionConfig} must have a {@link VcnControlPlaneConfig}, containing
- * all connection, authentication and authorization parameters required to establish a Gateway
- * Connection with a remote endpoint.
- *
- * <p>A {@link VcnControlPlaneConfig} object can be shared by multiple {@link
- * VcnGatewayConnectionConfig}(s) if they will used for connecting with the same remote endpoint.
- *
- * @see VcnManager
- * @see VcnGatewayConnectionConfig
- */
-public abstract class VcnControlPlaneConfig {
- /** @hide */
- @Retention(RetentionPolicy.SOURCE)
- @IntDef({CONFIG_TYPE_IKE})
- public @interface ConfigType {}
-
- /** @hide */
- public static final int CONFIG_TYPE_IKE = 1;
-
- private static final String CONFIG_TYPE_KEY = "mConfigType";
- @ConfigType private final int mConfigType;
-
- /**
- * Package private constructor.
- *
- * @hide
- */
- VcnControlPlaneConfig(int configType) {
- mConfigType = configType;
- }
-
- /**
- * Constructs a VcnControlPlaneConfig object by deserializing a PersistableBundle.
- *
- * @param in the {@link PersistableBundle} containing an {@link VcnControlPlaneConfig} object
- * @hide
- */
- public static VcnControlPlaneConfig fromPersistableBundle(@NonNull PersistableBundle in) {
- Objects.requireNonNull(in, "PersistableBundle was null");
-
- int configType = in.getInt(CONFIG_TYPE_KEY);
- switch (configType) {
- case CONFIG_TYPE_IKE:
- return new VcnControlPlaneIkeConfig(in);
- default:
- throw new IllegalStateException("Unrecognized configType: " + configType);
- }
- }
-
- /**
- * Converts this VcnControlPlaneConfig to a PersistableBundle.
- *
- * @hide
- */
- @NonNull
- public PersistableBundle toPersistableBundle() {
- final PersistableBundle result = new PersistableBundle();
- result.putInt(CONFIG_TYPE_KEY, mConfigType);
- return result;
- }
-
- /** @hide */
- @Override
- public int hashCode() {
- return Objects.hash(mConfigType);
- }
-
- /** @hide */
- @Override
- public boolean equals(Object o) {
- if (!(o instanceof VcnControlPlaneConfig)) {
- return false;
- }
-
- return mConfigType == ((VcnControlPlaneConfig) o).mConfigType;
- }
-
- /**
- * Returns a deep copy of this object.
- *
- * @hide
- */
- public abstract VcnControlPlaneConfig copy();
-}
diff --git a/core/java/android/net/vcn/VcnControlPlaneIkeConfig.java b/core/java/android/net/vcn/VcnControlPlaneIkeConfig.java
deleted file mode 100644
index 22d7faf2fe18..000000000000
--- a/core/java/android/net/vcn/VcnControlPlaneIkeConfig.java
+++ /dev/null
@@ -1,158 +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.vcn;
-
-import static android.net.vcn.VcnControlPlaneConfig.CONFIG_TYPE_IKE;
-
-import android.annotation.NonNull;
-import android.net.ipsec.ike.IkeSessionParams;
-import android.net.ipsec.ike.TunnelModeChildSessionParams;
-import android.net.vcn.persistablebundleutils.IkeSessionParamsUtils;
-import android.net.vcn.persistablebundleutils.TunnelModeChildSessionParamsUtils;
-import android.os.PersistableBundle;
-import android.util.ArraySet;
-import android.util.Log;
-
-import java.util.Objects;
-
-/**
- * This class is an IKEv2 control plane configuration for a Virtual Carrier Network connection.
- *
- * <p>This class is an extension of the {@link VcnControlPlaneConfig}, containing IKEv2-specific
- * configuration, authentication and authorization parameters.
- *
- * @see VcnControlPlaneConfig
- */
-public final class VcnControlPlaneIkeConfig extends VcnControlPlaneConfig {
- private static final String TAG = VcnControlPlaneIkeConfig.class.getSimpleName();
-
- private static final String IKE_PARAMS_KEY = "mIkeParams";
- @NonNull private final IkeSessionParams mIkeParams;
-
- private static final String CHILD_PARAMS_KEY = "mChildParams";
- @NonNull private final TunnelModeChildSessionParams mChildParams;
-
- private static final ArraySet<String> BUNDLE_KEY_SET = new ArraySet<>();
-
- {
- BUNDLE_KEY_SET.add(IKE_PARAMS_KEY);
- BUNDLE_KEY_SET.add(CHILD_PARAMS_KEY);
- }
-
- /**
- * Constructs a VcnControlPlaneIkeConfig object.
- *
- * @param ikeParams the IKE Session negotiation parameters
- * @param childParams the tunnel mode Child Session negotiation parameters
- */
- public VcnControlPlaneIkeConfig(
- @NonNull IkeSessionParams ikeParams,
- @NonNull TunnelModeChildSessionParams childParams) {
- super(CONFIG_TYPE_IKE);
- mIkeParams = ikeParams;
- mChildParams = childParams;
- validate();
- }
-
- /**
- * Constructs a VcnControlPlaneIkeConfig object by deserializing a PersistableBundle.
- *
- * @param in the {@link PersistableBundle} containing an {@link VcnControlPlaneIkeConfig} object
- * @hide
- */
- public VcnControlPlaneIkeConfig(@NonNull PersistableBundle in) {
- super(CONFIG_TYPE_IKE);
- final PersistableBundle ikeParamsBundle = in.getPersistableBundle(IKE_PARAMS_KEY);
- final PersistableBundle childParamsBundle = in.getPersistableBundle(CHILD_PARAMS_KEY);
-
- Objects.requireNonNull(ikeParamsBundle, "IKE Session Params was null");
- Objects.requireNonNull(childParamsBundle, "Child Session Params was null");
-
- mIkeParams = IkeSessionParamsUtils.fromPersistableBundle(ikeParamsBundle);
- mChildParams = TunnelModeChildSessionParamsUtils.fromPersistableBundle(childParamsBundle);
-
- for (String key : in.keySet()) {
- if (!BUNDLE_KEY_SET.contains(key)) {
- Log.w(TAG, "Found an unexpected key in the PersistableBundle: " + key);
- }
- }
-
- validate();
- }
-
- private void validate() {
- Objects.requireNonNull(mIkeParams, "mIkeParams was null");
- Objects.requireNonNull(mChildParams, "mChildParams was null");
- }
-
- /**
- * Converts this VcnControlPlaneConfig to a PersistableBundle.
- *
- * @hide
- */
- @Override
- @NonNull
- public PersistableBundle toPersistableBundle() {
- final PersistableBundle result = super.toPersistableBundle();
- result.putPersistableBundle(
- IKE_PARAMS_KEY, IkeSessionParamsUtils.toPersistableBundle(mIkeParams));
- result.putPersistableBundle(
- CHILD_PARAMS_KEY,
- TunnelModeChildSessionParamsUtils.toPersistableBundle(mChildParams));
- return result;
- }
-
- /** Retrieves the IKE Session configuration. */
- @NonNull
- public IkeSessionParams getIkeSessionParams() {
- return mIkeParams;
- }
-
- /** Retrieves the tunnel mode Child Session configuration. */
- @NonNull
- public TunnelModeChildSessionParams getChildSessionParams() {
- return mChildParams;
- }
-
- /** @hide */
- @Override
- public int hashCode() {
- return Objects.hash(super.hashCode(), mIkeParams, mChildParams);
- }
-
- /** @hide */
- @Override
- public boolean equals(Object o) {
- if (!(o instanceof VcnControlPlaneIkeConfig)) {
- return false;
- }
-
- VcnControlPlaneIkeConfig other = (VcnControlPlaneIkeConfig) o;
-
- return super.equals(o)
- && Objects.equals(mIkeParams, other.mIkeParams)
- && Objects.equals(mChildParams, other.mChildParams);
- }
-
- /** @hide */
- @Override
- public VcnControlPlaneConfig copy() {
- return new VcnControlPlaneIkeConfig(
- new IkeSessionParams.Builder(mIkeParams).build(),
- new TunnelModeChildSessionParams.Builder(mChildParams).build());
- }
-}
diff --git a/core/java/android/net/vcn/VcnGatewayConnectionConfig.java b/core/java/android/net/vcn/VcnGatewayConnectionConfig.java
index 649e75e61268..adcbe2542ab6 100644
--- a/core/java/android/net/vcn/VcnGatewayConnectionConfig.java
+++ b/core/java/android/net/vcn/VcnGatewayConnectionConfig.java
@@ -24,6 +24,8 @@ import android.annotation.Nullable;
import android.annotation.SuppressLint;
import android.net.Network;
import android.net.NetworkCapabilities;
+import android.net.TunnelConnectionParams;
+import android.net.vcn.persistablebundleutils.TunnelConnectionParamsUtils;
import android.os.PersistableBundle;
import android.util.ArraySet;
@@ -151,8 +153,8 @@ public final class VcnGatewayConnectionConfig {
private static final String GATEWAY_CONNECTION_NAME_KEY = "mGatewayConnectionName";
@NonNull private final String mGatewayConnectionName;
- private static final String CTRL_PLANE_CONFIG_KEY = "mCtrlPlaneConfig";
- @NonNull private VcnControlPlaneConfig mCtrlPlaneConfig;
+ private static final String TUNNEL_CONNECTION_PARAMS_KEY = "mTunnelConnectionParams";
+ @NonNull private TunnelConnectionParams mTunnelConnectionParams;
private static final String EXPOSED_CAPABILITIES_KEY = "mExposedCapabilities";
@NonNull private final SortedSet<Integer> mExposedCapabilities;
@@ -169,13 +171,13 @@ public final class VcnGatewayConnectionConfig {
/** Builds a VcnGatewayConnectionConfig with the specified parameters. */
private VcnGatewayConnectionConfig(
@NonNull String gatewayConnectionName,
- @NonNull VcnControlPlaneConfig ctrlPlaneConfig,
+ @NonNull TunnelConnectionParams tunnelConnectionParams,
@NonNull Set<Integer> exposedCapabilities,
@NonNull Set<Integer> underlyingCapabilities,
@NonNull long[] retryIntervalsMs,
@IntRange(from = MIN_MTU_V6) int maxMtu) {
mGatewayConnectionName = gatewayConnectionName;
- mCtrlPlaneConfig = ctrlPlaneConfig;
+ mTunnelConnectionParams = tunnelConnectionParams;
mExposedCapabilities = new TreeSet(exposedCapabilities);
mUnderlyingCapabilities = new TreeSet(underlyingCapabilities);
mRetryIntervalsMs = retryIntervalsMs;
@@ -187,9 +189,10 @@ public final class VcnGatewayConnectionConfig {
/** @hide */
@VisibleForTesting(visibility = Visibility.PRIVATE)
public VcnGatewayConnectionConfig(@NonNull PersistableBundle in) {
- final PersistableBundle ctrlPlaneConfigBundle =
- in.getPersistableBundle(CTRL_PLANE_CONFIG_KEY);
- Objects.requireNonNull(ctrlPlaneConfigBundle, "ctrlPlaneConfigBundle was null");
+ final PersistableBundle tunnelConnectionParamsBundle =
+ in.getPersistableBundle(TUNNEL_CONNECTION_PARAMS_KEY);
+ Objects.requireNonNull(
+ tunnelConnectionParamsBundle, "tunnelConnectionParamsBundle was null");
final PersistableBundle exposedCapsBundle =
in.getPersistableBundle(EXPOSED_CAPABILITIES_KEY);
@@ -197,7 +200,8 @@ public final class VcnGatewayConnectionConfig {
in.getPersistableBundle(UNDERLYING_CAPABILITIES_KEY);
mGatewayConnectionName = in.getString(GATEWAY_CONNECTION_NAME_KEY);
- mCtrlPlaneConfig = VcnControlPlaneConfig.fromPersistableBundle(ctrlPlaneConfigBundle);
+ mTunnelConnectionParams =
+ TunnelConnectionParamsUtils.fromPersistableBundle(tunnelConnectionParamsBundle);
mExposedCapabilities = new TreeSet<>(PersistableBundleUtils.toList(
exposedCapsBundle, PersistableBundleUtils.INTEGER_DESERIALIZER));
mUnderlyingCapabilities = new TreeSet<>(PersistableBundleUtils.toList(
@@ -210,7 +214,7 @@ public final class VcnGatewayConnectionConfig {
private void validate() {
Objects.requireNonNull(mGatewayConnectionName, "gatewayConnectionName was null");
- Objects.requireNonNull(mCtrlPlaneConfig, "control plane config was null");
+ Objects.requireNonNull(mTunnelConnectionParams, "tunnel connection parameter was null");
Preconditions.checkArgument(
mExposedCapabilities != null && !mExposedCapabilities.isEmpty(),
@@ -262,13 +266,13 @@ public final class VcnGatewayConnectionConfig {
}
/**
- * Returns control plane configuration.
+ * Returns tunnel connection parameters.
*
* @hide
*/
@NonNull
- public VcnControlPlaneConfig getControlPlaneConfig() {
- return mCtrlPlaneConfig.copy();
+ public TunnelConnectionParams getTunnelConnectionParams() {
+ return mTunnelConnectionParams;
}
/**
@@ -360,7 +364,8 @@ public final class VcnGatewayConnectionConfig {
public PersistableBundle toPersistableBundle() {
final PersistableBundle result = new PersistableBundle();
- final PersistableBundle ctrlPlaneConfigBundle = mCtrlPlaneConfig.toPersistableBundle();
+ final PersistableBundle tunnelConnectionParamsBundle =
+ TunnelConnectionParamsUtils.toPersistableBundle(mTunnelConnectionParams);
final PersistableBundle exposedCapsBundle =
PersistableBundleUtils.fromList(
new ArrayList<>(mExposedCapabilities),
@@ -371,7 +376,7 @@ public final class VcnGatewayConnectionConfig {
PersistableBundleUtils.INTEGER_SERIALIZER);
result.putString(GATEWAY_CONNECTION_NAME_KEY, mGatewayConnectionName);
- result.putPersistableBundle(CTRL_PLANE_CONFIG_KEY, ctrlPlaneConfigBundle);
+ result.putPersistableBundle(TUNNEL_CONNECTION_PARAMS_KEY, tunnelConnectionParamsBundle);
result.putPersistableBundle(EXPOSED_CAPABILITIES_KEY, exposedCapsBundle);
result.putPersistableBundle(UNDERLYING_CAPABILITIES_KEY, underlyingCapsBundle);
result.putLongArray(RETRY_INTERVAL_MS_KEY, mRetryIntervalsMs);
@@ -409,7 +414,7 @@ public final class VcnGatewayConnectionConfig {
*/
public static final class Builder {
@NonNull private final String mGatewayConnectionName;
- @NonNull private final VcnControlPlaneConfig mCtrlPlaneConfig;
+ @NonNull private final TunnelConnectionParams 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;
@@ -427,18 +432,18 @@ public final class VcnGatewayConnectionConfig {
* 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 ctrlPlaneConfig the control plane configuration
- * @see VcnControlPlaneConfig
+ * @param tunnelConnectionParams the tunnel connection configuration
+ * @see TunnelConnectionParams
* @see VcnManager.VcnStatusCallback#onGatewayConnectionError
*/
public Builder(
@NonNull String gatewayConnectionName,
- @NonNull VcnControlPlaneConfig ctrlPlaneConfig) {
+ @NonNull TunnelConnectionParams tunnelConnectionParams) {
Objects.requireNonNull(gatewayConnectionName, "gatewayConnectionName was null");
- Objects.requireNonNull(ctrlPlaneConfig, "ctrlPlaneConfig was null");
+ Objects.requireNonNull(tunnelConnectionParams, "tunnelConnectionParams was null");
mGatewayConnectionName = gatewayConnectionName;
- mCtrlPlaneConfig = ctrlPlaneConfig;
+ mTunnelConnectionParams = tunnelConnectionParams;
}
/**
@@ -583,7 +588,7 @@ public final class VcnGatewayConnectionConfig {
public VcnGatewayConnectionConfig build() {
return new VcnGatewayConnectionConfig(
mGatewayConnectionName,
- mCtrlPlaneConfig,
+ mTunnelConnectionParams,
mExposedCapabilities,
mUnderlyingCapabilities,
mRetryIntervalsMs,
diff --git a/core/java/android/net/vcn/persistablebundleutils/TunnelConnectionParamsUtils.java b/core/java/android/net/vcn/persistablebundleutils/TunnelConnectionParamsUtils.java
new file mode 100644
index 000000000000..690e4e76ea5f
--- /dev/null
+++ b/core/java/android/net/vcn/persistablebundleutils/TunnelConnectionParamsUtils.java
@@ -0,0 +1,106 @@
+/*
+ * 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.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;
+import android.os.PersistableBundle;
+
+import java.util.Objects;
+
+/**
+ * Utility class to convert TunnelConnectionParams to/from PersistableBundle
+ *
+ * @hide
+ */
+public final class TunnelConnectionParamsUtils {
+ private static final int EXPECTED_BUNDLE_KEY_CNT = 1;
+
+ private static final String PARAMS_TYPE_IKE = "IKE";
+
+ /** Serializes an TunnelConnectionParams to a PersistableBundle. */
+ @NonNull
+ public static PersistableBundle toPersistableBundle(@NonNull TunnelConnectionParams 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");
+ }
+ }
+
+ /** Constructs an TunnelConnectionParams by deserializing a PersistableBundle. */
+ @NonNull
+ public static TunnelConnectionParams 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());
+ }
+
+ if (in.get(PARAMS_TYPE_IKE) != null) {
+ return IkeTunnelConnectionParamsUtils.deserializeIkeParams(
+ in.getPersistableBundle(PARAMS_TYPE_IKE));
+ }
+
+ throw new IllegalArgumentException(
+ "Invalid TunnelConnectionParams type " + in.keySet().iterator().next());
+ }
+
+ private static final class IkeTunnelConnectionParamsUtils {
+ private static final String IKE_PARAMS_KEY = "IKE_PARAMS_KEY";
+ private static final String CHILD_PARAMS_KEY = "CHILD_PARAMS_KEY";
+
+ @NonNull
+ public static PersistableBundle serializeIkeParams(
+ @NonNull IkeTunnelConnectionParams ikeParams) {
+ final PersistableBundle result = new PersistableBundle();
+
+ result.putPersistableBundle(
+ IKE_PARAMS_KEY,
+ IkeSessionParamsUtils.toPersistableBundle(ikeParams.getIkeSessionParams()));
+ result.putPersistableBundle(
+ CHILD_PARAMS_KEY,
+ TunnelModeChildSessionParamsUtils.toPersistableBundle(
+ ikeParams.getTunnelModeChildSessionParams()));
+ return result;
+ }
+
+ @NonNull
+ public static IkeTunnelConnectionParams deserializeIkeParams(
+ @NonNull PersistableBundle in) {
+ final PersistableBundle ikeBundle = in.getPersistableBundle(IKE_PARAMS_KEY);
+ final PersistableBundle childBundle = in.getPersistableBundle(CHILD_PARAMS_KEY);
+ Objects.requireNonNull(ikeBundle, "IkeSessionParams was null");
+ Objects.requireNonNull(ikeBundle, "TunnelModeChildSessionParams was null");
+
+ final IkeSessionParams ikeParams =
+ IkeSessionParamsUtils.fromPersistableBundle(ikeBundle);
+ final TunnelModeChildSessionParams childParams =
+ TunnelModeChildSessionParamsUtils.fromPersistableBundle(childBundle);
+ return new IkeTunnelConnectionParams(ikeParams, childParams);
+ }
+ }
+}