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

Commit f6fc980d authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Don't return null at Phone.getIccCard." into pi-dev

parents ca46a65c 649c8157
Loading
Loading
Loading
Loading
+4 −1
Original line number Original line Diff line number Diff line
@@ -3373,7 +3373,10 @@ public class GsmCdmaPhone extends Phone {


    @Override
    @Override
    public IccCard getIccCard() {
    public IccCard getIccCard() {
        return UiccController.getInstance().getUiccProfileForPhone(mPhoneId);
        // This used to always return a non-null object. But getUiccProfile() can return null.
        // For backward compatibility consideration, we return a dummy object instead of null.
        IccCard iccCard = getUiccProfile();
        return (iccCard != null) ? iccCard : new IccCard();
    }
    }


    private UiccProfile getUiccProfile() {
    private UiccProfile getUiccProfile() {
+73 −23
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


package com.android.internal.telephony;
package com.android.internal.telephony;


import android.os.AsyncResult;
import android.os.Handler;
import android.os.Handler;
import android.os.Message;
import android.os.Message;


@@ -37,23 +38,34 @@ import com.android.internal.telephony.uicc.IccRecords;
 * This interface is implemented by UiccProfile and the object PhoneApp
 * This interface is implemented by UiccProfile and the object PhoneApp
 * gets when it calls getIccCard is UiccProfile.
 * gets when it calls getIccCard is UiccProfile.
 */
 */
public interface IccCard {
public class IccCard {
    /**
    /**
     * @return combined Card and current App state
     * @return combined Card and current App state
     */
     */
    public State getState();
    public State getState() {
        return State.UNKNOWN;
    }


    // todo: delete
    // todo: delete
    /**
    /**
     * @return IccRecords object belonging to current UiccCardApplication
     * @return IccRecords object belonging to current UiccCardApplication
     */
     */
    public IccRecords getIccRecords();
    public IccRecords getIccRecords() {
        return null;
    }


    /**
    /**
     * Notifies handler of any transition into IccCardConstants.State.NETWORK_LOCKED
     * Notifies handler of any transition into IccCardConstants.State.NETWORK_LOCKED
     */
     */
    public void registerForNetworkLocked(Handler h, int what, Object obj);
    public void registerForNetworkLocked(Handler h, int what, Object obj) {
    public void unregisterForNetworkLocked(Handler h);
        return;
    }
    /**
     * Unregister for networkLocked state change.
     */
    public void unregisterForNetworkLocked(Handler h) {
        return;
    }


    /**
    /**
     * Supply the ICC PIN to the ICC
     * Supply the ICC PIN to the ICC
@@ -73,27 +85,37 @@ public interface IccCard {
     * && ((CommandException)(((AsyncResult)onComplete.obj).exception))
     * && ((CommandException)(((AsyncResult)onComplete.obj).exception))
     *          .getCommandError() == CommandException.Error.PASSWORD_INCORRECT
     *          .getCommandError() == CommandException.Error.PASSWORD_INCORRECT
     */
     */
    public void supplyPin (String pin, Message onComplete);
    public void supplyPin(String pin, Message onComplete) {
        sendMessageWithCardAbsentException(onComplete);
    }


    /**
    /**
     * Supply the ICC PUK to the ICC
     * Supply the ICC PUK to the ICC
     */
     */
    public void supplyPuk (String puk, String newPin, Message onComplete);
    public void supplyPuk(String puk, String newPin, Message onComplete) {
        sendMessageWithCardAbsentException(onComplete);
    }


    /**
    /**
     * Supply the ICC PIN2 to the ICC
     * Supply the ICC PIN2 to the ICC
     */
     */
    public void supplyPin2 (String pin2, Message onComplete);
    public void supplyPin2(String pin2, Message onComplete) {
        sendMessageWithCardAbsentException(onComplete);
    }


    /**
    /**
     * Supply the ICC PUK2 to the ICC
     * Supply the ICC PUK2 to the ICC
     */
     */
    public void supplyPuk2 (String puk2, String newPin2, Message onComplete);
    public void supplyPuk2(String puk2, String newPin2, Message onComplete) {
        sendMessageWithCardAbsentException(onComplete);
    }


    /**
    /**
     * Supply Network depersonalization code to the RIL
     * Supply Network depersonalization code to the RIL
     */
     */
    public void supplyNetworkDepersonalization (String pin, Message onComplete);
    public void supplyNetworkDepersonalization(String pin, Message onComplete) {
        sendMessageWithCardAbsentException(onComplete);
    }


    /**
    /**
     * Check whether ICC pin lock is enabled
     * Check whether ICC pin lock is enabled
@@ -102,7 +124,9 @@ public interface IccCard {
     * @return true for ICC locked enabled
     * @return true for ICC locked enabled
     *         false for ICC locked disabled
     *         false for ICC locked disabled
     */
     */
    public boolean getIccLockEnabled();
    public boolean getIccLockEnabled() {
        return false;
    }


    /**
    /**
     * Check whether ICC fdn (fixed dialing number) is enabled
     * Check whether ICC fdn (fixed dialing number) is enabled
@@ -111,7 +135,9 @@ public interface IccCard {
     * @return true for ICC fdn enabled
     * @return true for ICC fdn enabled
     *         false for ICC fdn disabled
     *         false for ICC fdn disabled
     */
     */
    public boolean getIccFdnEnabled();
    public boolean getIccFdnEnabled() {
        return false;
    }


     /**
     /**
      * Set the ICC pin lock enabled or disabled
      * Set the ICC pin lock enabled or disabled
@@ -125,7 +151,9 @@ public interface IccCard {
      *        ((AsyncResult)onComplete.obj).exception != null on fail
      *        ((AsyncResult)onComplete.obj).exception != null on fail
      */
      */
     public void setIccLockEnabled(boolean enabled,
     public void setIccLockEnabled(boolean enabled,
             String password, Message onComplete);
             String password, Message onComplete) {
         sendMessageWithCardAbsentException(onComplete);
     }


     /**
     /**
      * Set the ICC fdn enabled or disabled
      * Set the ICC fdn enabled or disabled
@@ -139,7 +167,9 @@ public interface IccCard {
      *        ((AsyncResult)onComplete.obj).exception != null on fail
      *        ((AsyncResult)onComplete.obj).exception != null on fail
      */
      */
     public void setIccFdnEnabled(boolean enabled,
     public void setIccFdnEnabled(boolean enabled,
             String password, Message onComplete);
             String password, Message onComplete) {
         sendMessageWithCardAbsentException(onComplete);
     }


     /**
     /**
      * Change the ICC password used in ICC pin lock
      * Change the ICC password used in ICC pin lock
@@ -153,7 +183,9 @@ public interface IccCard {
      *        ((AsyncResult)onComplete.obj).exception != null on fail
      *        ((AsyncResult)onComplete.obj).exception != null on fail
      */
      */
     public void changeIccLockPassword(String oldPassword, String newPassword,
     public void changeIccLockPassword(String oldPassword, String newPassword,
             Message onComplete);
             Message onComplete) {
         sendMessageWithCardAbsentException(onComplete);
     }


     /**
     /**
      * Change the ICC password used in ICC fdn enable
      * Change the ICC password used in ICC fdn enable
@@ -167,7 +199,9 @@ public interface IccCard {
      *        ((AsyncResult)onComplete.obj).exception != null on fail
      *        ((AsyncResult)onComplete.obj).exception != null on fail
      */
      */
     public void changeIccFdnPassword(String oldPassword, String newPassword,
     public void changeIccFdnPassword(String oldPassword, String newPassword,
             Message onComplete);
             Message onComplete) {
         sendMessageWithCardAbsentException(onComplete);
     }


    /**
    /**
     * Returns service provider name stored in ICC card.
     * Returns service provider name stored in ICC card.
@@ -185,26 +219,42 @@ public interface IccCard {
     *         yet available
     *         yet available
     *
     *
     */
     */
    public String getServiceProviderName ();
    public String getServiceProviderName() {
        return null;
    }


    /**
    /**
     * Checks if an Application of specified type present on the card
     * Checks if an Application of specified type present on the card
     * @param type is AppType to look for
     * @param type is AppType to look for
     */
     */
    public boolean isApplicationOnIcc(IccCardApplicationStatus.AppType type);
    public boolean isApplicationOnIcc(IccCardApplicationStatus.AppType type) {
        return false;
    }


    /**
    /**
     * @return true if a ICC card is present
     * @return true if a ICC card is present
     */
     */
    public boolean hasIccCard();
    public boolean hasIccCard() {
        return false;
    }


    /**
    /**
     * @return true if ICC card is PIN2 blocked
     * @return true if ICC card is PIN2 blocked
     */
     */
    public boolean getIccPin2Blocked();
    public boolean getIccPin2Blocked() {
        return false;
    }


    /**
    /**
     * @return true if ICC card is PUK2 blocked
     * @return true if ICC card is PUK2 blocked
     */
     */
    public boolean getIccPuk2Blocked();
    public boolean getIccPuk2Blocked() {
        return false;
    }

    private void sendMessageWithCardAbsentException(Message onComplete) {
        AsyncResult ret = AsyncResult.forMessage(onComplete);
        ret.exception = new RuntimeException("No valid IccCard");
        onComplete.sendToTarget();
    }
}
}
+87 −83
Original line number Original line Diff line number Diff line
@@ -82,7 +82,7 @@ import java.util.Set;
 *
 *
 * {@hide}
 * {@hide}
 */
 */
public class UiccProfile extends Handler implements IccCard {
public class UiccProfile extends IccCard {
    protected static final String LOG_TAG = "UiccProfile";
    protected static final String LOG_TAG = "UiccProfile";
    protected static final boolean DBG = true;
    protected static final boolean DBG = true;
    private static final boolean VDBG = false; //STOPSHIP if true
    private static final boolean VDBG = false; //STOPSHIP if true
@@ -148,7 +148,72 @@ public class UiccProfile extends Handler implements IccCard {
        @Override
        @Override
        public void onReceive(Context context, Intent intent) {
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) {
            if (intent.getAction().equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) {
                sendMessage(obtainMessage(EVENT_CARRIER_CONFIG_CHANGED));
                mHandler.sendMessage(mHandler.obtainMessage(EVENT_CARRIER_CONFIG_CHANGED));
            }
        }
    };

    @VisibleForTesting
    public final Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (mDisposed) {
                loge("handleMessage: Received " + msg.what
                        + " after dispose(); ignoring the message");
                return;
            }
            loglocal("handleMessage: Received " + msg.what + " for phoneId " + mPhoneId);
            switch (msg.what) {
                case EVENT_NETWORK_LOCKED:
                    mNetworkLockedRegistrants.notifyRegistrants();
                    // intentional fall through
                case EVENT_RADIO_OFF_OR_UNAVAILABLE:
                case EVENT_ICC_LOCKED:
                case EVENT_APP_READY:
                case EVENT_RECORDS_LOADED:
                case EVENT_EID_READY:
                    if (VDBG) log("handleMessage: Received " + msg.what);
                    updateExternalState();
                    break;

                case EVENT_ICC_RECORD_EVENTS:
                    if ((mCurrentAppType == UiccController.APP_FAM_3GPP) && (mIccRecords != null)) {
                        AsyncResult ar = (AsyncResult) msg.obj;
                        int eventCode = (Integer) ar.result;
                        if (eventCode == SIMRecords.EVENT_SPN) {
                            mTelephonyManager.setSimOperatorNameForPhone(
                                    mPhoneId, mIccRecords.getServiceProviderName());
                        }
                    }
                    break;

                case EVENT_CARRIER_PRIVILEGES_LOADED:
                    if (VDBG) log("handleMessage: EVENT_CARRIER_PRIVILEGES_LOADED");
                    onCarrierPrivilegesLoadedMessage();
                    updateExternalState();
                    break;

                case EVENT_CARRIER_CONFIG_CHANGED:
                    handleCarrierNameOverride();
                    break;

                case EVENT_OPEN_LOGICAL_CHANNEL_DONE:
                case EVENT_CLOSE_LOGICAL_CHANNEL_DONE:
                case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
                case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
                case EVENT_SIM_IO_DONE:
                    AsyncResult ar = (AsyncResult) msg.obj;
                    if (ar.exception != null) {
                        loglocal("handleMessage: Exception " + ar.exception);
                        log("handleMessage: Error in SIM access with exception" + ar.exception);
                    }
                    AsyncResult.forMessage((Message) ar.userObj, ar.result, ar.exception);
                    ((Message) ar.userObj).sendToTarget();
                    break;

                default:
                    loge("handleMessage: Unhandled message with number: " + msg.what);
                    break;
            }
            }
        }
        }
    };
    };
