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

Commit 56e75289 authored by Sandeep Gutta's avatar Sandeep Gutta
Browse files

Add subId from SIM Ready event

Add SubscriptionInfo record early when ICCID avaialble
from SIM Ready event.

Bug: 112248844
Test: manual - verified whether subId added correctly in
SIM Ready and SIM Locked scenarios and
atest FrameworksTelephonyTests:SubscriptionInfoUpdaterTest

Change-Id: I70940fb7bfe2ef5d5c04a1d782699b34f96321df
parent 235b6090
Loading
Loading
Loading
Loading
+27 −3
Original line number Diff line number Diff line
@@ -410,6 +410,26 @@ public class SubscriptionInfoUpdater extends Handler {

    protected void handleSimReady(int phoneId) {
        List<Integer> cardIds = new ArrayList<>();
        logd("handleSimReady: phoneId: " + phoneId);

        if (sIccId[phoneId] != null && sIccId[phoneId].equals(ICCID_STRING_FOR_NO_SIM)) {
            logd(" SIM" + (phoneId + 1) + " hot plug in");
            sIccId[phoneId] = null;
        }

        // ICCID is not available in IccRecords by the time SIM Ready event received
        // hence get ICCID from UiccSlot.
        UiccSlot uiccSlot = UiccController.getInstance().getUiccSlotForPhone(phoneId);
        String iccId = (uiccSlot != null) ? IccUtils.stripTrailingFs(uiccSlot.getIccId()) : null;
        if (!TextUtils.isEmpty(iccId)) {
            // Call updateSubscriptionInfoByIccId() only if was
            // not done earlier from SIM Locked event
            if (sIccId[phoneId] == null) {
                sIccId[phoneId] = iccId;

                updateSubscriptionInfoByIccId(phoneId, true /* updateEmbeddedSubs */);
            }
        }

        cardIds.add(getCardIdFromPhoneId(phoneId));
        updateEmbeddedSubscriptions(cardIds, (hasChanges) -> {
@@ -422,7 +442,6 @@ public class SubscriptionInfoUpdater extends Handler {
        broadcastSimApplicationStateChanged(phoneId, TelephonyManager.SIM_STATE_NOT_READY);
    }


    protected void handleSimNotReady(int phoneId) {
        logd("handleSimNotReady: phoneId: " + phoneId);
        boolean isFinalState = false;
@@ -485,9 +504,14 @@ public class SubscriptionInfoUpdater extends Handler {
            logd("handleSimLoaded: IccID null");
            return;
        }

        // Call updateSubscriptionInfoByIccId() only if was not done earlier from SIM READY event
        if (sIccId[phoneId] == null) {
            sIccId[phoneId] = IccUtils.stripTrailingFs(records.getFullIccId());

            updateSubscriptionInfoByIccId(phoneId, true /* updateEmbeddedSubs */);
        }

        List<SubscriptionInfo> subscriptionInfos =
                mSubscriptionController.getSubInfoUsingSlotIndexPrivileged(phoneId);
        if (subscriptionInfos == null || subscriptionInfos.isEmpty()) {
+0 −35
Original line number Diff line number Diff line
@@ -77,41 +77,6 @@ public class VendorSubscriptionInfoUpdater extends SubscriptionInfoUpdater {
        }
    }

    @Override
    protected void handleSimReady(int phoneId) {
        List<Integer> cardIds = new ArrayList<>();
        Rlog.d(LOG_TAG, "handleSimReady: phoneId: " + phoneId);

        if (sIccId[phoneId] != null && sIccId[phoneId].equals(ICCID_STRING_FOR_NO_SIM)) {
            Rlog.d(LOG_TAG, " SIM" + (phoneId + 1) + " hot plug in");
            sIccId[phoneId] = null;
        }
        UiccSlot uiccSlot = UiccController.getInstance().getUiccSlotForPhone(phoneId);
        if (uiccSlot == null) {
            Rlog.d(LOG_TAG, "handleSimReady: uiccSlot null");
            return;
        }

        String iccId = uiccSlot.getIccId();
        if (IccUtils.stripTrailingFs(iccId) == null) {
            Rlog.d(LOG_TAG, "handleSimReady: IccID null");
            return;
        }
        sIccId[phoneId] = IccUtils.stripTrailingFs(iccId);

        updateSubscriptionInfoByIccId(phoneId, true /* updateEmbeddedSubs */);

        cardIds.add(getCardIdFromPhoneId(phoneId));
        updateEmbeddedSubscriptions(cardIds, (hasChanges) -> {
            if (hasChanges) {
                mSubscriptionController.notifySubscriptionInfoChanged();
            }
        });
        broadcastSimStateChanged(phoneId, IccCardConstants.INTENT_VALUE_ICC_READY, null);
        broadcastSimCardStateChanged(phoneId, TelephonyManager.SIM_STATE_PRESENT);
        broadcastSimApplicationStateChanged(phoneId, TelephonyManager.SIM_STATE_NOT_READY);
    }

    @Override
    protected void handleSimLoaded(int phoneId) {
        // mIsRecordUpdateRequired set to false if sIccId has a valid Iccid to skip
+40 −0
Original line number Diff line number Diff line
@@ -902,4 +902,44 @@ public class SubscriptionInfoUpdaterTest extends TelephonyTest {
        verify(mSubscriptionController, times(1)).refreshCachedActiveSubscriptionInfoList();
        verify(mSubscriptionController, times(1)).notifySubscriptionInfoChanged();
    }

    @Test
    @SmallTest
    public void testSimReady() throws Exception {
        replaceInstance(SubscriptionInfoUpdater.class, "sIccId", null,new String[]{""});

        doReturn(FAKE_ICCID_1).when(mUiccSlot).getIccId();

        mUpdater.updateInternalIccState(
            IccCardConstants.INTENT_VALUE_ICC_READY, "TESTING", FAKE_SUB_ID_1);
        processAllMessages();

        verify(mSubscriptionController).clearSubInfoRecord(eq(FAKE_SUB_ID_1));
        verify(mSubscriptionManager, times(1)).addSubscriptionInfoRecord(
                eq(FAKE_ICCID_1), eq(FAKE_SUB_ID_1));
        assertTrue(mUpdater.isSubInfoInitialized());
        verify(mSubscriptionController, times(1)).notifySubscriptionInfoChanged();
    }

    @Test
    @SmallTest
    public void testSimReadyAndLoaded() throws Exception {
        replaceInstance(SubscriptionInfoUpdater.class, "sIccId", null,new String[]{""});

        doReturn(null).when(mUiccSlot).getIccId();

        mUpdater.updateInternalIccState(
            IccCardConstants.INTENT_VALUE_ICC_READY, "TESTING", FAKE_SUB_ID_1);
        processAllMessages();

        verify(mSubscriptionManager, times(0)).addSubscriptionInfoRecord(
                eq(FAKE_ICCID_1), eq(FAKE_SUB_ID_1));

        loadSim();

        SubscriptionManager mSubscriptionManager = SubscriptionManager.from(mContext);
        verify(mSubscriptionManager, times(1)).addSubscriptionInfoRecord(
                eq(FAKE_ICCID_1), eq(FAKE_SUB_ID_1));
        verify(mSubscriptionController, times(1)).notifySubscriptionInfoChanged();
    }
}