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

Commit cdadaad0 authored by Jaikumar Ganesh's avatar Jaikumar Ganesh
Browse files

Remove duplicate code in Sim/Ruim card, handle IccCardStatus.

a) Push code to IccCard.java base class.
b) Handle IccCardStatus.
c) Add some helper functions for USIM use.
parent a0ad661f
Loading
Loading
Loading
Loading
+8 −18
Original line number Diff line number Diff line
@@ -82,15 +82,6 @@ public interface CommandsInterface {
        }
    }

    enum IccStatus {
        ICC_ABSENT,
        ICC_NOT_READY,
        ICC_READY,
        ICC_PIN,
        ICC_PUK,
        ICC_NETWORK_PERSONALIZATION
    }

    //***** Constants

    // Used as parameter to dial() and setCLIR() below
@@ -533,15 +524,6 @@ public interface CommandsInterface {
     void registerForCdmaOtaProvision(Handler h,int what, Object obj);
     void unregisterForCdmaOtaProvision(Handler h);

    /**
     * Returns current ICC status.
     *
     * AsyncResult.result is IccStatus
     *
     */

    void getIccStatus(Message result);

    /**
     * Supply the ICC PIN to the ICC card
     *
@@ -1366,4 +1348,12 @@ public interface CommandsInterface {
     * @param response callback message
     */
    public void exitEmergencyCallbackMode(Message response);

    /**
     * Request the status of the ICC and UICC cards.
     *
     * @param response
     *          Callback message containing {@link IccCardStatus} structure for the card.
     */
    public void getIccCardStatus(Message result);
}
+539 −73

File changed.

Preview size limit exceeded, changes collapsed.

