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

Commit a8a3d652 authored by Amit Mahajan's avatar Amit Mahajan
Browse files

Read ICCID before broadcasting state LOCKED.

Test: Basic telephony sanity
Bug: 64131518
Change-Id: Id22fa01d87383d6746b9a264dda47f55d1bb9e67
parent 49470fb0
Loading
Loading
Loading
Loading
+16 −72
Original line number Diff line number Diff line
@@ -51,8 +51,6 @@ import android.text.TextUtils;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.euicc.EuiccController;
import com.android.internal.telephony.uicc.IccCardProxy;
import com.android.internal.telephony.uicc.IccConstants;
import com.android.internal.telephony.uicc.IccFileHandler;
import com.android.internal.telephony.uicc.IccRecords;
import com.android.internal.telephony.uicc.IccUtils;

@@ -68,7 +66,6 @@ public class SubscriptionInfoUpdater extends Handler {
    private static final String LOG_TAG = "SubscriptionInfoUpdater";
    private static final int PROJECT_SIM_NUM = TelephonyManager.getDefault().getPhoneCount();

    private static final int EVENT_SIM_LOCKED_QUERY_ICCID_DONE = 1;
    private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 2;
    private static final int EVENT_SIM_LOADED = 3;
    private static final int EVENT_SIM_ABSENT = 4;
@@ -240,61 +237,9 @@ public class SubscriptionInfoUpdater extends Handler {
        return true;
    }

    public void setDisplayNameForNewSub(String newSubName, int subId, int newNameSource) {
        SubscriptionInfo subInfo = mSubscriptionManager.getActiveSubscriptionInfo(subId);
        if (subInfo != null) {
            // overwrite SIM display name if it is not assigned by user
            int oldNameSource = subInfo.getNameSource();
            CharSequence oldSubName = subInfo.getDisplayName();
            logd("[setDisplayNameForNewSub] subId = " + subInfo.getSubscriptionId()
                    + ", oldSimName = " + oldSubName + ", oldNameSource = " + oldNameSource
                    + ", newSubName = " + newSubName + ", newNameSource = " + newNameSource);
            if (oldSubName == null ||
                (oldNameSource ==
                    SubscriptionManager.NAME_SOURCE_DEFAULT_SOURCE && newSubName != null) ||
                (oldNameSource == SubscriptionManager.NAME_SOURCE_SIM_SOURCE && newSubName != null
                        && !newSubName.equals(oldSubName))) {
                mSubscriptionManager.setDisplayName(newSubName, subInfo.getSubscriptionId(),
                        newNameSource);
            }
        } else {
            logd("SUB" + (subId + 1) + " SubInfo not created yet");
        }
    }

    @Override
    public void handleMessage(Message msg) {
        switch (msg.what) {
            case EVENT_SIM_LOCKED_QUERY_ICCID_DONE: {
                AsyncResult ar = (AsyncResult)msg.obj;
                QueryIccIdUserObj uObj = (QueryIccIdUserObj) ar.userObj;
                int slotId = uObj.slotId;
                logd("handleMessage : <EVENT_SIM_LOCKED_QUERY_ICCID_DONE> SIM" + (slotId + 1));
                if (ar.exception == null) {
                    if (ar.result != null) {
                        byte[] data = (byte[])ar.result;
                        mIccId[slotId] = stripIccIdSuffix(
                                IccUtils.bchToString(data, 0, data.length));
                    } else {
                        logd("Null ar");
                        mIccId[slotId] = ICCID_STRING_FOR_NO_SIM;
                    }
                } else {
                    mIccId[slotId] = ICCID_STRING_FOR_NO_SIM;
                    logd("Query IccId fail: " + ar.exception);
                }
                logd("sIccId[" + slotId + "] = " + mIccId[slotId]);
                if (isAllIccIdQueryDone()) {
                    updateSubscriptionInfoByIccId();
                }
                broadcastSimStateChanged(slotId, IccCardConstants.INTENT_VALUE_ICC_LOCKED,
                                         uObj.reason);
                if (!ICCID_STRING_FOR_NO_SIM.equals(mIccId[slotId])) {
                    updateCarrierServices(slotId, IccCardConstants.INTENT_VALUE_ICC_LOCKED);
                }
                break;
            }

            case EVENT_GET_NETWORK_SELECTION_MODE_DONE: {
                AsyncResult ar = (AsyncResult)msg.obj;
                Integer slotId = (Integer)ar.userObj;
@@ -367,25 +312,24 @@ public class SubscriptionInfoUpdater extends Handler {
            mIccId[slotId] = null;
        }


        IccFileHandler fileHandler = mPhone[slotId].getIccCard() == null ? null :
                mPhone[slotId].getIccCard().getIccFileHandler();

        if (fileHandler != null) {
        String iccId = mIccId[slotId];
        if (iccId == null) {
                logd("Querying IccId");
                fileHandler.loadEFTransparent(IccConstants.EF_ICCID,
                        obtainMessage(EVENT_SIM_LOCKED_QUERY_ICCID_DONE,
                                new QueryIccIdUserObj(reason, slotId)));
            IccRecords records = mPhone[slotId].getIccCard().getIccRecords();
            if (stripIccIdSuffix(records.getFullIccId()) == null) {
                logd("handleSimLocked: IccID null");
                return;
            }
            mIccId[slotId] = stripIccIdSuffix(records.getFullIccId());
        } else {
            logd("NOT Querying IccId its already set sIccid[" + slotId + "]=" + iccId);
                updateCarrierServices(slotId, IccCardConstants.INTENT_VALUE_ICC_LOCKED);
                broadcastSimStateChanged(slotId, IccCardConstants.INTENT_VALUE_ICC_LOCKED, reason);
        }
        } else {
            logd("sFh[" + slotId + "] is null, ignore");

        if (isAllIccIdQueryDone()) {
            updateSubscriptionInfoByIccId();
        }

        updateCarrierServices(slotId, IccCardConstants.INTENT_VALUE_ICC_LOCKED);
        broadcastSimStateChanged(slotId, IccCardConstants.INTENT_VALUE_ICC_LOCKED, reason);
    }

    private void handleSimLoaded(int slotId) {
@@ -401,7 +345,7 @@ public class SubscriptionInfoUpdater extends Handler {
            return;
        }
        if (stripIccIdSuffix(records.getFullIccId()) == null) {
            logd("onRecieve: IccID null");
            logd("handleSimLoaded: IccID null");
            return;
        }
        mIccId[slotId] = stripIccIdSuffix(records.getFullIccId());
+1 −12
Original line number Diff line number Diff line
@@ -437,17 +437,6 @@ public class IccCardProxy extends Handler implements IccCard {
            case APPSTATE_DETECTED:
                HandleDetectedState();
                break;
            case APPSTATE_PIN:
                setExternalState(State.PIN_REQUIRED);
                break;
            case APPSTATE_PUK:
                PinState pin1State = mUiccApplication.getPin1State();
                if (pin1State.isPermBlocked()) {
                    setExternalState(State.PERM_DISABLED);
                    return;
                }
                setExternalState(State.PUK_REQUIRED);
                break;
            case APPSTATE_SUBSCRIPTION_PERSO:
                if (mUiccApplication.getPersoSubState() ==
                        PersoSubState.PERSOSUBSTATE_SIM_NETWORK) {
@@ -467,12 +456,12 @@ public class IccCardProxy extends Handler implements IccCard {
        }
        if (mUiccApplication != null) {
            mUiccApplication.registerForReady(this, EVENT_APP_READY, null);
            mUiccApplication.registerForLocked(this, EVENT_ICC_LOCKED, null);
            mUiccApplication.registerForNetworkLocked(this, EVENT_NETWORK_LOCKED, null);
        }
        if (mIccRecords != null) {
            mIccRecords.registerForImsiReady(this, EVENT_IMSI_READY, null);
            mIccRecords.registerForRecordsLoaded(this, EVENT_RECORDS_LOADED, null);
            mIccRecords.registerForLockedRecordsLoaded(this, EVENT_ICC_LOCKED, null);
            mIccRecords.registerForRecordsEvents(this, EVENT_ICC_RECORD_EVENTS, null);
        }
    }
+40 −6
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ public abstract class IccRecords extends Handler implements IccConstants {
    protected TelephonyManager mTelephonyManager;

    protected RegistrantList mRecordsLoadedRegistrants = new RegistrantList();
    protected RegistrantList mLockedRecordsLoadedRegistrants = new RegistrantList();
    protected RegistrantList mImsiReadyRegistrants = new RegistrantList();
    protected RegistrantList mRecordsEventsRegistrants = new RegistrantList();
    protected RegistrantList mNewSmsRegistrants = new RegistrantList();
@@ -68,6 +69,8 @@ public abstract class IccRecords extends Handler implements IccConstants {
    // ***** Cached SIM State; cleared on channel close

    protected boolean mRecordsRequested = false; // true if we've made requests for the sim records
    protected boolean mLockedRecordsRequested = false; // true if parent app is locked and we've
                                                       // made requests for the sim records

    protected String mIccId;  // Includes only decimals (no hex)
    protected String mFullIccId;  // Includes hex characters in ICCID
@@ -155,6 +158,7 @@ public abstract class IccRecords extends Handler implements IccConstants {
                + " recordsToLoad=" + mRecordsToLoad
                + " adnCache=" + mAdnCache
                + " recordsRequested=" + mRecordsRequested
                + " lockedRecordsRequested=" + mLockedRecordsRequested
                + " iccid=" + iccIdToPrint
                + " msisdnTag=" + mMsisdnTag
                + " voiceMailNum=" + Rlog.pii(VDBG, mVoiceMailNum)
@@ -291,7 +295,7 @@ public abstract class IccRecords extends Handler implements IccConstants {
        Registrant r = new Registrant(h, what, obj);
        mRecordsLoadedRegistrants.add(r);

        if (mRecordsToLoad == 0 && mRecordsRequested == true) {
        if (getRecordsLoaded()) {
            r.notifyRegistrant(new AsyncResult(null, null, null));
        }
    }
@@ -299,6 +303,29 @@ public abstract class IccRecords extends Handler implements IccConstants {
        mRecordsLoadedRegistrants.remove(h);
    }

    /**
     * Register to be notified when records are loaded for a locked SIM
     */
    public void registerForLockedRecordsLoaded(Handler h, int what, Object obj) {
        if (mDestroyed.get()) {
            return;
        }

        Registrant r = new Registrant(h, what, obj);
        mLockedRecordsLoadedRegistrants.add(r);

        if (getLockedRecordsLoaded()) {
            r.notifyRegistrant(new AsyncResult(null, null, null));
        }
    }

    /**
     * Unregister corresponding to registerForLockedRecordsLoaded()
     */
    public void unregisterForLockedRecordsLoaded(Handler h) {
        mLockedRecordsLoadedRegistrants.remove(h);
    }

    public void registerForImsiReady(Handler h, int what, Object obj) {
        if (mDestroyed.get()) {
            return;
@@ -560,11 +587,11 @@ public abstract class IccRecords extends Handler implements IccConstants {
    }

    public boolean getRecordsLoaded() {
        if (mRecordsToLoad == 0 && mRecordsRequested == true) {
            return true;
        } else {
            return false;
        return mRecordsToLoad == 0 && mRecordsRequested;
    }

    protected boolean getLockedRecordsLoaded() {
        return mRecordsToLoad == 0 && mLockedRecordsRequested;
    }

    //***** Overridden from Handler
@@ -822,6 +849,12 @@ public abstract class IccRecords extends Handler implements IccConstants {
            pw.println("  recordsLoadedRegistrants[" + i + "]="
                    + ((Registrant)mRecordsLoadedRegistrants.get(i)).getHandler());
        }
        pw.println(" mLockedRecordsLoadedRegistrants: size="
                + mLockedRecordsLoadedRegistrants.size());
        for (int i = 0; i < mLockedRecordsLoadedRegistrants.size(); i++) {
            pw.println("  mLockedRecordsLoadedRegistrants[" + i + "]="
                    + ((Registrant) mLockedRecordsLoadedRegistrants.get(i)).getHandler());
        }
        pw.println(" mImsiReadyRegistrants: size=" + mImsiReadyRegistrants.size());
        for (int i = 0; i < mImsiReadyRegistrants.size(); i++) {
            pw.println("  mImsiReadyRegistrants[" + i + "]="
@@ -844,6 +877,7 @@ public abstract class IccRecords extends Handler implements IccConstants {
                    + ((Registrant)mNetworkSelectionModeAutomaticRegistrants.get(i)).getHandler());
        }
        pw.println(" mRecordsRequested=" + mRecordsRequested);
        pw.println(" mLockedRecordsRequested=" + mLockedRecordsRequested);
        pw.println(" mRecordsToLoad=" + mRecordsToLoad);
        pw.println(" mRdnCache=" + mAdnCache);

+13 −3
Original line number Diff line number Diff line
@@ -82,6 +82,9 @@ public class IsimUiccRecords extends IccRecords implements IsimRecords {
        super(app, c, ci);

        mRecordsRequested = false;  // No load request is made till SIM ready
        //todo: currently locked state for ISIM is not handled well and may cause app state to not
        //be broadcast
        mLockedRecordsRequested = false;

        // recordsToLoad is set to 0 because no requests are made yet
        mRecordsToLoad = 0;
@@ -196,6 +199,7 @@ public class IsimUiccRecords extends IccRecords implements IsimRecords {
        auth_rsp = null;

        mRecordsRequested = false;
        mLockedRecordsRequested = false;
    }

    private class EfIsimImpiLoaded implements IccRecords.IccRecordLoaded {
@@ -291,19 +295,25 @@ public class IsimUiccRecords extends IccRecords implements IsimRecords {
        mRecordsToLoad -= 1;
        if (DBG) log("onRecordLoaded " + mRecordsToLoad + " requested: " + mRecordsRequested);

        if (mRecordsToLoad == 0 && mRecordsRequested == true) {
        if (getRecordsLoaded()) {
            onAllRecordsLoaded();
        } else if (getLockedRecordsLoaded()) {
            onLockedAllRecordsLoaded();
        } else if (mRecordsToLoad < 0) {
            loge("recordsToLoad <0, programmer error suspected");
            mRecordsToLoad = 0;
        }
    }

    private void onLockedAllRecordsLoaded() {
        if (DBG) log("SIM locked; record load complete");
        mLockedRecordsLoadedRegistrants.notifyRegistrants(new AsyncResult(null, null, null));
    }

    @Override
    protected void onAllRecordsLoaded() {
       if (DBG) log("record load complete");
        mRecordsLoadedRegistrants.notifyRegistrants(
                new AsyncResult(null, null, null));
        mRecordsLoadedRegistrants.notifyRegistrants(new AsyncResult(null, null, null));
    }

    private void handleFileUpdate(int efid) {
+25 −4
Original line number Diff line number Diff line
@@ -98,6 +98,7 @@ public class RuimRecords extends IccRecords {
    private static final int EVENT_GET_SMS_DONE = 22;

    private static final int EVENT_RUIM_REFRESH = 31;
    private static final int EVENT_APP_LOCKED = 32;

    public RuimRecords(UiccCardApplication app, Context c, CommandsInterface ci) {
        super(app, c, ci);
@@ -105,6 +106,7 @@ public class RuimRecords extends IccRecords {
        mAdnCache = new AdnRecordCache(mFh);

        mRecordsRequested = false;  // No load request is made till SIM ready
        mLockedRecordsRequested = false;

        // recordsToLoad is set to 0 because no requests are made yet
        mRecordsToLoad = 0;
@@ -116,6 +118,7 @@ public class RuimRecords extends IccRecords {
        resetRecords();

        mParentApp.registerForReady(this, EVENT_APP_READY, null);
        mParentApp.registerForLocked(this, EVENT_APP_LOCKED, null);
        if (DBG) log("RuimRecords X ctor this=" + this);
    }

@@ -152,6 +155,7 @@ public class RuimRecords extends IccRecords {
        // read requests made so far are not valid. This is set to
        // true only when fresh set of read requests are made.
        mRecordsRequested = false;
        mLockedRecordsRequested = false;
    }

    public String getMdnNumber() {
@@ -597,11 +601,16 @@ public class RuimRecords extends IccRecords {
            return;
        }

        try { switch (msg.what) {
        try {
            switch (msg.what) {
            case EVENT_APP_READY:
                onReady();
                break;

                case EVENT_APP_LOCKED:
                    onLocked();
                    break;

            case EVENT_GET_DEVICE_IDENTITY_DONE:
                log("Event EVENT_GET_DEVICE_IDENTITY_DONE Received");
            break;
@@ -745,14 +754,20 @@ public class RuimRecords extends IccRecords {
        mRecordsToLoad -= 1;
        if (DBG) log("onRecordLoaded " + mRecordsToLoad + " requested: " + mRecordsRequested);

        if (mRecordsToLoad == 0 && mRecordsRequested == true) {
        if (getRecordsLoaded()) {
            onAllRecordsLoaded();
        } else if (getLockedRecordsLoaded()) {
            onLockedAllRecordsLoaded();
        } else if (mRecordsToLoad < 0) {
            loge("recordsToLoad <0, programmer error suspected");
            mRecordsToLoad = 0;
        }
    }

    private void onLockedAllRecordsLoaded() {
        mLockedRecordsLoadedRegistrants.notifyRegistrants(new AsyncResult(null, null, null));
    }

    @Override
    protected void onAllRecordsLoaded() {
        if (DBG) log("record load complete");
@@ -790,8 +805,7 @@ public class RuimRecords extends IccRecords {
            setSimLanguage(mEFli, mEFpl);
        }

        mRecordsLoadedRegistrants.notifyRegistrants(
            new AsyncResult(null, null, null));
        mRecordsLoadedRegistrants.notifyRegistrants(new AsyncResult(null, null, null));

        // TODO: The below is hacky since the SubscriptionController may not be ready at this time.
        if (!TextUtils.isEmpty(mMdn)) {
@@ -812,6 +826,13 @@ public class RuimRecords extends IccRecords {
        mCi.getCDMASubscription(obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_DONE));
    }

    private void onLocked() {
        if (DBG) log("only fetch EF_ICCID in locked state");
        mLockedRecordsRequested = true;

        mFh.loadEFTransparent(EF_ICCID, obtainMessage(EVENT_GET_ICCID_DONE));
        mRecordsToLoad++;
    }

    private void fetchRuimRecords() {
        mRecordsRequested = true;
Loading