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

Commit 26001604 authored by Arun kumar Voddu's avatar Arun kumar Voddu Committed by Android (Google) Code Review
Browse files

Merge "Get and Set the TPMR value to EF_SMSS field in ISIM/USIM"

parents 36277556 43d6c2de
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ public interface IccConstants {
    static final int EF_CFIS = 0x6FCB;
    static final int EF_IMG = 0x4F20;
    static final int EF_PSISMSC = 0x6FE5;
    static final int EF_SMSS = 0x6F43;

    // USIM SIM file ids from TS 131.102
    public static final int EF_PBR = 0x4F30;
+107 −1
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.telephony.CellIdentity;
import android.telephony.SubscriptionInfo;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;

import com.android.internal.annotations.VisibleForTesting;
@@ -40,6 +41,7 @@ import com.android.internal.telephony.util.ArrayUtils;
import com.android.telephony.Rlog;

import java.io.FileDescriptor;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.lang.annotation.Retention;
@@ -55,8 +57,11 @@ import java.util.concurrent.atomic.AtomicInteger;
 * {@hide}
 */
public abstract class IccRecords extends Handler implements IccConstants {
    private static final String LOG_TAG = "IccRecords";
    protected static final boolean DBG = true;
    protected static final boolean VDBG = false; // STOPSHIP if true
    private static final boolean FORCE_VERBOSE_STATE_LOGGING = false; /* stopship if true */
    protected static final boolean VDBG =  FORCE_VERBOSE_STATE_LOGGING ||
            Rlog.isLoggable(LOG_TAG, Log.VERBOSE);

    public static final int PLMN_MIN_LENGTH = CellIdentity.MCC_LENGTH
            + CellIdentity.MNC_MIN_LENGTH;
@@ -121,6 +126,10 @@ public abstract class IccRecords extends Handler implements IccConstants {

    protected boolean mRecordsRequested = false; // true if we've made requests for the sim records
    protected int mLockedRecordsReqReason = LOCKED_RECORDS_REQ_REASON_NONE;
    // EF_SMSS fields tpmr invalid, min and max declarations
    protected static final int SMSS_INVALID_TPMR = -1;
    private static final int TPMR_MIN = 0x00;
    private static final int TPMR_MAX = 0xFF;

    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PROTECTED)
    public String mIccId;  // Includes only decimals (no hex)
@@ -179,6 +188,10 @@ public abstract class IccRecords extends Handler implements IccConstants {
    // Reference: TS 31.102 section 4.5.9
    protected String mPsiSmsc;

    // EF_SMSS value which is combination of TPMR and Memory exceed flag
    // Reference: TS 31.102 section 4.2.9
    protected byte[] mSmssValues;

    CarrierTestOverride mCarrierTestOverride;

    //Arbitrary offset for the Handler
@@ -240,6 +253,10 @@ public abstract class IccRecords extends Handler implements IccConstants {

    // TAG value to retrieve EF_PSISMSC from parsed SimTlv object
    private static final int TAG_TLV_USIM_VALUE_80 = 0x80;

    // call back received on this upon EF_SMSS record update.
    public static final int EVENT_SET_SMSS_RECORD_DONE = 201;

    /**
     * There are two purposes for this class. First, each instance of AuthAsyncResponse acts as a
     * lock to for calling thead to wait in getIccSimChallengeResponse(). Second, pass the IMS
@@ -962,6 +979,26 @@ public abstract class IccRecords extends Handler implements IccConstants {
                }
                break;

            case EVENT_SET_SMSS_RECORD_DONE:
                ar = (AsyncResult) msg.obj;
                SmssRecord smssRecord = null;
                if (ar.userObj != null) {
                    smssRecord = (SmssRecord) ar.userObj;
                }
                if (ar.exception == null && smssRecord.getSmssValue() != null) {
                    mSmssValues = smssRecord.getSmssValue().clone();
                } else {
                    loge("SIM EF_SMSS field updating error=" + ar.exception);
                }
                if (smssRecord != null && smssRecord.getMessage() != null) {
                    Message message = smssRecord.getMessage();
                    AsyncResult.forMessage(message, ar.result, ar.exception);
                    message.sendToTarget();
                } else {
                    loge("smssRecord or smssRecord.getMessage() object is null");
                }
                break;

            default:
                super.handleMessage(msg);
        }
@@ -1568,4 +1605,73 @@ public abstract class IccRecords extends Handler implements IccConstants {
            return "{fullName = " + fullName + ", shortName = " + shortName + "}";
        }
    }

    /**
     * Sets the elementary (EF_SMSS) field with latest last used TP-Message reference value.
     * First byte of EF_SMSS represents the TPMR value as per the spec
     * (Section 4.2.9 of 3GPP TS 31.102)
     *
     * @param tpmr: Last used TP-Message reference parameter of type int
     * @param onComplete: android.os.Message to be notified upon completion
     */
    public void setSmssTpmrValue(int tpmr, Message onComplete) {
        if(VDBG) log("setSmssTpmrValue()");
        if (mSmssValues != null && mSmssValues.length > 0 && tpmr >= TPMR_MIN && tpmr <= TPMR_MAX) {
            byte[] tempSmss = mSmssValues.clone();
            tempSmss[0] = (byte) (tpmr & 0xFF);
            SmssRecord smssRecord = createSmssRecord(onComplete, tempSmss);
            mFh.updateEFTransparent(IccConstants.EF_SMSS, tempSmss,
                    obtainMessage(EVENT_SET_SMSS_RECORD_DONE, smssRecord));
        } else if (onComplete != null) {
            loge("Failed to set EF_SMSS [TPMR] field to SIM");
            if (mSmssValues == null || mSmssValues.length <= 0) {
                AsyncResult.forMessage((onComplete)).exception =
                        new FileNotFoundException("EF_SMSS file not found");
            } else if (tpmr < TPMR_MIN || tpmr > TPMR_MAX) {
                AsyncResult.forMessage((onComplete)).exception =
                        new IllegalArgumentException("TPMR value is not in allowed range");
            }
            onComplete.sendToTarget();
        }
    }

    /**
     * Fetches the last used TPMR value from elementary (EF_SMSS) field. First byte of EF_SMSS
     * represents the TPMR value as per the spec (Section 4.2.9 of 3GPP TS 31.102)
     *
     * @return TP-Message reference parameter of type int, -1 in case if it fails to read the
     * EF_SMSS field from the sim.
     */
    public int getSmssTpmrValue() {
        if (mSmssValues != null && mSmssValues.length > 0) {
            return  (mSmssValues[0] & 0xFF);
        }
        loge("IccRecords - EF_SMSS is null");
        return SMSS_INVALID_TPMR;
    }

    @VisibleForTesting
    public SmssRecord createSmssRecord(Message msg, byte[] smss) {
        return new SmssRecord(msg, smss);
    }


    static class SmssRecord {

        private Message mMsg;
        private byte[] mSmss;

        SmssRecord (Message msg, byte[] smss) {
            mMsg = msg;
            mSmss = smss;
        }

        private byte[] getSmssValue() {
            return mSmss;
        }

        private Message getMessage() {
            return mMsg;
        }
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ public final class IsimFileHandler extends IccFileHandler implements IccConstant
        case EF_DOMAIN:
        case EF_IST:
        case EF_PCSCF:
        case EF_SMSS:
            return MF_SIM + DF_ADF;
        }
        String path = getCommonIccEFPath(efid);
+28 −4
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.os.AsyncResult;
import android.os.Build;
import android.os.Message;
import android.telephony.SubscriptionManager;
import android.util.Log;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.CommandsInterface;
@@ -42,7 +43,9 @@ public class IsimUiccRecords extends IccRecords implements IsimRecords {
    protected static final String LOG_TAG = "IsimUiccRecords";

    private static final boolean DBG = true;
    private static final boolean VDBG = false; // STOPSHIP if true
    private static final boolean FORCE_VERBOSE_STATE_LOGGING = false; /* stopship if true */
    private static final boolean VDBG =  FORCE_VERBOSE_STATE_LOGGING ||
            Rlog.isLoggable(LOG_TAG, Log.VERBOSE);
    private static final boolean DUMP_RECORDS = false;  // Note: PII is logged when this is true
                                                        // STOPSHIP if true
    public static final String INTENT_ISIM_REFRESH = "com.android.intent.isim_refresh";
@@ -70,8 +73,9 @@ public class IsimUiccRecords extends IccRecords implements IsimRecords {
                + " mIsimDomain=" + mIsimDomain
                + " mIsimImpu=" + mIsimImpu
                + " mIsimIst=" + mIsimIst
                + " mIsimPcscf=" + mIsimPcscf
                + " mPsiSmsc=" + mPsiSmsc) : "");
                + " mIsimPcscf=" + Arrays.toString(mIsimPcscf)
                + " mPsiSmsc=" + mPsiSmsc
                + " mSmss TPMR=" + getSmssTpmrValue()) : "");
    }

    public IsimUiccRecords(UiccCardApplication app, Context c, CommandsInterface ci) {
@@ -113,7 +117,6 @@ public class IsimUiccRecords extends IccRecords implements IsimRecords {
                    broadcastRefresh();
                    super.handleMessage(msg);
                    break;

                default:
                    super.handleMessage(msg);   // IccRecords handles generic record load responses

@@ -145,6 +148,9 @@ public class IsimUiccRecords extends IccRecords implements IsimRecords {
        mFh.loadEFLinearFixedAll(EF_PCSCF, obtainMessage(
                    IccRecords.EVENT_GET_ICC_RECORD_DONE, new EfIsimPcscfLoaded()));
        mRecordsToLoad++;
        mFh.loadEFTransparent(EF_SMSS,  obtainMessage(
                IccRecords.EVENT_GET_ICC_RECORD_DONE, new EfIsimSmssLoaded()));
        mRecordsToLoad++;

        mFh.loadEFLinearFixed(EF_PSISMSC, 1, obtainMessage(
                IccRecords.EVENT_GET_ICC_RECORD_DONE, new EfIsimPsiSmscLoaded()));
@@ -218,6 +224,23 @@ public class IsimUiccRecords extends IccRecords implements IsimRecords {
            if (DUMP_RECORDS) log("EF_IST=" + mIsimIst);
        }
    }

    private class EfIsimSmssLoaded implements IccRecords.IccRecordLoaded {

        @Override
        public String getEfName() {
            return "EF_ISIM_SMSS";
        }

        @Override
        public void onRecordLoaded(AsyncResult ar) {
            mSmssValues = (byte[]) ar.result;
            if (VDBG) {
                log("IsimUiccRecords - EF_SMSS TPMR value = " + getSmssTpmrValue());
            }
        }
    }

    private class EfIsimPcscfLoaded implements IccRecords.IccRecordLoaded {
        public String getEfName() {
            return "EF_ISIM_PCSCF";
@@ -468,6 +491,7 @@ public class IsimUiccRecords extends IccRecords implements IsimRecords {
            pw.println(" mIsimIst" + mIsimIst);
            pw.println(" mIsimPcscf" + mIsimPcscf);
            pw.println(" mPsismsc=" + mPsiSmsc);
            pw.println(" mSmss TPMR=" + getSmssTpmrValue());
        }
        pw.flush();
    }
+26 −5
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.telephony.PhoneNumberUtils;
import android.telephony.SmsMessage;
import android.telephony.SubscriptionInfo;
import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;

import com.android.internal.telephony.CommandsInterface;
@@ -54,8 +55,9 @@ public class SIMRecords extends IccRecords {
    protected static final String LOG_TAG = "SIMRecords";

    private static final boolean CRASH_RIL = false;

    private static final boolean VDBG = false;
    private static final boolean FORCE_VERBOSE_STATE_LOGGING = false; /* stopship if true */
    private static final boolean VDBG =  FORCE_VERBOSE_STATE_LOGGING ||
            Rlog.isLoggable(LOG_TAG, Log.VERBOSE);

    // ***** Instance Variables

@@ -109,7 +111,8 @@ public class SIMRecords extends IccRecords {
                + " mEfCff=" + mEfCff
                + " mEfCfis=" + mEfCfis
                + " getOperatorNumeric=" + getOperatorNumeric()
                + " mPsiSmsc=" + mPsiSmsc;
                + " mPsiSmsc=" + mPsiSmsc
                + " TPMR=" + getSmssTpmrValue();
    }

    // ***** Constants
@@ -185,7 +188,9 @@ public class SIMRecords extends IccRecords {
    private static final int EVENT_GET_FPLMN_DONE = 41 + SIM_RECORD_EVENT_BASE;
    private static final int EVENT_GET_FPLMN_SIZE_DONE = 42 + SIM_RECORD_EVENT_BASE;
    private static final int EVENT_SET_FPLMN_DONE = 43 + SIM_RECORD_EVENT_BASE;
    protected static final int EVENT_GET_SMSS_RECORD_DONE = 46 + SIM_RECORD_EVENT_BASE;
    protected static final int EVENT_GET_PSISMSC_DONE = 47 + SIM_RECORD_EVENT_BASE;

    // ***** Constructor

    public SIMRecords(UiccCardApplication app, Context c, CommandsInterface ci) {
@@ -641,7 +646,6 @@ public class SIMRecords extends IccRecords {
                    " while being destroyed. Ignoring.");
            return;
        }

        try {
            switch (msg.what) {
                /* IO events */
@@ -1297,7 +1301,7 @@ public class SIMRecords extends IccRecords {
                    isRecordLoadResponse = true;
                    ar = (AsyncResult) msg.obj;
                    if (ar.exception != null) {
                        loge("Failed to read USIM EF_SMSS field error=" + ar.exception);
                        loge("Failed to read USIM EF_PSISMSC field error=" + ar.exception);
                    } else {
                        data = (byte[]) ar.result;
                        if (data != null && data.length > 0) {
@@ -1309,6 +1313,19 @@ public class SIMRecords extends IccRecords {
                    }
                    break;

                case EVENT_GET_SMSS_RECORD_DONE:
                    isRecordLoadResponse = true;
                    ar = (AsyncResult) msg.obj;
                    if (ar.exception != null) {
                        loge("Failed to read USIM EF_SMSS field error=" + ar.exception);
                    } else {
                        mSmssValues = (byte[]) ar.result;
                        if (VDBG) {
                            log("SIMRecords - EF_SMSS TPMR value = " + getSmssTpmrValue());
                        }
                    }
                    break;

                default:
                    super.handleMessage(msg);   // IccRecords handles generic record load responses
            }
@@ -1707,6 +1724,9 @@ public class SIMRecords extends IccRecords {
            mRecordsToLoad++;
        }

        mFh.loadEFTransparent(EF_SMSS, obtainMessage(EVENT_GET_SMSS_RECORD_DONE));
        mRecordsToLoad++;

        if (CRASH_RIL) {
            String sms = "0107912160130310f20404d0110041007030208054832b0120"
                         + "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
@@ -2166,6 +2186,7 @@ public class SIMRecords extends IccRecords {
        pw.println(" mFplmns[]=" + Arrays.toString(mFplmns));
        pw.println(" mEhplmns[]=" + Arrays.toString(mEhplmns));
        pw.println(" mPsismsc=" + mPsiSmsc);
        pw.println(" TPMR=" + getSmssTpmrValue());
        pw.flush();
    }
}
Loading