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

Commit 9b2016df authored by Jordan Liu's avatar Jordan Liu Committed by android-build-merger
Browse files

Merge "Support to read hex characters from ICCID in card."

am: c89d0c91

Change-Id: I76581ec845e4be5f8cced29680c3ffeb0b66e1cc
parents 53382ab7 c89d0c91
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import android.util.Log;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.IccCardConstants.State;
import com.android.internal.telephony.uicc.IccUtils;

import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -854,8 +855,10 @@ public class SubscriptionController extends ISub.Stub {
            ContentResolver resolver = mContext.getContentResolver();
            Cursor cursor = resolver.query(SubscriptionManager.CONTENT_URI,
                    new String[]{SubscriptionManager.UNIQUE_KEY_SUBSCRIPTION_ID,
                            SubscriptionManager.SIM_SLOT_INDEX, SubscriptionManager.NAME_SOURCE},
                    SubscriptionManager.ICC_ID + "=?", new String[]{iccId}, null);
                            SubscriptionManager.SIM_SLOT_INDEX, SubscriptionManager.NAME_SOURCE,
                            SubscriptionManager.ICC_ID},
                    SubscriptionManager.ICC_ID + "=?" + " OR " + SubscriptionManager.ICC_ID + "=?",
                            new String[]{iccId, IccUtils.getDecimalSubstring(iccId)}, null);

            boolean setDisplayName = false;
            try {
@@ -867,6 +870,7 @@ public class SubscriptionController extends ISub.Stub {
                    int subId = cursor.getInt(0);
                    int oldSimInfoId = cursor.getInt(1);
                    int nameSource = cursor.getInt(2);
                    String oldIccId = cursor.getString(3);
                    ContentValues value = new ContentValues();

                    if (slotIndex != oldSimInfoId) {
@@ -877,6 +881,11 @@ public class SubscriptionController extends ISub.Stub {
                        setDisplayName = true;
                    }

                    if (oldIccId != null && oldIccId.length() < iccId.length()
                            && (oldIccId.equals(IccUtils.getDecimalSubstring(iccId)))) {
                        value.put(SubscriptionManager.ICC_ID, iccId);
                    }

                    if (value.size() > 0) {
                        resolver.update(SubscriptionManager.CONTENT_URI, value,
                                SubscriptionManager.UNIQUE_KEY_SUBSCRIPTION_ID +
+13 −7
Original line number Diff line number Diff line
@@ -273,7 +273,7 @@ public class SubscriptionInfoUpdater extends Handler {
                if (ar.exception == null) {
                    if (ar.result != null) {
                        byte[] data = (byte[])ar.result;
                        mIccId[slotId] = IccUtils.bcdToString(data, 0, data.length);
                        mIccId[slotId] = IccUtils.bchToString(data, 0, data.length);
                    } else {
                        logd("Null ar");
                        mIccId[slotId] = ICCID_STRING_FOR_NO_SIM;
@@ -399,11 +399,11 @@ public class SubscriptionInfoUpdater extends Handler {
            logd("handleSimLoaded: IccRecords null");
            return;
        }
        if (records.getIccId() == null) {
            logd("handleSimLoaded: IccID null");
        if (records.getFullIccId() == null) {
            logd("onRecieve: IccID null");
            return;
        }
        mIccId[slotId] = records.getIccId();
        mIccId[slotId] = records.getFullIccId();

        if (isAllIccIdQueryDone()) {
            updateSubscriptionInfoByIccId();
@@ -563,16 +563,19 @@ public class SubscriptionInfoUpdater extends Handler {

        ContentResolver contentResolver = mContext.getContentResolver();
        String[] oldIccId = new String[PROJECT_SIM_NUM];
        String[] decIccId = new String[PROJECT_SIM_NUM];
        for (int i = 0; i < PROJECT_SIM_NUM; i++) {
            oldIccId[i] = null;
            List<SubscriptionInfo> oldSubInfo =
                    SubscriptionController.getInstance().getSubInfoUsingSlotIndexWithCheck(i, false,
                    mContext.getOpPackageName());
            decIccId[i] = IccUtils.getDecimalSubstring(mIccId[i]);
            if (oldSubInfo != null && oldSubInfo.size() > 0) {
                oldIccId[i] = oldSubInfo.get(0).getIccId();
                logd("updateSubscriptionInfoByIccId: oldSubId = "
                        + oldSubInfo.get(0).getSubscriptionId());
                if (mInsertSimState[i] == SIM_NOT_CHANGE && !mIccId[i].equals(oldIccId[i])) {
                if (mInsertSimState[i] == SIM_NOT_CHANGE && !(mIccId[i].equals(oldIccId[i])
                            || (decIccId[i] != null && decIccId[i].equals(oldIccId[i])))) {
                    mInsertSimState[i] = SIM_CHANGED;
                }
                if (mInsertSimState[i] != SIM_NOT_CHANGE) {
@@ -614,7 +617,7 @@ public class SubscriptionInfoUpdater extends Handler {
                } else /*if (sInsertSimState[i] != SIM_NOT_INSERT)*/ {
                    mSubscriptionManager.addSubscriptionInfoRecord(mIccId[i], i);
                }
                if (isNewSim(mIccId[i], oldIccId)) {
                if (isNewSim(mIccId[i], decIccId[i], oldIccId)) {
                    nNewCardCount++;
                    switch (i) {
                        case PhoneConstants.SUB1:
@@ -780,12 +783,15 @@ public class SubscriptionInfoUpdater extends Handler {
        return -1;
    }

    private boolean isNewSim(String iccId, String[] oldIccId) {
    private boolean isNewSim(String iccId, String decIccId, String[] oldIccId) {
        boolean newSim = true;
        for(int i = 0; i < PROJECT_SIM_NUM; i++) {
            if(iccId.equals(oldIccId[i])) {
                newSim = false;
                break;
            } else if (decIccId != null && decIccId.equals(oldIccId[i])) {
                newSim = false;
                break;
            }
        }
        logd("newSim = " + newSim);
+29 −5
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ 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;
@@ -254,7 +255,7 @@ public class SubscriptionInfoUpdaterTest extends TelephonyTest {
        /* mock new sim got loaded and there is no sim loaded before */
        doReturn(null).when(mSubscriptionController)
                .getSubInfoUsingSlotIndexWithCheck(eq(FAKE_SUB_ID_1), anyBoolean(), anyString());
        doReturn("89012604200000000000").when(mIccRecord).getIccId();
        doReturn("89012604200000000000").when(mIccRecord).getFullIccId();
        doReturn(FAKE_MCC_MNC_1).when(mTelephonyManager).getSimOperatorNumeric(FAKE_SUB_ID_1);
        Intent intentInternalSimStateChanged =
                new Intent(IccCardProxy.ACTION_INTERNAL_SIM_STATE_CHANGED);
@@ -322,7 +323,7 @@ public class SubscriptionInfoUpdaterTest extends TelephonyTest {
        /* mock new sim got loaded and there is no sim loaded before */
        doReturn(null).when(mSubscriptionController)
                .getSubInfoUsingSlotIndexWithCheck(eq(FAKE_SUB_ID_1), anyBoolean(), anyString());
        doReturn("89012604200000000000").when(mIccRecord).getIccId();
        doReturn("89012604200000000000").when(mIccRecord).getFullIccId();
        // operator numeric is empty
        doReturn("").when(mTelephonyManager).getSimOperatorNumeric(FAKE_SUB_ID_1);
        Intent mIntent = new Intent(IccCardProxy.ACTION_INTERNAL_SIM_STATE_CHANGED);
@@ -414,7 +415,7 @@ public class SubscriptionInfoUpdaterTest extends TelephonyTest {
        doReturn(null).when(mSubscriptionController)
                .getSubInfoUsingSlotIndexWithCheck(anyInt(), anyBoolean(), anyString());
        verify(mSubscriptionController, times(0)).clearSubInfo();
        doReturn("89012604200000000000").when(mIccRecord).getIccId();
        doReturn("89012604200000000000").when(mIccRecord).getFullIccId();

        // Mock sending a sim loaded for SIM 1
        Intent mIntent = new Intent(IccCardProxy.ACTION_INTERNAL_SIM_STATE_CHANGED);
@@ -430,7 +431,7 @@ public class SubscriptionInfoUpdaterTest extends TelephonyTest {
        verify(mSubscriptionController, times(0)).setMccMnc(anyString(), anyInt());

        // Mock sending a sim loaded for SIM 2
        doReturn("89012604200000000001").when(mIccRecord).getIccId();
        doReturn("89012604200000000001").when(mIccRecord).getFullIccId();
        mIntent = new Intent(IccCardProxy.ACTION_INTERNAL_SIM_STATE_CHANGED);
        mIntent.putExtra(IccCardConstants.INTENT_KEY_ICC_STATE,
                IccCardConstants.INTENT_VALUE_ICC_LOADED);
@@ -603,4 +604,27 @@ public class SubscriptionInfoUpdaterTest extends TelephonyTest {
        verify(mContentProvider, never()).update(eq(SubscriptionManager.CONTENT_URI), any(),
                any(), isNull());
    }

    @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);

        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]);
    }
}