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

Commit 99eb9426 authored by Abhishek Adappa's avatar Abhishek Adappa Committed by Preeti Ahuja
Browse files

Telephony: Specify file path when reading contacts from EF_ADN

Some cards, like RUIM and UICC with CSIM, have the same file ID for
multiple EFs. e.g. EF_ADN and EF_CSIM_LI. When trying to retrieve
the EF_ADN from such a card, the path gets mapped to that of
EF_CSIM_LI resulting in incorrect behavior.

To avoid this, specify the EF Id and the path to uniquely identify
EF_ADN, when reading contacts.

Change-Id: I2dd94192d5db51b569c02ac1a46e8fcd71910a47
CRs-Fixed: 428259, 533392
(cherry picked from commit 631da802510a313774c470c273eebd21d6af905c)
(cherry picked from commit eb47b59d3ff5cce2be1211f3e2bdd6725adf2cf7)
(cherry picked from commit f34c191c176eb3ab46c20848fedf980a25088206)
parent a82f430b
Loading
Loading
Loading
Loading
+44 −8
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ import android.os.Looper;
import android.os.Message;
import android.telephony.Rlog;

import com.android.internal.telephony.uicc.IccConstants;

public class AdnRecordLoader extends Handler {
    final static String LOG_TAG = "AdnRecordLoader";
    final static boolean VDBG = false;
@@ -64,6 +66,14 @@ public class AdnRecordLoader extends Handler {
        mFh = fh;
    }

    private String getEFPath(int efid) {
        if (efid == IccConstants.EF_ADN) {
            return IccConstants.MF_SIM + IccConstants.DF_TELECOM;
        }

        return null;
    }

