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


        if (isAllIccIdQueryDone()) {
        if (isAllIccIdQueryDone()) {
            updateSubscriptionInfoByIccId();
            updateSubscriptionInfoByIccId();
@@ -808,6 +809,15 @@ public class SubscriptionInfoUpdater extends Handler {
        IntentBroadcaster.getInstance().broadcastStickyIntent(i, slotId);
        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() {
    public void dispose() {
        logd("[dispose]");
        logd("[dispose]");
        mContext.unregisterReceiver(sReceiver);
        mContext.unregisterReceiver(sReceiver);
+16 −17
Original line number Original line Diff line number Diff line
@@ -66,7 +66,6 @@ import org.mockito.Mock;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.mockito.stubbing.Answer;


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


    @Test
    @Test
    @SmallTest
    @SmallTest
    public void testHexIccId() throws Exception {
    public void testHexIccIdSuffix() throws Exception {
        SubscriptionInfo subInfo = new SubscriptionInfo(1, "898600910916", 0, "China Mobile",
        doReturn(null).when(mSubscriptionController)
                "CMCC", 0, 255, null, 0, null, 460, 0, "cn");
                .getSubInfoUsingSlotIndexWithCheck(anyInt(), anyBoolean(), anyString());
        doReturn(Arrays.asList(subInfo)).when(mSubscriptionController)
        verify(mSubscriptionController, times(0)).clearSubInfo();
                .getSubInfoUsingSlotIndexWithCheck(eq(FAKE_SUB_ID_1), anyBoolean(), anyString());
        doReturn("890126042000000000Ff").when(mIccRecord).getFullIccId();
        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);


        // 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);
        waitForMs(100);


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