Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 82e00870 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Strip the 'F' padding at the end of the full iccid"

parents 0d5b34f9 a897bda2
Loading
Loading
Loading
Loading
+13 −3
Original line number Diff line number Diff line
@@ -273,7 +273,8 @@ public class SubscriptionInfoUpdater extends Handler {
                if (ar.exception == null) {
                    if (ar.result != null) {
                        byte[] data = (byte[])ar.result;
                        mIccId[slotId] = IccUtils.bchToString(data, 0, data.length);
                        mIccId[slotId] = stripIccIdSuffix(
                                IccUtils.bchToString(data, 0, data.length));
                    } else {
                        logd("Null ar");
                        mIccId[slotId] = ICCID_STRING_FOR_NO_SIM;
@@ -399,11 +400,11 @@ public class SubscriptionInfoUpdater extends Handler {
            logd("handleSimLoaded: IccRecords null");
            return;
        }
        if (records.getFullIccId() == null) {
        if (stripIccIdSuffix(records.getFullIccId()) == null) {
            logd("onRecieve: IccID null");
            return;
        }
        mIccId[slotId] = records.getFullIccId();
        mIccId[slotId] = stripIccIdSuffix(records.getFullIccId());

        if (isAllIccIdQueryDone()) {
            updateSubscriptionInfoByIccId();
@@ -808,6 +809,15 @@ public class SubscriptionInfoUpdater extends Handler {
        IntentBroadcaster.getInstance().broadcastStickyIntent(i, slotId);
    }

    // Remove trailing F's from full hexadecimal IccId, as they should be considered padding
    private String stripIccIdSuffix(String hexIccId) {
        if (hexIccId == null) {
            return null;
        } else {
            return hexIccId.replaceAll("(?i)f*$", "");
        }
    }

    public void dispose() {
        logd("[dispose]");
        mContext.unregisterReceiver(sReceiver);
+16 −17
Original line number Diff line number Diff line
@@ -66,7 +66,6 @@ import org.mockito.Mock;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -607,24 +606,24 @@ public class SubscriptionInfoUpdaterTest extends TelephonyTest {

    @Test
    @SmallTest
    public void testHexIccId() throws Exception {
        SubscriptionInfo subInfo = new SubscriptionInfo(1, "898600910916", 0, "China Mobile",
                "CMCC", 0, 255, null, 0, null, 460, 0, "cn");
        doReturn(Arrays.asList(subInfo)).when(mSubscriptionController)
                .getSubInfoUsingSlotIndexWithCheck(eq(FAKE_SUB_ID_1), anyBoolean(), anyString());
        doReturn("898600910916f4078561").when(mIccRecord).getFullIccId();
        doReturn(FAKE_MCC_MNC_1).when(mTelephonyManager).getSimOperatorNumeric(eq(FAKE_SUB_ID_1));
        Intent intentInternalSimStateChanged =
                new Intent(IccCardProxy.ACTION_INTERNAL_SIM_STATE_CHANGED);
        intentInternalSimStateChanged.putExtra(IccCardConstants.INTENT_KEY_ICC_STATE,
                IccCardConstants.INTENT_VALUE_ICC_LOADED);
        intentInternalSimStateChanged.putExtra(PhoneConstants.PHONE_KEY, FAKE_SUB_ID_1);
    public void testHexIccIdSuffix() throws Exception {
        doReturn(null).when(mSubscriptionController)
                .getSubInfoUsingSlotIndexWithCheck(anyInt(), anyBoolean(), anyString());
        verify(mSubscriptionController, times(0)).clearSubInfo();
        doReturn("890126042000000000Ff").when(mIccRecord).getFullIccId();

        // Mock sending a sim loaded for SIM 1
        Intent mIntent = new Intent(IccCardProxy.ACTION_INTERNAL_SIM_STATE_CHANGED);
        mIntent.putExtra(IccCardConstants.INTENT_KEY_ICC_STATE,
                IccCardConstants.INTENT_VALUE_ICC_LOADED);
        mIntent.putExtra(PhoneConstants.PHONE_KEY, FAKE_SUB_ID_1);
        mContext.sendBroadcast(mIntent);
        waitForMs(100);

        Field field = SubscriptionInfoUpdater.class.getDeclaredField("mInsertSimState");
        field.setAccessible(true);
        int[] mState = (int[]) field.get(mUpdater);
        assertEquals(SubscriptionInfoUpdater.SIM_NOT_CHANGE, mState[FAKE_SUB_ID_1]);
        SubscriptionManager mSubscriptionManager = SubscriptionManager.from(mContext);
        verify(mSubscriptionController, times(1)).notifySubscriptionInfoChanged();
        verify(mSubscriptionManager, times(1)).addSubscriptionInfoRecord(eq("890126042000000000"),
                eq(FAKE_SUB_ID_1));
        verify(mSubscriptionController, times(0)).clearSubInfo();
    }
}