@@ -166,11 +231,11 @@ public class UiccProfile extends Handler implements IccCard {
        }
        }


        if (mUiccCard instanceof EuiccCard) {
        if (mUiccCard instanceof EuiccCard) {
            ((EuiccCard) mUiccCard).registerForEidReady(this, EVENT_EID_READY, null);
            ((EuiccCard) mUiccCard).registerForEidReady(mHandler, EVENT_EID_READY, null);
        }
        }


        update(c, ci, ics);
        update(c, ci, ics);
        ci.registerForOffOrNotAvailable(this, EVENT_RADIO_OFF_OR_UNAVAILABLE, null);
        ci.registerForOffOrNotAvailable(mHandler, EVENT_RADIO_OFF_OR_UNAVAILABLE, null);
        resetProperties();
        resetProperties();


        IntentFilter intentfilter = new IntentFilter();
        IntentFilter intentfilter = new IntentFilter();
@@ -192,10 +257,10 @@ public class UiccProfile extends Handler implements IccCard {
            InstallCarrierAppUtils.unregisterPackageInstallReceiver(mContext);
            InstallCarrierAppUtils.unregisterPackageInstallReceiver(mContext);


            if (mUiccCard instanceof EuiccCard) {
            if (mUiccCard instanceof EuiccCard) {
                ((EuiccCard) mUiccCard).unregisterForEidReady(this);
                ((EuiccCard) mUiccCard).unregisterForEidReady(mHandler);
            }
            }


            mCi.unregisterForOffOrNotAvailable(this);
            mCi.unregisterForOffOrNotAvailable(mHandler);
            mContext.unregisterReceiver(mReceiver);
            mContext.unregisterReceiver(mReceiver);


            if (mCatService != null) mCatService.dispose();
            if (mCatService != null) mCatService.dispose();
@@ -238,67 +303,6 @@ public class UiccProfile extends Handler implements IccCard {
        }
        }
    }
    }


    @Override
    public void handleMessage(Message msg) {
        if (mDisposed) {
            loge("handleMessage: Received " + msg.what + " after dispose(); ignoring the message");
            return;
        }
        loglocal("handleMessage: Received " + msg.what + " for phoneId " + mPhoneId);
        switch (msg.what) {
            case EVENT_NETWORK_LOCKED:
                mNetworkLockedRegistrants.notifyRegistrants();
                // intentional fall through
            case EVENT_RADIO_OFF_OR_UNAVAILABLE:
            case EVENT_ICC_LOCKED:
            case EVENT_APP_READY:
            case EVENT_RECORDS_LOADED:
            case EVENT_EID_READY:
                if (VDBG) log("handleMessage: Received " + msg.what);
                updateExternalState();
                break;

            case EVENT_ICC_RECORD_EVENTS:
                if ((mCurrentAppType == UiccController.APP_FAM_3GPP) && (mIccRecords != null)) {
                    AsyncResult ar = (AsyncResult) msg.obj;
                    int eventCode = (Integer) ar.result;
                    if (eventCode == SIMRecords.EVENT_SPN) {
                        mTelephonyManager.setSimOperatorNameForPhone(
                                mPhoneId, mIccRecords.getServiceProviderName());
                    }
                }
                break;

            case EVENT_CARRIER_PRIVILEGES_LOADED:
                if (VDBG) log("handleMessage: EVENT_CARRIER_PRIVILEGES_LOADED");
                onCarrierPrivilegesLoadedMessage();
                updateExternalState();
                break;

            case EVENT_CARRIER_CONFIG_CHANGED:
                handleCarrierNameOverride();
                break;

            case EVENT_OPEN_LOGICAL_CHANNEL_DONE:
            case EVENT_CLOSE_LOGICAL_CHANNEL_DONE:
            case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
            case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
            case EVENT_SIM_IO_DONE:
                AsyncResult ar = (AsyncResult) msg.obj;
                if (ar.exception != null) {
                    loglocal("handleMessage: Exception " + ar.exception);
                    log("handleMessage: Error in SIM access with exception" + ar.exception);
                }
                AsyncResult.forMessage((Message) ar.userObj, ar.result, ar.exception);
                ((Message) ar.userObj).sendToTarget();
                break;

            default:
                loge("handleMessage: Unhandled message with number: " + msg.what);
                break;
        }
    }

    /**
    /**
     * Override the carrier name with either carrier config or SPN
     * Override the carrier name with either carrier config or SPN
     * if an override is provided.
     * if an override is provided.
@@ -516,12 +520,12 @@ public class UiccProfile extends Handler implements IccCard {
        for (UiccCardApplication app : mUiccApplications) {
        for (UiccCardApplication app : mUiccApplications) {
            if (app != null) {
            if (app != null) {
                if (VDBG) log("registerUiccCardEvents: registering for EVENT_APP_READY");
                if (VDBG) log("registerUiccCardEvents: registering for EVENT_APP_READY");
                app.registerForReady(this, EVENT_APP_READY, null);
                app.registerForReady(mHandler, EVENT_APP_READY, null);
                IccRecords ir = app.getIccRecords();
                IccRecords ir = app.getIccRecords();
                if (ir != null) {
                if (ir != null) {
                    if (VDBG) log("registerUiccCardEvents: registering for EVENT_RECORDS_LOADED");
                    if (VDBG) log("registerUiccCardEvents: registering for EVENT_RECORDS_LOADED");
                    ir.registerForRecordsLoaded(this, EVENT_RECORDS_LOADED, null);
                    ir.registerForRecordsLoaded(mHandler, EVENT_RECORDS_LOADED, null);
                    ir.registerForRecordsEvents(this, EVENT_ICC_RECORD_EVENTS, null);
                    ir.registerForRecordsEvents(mHandler, EVENT_ICC_RECORD_EVENTS, null);
                }
                }
            }
            }
        }
        }
@@ -530,11 +534,11 @@ public class UiccProfile extends Handler implements IccCard {
    private void unregisterAllAppEvents() {
    private void unregisterAllAppEvents() {
        for (UiccCardApplication app : mUiccApplications) {
        for (UiccCardApplication app : mUiccApplications) {
            if (app != null) {
            if (app != null) {
                app.unregisterForReady(this);
                app.unregisterForReady(mHandler);
                IccRecords ir = app.getIccRecords();
                IccRecords ir = app.getIccRecords();
                if (ir != null) {
                if (ir != null) {
                    ir.unregisterForRecordsLoaded(this);
                    ir.unregisterForRecordsLoaded(mHandler);
                    ir.unregisterForRecordsEvents(this);
                    ir.unregisterForRecordsEvents(mHandler);
                }
                }
            }
            }
        }
        }
@@ -543,15 +547,15 @@ public class UiccProfile extends Handler implements IccCard {
    private void registerCurrAppEvents() {
    private void registerCurrAppEvents() {
        // In case of locked, only listen to the current application.
        // In case of locked, only listen to the current application.
        if (mIccRecords != null) {
        if (mIccRecords != null) {
            mIccRecords.registerForLockedRecordsLoaded(this, EVENT_ICC_LOCKED, null);
            mIccRecords.registerForLockedRecordsLoaded(mHandler, EVENT_ICC_LOCKED, null);
            mIccRecords.registerForNetworkLockedRecordsLoaded(this, EVENT_NETWORK_LOCKED, null);
            mIccRecords.registerForNetworkLockedRecordsLoaded(mHandler, EVENT_NETWORK_LOCKED, null);
        }
        }
    }
    }


    private void unregisterCurrAppEvents() {
    private void unregisterCurrAppEvents() {
        if (mIccRecords != null) {
        if (mIccRecords != null) {
            mIccRecords.unregisterForLockedRecordsLoaded(this);
            mIccRecords.unregisterForLockedRecordsLoaded(mHandler);
            mIccRecords.unregisterForNetworkLockedRecordsLoaded(this);
            mIccRecords.unregisterForNetworkLockedRecordsLoaded(mHandler);
        }
        }
    }
    }


@@ -897,7 +901,7 @@ public class UiccProfile extends Handler implements IccCard {
            log("Before privilege rules: " + mCarrierPrivilegeRules + " : " + ics.mCardState);
            log("Before privilege rules: " + mCarrierPrivilegeRules + " : " + ics.mCardState);
            if (mCarrierPrivilegeRules == null && ics.mCardState == CardState.CARDSTATE_PRESENT) {
            if (mCarrierPrivilegeRules == null && ics.mCardState == CardState.CARDSTATE_PRESENT) {
                mCarrierPrivilegeRules = new UiccCarrierPrivilegeRules(this,
                mCarrierPrivilegeRules = new UiccCarrierPrivilegeRules(this,
                        obtainMessage(EVENT_CARRIER_PRIVILEGES_LOADED));
                        mHandler.obtainMessage(EVENT_CARRIER_PRIVILEGES_LOADED));
            } else if (mCarrierPrivilegeRules != null
            } else if (mCarrierPrivilegeRules != null
                    && ics.mCardState != CardState.CARDSTATE_PRESENT) {
                    && ics.mCardState != CardState.CARDSTATE_PRESENT) {
                mCarrierPrivilegeRules = null;
                mCarrierPrivilegeRules = null;
@@ -1270,7 +1274,7 @@ public class UiccProfile extends Handler implements IccCard {
        loglocal("iccOpenLogicalChannel: " + aid + " , " + p2 + " by pid:" + Binder.getCallingPid()
        loglocal("iccOpenLogicalChannel: " + aid + " , " + p2 + " by pid:" + Binder.getCallingPid()
                + " uid:" + Binder.getCallingUid());
                + " uid:" + Binder.getCallingUid());
        mCi.iccOpenLogicalChannel(aid, p2,
        mCi.iccOpenLogicalChannel(aid, p2,
                obtainMessage(EVENT_OPEN_LOGICAL_CHANNEL_DONE, response));
                mHandler.obtainMessage(EVENT_OPEN_LOGICAL_CHANNEL_DONE, response));
    }
    }


    /**
    /**
@@ -1279,7 +1283,7 @@ public class UiccProfile extends Handler implements IccCard {
    public void iccCloseLogicalChannel(int channel, Message response) {
    public void iccCloseLogicalChannel(int channel, Message response) {
        loglocal("iccCloseLogicalChannel: " + channel);
        loglocal("iccCloseLogicalChannel: " + channel);
        mCi.iccCloseLogicalChannel(channel,
        mCi.iccCloseLogicalChannel(channel,
                obtainMessage(EVENT_CLOSE_LOGICAL_CHANNEL_DONE, response));
                mHandler.obtainMessage(EVENT_CLOSE_LOGICAL_CHANNEL_DONE, response));
    }
    }


    /**
    /**
@@ -1288,7 +1292,7 @@ public class UiccProfile extends Handler implements IccCard {
    public void iccTransmitApduLogicalChannel(int channel, int cla, int command,
    public void iccTransmitApduLogicalChannel(int channel, int cla, int command,
            int p1, int p2, int p3, String data, Message response) {
            int p1, int p2, int p3, String data, Message response) {
        mCi.iccTransmitApduLogicalChannel(channel, cla, command, p1, p2, p3,
        mCi.iccTransmitApduLogicalChannel(channel, cla, command, p1, p2, p3,
                data, obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, response));
                data, mHandler.obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, response));
    }
    }


    /**
    /**
@@ -1297,7 +1301,7 @@ public class UiccProfile extends Handler implements IccCard {
    public void iccTransmitApduBasicChannel(int cla, int command,
    public void iccTransmitApduBasicChannel(int cla, int command,
            int p1, int p2, int p3, String data, Message response) {
            int p1, int p2, int p3, String data, Message response) {
        mCi.iccTransmitApduBasicChannel(cla, command, p1, p2, p3,
        mCi.iccTransmitApduBasicChannel(cla, command, p1, p2, p3,
                data, obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, response));
                data, mHandler.obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, response));
    }
    }


    /**
    /**
@@ -1306,7 +1310,7 @@ public class UiccProfile extends Handler implements IccCard {
    public void iccExchangeSimIO(int fileID, int command, int p1, int p2, int p3,
    public void iccExchangeSimIO(int fileID, int command, int p1, int p2, int p3,
            String pathID, Message response) {
            String pathID, Message response) {
        mCi.iccIO(command, fileID, pathID, p1, p2, p3, null, null,
        mCi.iccIO(command, fileID, pathID, p1, p2, p3, null, null,
                obtainMessage(EVENT_SIM_IO_DONE, response));
                mHandler.obtainMessage(EVENT_SIM_IO_DONE, response));
    }
    }


    /**
    /**
+39 −0
Original line number Original line Diff line number Diff line
@@ -57,8 +57,10 @@ import android.telephony.gsm.GsmCellLocation;
import android.test.suitebuilder.annotation.SmallTest;
import android.test.suitebuilder.annotation.SmallTest;


import com.android.internal.telephony.test.SimulatedCommands;
import com.android.internal.telephony.test.SimulatedCommands;
import com.android.internal.telephony.uicc.IccCardApplicationStatus;
import com.android.internal.telephony.uicc.IccException;
import com.android.internal.telephony.uicc.IccException;
import com.android.internal.telephony.uicc.IccRecords;
import com.android.internal.telephony.uicc.IccRecords;
import com.android.internal.telephony.uicc.UiccProfile;


import org.junit.After;
import org.junit.After;
import org.junit.Before;
import org.junit.Before;
@@ -79,6 +81,7 @@ public class GsmCdmaPhoneTest extends TelephonyTest {


    private static final int EVENT_EMERGENCY_CALLBACK_MODE_EXIT = 1;
    private static final int EVENT_EMERGENCY_CALLBACK_MODE_EXIT = 1;
    private static final int EVENT_EMERGENCY_CALL_TOGGLE = 2;
    private static final int EVENT_EMERGENCY_CALL_TOGGLE = 2;
    private static final int EVENT_SET_ICC_LOCK_ENABLED = 3;


    private class GsmCdmaPhoneTestHandler extends HandlerThread {
    private class GsmCdmaPhoneTestHandler extends HandlerThread {


@@ -812,4 +815,40 @@ public class GsmCdmaPhoneTest extends TelephonyTest {
        waitForMs(100);
        waitForMs(100);
        verify(mEriManager, times(1)).loadEriFile();
        verify(mEriManager, times(1)).loadEriFile();
    }
    }

    @Test
    @SmallTest
    public void testGetEmptyIccCard() {
        doReturn(null).when(mUiccController).getUiccProfileForPhone(anyInt());

        IccCard iccCard = mPhoneUT.getIccCard();

        // The iccCard should be a dummy object, not null.
        assertTrue(!(iccCard instanceof UiccProfile));

        assertTrue(iccCard != null);
        assertEquals(IccCardConstants.State.UNKNOWN, iccCard.getState());
        assertEquals(null, iccCard.getIccRecords());
        assertEquals(false, iccCard.getIccLockEnabled());
        assertEquals(false, iccCard.getIccFdnEnabled());
        assertEquals(false, iccCard.isApplicationOnIcc(
                IccCardApplicationStatus.AppType.APPTYPE_SIM));
        assertEquals(false, iccCard.hasIccCard());
        assertEquals(false, iccCard.getIccPin2Blocked());
        assertEquals(false, iccCard.getIccPuk2Blocked());

        Message onComplete = mTestHandler.obtainMessage(EVENT_SET_ICC_LOCK_ENABLED);
        iccCard.setIccLockEnabled(true, "password", onComplete);

        waitForMs(100);

        ArgumentCaptor<Message> messageArgumentCaptor = ArgumentCaptor.forClass(Message.class);
        // Verify that message is sent back with exception.
        verify(mTestHandler, times(1)).sendMessageAtTime(messageArgumentCaptor.capture(),
                anyLong());
        Message message = messageArgumentCaptor.getAllValues().get(0);
        AsyncResult ret = (AsyncResult) message.obj;
        assertEquals(EVENT_SET_ICC_LOCK_ENABLED, message.what);
        assertTrue(ret.exception != null);
    }
}
}
+10 −5
Original line number Original line Diff line number Diff line
@@ -310,7 +310,8 @@ public class UiccProfileTest extends TelephonyTest {
        waitForMs(50);
        waitForMs(50);
        assertEquals(3, mUiccProfile.getNumApplications());
        assertEquals(3, mUiccProfile.getNumApplications());


        mUiccProfile.sendMessage(mUiccProfile.obtainMessage(UiccProfile.EVENT_APP_READY));
        mUiccProfile.mHandler.sendMessage(
                mUiccProfile.mHandler.obtainMessage(UiccProfile.EVENT_APP_READY));
        waitForMs(SCARY_SLEEP_MS);
        waitForMs(SCARY_SLEEP_MS);
        assertEquals(mUiccProfile.getState(), State.NOT_READY);
        assertEquals(mUiccProfile.getState(), State.NOT_READY);
    }
    }
@@ -342,7 +343,8 @@ public class UiccProfileTest extends TelephonyTest {
        waitForMs(50);
        waitForMs(50);
        assertEquals(3, mUiccProfile.getNumApplications());
        assertEquals(3, mUiccProfile.getNumApplications());


        mUiccProfile.sendMessage(mUiccProfile.obtainMessage(UiccProfile.EVENT_APP_READY));
        mUiccProfile.mHandler.sendMessage(
                mUiccProfile.mHandler.obtainMessage(UiccProfile.EVENT_APP_READY));
        waitForMs(SCARY_SLEEP_MS);
        waitForMs(SCARY_SLEEP_MS);
        // state is loaded as all records are loaded right away as SimulatedCommands returns
        // state is loaded as all records are loaded right away as SimulatedCommands returns
        // response for them right away. Ideally applications and records should be mocked.
        // response for them right away. Ideally applications and records should be mocked.
@@ -376,7 +378,8 @@ public class UiccProfileTest extends TelephonyTest {
        waitForMs(50);
        waitForMs(50);
        assertEquals(3, mUiccProfile.getNumApplications());
        assertEquals(3, mUiccProfile.getNumApplications());


        mUiccProfile.sendMessage(mUiccProfile.obtainMessage(UiccProfile.EVENT_APP_READY));
        mUiccProfile.mHandler.sendMessage(
                mUiccProfile.mHandler.obtainMessage(UiccProfile.EVENT_APP_READY));
        waitForMs(SCARY_SLEEP_MS);
        waitForMs(SCARY_SLEEP_MS);
        // state is loaded as all records are loaded right away as SimulatedCommands returns
        // state is loaded as all records are loaded right away as SimulatedCommands returns
        // response for them right away. Ideally applications and records should be mocked.
        // response for them right away. Ideally applications and records should be mocked.
@@ -400,7 +403,8 @@ public class UiccProfileTest extends TelephonyTest {
        waitForMs(50);
        waitForMs(50);
        assertEquals(0, mUiccProfile.getNumApplications());
        assertEquals(0, mUiccProfile.getNumApplications());


        mUiccProfile.sendMessage(mUiccProfile.obtainMessage(UiccProfile.EVENT_APP_READY));
        mUiccProfile.mHandler.sendMessage(
                mUiccProfile.mHandler.obtainMessage(UiccProfile.EVENT_APP_READY));
        waitForMs(SCARY_SLEEP_MS);
        waitForMs(SCARY_SLEEP_MS);
        // state is loaded since there is no applications.
        // state is loaded since there is no applications.
        assertEquals(State.NOT_READY, mUiccProfile.getState());
        assertEquals(State.NOT_READY, mUiccProfile.getState());
@@ -426,7 +430,8 @@ public class UiccProfileTest extends TelephonyTest {
        waitForMs(50);
        waitForMs(50);
        assertEquals(1, mUiccProfile.getNumApplications());
        assertEquals(1, mUiccProfile.getNumApplications());


        mUiccProfile.sendMessage(mUiccProfile.obtainMessage(UiccProfile.EVENT_APP_READY));
        mUiccProfile.mHandler.sendMessage(
                mUiccProfile.mHandler.obtainMessage(UiccProfile.EVENT_APP_READY));
        waitForMs(SCARY_SLEEP_MS);
        waitForMs(SCARY_SLEEP_MS);
        // state is loaded since there is no applications.
        // state is loaded since there is no applications.
        assertEquals(State.NOT_READY, mUiccProfile.getState());
        assertEquals(State.NOT_READY, mUiccProfile.getState());