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

Commit 42aeea38 authored by nharold's avatar nharold Committed by Gerrit Code Review
Browse files

Merge changes from topic 'query-fplmn-sync'

* changes:
  Add support for querying Forbidden PLMNs
  Update file formatting for SIMRecords.java
parents 98399f06 abf5bc82
Loading
Loading
Loading
Loading
+31 −1
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import android.os.RegistrantList;
import android.telephony.Rlog;
import android.telephony.SubscriptionInfo;
import android.telephony.TelephonyManager;
import android.text.TextUtils;

import com.android.internal.telephony.CommandsInterface;
import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppState;
@@ -34,7 +33,9 @@ import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * {@hide}
@@ -97,6 +98,13 @@ public abstract class IccRecords extends Handler implements IccConstants {

    private final Object mLock = new Object();

    //Arbitrary offset for the Handler
    protected static final int HANDLER_ACTION_BASE = 0x12E500;
    protected static final int HANDLER_ACTION_NONE = HANDLER_ACTION_BASE + 0;
    protected static final int HANDLER_ACTION_SEND_RESPONSE = HANDLER_ACTION_BASE + 1;
    protected static AtomicInteger sNextRequestId = new AtomicInteger(1);
    protected final HashMap<Integer, Message> mPendingResponses = new HashMap<>();

    // ***** Constants

    // Markers for mncLength
@@ -204,6 +212,28 @@ public abstract class IccRecords extends Handler implements IccConstants {
        return mAdnCache;
    }

    /**
     * Adds a message to the pending requests list by generating a unique
     * (integer) hash key and returning it. The message should never be null.
     */
    public int storePendingResponseMessage(Message msg) {
        int key = sNextRequestId.getAndIncrement();
        synchronized (mPendingResponses) {
            mPendingResponses.put(key, msg);
        }
        return key;
    }

    /**
     * Returns the pending request, if any or null
     */
    public Message retrievePendingResponseMessage(Integer key) {
        Message m;
        synchronized (mPendingResponses) {
            return mPendingResponses.remove(key);
        }
    }

    /**
     * Returns the ICC ID stripped at the first hex character. Some SIMs have ICC IDs
     * containing hex digits; {@link #getFullIccId()} should be used to get the full ID including
+553 −528
Original line number Diff line number Diff line
@@ -180,8 +180,6 @@ public class SIMRecords extends IccRecords {
    private static final int EVENT_APP_LOCKED = 2 + SYSTEM_EVENT_BASE;
    private static final int EVENT_SIM_REFRESH = 3 + SYSTEM_EVENT_BASE;



    // Lookup table for carriers known to produce SIMs which incorrectly indicate MNC length.

    private static final String[] MCCMNC_CODES_HAVING_3DIGITS_MNC = {
@@ -354,7 +352,7 @@ public class SIMRecords extends IccRecords {
     * When the operation is complete, onComplete will be sent to its handler
     *
     * @param alphaTag alpha-tagging of the dailing nubmer (up to 10 characters)
     * @param number dailing nubmer (up to 20 digits)
     * @param number dialing number (up to 20 digits)
     *        if the number starts with '+', then set to international TOA
     * @param onComplete
     *        onComplete.obj will be an AsyncResult
@@ -664,7 +662,8 @@ public class SIMRecords extends IccRecords {
            return;
        }

        try { switch (msg.what) {
        try {
            switch (msg.what) {
                case EVENT_APP_READY:
                    onReady();
                    break;
@@ -696,8 +695,8 @@ public class SIMRecords extends IccRecords {
                    log("IMSI: mMncLength=" + mMncLength);
                    log("IMSI: " + mImsi.substring(0, 6) + Rlog.pii(LOG_TAG, mImsi.substring(6)));

                if (((mMncLength == UNKNOWN) || (mMncLength == 2)) &&
                        ((mImsi != null) && (mImsi.length() >= 6))) {
                    if (((mMncLength == UNKNOWN) || (mMncLength == 2))
                            && ((mImsi != null) && (mImsi.length() >= 6))) {
                        String mccmncCode = mImsi.substring(0, 6);
                        for (String mccmnc : MCCMNC_CODES_HAVING_3DIGITS_MNC) {
                            if (mccmnc.equals(mccmncCode)) {
@@ -723,7 +722,8 @@ public class SIMRecords extends IccRecords {

                    if (mMncLength != UNKNOWN && mMncLength != UNINITIALIZED) {
                        log("update mccmnc=" + mImsi.substring(0, 3 + mMncLength));
                    // finally have both the imsi and the mncLength and can parse the imsi properly
                        // finally have both the imsi and the mncLength and
                        // can parse the imsi properly
                        MccTable.updateMccMncConfiguration(mContext,
                                mImsi.substring(0, 3 + mMncLength), false);
                    }
@@ -784,7 +784,8 @@ public class SIMRecords extends IccRecords {
                    if (ar.exception != null) {

                        log("Invalid or missing EF"
                        + ((msg.what == EVENT_GET_CPHS_MAILBOX_DONE) ? "[MAILBOX]" : "[MBDN]"));
                                + ((msg.what == EVENT_GET_CPHS_MAILBOX_DONE)
                                    ? "[MAILBOX]" : "[MBDN]"));

                        // Bug #645770 fall back to CPHS
                        // FIXME should use SST to decide
@@ -803,8 +804,9 @@ public class SIMRecords extends IccRecords {

                    adn = (AdnRecord) ar.result;

                log("VM: " + adn +
                        ((msg.what == EVENT_GET_CPHS_MAILBOX_DONE) ? " EF[MAILBOX]" : " EF[MBDN]"));
                    log("VM: " + adn
                            + ((msg.what == EVENT_GET_CPHS_MAILBOX_DONE)
                                ? " EF[MAILBOX]" : " EF[MBDN]"));

                    if (adn.isEmpty() && msg.what == EVENT_GET_MBDN_DONE) {
                        // Bug #645770 fall back to CPHS
@@ -851,8 +853,7 @@ public class SIMRecords extends IccRecords {
                    }

                    if (ar.userObj != null) {
                    AsyncResult.forMessage(((Message) ar.userObj)).exception
                            = ar.exception;
                        AsyncResult.forMessage(((Message) ar.userObj)).exception = ar.exception;
                        ((Message) ar.userObj).sendToTarget();
                    }
                    break;
@@ -866,8 +867,7 @@ public class SIMRecords extends IccRecords {
                    if (DBG) log("EF_MWIS : " + IccUtils.bytesToHexString(data));

                    if (ar.exception != null) {
                    if(DBG) log("EVENT_GET_MWIS_DONE exception = "
                            + ar.exception);
                        if (DBG) log("EVENT_GET_MWIS_DONE exception = " + ar.exception);
                        break;
                    }

@@ -888,8 +888,10 @@ public class SIMRecords extends IccRecords {
                    if (DBG) log("EF_CPHS_MWI: " + IccUtils.bytesToHexString(data));

                    if (ar.exception != null) {
                    if(DBG) log("EVENT_GET_VOICE_MAIL_INDICATOR_CPHS_DONE exception = "
                        if (DBG) {
                            log("EVENT_GET_VOICE_MAIL_INDICATOR_CPHS_DONE exception = "
                                    + ar.exception);
                        }
                        break;
                    }

@@ -910,7 +912,6 @@ public class SIMRecords extends IccRecords {
                    mFullIccId = IccUtils.bchToString(data, 0, data.length);

                    log("iccid: " + SubscriptionInfo.givePrintableIccid(mFullIccId));

                    break;


@@ -948,8 +949,9 @@ public class SIMRecords extends IccRecords {
                            log("setting5 mMncLength=" + mMncLength);
                        }
                    } finally {
                    if (((mMncLength == UNINITIALIZED) || (mMncLength == UNKNOWN) ||
                            (mMncLength == 2)) && ((mImsi != null) && (mImsi.length() >= 6))) {
                        if (((mMncLength == UNINITIALIZED) || (mMncLength == UNKNOWN)
                                    || (mMncLength == 2)) && ((mImsi != null)
                                    && (mImsi.length() >= 6))) {
                            String mccmncCode = mImsi.substring(0, 6);
                            log("mccmncCode=" + mccmncCode);
                            for (String mccmnc : MCCMNC_CODES_HAVING_3DIGITS_MNC) {
@@ -975,7 +977,8 @@ public class SIMRecords extends IccRecords {
                            } else {
                                // Indicate we got this info, but it didn't contain the length.
                                mMncLength = UNKNOWN;
                            log("MNC length not present in EF_AD setting9 mMncLength=" + mMncLength);
                                log("MNC length not present in EF_AD setting9 "
                                        + "mMncLength=" + mMncLength);
                            }
                        }
                        if (mImsi != null && mMncLength != UNKNOWN) {
@@ -1043,8 +1046,7 @@ public class SIMRecords extends IccRecords {

                    for (; tlv.isValidObject(); tlv.nextObject()) {
                        if (tlv.getTag() == TAG_FULL_NETWORK_NAME) {
                        mPnnHomeName
                            = IccUtils.networkNameToString(
                            mPnnHomeName = IccUtils.networkNameToString(
                                    tlv.getData(), 0, tlv.getData().length);
                            break;
                        }
@@ -1055,8 +1057,9 @@ public class SIMRecords extends IccRecords {
                    isRecordLoadResponse = true;

                    ar = (AsyncResult) msg.obj;
                if (ar.exception != null)
                    if (ar.exception != null) {
                        break;
                    }

                    handleSmses((ArrayList<byte []>) ar.result);
                    break;
@@ -1141,8 +1144,7 @@ public class SIMRecords extends IccRecords {
                        * onCphsCompleted to null
                        */
                        if (ar.exception == null && ar.userObj != null) {
                        AsyncResult.forMessage(((Message) ar.userObj)).exception
                                = null;
                            AsyncResult.forMessage(((Message) ar.userObj)).exception = null;
                            ((Message) ar.userObj).sendToTarget();

                            if (DBG) log("Callback with MBDN successful.");
@@ -1150,25 +1152,25 @@ public class SIMRecords extends IccRecords {
                            onCphsCompleted = null;
                        }

                    new AdnRecordLoader(mFh).
                            updateEF(adn, EF_MAILBOX_CPHS, EF_EXT1, 1, null,
                        new AdnRecordLoader(mFh)
                                .updateEF(adn, EF_MAILBOX_CPHS, EF_EXT1, 1, null,
                                obtainMessage(EVENT_SET_CPHS_MAILBOX_DONE,
                                        onCphsCompleted));
                    } else {
                        if (ar.userObj != null) {
                            CarrierConfigManager configLoader = (CarrierConfigManager)
                                    mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE);
                        if (ar.exception != null && configLoader != null &&
                                configLoader.getConfig().getBoolean(
                            if (ar.exception != null && configLoader != null
                                    && configLoader.getConfig().getBoolean(
                                    CarrierConfigManager.KEY_EDITABLE_VOICEMAIL_NUMBER_BOOL)) {
                                // GsmCdmaPhone will store vm number on device
                                // when IccVmNotSupportedException occurred
                            AsyncResult.forMessage(((Message) ar.userObj)).exception
                                = new IccVmNotSupportedException(
                                AsyncResult.forMessage(((Message) ar.userObj)).exception =
                                        new IccVmNotSupportedException(
                                            "Update SIM voice mailbox error");
                            } else {
                            AsyncResult.forMessage(((Message) ar.userObj)).exception
                                = ar.exception;
                                AsyncResult.forMessage(((Message) ar.userObj))
                                    .exception = ar.exception;
                            }
                            ((Message) ar.userObj).sendToTarget();
                        }
@@ -1181,8 +1183,7 @@ public class SIMRecords extends IccRecords {
                        mVoiceMailNum = mNewVoiceMailNum;
                        mVoiceMailTag = mNewVoiceMailTag;
                    } else {
                    if (DBG) log("Set CPHS MailBox with exception: "
                            + ar.exception);
                        if (DBG) log("Set CPHS MailBox with exception: " + ar.exception);
                    }
                    if (ar.userObj != null) {
                        if (DBG) log("Callback with CPHS MB successful.");
@@ -1330,6 +1331,19 @@ public class SIMRecords extends IccRecords {
                    } else {
                        mFplmns = parseBcdPlmnList(data, "Forbidden");
                    }
                    if (msg.arg1 == HANDLER_ACTION_SEND_RESPONSE) {
                        if (VDBG) logv("getForbiddenPlmns(): send async response");
                        isRecordLoadResponse = false;
                        Message response = retrievePendingResponseMessage(msg.arg2);
                        if (response != null) {
                            AsyncResult.forMessage(
                                    response, Arrays.copyOf(mFplmns, mFplmns.length), null);
                            response.sendToTarget();
                        } else {
                            loge("Failed to retrieve a response message for FPLMN");
                            break;
                        }
                    }
                    break;

                case EVENT_CARRIER_CONFIG_CHANGED:
@@ -1338,8 +1352,8 @@ public class SIMRecords extends IccRecords {

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

        }}catch (RuntimeException exc) {
            }
        } catch (RuntimeException exc) {
            // I don't want these exceptions to be fatal
            logw("Exception parsing SIM record", exc);
        } finally {
@@ -1630,6 +1644,16 @@ public class SIMRecords extends IccRecords {
        }
    }

    /**
     * String[] of forbidden PLMNs will be sent to the Message's handler
     * in the result field of an AsyncResult in the response.obj.
     */
    public void getForbiddenPlmns(Message response) {
        int key = storePendingResponseMessage(response);
        mFh.loadEFTransparent(EF_FPLMN, obtainMessage(
                    EVENT_GET_FPLMN_DONE, HANDLER_ACTION_SEND_RESPONSE, key));
    }

    @Override
    public void onReady() {
        fetchSimRecords();
@@ -1738,7 +1762,8 @@ public class SIMRecords extends IccRecords {
        mFh.loadEFTransparent(EF_EHPLMN, obtainMessage(EVENT_GET_EHPLMN_DONE));
        mRecordsToLoad++;

        mFh.loadEFTransparent(EF_FPLMN, obtainMessage(EVENT_GET_FPLMN_DONE));
        mFh.loadEFTransparent(EF_FPLMN, obtainMessage(
                    EVENT_GET_FPLMN_DONE, HANDLER_ACTION_NONE, -1));
        mRecordsToLoad++;

        loadEfLiAndEfPl();
@@ -1853,10 +1878,10 @@ public class SIMRecords extends IccRecords {
        if (start) {
            // Check previous state to see if there is outstanding
            // SPN read
            if(mSpnState == GetSpnFsmState.READ_SPN_3GPP ||
               mSpnState == GetSpnFsmState.READ_SPN_CPHS ||
               mSpnState == GetSpnFsmState.READ_SPN_SHORT_CPHS ||
               mSpnState == GetSpnFsmState.INIT) {
            if (mSpnState == GetSpnFsmState.READ_SPN_3GPP
                    || mSpnState == GetSpnFsmState.READ_SPN_CPHS
                    || mSpnState == GetSpnFsmState.READ_SPN_SHORT_CPHS
                    || mSpnState == GetSpnFsmState.INIT) {
                // Set INIT then return so the INIT code
                // will run when the outstanding read done.
                mSpnState = GetSpnFsmState.INIT;