    /**
     * Resulting AdnRecord is placed in response.obj.result
     * or response.obj.exception is set
@@ -76,9 +86,15 @@ public class AdnRecordLoader extends Handler {
        mRecordNumber = recordNumber;
        mUserResponse = response;

        if (ef == IccConstants.EF_ADN) {
            mFh.loadEFLinearFixed(
                        ef, getEFPath(ef), recordNumber,
                        obtainMessage(EVENT_ADN_LOAD_DONE));
        } else {
            mFh.loadEFLinearFixed(
                    ef, recordNumber,
                    obtainMessage(EVENT_ADN_LOAD_DONE));
        }

    }

@@ -94,10 +110,20 @@ public class AdnRecordLoader extends Handler {
        mExtensionEF = extensionEF;
        mUserResponse = response;

        /* If we are loading from EF_ADN, specifically
         * specify the path as well, since, on some cards,
         * the fileid is not unique.
         */
        if (ef == IccConstants.EF_ADN) {

            mFh.loadEFLinearFixedAll(
                    ef, getEFPath(ef),
                    obtainMessage(EVENT_ADN_LOAD_ALL_DONE));
        } else {
            mFh.loadEFLinearFixedAll(
                        ef,
                        obtainMessage(EVENT_ADN_LOAD_ALL_DONE));

        }
    }

    /**
@@ -121,9 +147,14 @@ public class AdnRecordLoader extends Handler {
        mUserResponse = response;
        mPin2 = pin2;

        if (ef == IccConstants.EF_ADN) {
            mFh.getEFLinearRecordSize( ef, getEFPath(ef),
                obtainMessage(EVENT_EF_LINEAR_RECORD_SIZE_DONE, adn));
        } else {
            mFh.getEFLinearRecordSize( ef,
                    obtainMessage(EVENT_EF_LINEAR_RECORD_SIZE_DONE, adn));
        }
    }

    //***** Overridden from Handler

@@ -163,8 +194,13 @@ public class AdnRecordLoader extends Handler {
                                ar.exception);
                    }

                    if (mEf == IccConstants.EF_ADN) {
                        mFh.updateEFLinearFixed(mEf, getEFPath(mEf), mRecordNumber,
                                data, mPin2, obtainMessage(EVENT_UPDATE_RECORD_DONE));
                    } else {
                        mFh.updateEFLinearFixed(mEf, mRecordNumber,
                                data, mPin2, obtainMessage(EVENT_UPDATE_RECORD_DONE));
                    }

                    mPendingExtLoads = 1;

+83 −11
Original line number Diff line number Diff line
@@ -146,7 +146,9 @@ public abstract class IccFileHandler extends Handler implements IccConstants {
            mLoadAll = true;
            mLoadPart = false;
            mOnLoaded = onLoaded;
            mPath = null;
        }

        LoadLinearFixedContext(int efid, ArrayList<Integer> recordNums, String path,
                Message onLoaded) {
            mEfid = efid;
@@ -191,21 +193,36 @@ public abstract class IccFileHandler extends Handler implements IccConstants {
     * Load a record from a SIM Linear Fixed EF
     *
     * @param fileid EF id
     * @param path Path of the EF on the card
     * @param recordNum 1-based (not 0-based) record number
     * @param onLoaded
     *
     * ((AsyncResult)(onLoaded.obj)).result is the byte[]
     *
     */
    public void loadEFLinearFixed(int fileid, int recordNum, Message onLoaded) {
    public void loadEFLinearFixed(int fileid, String path, int recordNum, Message onLoaded) {
        Message response
                = obtainMessage(EVENT_GET_RECORD_SIZE_DONE,
                        new LoadLinearFixedContext(fileid, recordNum, onLoaded));
                        new LoadLinearFixedContext(fileid, recordNum, path, onLoaded));

        mCi.iccIOForApp(COMMAND_GET_RESPONSE, fileid, getEFPath(fileid),
        mCi.iccIOForApp(COMMAND_GET_RESPONSE, fileid, path,
                        0, 0, GET_RESPONSE_EF_SIZE_BYTES, null, null, mAid, response);
    }

    /**
     * Load a record from a SIM Linear Fixed EF
     *
     * @param fileid EF id
     * @param recordNum 1-based (not 0-based) record number
     * @param onLoaded
     *
     * ((AsyncResult)(onLoaded.obj)).result is the byte[]
     *
     */
    public void loadEFLinearFixed(int fileid, int recordNum, Message onLoaded) {
        loadEFLinearFixed(fileid, getEFPath(fileid), recordNum, onLoaded);
    }

    /**
     * Load a image instance record from a SIM Linear Fixed EF-IMG
     *
@@ -230,19 +247,33 @@ public abstract class IccFileHandler extends Handler implements IccConstants {
     * get record size for a linear fixed EF
     *
     * @param fileid EF id
     * @param path Path of the EF on the card
     * @param onLoaded ((AsnyncResult)(onLoaded.obj)).result is the recordSize[]
     *        int[0] is the record length int[1] is the total length of the EF
     *        file int[3] is the number of records in the EF file So int[0] *
     *        int[3] = int[1]
     */
    public void getEFLinearRecordSize(int fileid, Message onLoaded) {
    public void getEFLinearRecordSize(int fileid, String path, Message onLoaded) {
        Message response
                = obtainMessage(EVENT_GET_EF_LINEAR_RECORD_SIZE_DONE,
                        new LoadLinearFixedContext(fileid, onLoaded));
        mCi.iccIOForApp(COMMAND_GET_RESPONSE, fileid, getEFPath(fileid),
                        new LoadLinearFixedContext(fileid, path, onLoaded));
        mCi.iccIOForApp(COMMAND_GET_RESPONSE, fileid, path,
                    0, 0, GET_RESPONSE_EF_SIZE_BYTES, null, null, mAid, response);
    }

    /**
     * get record size for a linear fixed EF
     *
     * @param fileid EF id
     * @param onLoaded ((AsnyncResult)(onLoaded.obj)).result is the recordSize[]
     *        int[0] is the record length int[1] is the total length of the EF
     *        file int[3] is the number of records in the EF file So int[0] *
     *        int[3] = int[1]
     */
    public void getEFLinearRecordSize(int fileid, Message onLoaded) {
        getEFLinearRecordSize(fileid, getEFPath(fileid), onLoaded);
    }

    /**
     * Load all records from a SIM Linear Fixed EF
     *
@@ -253,13 +284,28 @@ public abstract class IccFileHandler extends Handler implements IccConstants {
     *
     */
    public void loadEFLinearFixedAll(int fileid, Message onLoaded) {
        loadEFLinearFixedAll(fileid, getEFPath(fileid), onLoaded);
    }

    /**
     * Load all records from a SIM Linear Fixed EF
     *
     * @param fileid EF id
     * @param path Path of the EF on the card
     * @param onLoaded
     *
     * ((AsyncResult)(onLoaded.obj)).result is an ArrayList<byte[]>
     *
     */
    public void loadEFLinearFixedAll(int fileid, String path, Message onLoaded) {
        Message response = obtainMessage(EVENT_GET_RECORD_SIZE_DONE,
                        new LoadLinearFixedContext(fileid,onLoaded));
                        new LoadLinearFixedContext(fileid, path, onLoaded));

        mCi.iccIOForApp(COMMAND_GET_RESPONSE, fileid, getEFPath(fileid),
        mCi.iccIOForApp(COMMAND_GET_RESPONSE, fileid, path,
                        0, 0, GET_RESPONSE_EF_SIZE_BYTES, null, null, mAid, response);
    }


    /**
     * Load several records from a SIM Linear Fixed EF
     *
@@ -343,6 +389,23 @@ public abstract class IccFileHandler extends Handler implements IccConstants {
                highOffset, lowOffset, length, null, null, mAid, response);
    }

    /**
     * Update a record in a linear fixed EF
     * @param fileid EF id
     * @param path Path of the EF on the card
     * @param recordNum 1-based (not 0-based) record number
     * @param data must be exactly as long as the record in the EF
     * @param pin2 for CHV2 operations, otherwist must be null
     * @param onComplete onComplete.obj will be an AsyncResult
     *                   onComplete.obj.userObj will be a IccIoResult on success
     */
    public void updateEFLinearFixed(int fileid, String path, int recordNum, byte[] data,
            String pin2, Message onComplete) {
        mCi.iccIOForApp(COMMAND_UPDATE_RECORD, fileid, path,
                        recordNum, READ_RECORD_MODE_ABSOLUTE, data.length,
                        IccUtils.bytesToHexString(data), pin2, mAid, onComplete);
    }

    /**
     * Update a record in a linear fixed EF
     * @param fileid EF id
@@ -459,6 +522,7 @@ public abstract class IccFileHandler extends Handler implements IccConstants {
                }

                data = result.payload;
                path = lc.mPath;

                if (TYPE_EF != data[RESPONSE_DATA_FILE_TYPE]) {
                    throw new IccFileTypeMismatch();
@@ -481,7 +545,10 @@ public abstract class IccFileHandler extends Handler implements IccConstants {
                     lc.initLCResults(lc.mCountRecords);
                 }

                 mCi.iccIOForApp(COMMAND_READ_RECORD, lc.mEfid, getEFPath(lc.mEfid),
                 if (path == null) {
                     path = getEFPath(lc.mEfid);
                 }
                 mCi.iccIOForApp(COMMAND_READ_RECORD, lc.mEfid, path,
                         lc.mRecordNum,
                         READ_RECORD_MODE_ABSOLUTE,
                         lc.mRecordSize, null, null, mAid,
@@ -524,6 +591,7 @@ public abstract class IccFileHandler extends Handler implements IccConstants {
                lc = (LoadLinearFixedContext) ar.userObj;
                result = (IccIoResult) ar.result;
                response = lc.mOnLoaded;
                path = lc.mPath;

                if (processException(response, (AsyncResult) msg.obj)) {
                    break;
@@ -537,7 +605,11 @@ public abstract class IccFileHandler extends Handler implements IccConstants {
                    if (lc.mRecordNum > lc.mCountRecords) {
                        sendResult(response, lc.results, null);
                    } else {
                        mCi.iccIOForApp(COMMAND_READ_RECORD, lc.mEfid, getEFPath(lc.mEfid),
                        if (path == null) {
                            path = getEFPath(lc.mEfid);
                        }

                        mCi.iccIOForApp(COMMAND_READ_RECORD, lc.mEfid, path,
                                    lc.mRecordNum,
                                    READ_RECORD_MODE_ABSOLUTE,
                                    lc.mRecordSize, null, null, mAid,