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

Commit 98b63c93 authored by Hall Liu's avatar Hall Liu
Browse files

Read EHPLMN and HPLMN into SubscriptionInfo

Read the EHPLMN and HPLMNs from the SIM into SubscriptionInfo, and also
use this information to determine whether a network scan is allowed when
the location switch is off.

Bug: 130253962
Test: manual
Change-Id: Ib8db766f9e3278021e0e0a1bd93b9d36d34edf37
parent a57700c0
Loading
Loading
Loading
Loading
+19 −10
Original line number Diff line number Diff line
@@ -38,13 +38,16 @@ import android.telephony.LocationAccessPolicy;
import android.telephony.NetworkScan;
import android.telephony.NetworkScanRequest;
import android.telephony.RadioAccessSpecifier;
import android.telephony.SubscriptionInfo;
import android.telephony.TelephonyScanManager;
import android.util.Log;

import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Manages radio access network scan requests.
@@ -172,15 +175,22 @@ public final class NetworkScanRequestTracker {
    }

    /**
     * @return S list of MCC/MNC ids that apps should be allowed to see as results from a network
     * @return A list of MCC/MNC ids that apps should be allowed to see as results from a network
     * scan when scan results are restricted due to location privacy.
     */
    public static List<String> getAllowedMccMncsForLocationRestrictedScan(Context context) {
    public static Set<String> getAllowedMccMncsForLocationRestrictedScan(Context context) {
        return withCleanCallingIdentity(() -> SubscriptionController.getInstance()
                .getAllSubInfoList(context.getOpPackageName()).stream()
                .filter(subInfo -> subInfo.getMccString() != null)
                .map(subInfo -> subInfo.getMccString() + subInfo.getMncString())
                .collect(Collectors.toList()));
            .getAvailableSubscriptionInfoList(context.getOpPackageName()).stream()
            .flatMap(NetworkScanRequestTracker::getAllowableMccMncsFromSubscriptionInfo)
            .collect(Collectors.toSet()));
    }

    private static Stream<String> getAllowableMccMncsFromSubscriptionInfo(SubscriptionInfo info) {
        Stream<String> plmns = Stream.of(info.getEhplmns(), info.getHplmns()).flatMap(List::stream);
        if (info.getMccString() != null && info.getMncString() != null) {
            plmns = Stream.concat(plmns, Stream.of(info.getMccString() + info.getMncString()));
        }
        return plmns;
    }

    /** Sends a message back to the application via its callback. */
