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

Commit cf7ff3fc authored by sqian's avatar sqian
Browse files

Add Iccid_prefix in Carrier Idenfitication

Bug: 64131637
Test: Manual
Change-Id: Ic7cbb8ed9b6357fafd1bf164876a25f52515b299
parent 4f496151
Loading
Loading
Loading
Loading
+33 −10
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@
 */
package com.android.internal.telephony;

import static android.provider.Telephony.CarrierIdentification;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
@@ -42,8 +44,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

import static android.provider.Telephony.CarrierIdentification;

/**
 * CarrierIdentifier identifies the subscription carrier and returns a canonical carrier Id
 * and a user friendly carrier name. CarrierIdentifier reads subscription info and check against
@@ -325,6 +325,8 @@ public class CarrierIdentifier extends Handler {
                cursor.getString(cursor.getColumnIndexOrThrow(CarrierIdentification.MCCMNC)),
                cursor.getString(cursor.getColumnIndexOrThrow(
                        CarrierIdentification.IMSI_PREFIX_XPATTERN)),
                cursor.getString(cursor.getColumnIndexOrThrow(
                        CarrierIdentification.ICCID_PREFIX)),
                cursor.getString(cursor.getColumnIndexOrThrow(CarrierIdentification.GID1)),
                cursor.getString(cursor.getColumnIndexOrThrow(CarrierIdentification.GID2)),
                cursor.getString(cursor.getColumnIndexOrThrow(CarrierIdentification.PLMN)),
@@ -347,8 +349,9 @@ public class CarrierIdentifier extends Handler {
         * rule 1 {mccmnc, imsi} rule 2 {mccmnc, imsi, gid1} and rule 3 {mccmnc, imsi, gid2} all
         * matches with subscription data. rule 2 wins with the highest matching score.
         */
        private static final int SCORE_MCCMNC          = 1 << 6;
        private static final int SCORE_IMSI_PREFIX     = 1 << 5;
        private static final int SCORE_MCCMNC          = 1 << 7;
        private static final int SCORE_IMSI_PREFIX     = 1 << 6;
        private static final int SCORE_ICCID_PREFIX    = 1 << 5;
        private static final int SCORE_GID1            = 1 << 4;
        private static final int SCORE_GID2            = 1 << 3;
        private static final int SCORE_PLMN            = 1 << 2;
