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

Commit abf5bc82 authored by Nathan Harold's avatar Nathan Harold
Browse files

Add support for querying Forbidden PLMNs

Bug: 32277497
Test: Verified API using multiple SIMs
Change-Id: I5dbb6976ed6d50146992342ec085f28d2043200a
parent 66c56305
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
+26 −4
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
@@ -1333,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:
@@ -1633,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();
@@ -1741,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();