@@ -194,12 +204,11 @@ public final class NetworkScanRequestTracker {

        if (result != null) {
            if (what == TelephonyScanManager.CALLBACK_RESTRICTED_SCAN_RESULTS) {
                //List<String> allowedMccMncs =
                //        getAllowedMccMncsForLocationRestrictedScan(nsri.mPhone.getContext());
                Set<String> allowedMccMncs =
                        getAllowedMccMncsForLocationRestrictedScan(nsri.mPhone.getContext());

                result = result.stream().map(CellInfo::sanitizeLocationInfo)
                        // STOPSHIP Revisit PLMN check (b/130253962).
                        //.filter(ci -> doesCellInfoCorrespondToKnownMccMnc(ci, allowedMccMncs))
                        .filter(ci -> doesCellInfoCorrespondToKnownMccMnc(ci, allowedMccMncs))
                        .collect(Collectors.toList());
            }

+44 −4
Original line number Diff line number Diff line
@@ -389,6 +389,13 @@ public class SubscriptionController extends ISub.Stub {
                SubscriptionManager.MCC_STRING));
        String mnc = cursor.getString(cursor.getColumnIndexOrThrow(
                SubscriptionManager.MNC_STRING));
        String ehplmnsRaw = cursor.getString(cursor.getColumnIndexOrThrow(
                SubscriptionManager.EHPLMNS));
        String hplmnsRaw = cursor.getString(cursor.getColumnIndexOrThrow(
                SubscriptionManager.HPLMNS));
        String[] ehplmns = ehplmnsRaw == null ? null : ehplmnsRaw.split(",");
        String[] hplmns = hplmnsRaw == null ? null : hplmnsRaw.split(",");

        // cardId is the private ICCID/EID string, also known as the card string
        String cardId = cursor.getString(cursor.getColumnIndexOrThrow(
                SubscriptionManager.CARD_ID));
@@ -435,10 +442,12 @@ public class SubscriptionController extends ISub.Stub {
        if (!TextUtils.isEmpty(line1Number) && !line1Number.equals(number)) {
            number = line1Number;
        }
        return new SubscriptionInfo(id, iccId, simSlotIndex, displayName, carrierName,
            nameSource, iconTint, number, dataRoaming, iconBitmap, mcc, mnc, countryIso,
            isEmbedded, accessRules, cardId, publicCardId, isOpportunistic, groupUUID,
            false /* isGroupDisabled */, carrierId, profileClass, subType);
        SubscriptionInfo info = new SubscriptionInfo(id, iccId, simSlotIndex, displayName,
                carrierName, nameSource, iconTint, number, dataRoaming, iconBitmap, mcc, mnc,
                countryIso, isEmbedded, accessRules, cardId, publicCardId, isOpportunistic,
                groupUUID, false /* isGroupDisabled */, carrierId, profileClass, subType);
        info.setAssociatedPlmns(ehplmns, hplmns);
        return info;
    }

    /**
@@ -1648,6 +1657,37 @@ public class SubscriptionController extends ISub.Stub {
        }
    }

    /**
     * Set the EHPLMNs and HPLMNs associated with the subscription.
     */
    public void setAssociatedPlmns(String[] ehplmns, String[] hplmns, int subId) {
        if (DBG) logd("[setAssociatedPlmns]+ subId:" + subId);

        validateSubId(subId);
        int phoneId = getPhoneId(subId);

        if (phoneId < 0 || phoneId >= mTelephonyManager.getPhoneCount()) {
            if (DBG) logd("[setAssociatedPlmns]- fail");
            return;
        }

        String formattedEhplmns = ehplmns == null ? "" : String.join(",", ehplmns);
        String formattedHplmns = hplmns == null ? "" : String.join(",", hplmns);

        ContentValues value = new ContentValues(2);
        value.put(SubscriptionManager.EHPLMNS, formattedEhplmns);
        value.put(SubscriptionManager.HPLMNS, formattedHplmns);

        int count = mContext.getContentResolver().update(
                SubscriptionManager.getUriForSubscriptionId(subId), value, null, null);

        // Refresh the Cache of Active Subscription Info List
        refreshCachedActiveSubscriptionInfoList();

        if (DBG) logd("[setAssociatedPlmns]- update result :" + count);
        notifySubscriptionInfoChanged();
    }

    /**
     * Set data roaming by simInfo index
     * @param roaming 0:Don't allow data when roaming, 1:Allow data when roaming
+6 −0
Original line number Diff line number Diff line
@@ -439,6 +439,12 @@ public class SubscriptionInfoUpdater extends Handler {
                    SubscriptionController.getInstance().setDisplayNumber(msisdn, subId);
                }

                String[] ehplmns = records.getEhplmns();
                String[] hplmns = records.getHplmns();
                if (ehplmns != null || hplmns != null) {
                    SubscriptionController.getInstance().setAssociatedPlmns(ehplmns, hplmns, subId);
                }

                SubscriptionInfo subInfo = mSubscriptionManager.getActiveSubscriptionInfo(subId);
                String nameToSet;
                String simCarrierName = tm.getSimOperatorName(subId);
+19 −0
Original line number Diff line number Diff line
@@ -988,6 +988,25 @@ public abstract class IccRecords extends Handler implements IccConstants {
     */
    protected abstract void loge(String s);

    /**
     * @return String array containing EHPLMNs associated with the card.
     */
    public String[] getEhplmns() {
        return mEhplmns;
    }

    /**
     * @return String array containing HPLMNs associated with the card.
     */
    public String[] getHplmns() {
        if (mHplmnActRecords == null) return null;
        String[] hplmns = new String[mHplmnActRecords.length];
        for (int i = 0; i < mHplmnActRecords.length; i++) {
            hplmns[i] = mHplmnActRecords[i].plmn;
        }
        return hplmns;
    }

    /**
     * Return an interface to retrieve the ISIM records for IMS, if available.
     * @return the interface to retrieve the ISIM records, or null if not supported
+2 −0
Original line number Diff line number Diff line
@@ -73,6 +73,8 @@ public class FakeTelephonyProvider extends MockContentProvider {
                    + SubscriptionManager.MNC + " INTEGER DEFAULT 0,"
                    + SubscriptionManager.MCC_STRING + " TEXT,"
                    + SubscriptionManager.MNC_STRING + " TEXT,"
                    + SubscriptionManager.EHPLMNS + " TEXT,"
                    + SubscriptionManager.HPLMNS + " TEXT,"
                    + SubscriptionManager.SIM_PROVISIONING_STATUS
                    + " INTEGER DEFAULT " + SubscriptionManager.SIM_PROVISIONED + ","
                    + SubscriptionManager.IS_EMBEDDED + " INTEGER DEFAULT 0,"
Loading