@@ -360,6 +363,7 @@ public class CarrierIdentifier extends Handler {
        // carrier matching attributes
        private String mMccMnc;
        private String mImsiPrefixPattern;
        private String mIccidPrefix;
        private String mGid1;
        private String mGid2;
        private String mPlmn;
@@ -373,10 +377,12 @@ public class CarrierIdentifier extends Handler {

        private int mScore = 0;

        CarrierMatchingRule(String mccmnc, String imsiPrefixPattern, String gid1, String gid2,
                String plmn, String spn, String apn, int cid, String name) {
        CarrierMatchingRule(String mccmnc, String imsiPrefixPattern, String iccidPrefix,
                String gid1, String gid2, String plmn, String spn, String apn, int cid,
                String name) {
            mMccMnc = mccmnc;
            mImsiPrefixPattern = imsiPrefixPattern;
            mIccidPrefix = iccidPrefix;
            mGid1 = gid1;
            mGid2 = gid2;
            mPlmn = plmn;
@@ -388,9 +394,9 @@ public class CarrierIdentifier extends Handler {

        // Calculate matching score. Values which aren't set in the rule are considered "wild".
        // All values in the rule must match in order for the subscription to be considered part of
        // the carrier. otherwise, a invalid score -1 will be assigned. A match from a higher tier
        // the carrier. Otherwise, a invalid score -1 will be assigned. A match from a higher tier
        // will beat any subsequent match which does not match at that tier. When there are multiple
        // matches at the same tier, the longest, best match will be used.
        // matches at the same tier, the match with highest score will be used.
        public void match(CarrierMatchingRule subscriptionRule) {
            mScore = 0;
            if (mMccMnc != null) {
@@ -407,6 +413,13 @@ public class CarrierIdentifier extends Handler {
                }
                mScore += SCORE_IMSI_PREFIX;
            }
            if (mIccidPrefix != null) {
                if (!iccidPrefixMatch(subscriptionRule.mIccidPrefix, mIccidPrefix)) {
                    mScore = SCORE_INVALID;
                    return;
                }
                mScore += SCORE_ICCID_PREFIX;
            }
            if (mGid1 != null) {
                // full string match. carrier matching should cover the corner case that gid1
                // with garbage tail due to SIM manufacture issues.
@@ -463,6 +476,13 @@ public class CarrierIdentifier extends Handler {
            return true;
        }

        private boolean iccidPrefixMatch(String iccid, String prefix) {
            if (iccid == null || prefix == null) {
                return false;
            }
            return iccid.startsWith(prefix);
        }

        public String toString() {
            return "[CarrierMatchingRule] -"
                    + " mccmnc: " + mMccMnc
@@ -470,6 +490,7 @@ public class CarrierIdentifier extends Handler {
                    + " gid2: " + mGid2
                    + " plmn: " + mPlmn
                    + " imsi_prefix: " + mImsiPrefixPattern
                    + " iccid_prefix" + mIccidPrefix
                    + " spn: " + mSpn
                    + " apn: " + mApn
                    + " name: " + mName
@@ -488,6 +509,7 @@ public class CarrierIdentifier extends Handler {
            return;
        }
        final String mccmnc = mTelephonyMgr.getSimOperatorNumericForPhone(mPhone.getPhoneId());
        final String iccid = mPhone.getIccSerialNumber();
        final String gid1 = mPhone.getGroupIdLevel1();
        final String gid2 = mPhone.getGroupIdLevel2();
        final String imsi = mPhone.getSubscriberId();
@@ -500,14 +522,15 @@ public class CarrierIdentifier extends Handler {
                    + " gid1: " + gid1
                    + " gid2: " + gid2
                    + " imsi: " + Rlog.pii(LOG_TAG, imsi)
                    + " iccid: " + Rlog.pii(LOG_TAG, iccid)
                    + " plmn: " + plmn
                    + " spn: " + spn
                    + " apn: " + apn);
        }

        CarrierMatchingRule subscriptionRule = new CarrierMatchingRule(
                mccmnc, imsi, gid1, gid2, plmn,  spn, apn, TelephonyManager.UNKNOWN_CARRIER_ID,
                null);
                mccmnc, imsi, iccid, gid1, gid2, plmn,  spn, apn,
                TelephonyManager.UNKNOWN_CARRIER_ID, null);

        int maxScore = CarrierMatchingRule.SCORE_INVALID;
        CarrierMatchingRule maxRule = null;
+13 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ public class CarrierTestOverride {
       <carrierTestOverride key="imsi" value="310010123456789"/>
       <carrierTestOverride key="spn" value="Verizon"/>
       <carrierTestOverride key="pnn" value="Verizon network"/>
       <carrierTestOverride key="iccid" value="123456789012345678901"/>
       </carrierTestOverrides>
     */
    static final String DATA_CARRIER_TEST_OVERRIDE_PATH =
@@ -62,6 +63,7 @@ public class CarrierTestOverride {
    static final String CARRIER_TEST_XML_ITEM_KEY_STRING_IMSI = "imsi";
    static final String CARRIER_TEST_XML_ITEM_KEY_STRING_SPN = "spn";
    static final String CARRIER_TEST_XML_ITEM_KEY_STRING_PNN = "pnn";
    static final String CARRIER_TEST_XML_ITEM_KEY_STRING_ICCID = "iccid";

    private HashMap<String, String> mCarrierTestParamMap;

@@ -131,6 +133,17 @@ public class CarrierTestOverride {
        }
    }

    String getFakeIccid() {
        try {
            String iccid = mCarrierTestParamMap.get(CARRIER_TEST_XML_ITEM_KEY_STRING_ICCID);
            Rlog.d(LOG_TAG, "reading iccid from CarrierTestConfig file: " + iccid);
            return iccid;
        } catch (NullPointerException e) {
            Rlog.w(LOG_TAG, "No iccid in CarrierTestConfig file ");
            return null;
        }
    }

    private void loadCarrierTestOverrides() {

        FileReader carrierTestConfigReader;
+11 −2
Original line number Diff line number Diff line
@@ -73,6 +73,8 @@ public abstract class IccRecords extends Handler implements IccConstants {
                                                       // made requests for the sim records

    protected String mIccId;  // Includes only decimals (no hex)
    protected String mFakeIccId;

    protected String mFullIccId;  // Includes hex characters in ICCID
    protected String mMsisdn = null;  // My mobile number
    protected String mMsisdnTag = null;
@@ -160,6 +162,7 @@ public abstract class IccRecords extends Handler implements IccConstants {
                + " recordsRequested=" + mRecordsRequested
                + " lockedRecordsRequested=" + mLockedRecordsRequested
                + " iccid=" + iccIdToPrint
                + (mCarrierTestOverride.isInTestMode() ? "mFakeIccid=" + mFakeIccId : "")
                + " msisdnTag=" + mMsisdnTag
                + " voiceMailNum=" + Rlog.pii(VDBG, mVoiceMailNum)
                + " voiceMailTag=" + mVoiceMailTag
@@ -173,7 +176,6 @@ public abstract class IccRecords extends Handler implements IccConstants {
                + " mailboxIndex=" + mMailboxIndex
                + " spn=" + mSpn
                + (mCarrierTestOverride.isInTestMode() ? " mFakeSpn=" + mFakeSpn : "");

    }

    /**
@@ -218,6 +220,9 @@ public abstract class IccRecords extends Handler implements IccConstants {

            mFakePnnHomeName = mCarrierTestOverride.getFakePnnHomeName();
            log("load mFakePnnHomeName: " + mFakePnnHomeName);

            mFakeIccId = mCarrierTestOverride.getFakeIccid();
            log("load mFakeIccId: " + mFakeIccId);
        }
    }

@@ -276,8 +281,12 @@ public abstract class IccRecords extends Handler implements IccConstants {
     * @return ICC ID without hex digits
     */
    public String getIccId() {
        if (mCarrierTestOverride.isInTestMode() && mFakeIccId != null) {
            return mFakeIccId;
        } else {
            return mIccId;
        }
    }

    /**
     * Returns the full ICC ID including hex digits.
+0 −1
Original line number Diff line number Diff line
@@ -2239,7 +2239,6 @@ public class SIMRecords extends IccRecords {
        pw.println(" mEfCfis[]=" + Arrays.toString(mEfCfis));
        pw.println(" mSpnDisplayCondition=" + mSpnDisplayCondition);
        pw.println(" mSpdiNetworks[]=" + mSpdiNetworks);
        pw.println(" mPnnHomeName=" + mPnnHomeName);
        pw.println(" mUsimServiceTable=" + mUsimServiceTable);
        pw.println(" mGid1=" + mGid1);
        if (mCarrierTestOverride.isInTestMode()) {
+14 −6
Original line number Diff line number Diff line
@@ -16,6 +16,13 @@

package com.android.internal.telephony;

import static com.android.internal.telephony.TelephonyTestUtils.waitForMs;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doReturn;

import android.database.Cursor;
import android.database.MatrixCursor;
import android.net.Uri;
@@ -25,16 +32,12 @@ import android.provider.Telephony.Carriers;
import android.test.mock.MockContentProvider;
import android.test.mock.MockContentResolver;
import android.test.suitebuilder.annotation.SmallTest;
import java.util.Arrays;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import static com.android.internal.telephony.TelephonyTestUtils.waitForMs;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doReturn;
import java.util.Arrays;

public class CarrierIdentifierTest extends TelephonyTest {
    private static final String MCCMNC = "311480";
@@ -210,6 +213,7 @@ public class CarrierIdentifierTest extends TelephonyTest {
                                CarrierIdentification.GID2,
                                CarrierIdentification.PLMN,
                                CarrierIdentification.IMSI_PREFIX_XPATTERN,
                                CarrierIdentification.ICCID_PREFIX,
                                CarrierIdentification.SPN,
                                CarrierIdentification.APN,
                                CarrierIdentification.NAME,
@@ -222,6 +226,7 @@ public class CarrierIdentifierTest extends TelephonyTest {
                        null,                   // gid2
                        null,                   // plmn
                        null,                   // imsi_prefix
                        null,                   // iccid_prefix
                        null,                   // spn
                        null,                   // apn
                        NAME,                   // carrier name
@@ -234,6 +239,7 @@ public class CarrierIdentifierTest extends TelephonyTest {
                        null,                   // gid2
                        null,                   // plmn
                        null,                   // imsi_prefix
                        null,                   // iccid_prefix
                        null,                   // spn
                        null,                   // apn
                        NAME_TMO,               // carrier name
@@ -246,6 +252,7 @@ public class CarrierIdentifierTest extends TelephonyTest {
                        null,                   // gid2
                        null,                   // plmn
                        null,                   // imsi_prefix
                        null,                   // iccid_prefix
                        SPN_FI,                 // spn
                        null,                   // apn
                        NAME_FI,                // carrier name
@@ -258,6 +265,7 @@ public class CarrierIdentifierTest extends TelephonyTest {
                        null,                   // gid2
                        null,                   // plmn
                        null,                   // imsi_prefix
                        null,                   // iccid_prefix
                        null,                   // spn
                        APN_DOCOMO,             // apn
                        NAME_DOCOMO,            // carrier name