aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYincheng Zhao <yinchengzhao@google.com>2019-10-24 14:39:35 -0700
committerandroid-build-merger <android-build-merger@google.com>2019-10-24 14:39:35 -0700
commit20cd3f579f3584527461e616fd95007d21d96b20 (patch)
treebed3a8786c2d153a5bcb0a886f85467d37596308
parentaff26611472d3e8110508aed187f4d44c15ea74e (diff)
parent67016a41b5968b56b29882ccf9d698a0aeab7d7e (diff)
downloadtelephony-b_141248619.tar.gz
Merge changes from topic "setFplmn"b_141248619
am: 67016a41b5 Change-Id: I2c9b83d55f0659db9b52b1f9d147221203cac6c5
-rw-r--r--src/java/com/android/internal/telephony/uicc/SIMRecords.java1
-rw-r--r--tests/telephonytests/src/com/android/internal/telephony/CellIdentityTest.java18
-rw-r--r--tests/telephonytests/src/com/android/internal/telephony/uicc/IccRecordsTest.java15
-rw-r--r--tests/telephonytests/src/com/android/internal/telephony/uicc/IccUtilsTest.java43
-rw-r--r--tests/telephonytests/src/com/android/internal/telephony/uicc/SIMRecordsTest.java174
5 files changed, 251 insertions, 0 deletions
diff --git a/src/java/com/android/internal/telephony/uicc/SIMRecords.java b/src/java/com/android/internal/telephony/uicc/SIMRecords.java
index 2d5a6bfcb3..8b9bdb185c 100644
--- a/src/java/com/android/internal/telephony/uicc/SIMRecords.java
+++ b/src/java/com/android/internal/telephony/uicc/SIMRecords.java
@@ -1232,6 +1232,7 @@ public class SIMRecords extends IccRecords {
response.sendToTarget();
break;
}
+
int maxWritebaleFplmns = dataLength / FPLMN_BYTE_SIZE;
List<String> fplmnsToWrite;
if (fplmns.size() <= maxWritebaleFplmns) {
diff --git a/tests/telephonytests/src/com/android/internal/telephony/CellIdentityTest.java b/tests/telephonytests/src/com/android/internal/telephony/CellIdentityTest.java
index 5b0e5dbdf6..6b65a46443 100644
--- a/tests/telephonytests/src/com/android/internal/telephony/CellIdentityTest.java
+++ b/tests/telephonytests/src/com/android/internal/telephony/CellIdentityTest.java
@@ -54,6 +54,11 @@ public class CellIdentityTest extends AndroidTestCase {
// Latitude ranges from -1296000 to 1296000.
private static final int LATITUDE = 1296000;
+ private static final String PLMN_INVALID_SHORT = "1234";
+ private static final String PLMN_INVALID_LONG = "1234567";
+ private static final String PLMN_INVALID_NON_NUM = "12a45b";
+ private static final String PLMN_VALID = "12345";
+
private static final int MAX_LAC = 65535;
private static final int MAX_CID = 65535;
private static final int MAX_ARFCN = 65535;
@@ -84,6 +89,7 @@ public class CellIdentityTest extends AndroidTestCase {
assertEquals(CellInfo.UNAVAILABLE, gsm.getBsic());
}
+
@SmallTest
public void testEquals() {
CellIdentity ciA = new CellIdentityLte(
@@ -130,4 +136,16 @@ public class CellIdentityTest extends AndroidTestCase {
newCi = CellIdentity.CREATOR.createFromParcel(p);
assertEquals(ci, newCi);
}
+
+ @SmallTest
+ public void testIsValidPlmn() {
+ assertTrue(CellIdentity.isValidPlmn(PLMN_VALID));
+ }
+
+ @SmallTest
+ public void testIsValidPlmnInvalidPlmns() {
+ assertFalse(CellIdentity.isValidPlmn(PLMN_INVALID_SHORT));
+ assertFalse(CellIdentity.isValidPlmn(PLMN_INVALID_LONG));
+ assertFalse(CellIdentity.isValidPlmn(PLMN_INVALID_NON_NUM));
+ }
}
diff --git a/tests/telephonytests/src/com/android/internal/telephony/uicc/IccRecordsTest.java b/tests/telephonytests/src/com/android/internal/telephony/uicc/IccRecordsTest.java
index b38b5e86ef..666da41c36 100644
--- a/tests/telephonytests/src/com/android/internal/telephony/uicc/IccRecordsTest.java
+++ b/tests/telephonytests/src/com/android/internal/telephony/uicc/IccRecordsTest.java
@@ -30,9 +30,12 @@
package com.android.internal.telephony.uicc;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.*;
import android.os.HandlerThread;
+import android.os.Message;
+import android.util.Pair;
import com.android.internal.telephony.TelephonyTest;
@@ -92,4 +95,16 @@ public class IccRecordsTest extends TelephonyTest {
mIccRecords.setImsi("123456ABCDEF");
assertEquals(mIccRecords.getIMSI(), null);
}
+
+ @Test
+ public void testPendingTansaction() {
+ Message msg = Message.obtain();
+ Object obj = new Object();
+ int key = mIccRecords.storePendingTransaction(msg, obj);
+ Pair<Message, Object> pair = mIccRecords.retrievePendingTransaction(key);
+ assertEquals(msg, pair.first);
+ assertEquals(obj, pair.second);
+ pair = mIccRecords.retrievePendingTransaction(key);
+ assertNull(pair);
+ }
}
diff --git a/tests/telephonytests/src/com/android/internal/telephony/uicc/IccUtilsTest.java b/tests/telephonytests/src/com/android/internal/telephony/uicc/IccUtilsTest.java
new file mode 100644
index 0000000000..d2cebb330d
--- /dev/null
+++ b/tests/telephonytests/src/com/android/internal/telephony/uicc/IccUtilsTest.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2019 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.internal.telephony.uicc;
+
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+import android.text.TextUtils;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class IccUtilsTest extends AndroidTestCase {
+ private static final int NUM_FPLMN = 3;
+ private static final List<String> FPLMNS_SAMPLE = Arrays.asList("123456", "12345", "54321");
+ private static final int DATA_LENGTH = 12;
+
+ @SmallTest
+ public void testEncodeFplmns() {
+ byte[] encodedFplmns = IccUtils.encodeFplmns(FPLMNS_SAMPLE, DATA_LENGTH);
+ int numValidPlmns = 0;
+ for (int i = 0; i < NUM_FPLMN; i++) {
+ String parsed = IccUtils.bcdPlmnToString(encodedFplmns, i * IccUtils.FPLMN_BYTE_SIZE);
+ assertEquals(FPLMNS_SAMPLE.get(i), parsed);
+ // we count the valid (non empty) records and only increment if valid
+ if (!TextUtils.isEmpty(parsed)) numValidPlmns++;
+ }
+ assertEquals(NUM_FPLMN, numValidPlmns);
+ }
+}
diff --git a/tests/telephonytests/src/com/android/internal/telephony/uicc/SIMRecordsTest.java b/tests/telephonytests/src/com/android/internal/telephony/uicc/SIMRecordsTest.java
new file mode 100644
index 0000000000..419243e66e
--- /dev/null
+++ b/tests/telephonytests/src/com/android/internal/telephony/uicc/SIMRecordsTest.java
@@ -0,0 +1,174 @@
+/*
+ * Copyright (C) 2019 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.internal.telephony.uicc;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.verify;
+
+import android.content.Context;
+import android.os.AsyncResult;
+import android.os.Handler;
+import android.os.Message;
+import android.os.test.TestLooper;
+
+import androidx.test.runner.AndroidJUnit4;
+
+import com.android.internal.telephony.CommandsInterface;
+import com.android.internal.telephony.TelephonyTest;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+@RunWith(AndroidJUnit4.class)
+public class SIMRecordsTest extends TelephonyTest {
+ private static final List<String> SHORT_FPLMNS_LIST = Arrays.asList("12345", "123456", "09876");
+ private static final List<String> LONG_FPLMNS_LIST =
+ Arrays.asList("12345", "123456", "09876", "123456", "098237");
+ private static final List<String> EMPTY_FPLMN_LIST = new ArrayList<>();
+ private static final int EF_SIZE = 12;
+ private static final int MAX_NUM_FPLMN = 4;
+
+ @Mock private IccFileHandler mFhMock;
+
+ private SIMRecordsUT mSIMRecordsUT;
+ private TestLooper mTestLooper;
+ private Handler mTestHandler;
+ private SIMRecordsReceiver mSIMRecordsReceiver;
+ private SIMRecords mSIMRecord;
+
+ private class SIMRecordsUT extends SIMRecords {
+ SIMRecordsUT(UiccCardApplication app, Context c,
+ CommandsInterface ci, IccFileHandler mFhMock) {
+ super(app, c, ci);
+ mFh = mFhMock;
+ }
+ }
+
+ private class SIMRecordsReceiver {
+ private SIMRecordsUT mSIMRecordsUT;
+
+ public void set(SIMRecordsUT m) {
+ mSIMRecordsUT = m;
+ }
+
+ public SIMRecordsUT get() {
+ return mSIMRecordsUT;
+ }
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ super.setUp(getClass().getSimpleName());
+ mTestLooper = new TestLooper();
+ mTestHandler = new Handler(mTestLooper.getLooper());
+ mSIMRecordsReceiver = new SIMRecordsReceiver();
+ mTestHandler.post(
+ () -> {
+ SIMRecordsUT mSIMRecords =
+ new SIMRecordsUT(
+ mUiccCardApplication3gpp,
+ mContext,
+ mSimulatedCommands,
+ mFhMock);
+ mSIMRecordsReceiver.set(mSIMRecords);
+ });
+ mTestLooper.dispatchAll();
+ mSIMRecordsUT = mSIMRecordsReceiver.get();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ @Test
+ public void testSetForbiddenPlmnsPad() {
+ setUpSetForbiddenPlmnsTests();
+ Message message = Message.obtain(mTestHandler);
+ mSIMRecordsUT.setForbiddenPlmns(message, SHORT_FPLMNS_LIST);
+ mTestLooper.dispatchAll();
+
+ byte[] encodedFplmn = IccUtils.encodeFplmns(SHORT_FPLMNS_LIST, EF_SIZE);
+ AsyncResult ar = (AsyncResult) message.obj;
+ assertEquals(SHORT_FPLMNS_LIST.size(), (int) ar.result);
+ verify(mFhMock).getEFTransparentRecordSize(eq(mSIMRecordsUT.EF_FPLMN), any(Message.class));
+ verify(mFhMock).updateEFTransparent(
+ eq(mSIMRecordsUT.EF_FPLMN), eq(encodedFplmn), any(Message.class));
+ }
+
+ @Test
+ public void testSetForbiddenPlmnsTruncate() {
+ setUpSetForbiddenPlmnsTests();
+ Message message = Message.obtain(mTestHandler);
+ mSIMRecordsUT.setForbiddenPlmns(message, LONG_FPLMNS_LIST);
+ mTestLooper.dispatchAll();
+
+ byte[] encodedFplmn = IccUtils.encodeFplmns(LONG_FPLMNS_LIST, EF_SIZE);
+ AsyncResult ar = (AsyncResult) message.obj;
+ assertEquals(MAX_NUM_FPLMN, (int) ar.result);
+ verify(mFhMock).getEFTransparentRecordSize(eq(mSIMRecordsUT.EF_FPLMN), any(Message.class));
+ verify(mFhMock).updateEFTransparent(
+ eq(mSIMRecordsUT.EF_FPLMN), eq(encodedFplmn), any(Message.class));
+ }
+
+ @Test
+ public void testSetForbiddenPlmnsClear() {
+ setUpSetForbiddenPlmnsTests();
+ Message message = Message.obtain(mTestHandler);
+ mSIMRecordsUT.setForbiddenPlmns(message, EMPTY_FPLMN_LIST);
+ mTestLooper.dispatchAll();
+
+ byte[] encodedFplmn = IccUtils.encodeFplmns(EMPTY_FPLMN_LIST, EF_SIZE);
+ AsyncResult ar = (AsyncResult) message.obj;
+ assertEquals(EMPTY_FPLMN_LIST.size(), (int) ar.result);
+ verify(mFhMock).getEFTransparentRecordSize(eq(mSIMRecordsUT.EF_FPLMN), any(Message.class));
+ verify(mFhMock).updateEFTransparent(
+ eq(mSIMRecordsUT.EF_FPLMN), eq(encodedFplmn), any(Message.class));
+ }
+
+ private void setUpSetForbiddenPlmnsTests() {
+ doAnswer(
+ invocation -> {
+ Message response = invocation.getArgument(1);
+ AsyncResult.forMessage(response, EF_SIZE, null);
+ response.sendToTarget();
+ return null;
+ })
+ .when(mFhMock)
+ .getEFTransparentRecordSize(anyInt(), any(Message.class));
+ doAnswer(
+ invocation -> {
+ Message response = invocation.getArgument(2);
+ AsyncResult.forMessage(response, true, null);
+ response.sendToTarget();
+ return null;
+ })
+ .when(mFhMock)
+ .updateEFTransparent(anyInt(), any(byte[].class), any(Message.class));
+ }
+}