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

Commit 1f3278e1 authored by Wink Saville's avatar Wink Saville
Browse files

Refactor IccRecords and IccCard

IccRecords is now full base class for RuimRecords and SIMRecords
so we can use the IccRecords to represent both Ruim and SIM records
class.

Rename mSIMRecords to mIccRecords in PhoneBase.

Remove mRuimRecords.

Change-Id: If6afff3f99d41830c947de13c26586deff923c6f
parent 5de8226c
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@ import android.util.Log;

import com.android.internal.telephony.PhoneBase;
import com.android.internal.telephony.CommandsInterface.RadioState;
import com.android.internal.telephony.gsm.SIMRecords;

import android.os.SystemProperties;

/**
@@ -430,8 +432,14 @@ public abstract class IccCard {
            broadcastIccStateChangedIntent(INTENT_VALUE_ICC_LOCKED,
                  INTENT_VALUE_LOCKED_NETWORK);
        }

        /*
         * TODO: We need to try to remove this, maybe if the RIL sends up a RIL_UNSOL_SIM_REFRESH?
         */
        if (oldState != State.READY && newState == State.READY && LTE_AVAILABLE_ON_CDMA) {
            mPhone.mSIMRecords.onSimReady();
            if (mPhone.mIccRecords instanceof SIMRecords) {
                ((SIMRecords)mPhone.mIccRecords).onSimReady();
            }
        }
    }

+61 −4
Original line number Diff line number Diff line
@@ -21,9 +21,6 @@ import android.os.Handler;
import android.os.Message;
import android.os.Registrant;
import android.os.RegistrantList;
import android.util.Log;

import java.util.ArrayList;

/**
 * {@hide}
@@ -79,6 +76,11 @@ public abstract class IccRecords extends Handler implements IccConstants {
        this.phone = p;
    }

    /**
     * Call when the IccRecords object is no longer going to be used.
     */
    public abstract void dispose();

    protected abstract void onRadioOffOrNotAvailable();

    //***** Public Methods
@@ -99,6 +101,17 @@ public abstract class IccRecords extends Handler implements IccConstants {
        recordsLoadedRegistrants.remove(h);
    }

    /**
     * Get the International Mobile Subscriber ID (IMSI) on a SIM
     * for GSM, UMTS and like networks. Default is null if IMSI is
     * not supported or unavailable.
     *
     * @return null if SIM is not yet ready or unavailable
     */
    public String getIMSI() {
        return null;
    }

    public String getMsisdnNumber() {
        return msisdn;
    }
@@ -220,6 +233,7 @@ public abstract class IccRecords extends Handler implements IccConstants {
    }

    //***** Overridden from Handler
    @Override
    public abstract void handleMessage(Message msg);

    protected abstract void onRecordLoaded();
