Merge "CTS test IKE 3GPP APIs."
diff --git a/tests/cts/src/android/ipsec/ike/cts/IkeSessionParamsTest.java b/tests/cts/src/android/ipsec/ike/cts/IkeSessionParamsTest.java
index 9e1b6c7..3f26788 100644
--- a/tests/cts/src/android/ipsec/ike/cts/IkeSessionParamsTest.java
+++ b/tests/cts/src/android/ipsec/ike/cts/IkeSessionParamsTest.java
@@ -23,6 +23,7 @@
 import static android.net.ipsec.ike.IkeSessionParams.IkeAuthDigitalSignRemoteConfig;
 import static android.net.ipsec.ike.IkeSessionParams.IkeAuthEapConfig;
 import static android.net.ipsec.ike.IkeSessionParams.IkeAuthPskConfig;
+import static android.net.ipsec.ike.ike3gpp.Ike3gppDataListenerTest.TestIke3gppDataListener;
 import static android.system.OsConstants.AF_INET;
 import static android.system.OsConstants.AF_INET6;
 import static android.telephony.TelephonyManager.APPTYPE_USIM;
@@ -41,6 +42,8 @@
 import android.net.ipsec.ike.IkeSessionParams.ConfigRequestIpv4PcscfServer;
 import android.net.ipsec.ike.IkeSessionParams.ConfigRequestIpv6PcscfServer;
 import android.net.ipsec.ike.IkeSessionParams.IkeConfigRequest;
+import android.net.ipsec.ike.ike3gpp.Ike3gppExtension;
+import android.net.ipsec.ike.ike3gpp.Ike3gppParams;
 
 import androidx.test.ext.junit.runners.AndroidJUnit4;
 
@@ -423,4 +426,16 @@
         assertEquals(
                 mServerCaCert, ((IkeAuthDigitalSignRemoteConfig) remoteConfig).getRemoteCaCert());
     }
+
+    @Test
+    public void testBuildWithIke3gppExtension() throws Exception {
+        Ike3gppExtension ike3gppExtension =
+                new Ike3gppExtension(
+                        new Ike3gppParams.Builder().build(), new TestIke3gppDataListener());
+        IkeSessionParams sessionParams =
+                createIkeParamsBuilderMinimum().setIke3gppExtension(ike3gppExtension).build();
+
+        verifyIkeParamsMinimumWithoutAuth(sessionParams);
+        assertEquals(ike3gppExtension, sessionParams.getIke3gppExtension());
+    }
 }
