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

Commit 56a07915 authored by Abhishek Adappa's avatar Abhishek Adappa Committed by Linux Build Service Account
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.

Change-Id: Icf5997dd6a6ba5e1de675cf5f4334c78c2c037f1
CRs-Fixed: 478627
(cherry picked from commit 38feb8d225f8e81e3d24aa83f870998e2414ca87)
parent 28d57e84
Loading
Loading
Loading
Loading
+78 −13
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@ import com.android.internal.telephony.uicc.AdnRecordCache;
import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
import com.android.internal.telephony.uicc.IccConstants;
import com.android.internal.telephony.uicc.IccRecords;
import com.android.internal.telephony.uicc.UiccCard;
import com.android.internal.telephony.uicc.UiccCardApplication;

import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -40,12 +42,15 @@ public abstract class IccPhoneBookInterfaceManager extends IIccPhoneBook.Stub {
    protected static final boolean DBG = true;

    protected PhoneBase mPhone;
    private   UiccCardApplication mCurrentApp = null;
    protected AdnRecordCache mAdnCache;
    protected final Object mLock = new Object();
    protected int mRecordSize[];
    protected boolean mSuccess;
    private   boolean mIs3gCard = false;  // flag to determine if card is 3G or 2G
    protected List<AdnRecord> mRecords;


    protected static final boolean ALLOW_SIM_OP_IN_UI_THREAD = false;

    protected static final int EVENT_GET_SIZE_DONE = 1;
@@ -109,20 +114,80 @@ public abstract class IccPhoneBookInterfaceManager extends IIccPhoneBook.Stub {

    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() {
        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;

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

@@ -311,12 +376,12 @@ public abstract class IccPhoneBookInterfaceManager extends IIccPhoneBook.Stub {
    }

    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
@@ -405,6 +405,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 −2
Original line number Diff line number Diff line
@@ -1205,12 +1205,26 @@ public class CDMAPhone extends PhoneBase {
        return  mUiccController.getUiccCardApplication(UiccController.APP_FAM_3GPP2);
    }

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

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

    @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) {
@@ -1225,7 +1239,6 @@ public class CDMAPhone extends PhoneBase {
                log("Removing stale icc objects.");
                if (mIccRecords.get() != null) {
                    unregisterForRuimRecordEvents();
                    mRuimPhoneBookInterfaceManager.updateIccRecords(null);
                }
                mIccRecords.set(null);
                mUiccApplication.set(null);
@@ -1235,7 +1248,6 @@ public class CDMAPhone extends PhoneBase {
                mUiccApplication.set(newUiccApplication);
                mIccRecords.set(newUiccApplication.getIccRecords());
                registerForRuimRecordEvents();
                mRuimPhoneBookInterfaceManager.updateIccRecords(mIccRecords.get());
            }
        }
    }
+15 −3
Original line number Diff line number Diff line
@@ -116,7 +116,7 @@ public class GSMPhone extends PhoneBase {
    GsmCallTracker mCT;
    protected GsmServiceStateTracker mSST;
    ArrayList <GsmMmiCode> mPendingMMIs = new ArrayList<GsmMmiCode>();
    SimPhoneBookInterfaceManager mSimPhoneBookIntManager;
    protected SimPhoneBookInterfaceManager mSimPhoneBookIntManager;
    PhoneSubInfo mSubInfo;

    Registrant mPostDialHandler;
@@ -1510,12 +1510,26 @@ public class GSMPhone extends PhoneBase {
        return  mUiccController.getUiccCardApplication(UiccController.APP_FAM_3GPP);
    }

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

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

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

        UiccCardApplication app = mUiccApplication.get();
@@ -1524,7 +1538,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);
@@ -1534,7 +1547,6 @@ public class GSMPhone extends PhoneBase {
                mUiccApplication.set(newUiccApplication);
                mIccRecords.set(newUiccApplication.getIccRecords());
                registerForSimRecordEvents();
                mSimPhoneBookIntManager.updateIccRecords(mIccRecords.get());
            }
        }
    }