Loading src/java/com/android/internal/telephony/uicc/SIMRecords.java +1 −0 Original line number Diff line number Diff line Loading @@ -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) { Loading tests/telephonytests/src/com/android/internal/telephony/CellIdentityTest.java +18 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -84,6 +89,7 @@ public class CellIdentityTest extends AndroidTestCase { assertEquals(CellInfo.UNAVAILABLE, gsm.getBsic()); } @SmallTest public void testEquals() { CellIdentity ciA = new CellIdentityLte( Loading Loading @@ -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)); } } tests/telephonytests/src/com/android/internal/telephony/uicc/IccRecordsTest.java +15 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); } } tests/telephonytests/src/com/android/internal/telephony/uicc/IccUtilsTest.java 0 → 100644 +43 −0 Original line number Diff line number Diff line /* * 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); } } tests/telephonytests/src/com/android/internal/telephony/uicc/SIMRecordsTest.java 0 → 100644 +174 −0 Original line number Diff line number Diff line /* * 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)); } } Loading
src/java/com/android/internal/telephony/uicc/SIMRecords.java +1 −0 Original line number Diff line number Diff line Loading @@ -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) { Loading
tests/telephonytests/src/com/android/internal/telephony/CellIdentityTest.java +18 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -84,6 +89,7 @@ public class CellIdentityTest extends AndroidTestCase { assertEquals(CellInfo.UNAVAILABLE, gsm.getBsic()); } @SmallTest public void testEquals() { CellIdentity ciA = new CellIdentityLte( Loading Loading @@ -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)); } }
tests/telephonytests/src/com/android/internal/telephony/uicc/IccRecordsTest.java +15 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); } }
tests/telephonytests/src/com/android/internal/telephony/uicc/IccUtilsTest.java 0 → 100644 +43 −0 Original line number Diff line number Diff line /* * 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); } }
tests/telephonytests/src/com/android/internal/telephony/uicc/SIMRecordsTest.java 0 → 100644 +174 −0 Original line number Diff line number Diff line /* * 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)); } }