diff --git a/tests/cts/src/android/ipsec/ike/cts/ike3gpp/Ike3gppBackoffTimerTest.java b/tests/cts/src/android/ipsec/ike/cts/ike3gpp/Ike3gppBackoffTimerTest.java
new file mode 100644
index 0000000..a83c984
--- /dev/null
+++ b/tests/cts/src/android/ipsec/ike/cts/ike3gpp/Ike3gppBackoffTimerTest.java
@@ -0,0 +1,49 @@
+/*
+ * 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.ipsec.ike.ike3gpp;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class Ike3gppBackoffTimerTest {
+    private static final byte BACKOFF_TIMER = (byte) 0xAF;
+    private static final int BACKOFF_CAUSE = Ike3gppBackoffTimer.ERROR_TYPE_NETWORK_FAILURE;
+
+    private Ike3gppBackoffTimer mBackoffTimer;
+
+    @Before
+    public void setUp() {
+        mBackoffTimer = new Ike3gppBackoffTimer(BACKOFF_TIMER, BACKOFF_CAUSE);
+    }
+
+    @Test
+    public void testGetDataType() {
+        assertEquals(Ike3gppData.DATA_TYPE_NOTIFY_BACKOFF_TIMER, mBackoffTimer.getDataType());
+    }
+
+    @Test
+    public void testGetBackoffTimer() {
+        assertEquals(BACKOFF_TIMER, mBackoffTimer.getBackoffTimer());
+    }
+
+    @Test
+    public void testGetCause() {
+        assertEquals(BACKOFF_CAUSE, mBackoffTimer.getBackoffCause());
+    }
+}
diff --git a/tests/cts/src/android/ipsec/ike/cts/ike3gpp/Ike3gppDataListenerTest.java b/tests/cts/src/android/ipsec/ike/cts/ike3gpp/Ike3gppDataListenerTest.java
new file mode 100644
index 0000000..2bb83a0
--- /dev/null
+++ b/tests/cts/src/android/ipsec/ike/cts/ike3gpp/Ike3gppDataListenerTest.java
@@ -0,0 +1,50 @@
+/*
+ * 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.ipsec.ike.ike3gpp;
+
+import static org.junit.Assert.assertEquals;
+
+import android.net.ipsec.ike.ike3gpp.Ike3gppExtension.Ike3gppDataListener;
+
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class Ike3gppDataListenerTest {
+    @Test
+    public void testOnIke3gppDataReceived() {
+        List<Ike3gppData> ike3gppData =
+                Arrays.asList(Ike3gppN1ModeInformationTest.newN1ModeInformation());
+
+        TestIke3gppDataListener dataListener = new TestIke3gppDataListener();
+        dataListener.onIke3gppDataReceived(ike3gppData);
+
+        assertEquals(ike3gppData, dataListener.lastDataList);
+    }
+
+    public static class TestIke3gppDataListener implements Ike3gppDataListener {
+        public final List<Ike3gppData> lastDataList = new ArrayList<>();
+
+        @Override
+        public void onIke3gppDataReceived(List<Ike3gppData> ike3gppDataList) {
+            lastDataList.clear();
+            lastDataList.addAll(ike3gppDataList);
+        }
+    }
+}
diff --git a/tests/cts/src/android/ipsec/ike/cts/ike3gpp/Ike3gppExtensionTest.java b/tests/cts/src/android/ipsec/ike/cts/ike3gpp/Ike3gppExtensionTest.java
new file mode 100644
index 0000000..3c28ca5
--- /dev/null
+++ b/tests/cts/src/android/ipsec/ike/cts/ike3gpp/Ike3gppExtensionTest.java
@@ -0,0 +1,50 @@
+/*
+ * 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.ipsec.ike.ike3gpp;
+
+import static android.net.ipsec.ike.ike3gpp.Ike3gppDataListenerTest.TestIke3gppDataListener;
+
+import static org.junit.Assert.assertEquals;
+
+import android.net.ipsec.ike.ike3gpp.Ike3gppExtension.Ike3gppDataListener;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class Ike3gppExtensionTest {
+    private Ike3gppParams mParams;
+    private Ike3gppDataListener mDataListener;
+    private Ike3gppExtension mIke3gppExtension;
+
+    @Before
+    public void setUp() {
+        mParams = new Ike3gppParams.Builder().build();
+        mDataListener = new TestIke3gppDataListener();
+
+        mIke3gppExtension = new Ike3gppExtension(mParams, mDataListener);
+    }
+
+    @Test
+    public void testGetIke3gppParams() {
+        assertEquals(mParams, mIke3gppExtension.getIke3gppParams());
+    }
+
+    @Test
+    public void testGetIke3gppDataListener() {
+        assertEquals(mDataListener, mIke3gppExtension.getIke3gppDataListener());
+    }
+}
diff --git a/tests/cts/src/android/ipsec/ike/cts/ike3gpp/Ike3gppN1ModeInformationTest.java b/tests/cts/src/android/ipsec/ike/cts/ike3gpp/Ike3gppN1ModeInformationTest.java
new file mode 100644
index 0000000..56fb581
--- /dev/null
+++ b/tests/cts/src/android/ipsec/ike/cts/ike3gpp/Ike3gppN1ModeInformationTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.ipsec.ike.ike3gpp;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import com.android.internal.util.HexDump;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class Ike3gppN1ModeInformationTest {
+    private static final byte[] SNSSAI = HexDump.hexStringToByteArray("1122334455");
+
+    private Ike3gppN1ModeInformation mN1ModeInformation;
+
+    public static Ike3gppN1ModeInformation newN1ModeInformation() {
+        return new Ike3gppN1ModeInformation(SNSSAI);
+    }
+
+    @Before
+    public void setUp() {
+        mN1ModeInformation = newN1ModeInformation();
+    }
+
+    @Test
+    public void testGetDataType() {
+        assertEquals(
+                Ike3gppData.DATA_TYPE_NOTIFY_N1_MODE_INFORMATION, mN1ModeInformation.getDataType());
+    }
+
+    @Test
+    public void testGetSnssai() {
+        assertArrayEquals(SNSSAI, mN1ModeInformation.getSnssai());
+    }
+}
diff --git a/tests/cts/src/android/ipsec/ike/cts/ike3gpp/Ike3gppParamsTest.java b/tests/cts/src/android/ipsec/ike/cts/ike3gpp/Ike3gppParamsTest.java
new file mode 100644
index 0000000..b05def4
--- /dev/null
+++ b/tests/cts/src/android/ipsec/ike/cts/ike3gpp/Ike3gppParamsTest.java
@@ -0,0 +1,40 @@
+/*
+ * 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.ipsec.ike.ike3gpp;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class Ike3gppParamsTest {
+    public static final byte PDU_SESSION_ID = (byte) 5;
+
+    @Test
+    public void testBuildIke3gppParams() {
+        final Ike3gppParams params =
+                new Ike3gppParams.Builder().setPduSessionId(PDU_SESSION_ID).build();
+
+        assertEquals(PDU_SESSION_ID, params.getPduSessionId());
+    }
+
+    @Test
+    public void testBuildIke3gppParamsWithoutPduSessionId() {
+        final Ike3gppParams params = new Ike3gppParams.Builder().build();
+
+        assertEquals(Ike3gppParams.PDU_SESSION_ID_UNSET, params.getPduSessionId());
+    }
+}