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

Commit 2b30225d authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "telephony: Add ESN tracker"

parents 562c0761 2bbab410
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -44,6 +44,8 @@ public final class CsimFileHandler extends IccFileHandler implements IccConstant
        case EF_CSIM_IMSIM:
        case EF_CSIM_CDMAHOME:
        case EF_CSIM_EPRL:
        case EF_CSIM_MODEL:
        case EF_MODEL:
        case EF_CSIM_PRL:
        case EF_RUIM_ID:
            return MF_SIM + DF_ADF;
+2 −0
Original line number Diff line number Diff line
@@ -68,6 +68,7 @@ public interface IccConstants {
    static final int EF_RUIM_ID = 0x6f31;
    static final int EF_CST = 0x6f32;
    static final int EF_RUIM_SPN =0x6F41;
    static final int EF_MODEL = 0x6F90;

    // ETSI TS.102.221
    static final int EF_PL = 0x2F05;
@@ -78,6 +79,7 @@ public interface IccConstants {
    static final int EF_CSIM_IMSIM = 0x6F22;
    static final int EF_CSIM_CDMAHOME = 0x6F28;
    static final int EF_CSIM_EPRL = 0x6F5A;
    static final int EF_CSIM_MODEL = 0x6F81;
    static final int EF_CSIM_PRL = 0x6F30;
    // C.S0074-Av1.0 Section 4
    static final int EF_CSIM_MLPL = 0x4F20;
+2 −0
Original line number Diff line number Diff line
@@ -65,6 +65,8 @@ public final class RuimFileHandler extends IccFileHandler {
        case EF_CSIM_IMSIM:
        case EF_CSIM_CDMAHOME:
        case EF_CSIM_EPRL:
        case EF_CSIM_MODEL:
        case EF_MODEL:
        case EF_CSIM_PRL:
            return MF_SIM + DF_CDMA;
        case EF_CSIM_MSPL:
+203 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import static com.android.internal.telephony.TelephonyProperties.PROPERTY_APN_RU
import static com.android.internal.telephony.TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA;
import static com.android.internal.telephony.TelephonyProperties.PROPERTY_TEST_CSIM;

import java.io.UnsupportedEncodingException;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
@@ -31,11 +32,13 @@ import java.util.Arrays;
import java.util.Locale;
import android.content.Context;
import android.os.AsyncResult;
import android.os.Build;
import android.os.Message;
import android.os.SystemProperties;
import android.telephony.TelephonyManager;
import android.telephony.Rlog;
import android.text.TextUtils;
import com.android.internal.telephony.TelephonyProperties;

import com.android.internal.telephony.CommandsInterface;
import com.android.internal.telephony.GsmAlphabet;
@@ -70,6 +73,13 @@ public final class RuimRecords extends IccRecords {
    private String mHomeSystemId;
    private String mHomeNetworkId;

    // ***** Ruim constants
    static final int EF_MODEL_FILE_SIZE = 126;
    static final int MODEL_INFORMATION_SIZE = 32;
    static final int MANUFACTURER_NAME_SIZE = 32;
    static final int SOFTWARE_VERSION_INFORMATION_SIZE = 60;
    static final int LANGUAGE_INDICATOR_ENGLISH = 0x01;

    @Override
    public String toString() {
        return "RuimRecords: " + super.toString()
@@ -93,8 +103,10 @@ public final class RuimRecords extends IccRecords {
    // ***** Event Constants
    private static final int EVENT_GET_DEVICE_IDENTITY_DONE = 4;
    private static final int EVENT_GET_ICCID_DONE = 5;
    private static final int EVENT_GET_RUIM_CST_DONE = 8;
    private static final int EVENT_GET_CDMA_SUBSCRIPTION_DONE = 10;
    private static final int EVENT_UPDATE_DONE = 14;
    private static final int EVENT_SET_MODEL_DONE = 15;
    private static final int EVENT_GET_SST_DONE = 17;
    private static final int EVENT_GET_ALL_SMS_DONE = 18;
    private static final int EVENT_MARK_SMS_READ_DONE = 19;
@@ -102,6 +114,9 @@ public final class RuimRecords extends IccRecords {
    private static final int EVENT_SMS_ON_RUIM = 21;
    private static final int EVENT_GET_SMS_DONE = 22;

    // RUIM ID is 8 bytes data
    private static final int NUM_BYTES_RUIM_ID = 8;

    public RuimRecords(UiccCardApplication app, Context c, CommandsInterface ci) {
        super(app, c, ci);

@@ -579,7 +594,58 @@ public final class RuimRecords extends IccRecords {
            case EVENT_GET_SST_DONE:
                log("Event EVENT_GET_SST_DONE Received");
            break;
            case EVENT_SET_MODEL_DONE:
                ar = (AsyncResult) msg.obj;
                if (ar.exception != null) {
                    loge("Set EF Model failed" + ar.exception);
                }
                log("EVENT_SET_MODEL_DONE");
                break;
            case EVENT_GET_RUIM_CST_DONE:
                // CSIM flags
                boolean omhEnabled = false;
                boolean mmsicpEnabled = false;
                isRecordLoadResponse = true;
                ar = (AsyncResult) msg.obj;
                if (ar != null && ar.exception == null) {
                    data = (byte[]) ar.result;
                    log("EF CST data: " + IccUtils.bytesToHexString(data));
                    if (data == null) {
                        break;
                    }

                    // For CSIM card
                    if (mParentApp != null && mParentApp.getType() == AppType.APPTYPE_CSIM) {
                        // Service n35, Messaging and 3GPD Extensions
                        if (data.length > 4) {
                            omhEnabled = (0x04 == (0x04 & data[4])) ? true : false;
                            if (omhEnabled) {
                                // Service n19, Multimedia Messaging Service (MMS)
                                mmsicpEnabled = (0x04 == (0x04 & data[2])) ? true : false;
                            }
                        } else {
                            loge("CSIM EF CST data length = " + data.length);
                        }
                    } else {
                        if (data.length > 3) {
                            omhEnabled = (0x30 == (0x30 & data[3])) ? true : false;
                            // Judge the read MMSICP flag is enabled on CST or not
                            if (omhEnabled && data.length > 10) {
                                mmsicpEnabled = (0x0C == (0x0C & data[10])) ? true : false;
                            } else {
                                loge("OMH EF CST data length = " + data.length);
                            }
                        } else {
                            loge("OMH EF CST data length = " + data.length);
                        }
                    }
                    log("mms icp enabled =" + mmsicpEnabled + " omhEnabled " + omhEnabled);
                    SystemProperties.set(TelephonyProperties.PROPERTY_RUIM_OMH_CARD,
                            omhEnabled ? "true" : "false");
                }
                // We already know if it is an OMH card in this point
                fetchOMHCardRecords(omhEnabled);
                break;
            default:
                super.handleMessage(msg);   // IccRecords handles generic record load responses

@@ -594,6 +660,14 @@ public final class RuimRecords extends IccRecords {
        }
    }

    private void fetchOMHCardRecords(boolean isOMHCard) {
        // OMH related events
        if (isOMHCard) {
            // Write device's software version on EF6F90 on startup.
            setModel();
        }
    }

    /**
     * Returns an array of languages we have assets for.
     *
@@ -730,6 +804,8 @@ public final class RuimRecords extends IccRecords {
    }

    private void fetchRuimRecords() {
        boolean mESNTrackerEnabled = mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_telephony_ESN_Tracker_enabled);
        /* Don't read records if we don't expect
         * anyone to ask for them
         *
@@ -738,7 +814,7 @@ public final class RuimRecords extends IccRecords {
         * the app is not ready
         * then bail
         */
        if (mRecordsRequested || !mRecordsRequired
        if (mRecordsRequested || (mESNTrackerEnabled ? false : !mRecordsRequired)
            || AppState.APPSTATE_READY != mParentApp.getState()) {
            if (DBG) log("fetchRuimRecords: Abort fetching records rRecordsRequested = "
                            + mRecordsRequested
@@ -779,6 +855,25 @@ public final class RuimRecords extends IccRecords {
                obtainMessage(EVENT_GET_ICC_RECORD_DONE, new EfCsimCdmaHomeLoaded()));
        mRecordsToLoad++;

        if (mESNTrackerEnabled) {
            mFh.loadEFTransparent(EF_CSIM_MODEL,
                    obtainMessage(EVENT_GET_ICC_RECORD_DONE, new EfCsimModelLoaded()));
            mRecordsToLoad++;

            mFh.loadEFTransparent(EF_MODEL,
                    obtainMessage(EVENT_GET_ICC_RECORD_DONE, new EfRuimModelLoaded()));
            mRecordsToLoad++;

            // We need to read CST table first to see if it is a CT/OMH/Legacy card
            mFh.loadEFTransparent(IccConstants.EF_CST,
                    obtainMessage(EVENT_GET_RUIM_CST_DONE));
            mRecordsToLoad++;

            mFh.loadEFTransparent(EF_RUIM_ID,
                    obtainMessage(EVENT_GET_ICC_RECORD_DONE, new EfRuimIdLoaded()));
            mRecordsToLoad++;
        }

        // Entire PRL could be huge. We are only interested in
        // the first 4 bytes of the record.
        mFh.loadEFTransparent(EF_CSIM_EPRL, 4,
@@ -791,6 +886,113 @@ public final class RuimRecords extends IccRecords {
        // Further records that can be inserted are Operator/OEM dependent
    }

    private class EfCsimModelLoaded implements IccRecordLoaded {
        public String getEfName() {
            return "EF_CSIM_MODEL";
        }

        public void onRecordLoaded(AsyncResult ar) {
            byte[] data = (byte[]) ar.result;
            if (DBG)
                log("EF_CSIM_MODEL=" + IccUtils.bytesToHexString(data));
        }
    }

    private class EfRuimModelLoaded implements IccRecordLoaded {
        public String getEfName() {
            return "EF_RUIM_MODEL";
        }

        public void onRecordLoaded(AsyncResult ar) {
            byte[] data = (byte[]) ar.result;
            if (DBG)
                log("EF_RUIM_MODEL=" + IccUtils.bytesToHexString(data));
        }
    }

    private class EfRuimIdLoaded implements IccRecordLoaded {
        public String getEfName() {
            return "EF_RUIM_ID";
        }

        public void onRecordLoaded(AsyncResult ar) {
            // The first byte represent the num bytes of valid data for RUIM ID data.
            // It is valid RUIM ID data From the second byte to num+1 byte.
            // And the second byte is the lowest-order byte, the num+1 byte is highest-order
            byte[] data = (byte[]) ar.result;
            if (DBG)
                log("RuimId Data=" + IccUtils.bytesToHexString(data));
            if (data == null) {
                return;
            }
            int numOfBytes = data[0];
            if (numOfBytes < NUM_BYTES_RUIM_ID) {
                byte[] decodeData = new byte[numOfBytes];
                for (int i = 0; i < numOfBytes; i++) {
                    decodeData[i] = data[numOfBytes - i];
                }
                String ruimId = IccUtils.bytesToHexString(decodeData);
                if (DBG)
                    log("RUIM_ID=" + ruimId);
            }
        }
    }

    // Set software version/manufacturer information into EFmodel elementary
    private void setModel() {
        byte[] data = new byte[EF_MODEL_FILE_SIZE];
        byte[] model = null;
        byte[] manufacturer = null;
        byte[] softwareVersion = null;

        for (int i = 0; i < data.length; i++) {
            data[i] = (byte) 0xff;
        }
        // EFmodel will be written into UTF-8 characters
        try {
            model = Build.MODEL.getBytes("UTF-8");
            manufacturer = Build.MANUFACTURER.getBytes("UTF-8");
            String str = SystemProperties.get("persist.product.sw.version", Build.DISPLAY);
            softwareVersion = str.getBytes("UTF-8");
        } catch (UnsupportedEncodingException e) {
            loge("BearerData encode failed: " + e);
        }
        data[0] = UserData.ENCODING_OCTET;
        data[1] = LANGUAGE_INDICATOR_ENGLISH;

        // Restrict model length to prevent ArrayIndexOutOfBoundsException
        int offset = 2;
        int modelLen = (model.length > MODEL_INFORMATION_SIZE)
                ? MODEL_INFORMATION_SIZE : model.length;
        System.arraycopy(model, 0, data, offset, modelLen);
        offset += MODEL_INFORMATION_SIZE;
        // Restrict manufacture length to prevent ArrayIndexOutOfBoundsException
        int manufactureLen = (manufacturer.length > MANUFACTURER_NAME_SIZE)
                ? MANUFACTURER_NAME_SIZE : manufacturer.length;
        System.arraycopy(manufacturer, 0, data, offset, manufactureLen);
        // We need to restrict versionLength in case it is too long which maybe lead to
        // arrayoutofindex exception
        offset += MANUFACTURER_NAME_SIZE;
        int versionLength = (softwareVersion.length > SOFTWARE_VERSION_INFORMATION_SIZE)
                ? SOFTWARE_VERSION_INFORMATION_SIZE : softwareVersion.length;
        System.arraycopy(softwareVersion, 0, data, offset, versionLength);

        log("model: " + IccUtils.bytesToHexString(model) + "manufacturer: "
                + IccUtils.bytesToHexString(manufacturer) + "softwareVersion: "
                + IccUtils.bytesToHexString(softwareVersion));
        log("EF model write data : " + IccUtils.bytesToHexString(data) + " version length="
                + versionLength);

        if (mParentApp != null && mParentApp.getType() == AppType.APPTYPE_CSIM) {
            log("CSIM card type, set csim model");
            mFh.updateEFTransparent(IccConstants.EF_CSIM_MODEL, data,
                    obtainMessage(EVENT_SET_MODEL_DONE, IccConstants.EF_CSIM_MODEL));
        } else {
            mFh.updateEFTransparent(IccConstants.EF_MODEL, data,
                    obtainMessage(EVENT_SET_MODEL_DONE, IccConstants.EF_MODEL));
        }
    }

    /**
     * {@inheritDoc}
     *