+76 −29
Original line number Diff line number Diff line
@@ -45,42 +45,89 @@ public class IccCardStatus {
        PINSTATE_ENABLED_PERM_BLOCKED
    };

    public CardState  card_state;
    public PinState   universal_pin_state;
    public int        gsm_umts_subscription_app_index;
    public int        cdma_subscription_app_index;
    public int        num_applications;
    private CardState  mCardState;
    private PinState   mUniversalPinState;
    private int        mGsmUmtsSubscriptionAppIndex;
    private int        mCdmaSubscriptionAppIndex;
    private int        mNumApplications;

    ArrayList<IccCardApplication> application = new ArrayList<IccCardApplication>(CARD_MAX_APPS);
    private ArrayList<IccCardApplication> mApplications =
            new ArrayList<IccCardApplication>(CARD_MAX_APPS);

    CardState CardStateFromRILInt(int state) {
        CardState newState;
        /* RIL_CardState ril.h */
    public CardState getCardState() {
        return mCardState;
    }

    public void setCardState(int state) {
        switch(state) {
            case 0: newState = CardState.CARDSTATE_ABSENT; break;
            case 1: newState = CardState.CARDSTATE_PRESENT; break;
            case 2: newState = CardState.CARDSTATE_ERROR; break;
        case 0:
            mCardState = CardState.CARDSTATE_ABSENT;
            break;
        case 1:
            mCardState = CardState.CARDSTATE_PRESENT;
            break;
        case 2:
            mCardState = CardState.CARDSTATE_ERROR;
            break;
        default:
                throw new RuntimeException(
                            "Unrecognized RIL_CardState: " +state);
            throw new RuntimeException("Unrecognized RIL_CardState: " + state);
        }
        return newState;
    }

    PinState PinStateFromRILInt(int state) {
        PinState newState;
        /* RIL_PinState ril.h */
    public void setUniversalPinState(int state) {
        switch(state) {
            case 0: newState = PinState.PINSTATE_UNKNOWN; break;
            case 1: newState = PinState.PINSTATE_ENABLED_NOT_VERIFIED; break;
            case 2: newState = PinState.PINSTATE_ENABLED_VERIFIED; break;
            case 3: newState = PinState.PINSTATE_DISABLED; break;
            case 4: newState = PinState.PINSTATE_ENABLED_BLOCKED; break;
            case 5: newState = PinState.PINSTATE_ENABLED_PERM_BLOCKED; break;
        case 0:
            mUniversalPinState = PinState.PINSTATE_UNKNOWN;
            break;
        case 1:
            mUniversalPinState = PinState.PINSTATE_ENABLED_NOT_VERIFIED;
            break;
        case 2:
            mUniversalPinState = PinState.PINSTATE_ENABLED_VERIFIED;
            break;
        case 3:
            mUniversalPinState = PinState.PINSTATE_DISABLED;
            break;
        case 4:
            mUniversalPinState = PinState.PINSTATE_ENABLED_BLOCKED;
            break;
        case 5:
            mUniversalPinState = PinState.PINSTATE_ENABLED_PERM_BLOCKED;
            break;
        default:
                throw new RuntimeException(
                            "Unrecognized RIL_PinState: " +state);
            throw new RuntimeException("Unrecognized RIL_PinState: " + state);
        }
    }

    public int getGsmUmtsSubscriptionAppIndex() {
        return mGsmUmtsSubscriptionAppIndex;
    }

    public void setGsmUmtsSubscriptionAppIndex(int gsmUmtsSubscriptionAppIndex) {
        mGsmUmtsSubscriptionAppIndex = gsmUmtsSubscriptionAppIndex;
    }

    public int getCdmaSubscriptionAppIndex() {
        return mCdmaSubscriptionAppIndex;
    }
        return newState;

    public void setCdmaSubscriptionAppIndex(int cdmaSubscriptionAppIndex) {
        mCdmaSubscriptionAppIndex = cdmaSubscriptionAppIndex;
    }

    public int getNumApplications() {
        return mNumApplications;
    }

    public void setNumApplications(int numApplications) {
        mNumApplications = numApplications;
    }

    public void addApplication(IccCardApplication application) {
        mApplications.add(application);
    }

    public IccCardApplication getApplication(int index) {
        return mApplications.get(index);
    }
}
+12 −67
Original line number Diff line number Diff line
@@ -630,7 +630,7 @@ public final class RIL extends BaseCommands implements CommandsInterface {
    }

    public void
    getIccStatus(Message result) {
    getIccCardStatus(Message result) {
        //Note: This RIL request has not been renamed to ICC,
        //       but this request is also valid for SIM and RUIM
        RILRequest rr = RILRequest.obtain(RIL_REQUEST_GET_SIM_STATUS, result);
@@ -2732,24 +2732,22 @@ public final class RIL extends BaseCommands implements CommandsInterface {

    private Object
    responseIccCardStatus(Parcel p) {
        RadioState currentRadioState;
        IccCardApplication ca;

        currentRadioState = getRadioState();

        IccCardStatus status = new IccCardStatus();
        status.card_state                      = status.CardStateFromRILInt(p.readInt());
        status.universal_pin_state             = status.PinStateFromRILInt(p.readInt());
        status.gsm_umts_subscription_app_index = p.readInt();
        status.cdma_subscription_app_index     = p.readInt();
        status.num_applications                = p.readInt();
        status.setCardState(p.readInt());
        status.setUniversalPinState(p.readInt());
        status.setGsmUmtsSubscriptionAppIndex(p.readInt());
        status.setCdmaSubscriptionAppIndex(p.readInt());
        int numApplications = p.readInt();

        // limit to maximum allowed applications
        if (status.num_applications > IccCardStatus.CARD_MAX_APPS) {
            status.num_applications = IccCardStatus.CARD_MAX_APPS;
        if (numApplications > IccCardStatus.CARD_MAX_APPS) {
            numApplications = IccCardStatus.CARD_MAX_APPS;
        }
        status.setNumApplications(numApplications);

        for (int i = 0 ; i < status.num_applications ; i++) {
        for (int i = 0 ; i < numApplications ; i++) {
            ca = new IccCardApplication();
            ca.app_type       = ca.AppTypeFromRILInt(p.readInt());
            ca.app_state      = ca.AppStateFromRILInt(p.readInt());
@@ -2759,62 +2757,9 @@ public final class RIL extends BaseCommands implements CommandsInterface {
            ca.pin1_replaced  = p.readInt();
            ca.pin1           = p.readInt();
            ca.pin2           = p.readInt();
            status.application.add(ca);
        }

        // this is common for all radio technologies
        if (!status.card_state.isCardPresent()) {
            return IccStatus.ICC_ABSENT;
        }

        // check radio technology
        if( currentRadioState == RadioState.RADIO_OFF         ||
            currentRadioState == RadioState.RADIO_UNAVAILABLE ||
            currentRadioState == RadioState.SIM_NOT_READY     ||
            currentRadioState == RadioState.RUIM_NOT_READY    ||
            currentRadioState == RadioState.NV_NOT_READY      ||
            currentRadioState == RadioState.NV_READY            ) {
            return IccStatus.ICC_NOT_READY;
        }

        if( currentRadioState == RadioState.SIM_LOCKED_OR_ABSENT  ||
            currentRadioState == RadioState.SIM_READY             ||
            currentRadioState == RadioState.RUIM_LOCKED_OR_ABSENT ||
            currentRadioState == RadioState.RUIM_READY) {

            int index;

            // check for CDMA radio technology
            if (currentRadioState == RadioState.RUIM_LOCKED_OR_ABSENT ||
                currentRadioState == RadioState.RUIM_READY) {
                index = status.cdma_subscription_app_index;
            status.addApplication(ca);
        }
            else {
                index = status.gsm_umts_subscription_app_index;
            }

            // check if PIN required
            if (status.application.get(index).app_state.isPinRequired()) {
                return IccStatus.ICC_PIN;
            }
            if (status.application.get(index).app_state.isPukRequired()) {
                return IccStatus.ICC_PUK;
            }
            if (status.application.get(index).app_state.isSubscriptionPersoEnabled()) {
                return IccStatus.ICC_NETWORK_PERSONALIZATION;
            }
            if (status.application.get(index).app_state.isAppReady()) {
                return IccStatus.ICC_READY;
            }
            if (status.application.get(index).app_state.isAppNotReady()) {
                return IccStatus.ICC_NOT_READY;
            }
            return IccStatus.ICC_NOT_READY;
        }

        // Unrecognized ICC status. Treat it like a missing ICC.
        Log.e(LOG_TAG, "Unrecognized RIL_REQUEST_GET_SIM_STATUS result: " + status);
        return IccStatus.ICC_ABSENT;
        return status;
    }

    private Object
+12 −485

File changed.

Preview size limit exceeded, changes collapsed.

Loading