@@ -232,8 +246,51 @@ public abstract class IccRecords extends Handler implements IccConstants {
     * and TS 51.011 10.3.11 for details.
     *
     * If the SPN is not found on the SIM, the rule is always PLMN_ONLY.
     * Generally used for GSM/UMTS and the like SIMs.
     */
    public abstract int getDisplayRule(String plmn);

    /**
     * Return true if "Restriction of menu options for manual PLMN selection"
     * bit is set or EF_CSP data is unavailable, return false otherwise.
     * Generally used for GSM/UMTS and the like SIMs.
     */
    public boolean isCspPlmnEnabled() {
        return false;
    }

    /**
     * Returns the 5 or 6 digit MCC/MNC of the operator that
     * provided the SIM card. Returns null of SIM is not yet ready
     * or is not valid for the type of IccCard. Generally used for
     * GSM/UMTS and the like SIMS
     */
    public String getOperatorNumeric() {
        return null;
    }

    /**
     * Get the current Voice call forwarding flag for GSM/UMTS and the like SIMs
     *
     * @return true if enabled
     */
    public boolean getVoiceCallForwardingFlag() {
        return false;
    }

    /**
     * Set the voice call forwarding flag for GSM/UMTS and the like SIMs
     *
     * @param line to enable/disable
     * @param enable
     */
    protected abstract int getDisplayRule(String plmn);
    public void setVoiceCallForwardingFlag(int line, boolean enable) {
    }

    /**
     * Write string to log file
     *
     * @param s is the string to write
     */
    protected abstract void log(String s);
}
+27 −2
Original line number Diff line number Diff line
@@ -118,8 +118,8 @@ public abstract class PhoneBase extends Handler implements Phone {
    int mCallRingDelay;
    public boolean mIsTheCurrentActivePhone = true;
    boolean mIsVoiceCapable = true;
    public SIMRecords mSIMRecords;
    public SimCard mSimCard;
    public IccRecords mIccRecords;
    public IccCard mIccCard;
    public SMSDispatcher mSMS;

    /**
@@ -681,6 +681,31 @@ public abstract class PhoneBase extends Handler implements Phone {
        return null;
    }

    @Override
    public IccCard getIccCard() {
        return mIccCard;
    }

    @Override
    public String getIccSerialNumber() {
        return mIccRecords.iccid;
    }

    @Override
    public boolean getIccRecordsLoaded() {
        return mIccRecords.getRecordsLoaded();
    }

    @Override
    public boolean getMessageWaitingIndicator() {
        return mIccRecords.getVoiceMessageWaiting();
    }

    @Override
    public boolean getCallForwardingIndicator() {
        return mIccRecords.getVoiceCallForwardingFlag();
    }

    /**
     *  Query the status of the CDMA roaming preference
     */
+15 −42
Original line number Diff line number Diff line
@@ -48,58 +48,30 @@ public class CDMALTEPhone extends CDMAPhone {
    // Constructors
    public CDMALTEPhone(Context context, CommandsInterface ci, PhoneNotifier notifier) {
        this(context, ci, notifier, false);
        log("CDMALTEPhone Constructors");
    }

    public CDMALTEPhone(Context context, CommandsInterface ci, PhoneNotifier notifier,
            boolean unitTestMode) {
        super(context, ci, notifier, false);

        mSIMRecords = new SIMRecords(this);
        mSimCard = new SimCard(this, LOG_TAG, DBG);
    }

    @Override
    protected void initSST() {
    protected void initSstIcc() {
        mSST = new CdmaLteServiceStateTracker(this);
    }

    public void dispose() {
        synchronized (PhoneProxy.lockForRadioTechnologyChange) {
            super.dispose();
            mSIMRecords.dispose();
            mSimCard.dispose();
        }
    }

    @Override
    public void removeReferences() {
        super.removeReferences();
        this.mSIMRecords = null;
        this.mSimCard = null;
    }

    @Override
    public ServiceStateTracker getServiceStateTracker() {
        return mSST;
    }

    public IccCard getIccCard() {
        return mSimCard;
    }

    @Override
    public String getIccSerialNumber() {
        return mSIMRecords.iccid;
        mIccRecords = new SIMRecords(this);
        mIccCard = new SimCard(this, LOG_TAG, DBG);
    }

    @Override
    public DataState getDataConnectionState(String apnType) {
        // TODO: Remove instanceof if possible.
        boolean isCdmaDataConnectionTracker = false;
        if (mDataConnectionTracker instanceof CdmaDataConnectionTracker) {
            log("getDataConnectionState isCdmaDataConnectionTracker");
            isCdmaDataConnectionTracker = true;
        } else {
            log("getDataConnectionState NOT CdmaDataConnectionTracker");
        }
        log("getDataConnectionState");
        DataState ret = DataState.DISCONNECTED;

        if (!isCdmaDataConnectionTracker && (SystemProperties.get("adb.connected", "").length()
@@ -145,28 +117,29 @@ public class CDMALTEPhone extends CDMAPhone {
            }
        }

        log("getDataConnectionState apnType=" + apnType + " ret=" + ret);
        return ret;
    }

    public boolean updateCurrentCarrierInProvider() {
        if (mSIMRecords != null) {
        if (mIccRecords != null) {
            try {
                Uri uri = Uri.withAppendedPath(Telephony.Carriers.CONTENT_URI, "current");
                ContentValues map = new ContentValues();
                map.put(Telephony.Carriers.NUMERIC, mSIMRecords.getSIMOperatorNumeric());
                map.put(Telephony.Carriers.NUMERIC, mIccRecords.getOperatorNumeric());
                log("updateCurrentCarrierInProvider insert uri=" + uri);
                mContext.getContentResolver().insert(uri, map);
                return true;
            } catch (SQLException e) {
                Log.e(LOG_TAG, "[CDMALTEPhone] Can't store current operator", e);
                Log.e(LOG_TAG, "[CDMALTEPhone] Can't store current operator ret false", e);
            }
        } else {
            log("updateCurrentCarrierInProvider mIccRecords == null ret false");
        }
        return false;
    }

    public String getActiveApn(String apnType) {
        return mDataConnectionTracker.getActiveApnString(apnType);
    }

    @Override
    protected void log(String s) {
        if (DBG)
            Log.d(LOG_TAG, "[CDMALTEPhone] " + s);
+27 −31
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ import com.android.internal.telephony.CommandException;
import com.android.internal.telephony.CommandsInterface;
import com.android.internal.telephony.Connection;
import com.android.internal.telephony.DataConnection;
import com.android.internal.telephony.IccRecords;
import com.android.internal.telephony.MccTable;
import com.android.internal.telephony.IccCard;
import com.android.internal.telephony.IccException;
@@ -99,8 +100,6 @@ public class CDMAPhone extends PhoneBase {
    // Instance Variables
    CdmaCallTracker mCT;
    CdmaServiceStateTracker mSST;
    RuimRecords mRuimRecords;
    RuimCard mRuimCard;
    ArrayList <CdmaMmiCode> mPendingMmis = new ArrayList<CdmaMmiCode>();
    RuimPhoneBookInterfaceManager mRuimPhoneBookInterfaceManager;
    RuimSmsInterfaceManager mRuimSmsInterfaceManager;
@@ -142,19 +141,21 @@ public class CDMAPhone extends PhoneBase {
    // Constructors
    public CDMAPhone(Context context, CommandsInterface ci, PhoneNotifier notifier) {
        super(notifier, context, ci, false);
        initSST();
        initSstIcc();
        init(context, notifier);
    }

    public CDMAPhone(Context context, CommandsInterface ci, PhoneNotifier notifier,
            boolean unitTestMode) {
        super(notifier, context, ci, unitTestMode);
        initSST();
        initSstIcc();
        init(context, notifier);
    }

    protected void initSST() {
    protected void initSstIcc() {
        mSST = new CdmaServiceStateTracker(this);
        mIccRecords = new RuimRecords(this);
        mIccCard = new RuimCard(this, LOG_TAG, DBG);
    }

    protected void init(Context context, PhoneNotifier notifier) {
@@ -162,18 +163,16 @@ public class CDMAPhone extends PhoneBase {
        mCT = new CdmaCallTracker(this);
        mSMS = new CdmaSMSDispatcher(this);
        mIccFileHandler = new RuimFileHandler(this);
        mRuimRecords = new RuimRecords(this);
        mDataConnectionTracker = new CdmaDataConnectionTracker (this);
        mRuimCard = new RuimCard(this);
        mRuimPhoneBookInterfaceManager = new RuimPhoneBookInterfaceManager(this);
        mRuimSmsInterfaceManager = new RuimSmsInterfaceManager(this, mSMS);
        mSubInfo = new PhoneSubInfo(this);
        mEriManager = new EriManager(this, context, EriManager.ERI_FROM_XML);
        mCcatService = CatService.getInstance(mCM, mRuimRecords, mContext,
                mIccFileHandler, mRuimCard);
        mCcatService = CatService.getInstance(mCM, mIccRecords, mContext,
                mIccFileHandler, mIccCard);

        mCM.registerForAvailable(this, EVENT_RADIO_AVAILABLE, null);
        mRuimRecords.registerForRecordsLoaded(this, EVENT_RUIM_RECORDS_LOADED, null);
        mIccRecords.registerForRecordsLoaded(this, EVENT_RUIM_RECORDS_LOADED, null);
        mCM.registerForOffOrNotAvailable(this, EVENT_RADIO_OFF_OR_NOT_AVAILABLE, null);
        mCM.registerForOn(this, EVENT_RADIO_ON, null);
        mCM.setOnSuppServiceNotification(this, EVENT_SSN, null);
@@ -222,9 +221,10 @@ public class CDMAPhone extends PhoneBase {
    public void dispose() {
        synchronized(PhoneProxy.lockForRadioTechnologyChange) {
            super.dispose();
            log("dispose");

            //Unregister from all former registered events
            mRuimRecords.unregisterForRecordsLoaded(this); //EVENT_RUIM_RECORDS_LOADED
            mIccRecords.unregisterForRecordsLoaded(this); //EVENT_RUIM_RECORDS_LOADED
            mCM.unregisterForAvailable(this); //EVENT_RADIO_AVAILABLE
            mCM.unregisterForOffOrNotAvailable(this); //EVENT_RADIO_OFF_OR_NOT_AVAILABLE
            mCM.unregisterForOn(this); //EVENT_RADIO_ON
@@ -241,8 +241,8 @@ public class CDMAPhone extends PhoneBase {
            mSST.dispose();
            mSMS.dispose();
            mIccFileHandler.dispose(); // instance of RuimFileHandler
            mRuimRecords.dispose();
            mRuimCard.dispose();
            mIccRecords.dispose();
            mIccCard.dispose();
            mRuimPhoneBookInterfaceManager.dispose();
            mRuimSmsInterfaceManager.dispose();
            mSubInfo.dispose();
@@ -252,13 +252,14 @@ public class CDMAPhone extends PhoneBase {
    }

    public void removeReferences() {
            log("removeReferences");
            this.mRuimPhoneBookInterfaceManager = null;
            this.mRuimSmsInterfaceManager = null;
            this.mSMS = null;
            this.mSubInfo = null;
            this.mRuimRecords = null;
            this.mIccRecords = null;
            this.mIccFileHandler = null;
            this.mRuimCard = null;
            this.mIccCard = null;
            this.mDataConnectionTracker = null;
            this.mCT = null;
            this.mSST = null;
@@ -547,14 +548,6 @@ public class CDMAPhone extends PhoneBase {
        Log.e(LOG_TAG, "setLine1Number: not possible in CDMA");
    }

    public IccCard getIccCard() {
        return mRuimCard;
    }

    public String getIccSerialNumber() {
        return mRuimRecords.iccid;
    }

    public void setCallWaiting(boolean enable, Message onComplete) {
        Log.e(LOG_TAG, "method setCallWaiting is NOT supported in CDMA!");
    }
@@ -657,6 +650,7 @@ public class CDMAPhone extends PhoneBase {
            }
        }

        log("getDataConnectionState apnType=" + apnType + " ret=" + ret);
        return ret;
    }

@@ -733,7 +727,7 @@ public class CDMAPhone extends PhoneBase {
        Message resp;
        mVmNumber = voiceMailNumber;
        resp = obtainMessage(EVENT_SET_VM_NUMBER_DONE, 0, 0, onComplete);
        mRuimRecords.setVoiceMailNumber(alphaTag, mVmNumber, resp);
        mIccRecords.setVoiceMailNumber(alphaTag, mVmNumber, resp);
    }

    public String getVoiceMailNumber() {
@@ -755,7 +749,7 @@ public class CDMAPhone extends PhoneBase {
     * @hide
     */
    public int getVoiceMessageCount() {
        int voicemailCount =  mRuimRecords.getVoiceMessageCount();
        int voicemailCount =  mIccRecords.getVoiceMessageCount();
        // If mRuimRecords.getVoiceMessageCount returns zero, then there is possibility
        // that phone was power cycled and would have lost the voicemail count.
        // So get the count from preferences.
@@ -780,10 +774,6 @@ public class CDMAPhone extends PhoneBase {
        return ret;
    }

    public boolean getIccRecordsLoaded() {
        return mRuimRecords.getRecordsLoaded();
    }

    public void getCallForwardingOption(int commandInterfaceCFReason, Message onComplete) {
        Log.e(LOG_TAG, "getCallForwardingOption: not possible in CDMA");
    }
@@ -864,13 +854,13 @@ public class CDMAPhone extends PhoneBase {
    /*package*/ void
    updateMessageWaitingIndicator(boolean mwi) {
        // this also calls notifyMessageWaitingIndicator()
        mRuimRecords.setVoiceMessageWaiting(1, mwi ? -1 : 0);
        mIccRecords.setVoiceMessageWaiting(1, mwi ? -1 : 0);
    }

    /* This function is overloaded to send number of voicemails instead of sending true/false */
    /*package*/ void
    updateMessageWaitingIndicator(int mwi) {
        mRuimRecords.setVoiceMessageWaiting(1, mwi);
        mIccRecords.setVoiceMessageWaiting(1, mwi);
    }

    @Override
@@ -1417,6 +1407,7 @@ public class CDMAPhone extends PhoneBase {
                Uri uri = Uri.withAppendedPath(Telephony.Carriers.CONTENT_URI, "current");
                ContentValues map = new ContentValues();
                map.put(Telephony.Carriers.NUMERIC, operatorNumeric);
                log("updateCurrentCarrierInProvider insert uri=" + uri);
                getContext().getContentResolver().insert(uri, map);

                // Updates MCC MNC device configuration information
@@ -1429,4 +1420,9 @@ public class CDMAPhone extends PhoneBase {
        }
        return false;
    }

    protected void log(String s) {
        if (DBG)
            Log.d(LOG_TAG, "[CDMAPhone] " + s);
    }
}
Loading