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

Commit c9ebcc60 authored by Abhishek Adappa's avatar Abhishek Adappa Committed by Steve Kondik
Browse files

IccPhoneBookInterfaceManager will decide which Card App to use.

Phone will not tell IccPhoneBoookIntefaceManager which record
to use. Phone will only provide the card associated with it.

PhoneBook will iterate through the apps on the card to
determine if it is a 3G or 2G card and use EF_PBR or
EF_ADN respectively.

Reset mIs3gCard flag before determining if present card is 3G.

Change-Id: Icf5997dd6a6ba5e1de675cf5f4334c78c2c037f1
CRs-Fixed: 478627
parent c0eda364
Loading
Loading
Loading
Loading
+74 −13
Original line number Diff line number Diff line
@@ -113,23 +113,84 @@ public abstract class IccPhoneBookInterfaceManager {

    public IccPhoneBookInterfaceManager(PhoneBase phone) {
        this.mPhone = phone;
        IccRecords r = phone.mIccRecords.get();
        if (r != null) {
            mAdnCache = r.getAdnCache();
    }

    private void cleanUp() {
        if (mAdnCache != null) {
            mAdnCache.reset();
            mAdnCache = null;
        }
        mIs3gCard = false;
        mCurrentApp = null;
    }

    public void dispose() {
        if (mRecords != null) {
            mRecords.clear();
        }
        cleanUp();
    }

    public void updateIccRecords(IccRecords iccRecords) {
        if (iccRecords != null) {
            mAdnCache = iccRecords.getAdnCache();
        } else {
            mAdnCache = null;
    public void setIccCard(UiccCard card) {
        logd("Card update received: " + card);

        if (card == null) {
            logd("Card is null. Cleanup");
            cleanUp();
            return;
        }

        UiccCardApplication validApp = null;
        int numApps = card.getNumApplications();
        boolean isCurrentAppFound = false;
        mIs3gCard = false;

        for (int i = 0; i < numApps; i++) {
            UiccCardApplication app = card.getApplicationIndex(i);
            if (app != null) {
                // Determine if the card is a 3G card by looking
                // for a CSIM/USIM/ISIM app on the card
                AppType type = app.getType();
                if (type == AppType.APPTYPE_CSIM || type == AppType.APPTYPE_USIM
                        || type == AppType.APPTYPE_ISIM) {
                    logd("Card is 3G");
                    mIs3gCard = true;
                }
                // Check if the app we have is present.
                // If yes, then continue using that.
                if (!isCurrentAppFound) {
                    // if not, then find a valid app.
                    // It does not matter which app, since we are
                    // accessing non-app specific files
                    if (validApp == null && type != AppType.APPTYPE_UNKNOWN) {
                        validApp = app;
                    }

                    if (mCurrentApp == app) {
                        logd("Existing app found");
                        isCurrentAppFound = true;
                    }
                }

                // We have determined that this is 3g card
                // and we also found the current app
                // We are done
                if (mIs3gCard && isCurrentAppFound) {
                    break;
                }
            }
        }

        //Set a new currentApp if
        // - one was not set before
        // OR
        // - the previously set app no longer exists
        if (mCurrentApp == null || !isCurrentAppFound) {
            if (validApp != null) {
                logd("Setting currentApp: " + validApp);
                mCurrentApp = validApp;
                mAdnCache = mCurrentApp.getIccRecords().getAdnCache();
            }
        }
    }

@@ -309,12 +370,12 @@ public abstract class IccPhoneBookInterfaceManager {
    }

    private int updateEfForIccType(int efid) {
        // Check if we are trying to read ADN records
        if (efid == IccConstants.EF_ADN) {
            if (mPhone.getCurrentUiccAppType() == AppType.APPTYPE_USIM) {
        // If we are trying to read ADN records on a 3G card
        // use EF_PBR
        if (efid == IccConstants.EF_ADN && mIs3gCard) {
            logd("Translate EF_ADN to EF_PBR");
            return IccConstants.EF_PBR;
        }
        }
        return efid;
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -586,6 +586,10 @@ public abstract class PhoneBase extends Handler implements Phone {
        return mContext;
    }

    // Set the Card into the Phone Book.
    protected void setCardInPhoneBook() {
    }

    // Will be called when icc changed
    protected abstract void onUpdateIccAvailability();

+14 −0
Original line number Diff line number Diff line
@@ -1299,12 +1299,26 @@ public class CDMAPhone extends PhoneBase {
        return  mUiccController.getUiccCardApplication(mPhoneId, UiccController.APP_FAM_3GPP2);
    }

    // Set the Card into the Phone Book.
    @Override
    protected void setCardInPhoneBook() {
        if (mUiccController == null ) {
            return;
        }

        mRuimPhoneBookInterfaceManager.setIccCard(mUiccController.getUiccCard(mPhoneId));
    }

    @Override
    protected void onUpdateIccAvailability() {
        if (mUiccController == null ) {
            return;
        }

        // Get the latest info on the card and
        // send this to Phone Book
        setCardInPhoneBook();

        UiccCardApplication newUiccApplication = getUiccCardApplication();

        if (newUiccApplication == null) {
+15 −3
Original line number Diff line number Diff line
@@ -113,7 +113,7 @@ public class GSMPhone extends PhoneBase {
    GsmCallTracker mCT;
    GsmServiceStateTracker mSST;
    ArrayList <GsmMmiCode> mPendingMMIs = new ArrayList<GsmMmiCode>();
    SimPhoneBookInterfaceManager mSimPhoneBookIntManager;
    protected SimPhoneBookInterfaceManager mSimPhoneBookIntManager;
    PhoneSubInfo mSubInfo;


@@ -1574,12 +1574,26 @@ public class GSMPhone extends PhoneBase {
                    UiccController.APP_FAM_3GPP);
    }

    // Set the Card into the Phone Book.
    @Override
    protected void setCardInPhoneBook() {
        if (mUiccController == null ) {
            return;
        }

        mSimPhoneBookIntManager.setIccCard(mUiccController.getUiccCard(mPhoneId));
    }

    @Override
    protected void onUpdateIccAvailability() {
        if (mUiccController == null ) {
            return;
        }

        // Get the latest info on the card and
        // send this to Phone Book
        setCardInPhoneBook();

        UiccCardApplication newUiccApplication =
                mUiccController.getUiccCardApplication(mPhoneId, UiccController.APP_FAM_IMS);
        IsimUiccRecords newIsimUiccRecords = null;
@@ -1598,7 +1612,6 @@ public class GSMPhone extends PhoneBase {
                if (LOCAL_DEBUG) log("Removing stale icc objects.");
                if (mIccRecords.get() != null) {
                    unregisterForSimRecordEvents();
                    mSimPhoneBookIntManager.updateIccRecords(null);
                }
                mIccRecords.set(null);
                mUiccApplication.set(null);
@@ -1608,7 +1621,6 @@ public class GSMPhone extends PhoneBase {
                mUiccApplication.set(newUiccApplication);
                mIccRecords.set(newUiccApplication.getIccRecords());
                registerForSimRecordEvents();
                mSimPhoneBookIntManager.updateIccRecords(mIccRecords.get());
            }
        }
    }