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

Commit 023296f9 authored by Nathan Harold's avatar Nathan Harold Committed by android-build-merger
Browse files

Merge "Remove spn-conf.xml Support for SPN Override" am: 6e2094e3

am: 2c7f0f9d

Change-Id: Ibb382ec0230f0e8499a1bb6309d4e5433b3162cc
parents 215c1734 2c7f0f9d
Loading
Loading
Loading
Loading
+42 −42
Original line number Original line Diff line number Diff line
@@ -60,9 +60,6 @@ public class SIMRecords extends IccRecords {


    VoiceMailConstants mVmConfig;
    VoiceMailConstants mVmConfig;



    SpnOverride mSpnOverride;

    // ***** Cached SIM State; cleared on channel close
    // ***** Cached SIM State; cleared on channel close


    private int mCallForwardingStatus;
    private int mCallForwardingStatus;
@@ -99,7 +96,6 @@ public class SIMRecords extends IccRecords {
    public String toString() {
    public String toString() {
        return "SimRecords: " + super.toString()
        return "SimRecords: " + super.toString()
                + " mVmConfig" + mVmConfig
                + " mVmConfig" + mVmConfig
                + " mSpnOverride=" + mSpnOverride
                + " callForwardingEnabled=" + mCallForwardingStatus
                + " callForwardingEnabled=" + mCallForwardingStatus
                + " spnState=" + mSpnState
                + " spnState=" + mSpnState
                + " mCphsInfo=" + mCphsInfo
                + " mCphsInfo=" + mCphsInfo
@@ -214,7 +210,6 @@ public class SIMRecords extends IccRecords {
        mAdnCache = new AdnRecordCache(mFh);
        mAdnCache = new AdnRecordCache(mFh);


        mVmConfig = new VoiceMailConstants();
        mVmConfig = new VoiceMailConstants();
        mSpnOverride = new SpnOverride();


        mRecordsRequested = false;  // No load request is made till SIM ready
        mRecordsRequested = false;  // No load request is made till SIM ready


@@ -1640,57 +1635,63 @@ public class SIMRecords extends IccRecords {


    //***** Private methods
    //***** Private methods


    /**
     * Override the carrier name with either carrier config or SPN
     * if an override is provided.
     */
    private void handleCarrierNameOverride() {
    private void handleCarrierNameOverride() {
        final int phoneId = mParentApp.getPhoneId();
        SubscriptionController subCon = SubscriptionController.getInstance();
        final int subId = subCon.getSubIdUsingPhoneId(phoneId);
        if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
            loge("subId not valid for Phone " + phoneId);
            return;
        }

        CarrierConfigManager configLoader = (CarrierConfigManager)
        CarrierConfigManager configLoader = (CarrierConfigManager)
                mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE);
                mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE);
        if (configLoader != null && configLoader.getConfig().getBoolean(
        if (configLoader == null) {
                CarrierConfigManager.KEY_CARRIER_NAME_OVERRIDE_BOOL)) {
            loge("Failed to load a Carrier Config");
            String carrierName = configLoader.getConfig().getString(
            return;
                    CarrierConfigManager.KEY_CARRIER_NAME_STRING);
            setServiceProviderName(carrierName);
            mTelephonyManager.setSimOperatorNameForPhone(mParentApp.getPhoneId(),
                    carrierName);
        } else {
            setSpnFromConfig(getOperatorNumeric());
        }
        }


        /* update display name with carrier override */
        PersistableBundle config = configLoader.getConfigForSubId(subId);
        setDisplayName();
        boolean preferCcName = config.getBoolean(
                CarrierConfigManager.KEY_CARRIER_NAME_OVERRIDE_BOOL, false);
        String ccName = config.getString(CarrierConfigManager.KEY_CARRIER_NAME_STRING);
        // If carrier config is priority, use it regardless - the preference
        // and the name were both set by the carrier, so this is safe;
        // otherwise, if the SPN is priority but we don't have one *and* we have
        // a name in carrier config, use the carrier config name as a backup.
        if (preferCcName || (TextUtils.isEmpty(getServiceProviderName())
                             && !TextUtils.isEmpty(ccName))) {
            setServiceProviderName(ccName);
            mTelephonyManager.setSimOperatorNameForPhone(phoneId, ccName);
        }
        }


    private void setDisplayName() {
        updateCarrierNameForSubscription(subCon, subId);
        SubscriptionManager subManager = SubscriptionManager.from(mContext);
    }
        int[] subId = subManager.getSubId(mParentApp.getPhoneId());

    private void updateCarrierNameForSubscription(SubscriptionController subCon, int subId) {
        /* update display name with carrier override */
        SubscriptionInfo subInfo = subCon.getActiveSubscriptionInfo(
                subId, mContext.getOpPackageName());


        if ((subId == null) || subId.length <= 0) {
        if (subInfo == null || subInfo.getNameSource()
            log("subId not valid for Phone " + mParentApp.getPhoneId());
                == SubscriptionManager.NAME_SOURCE_USER_INPUT) {
            // either way, there is no subinfo to update
            return;
            return;
        }
        }


        SubscriptionInfo subInfo = subManager.getActiveSubscriptionInfo(subId[0]);
        if (subInfo != null && subInfo.getNameSource()
                    != SubscriptionManager.NAME_SOURCE_USER_INPUT) {
        CharSequence oldSubName = subInfo.getDisplayName();
        CharSequence oldSubName = subInfo.getDisplayName();
            String newCarrierName = mTelephonyManager.getSimOperatorName(subId[0]);
        String newCarrierName = mTelephonyManager.getSimOperatorName(subId);


        if (!TextUtils.isEmpty(newCarrierName) && !newCarrierName.equals(oldSubName)) {
        if (!TextUtils.isEmpty(newCarrierName) && !newCarrierName.equals(oldSubName)) {
            log("sim name[" + mParentApp.getPhoneId() + "] = " + newCarrierName);
            log("sim name[" + mParentApp.getPhoneId() + "] = " + newCarrierName);
                SubscriptionController.getInstance().setDisplayName(newCarrierName, subId[0]);
            subCon.setDisplayName(newCarrierName, subId);
            }
        } else {
            log("SUB[" + mParentApp.getPhoneId() + "] " + subId[0] + " SubInfo not created yet");
        }
        }
    }
    }


    private void setSpnFromConfig(String carrier) {
        if (mSpnOverride.containsCarrier(carrier)) {
            setServiceProviderName(mSpnOverride.getSpn(carrier));
            mTelephonyManager.setSimOperatorNameForPhone(
                    mParentApp.getPhoneId(), getServiceProviderName());
        }
    }


    private void setVoiceMailByCountry (String spn) {
    private void setVoiceMailByCountry (String spn) {
        if (mVmConfig.containsCarrier(spn)) {
        if (mVmConfig.containsCarrier(spn)) {
            mIsVoiceMailFixed = true;
            mIsVoiceMailFixed = true;
@@ -2223,7 +2224,6 @@ public class SIMRecords extends IccRecords {
        pw.println(" extends:");
        pw.println(" extends:");
        super.dump(fd, pw, args);
        super.dump(fd, pw, args);
        pw.println(" mVmConfig=" + mVmConfig);
        pw.println(" mVmConfig=" + mVmConfig);
        pw.println(" mSpnOverride=" + mSpnOverride);
        pw.println(" mCallForwardingStatus=" + mCallForwardingStatus);
        pw.println(" mCallForwardingStatus=" + mCallForwardingStatus);
        pw.println(" mSpnState=" + mSpnState);
        pw.println(" mSpnState=" + mSpnState);
        pw.println(" mCphsInfo=" + mCphsInfo);
        pw.println(" mCphsInfo=" + mCphsInfo);
+0 −114
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2009 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.telephony.uicc;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import android.os.Environment;
import android.telephony.Rlog;
import android.util.Xml;

import com.android.internal.util.XmlUtils;

public class SpnOverride {
    private HashMap<String, String> mCarrierSpnMap;


    static final String LOG_TAG = "SpnOverride";
    static final String PARTNER_SPN_OVERRIDE_PATH ="etc/spn-conf.xml";
    static final String OEM_SPN_OVERRIDE_PATH = "telephony/spn-conf.xml";

    SpnOverride () {
        mCarrierSpnMap = new HashMap<String, String>();
        loadSpnOverrides();
    }

    boolean containsCarrier(String carrier) {
        return mCarrierSpnMap.containsKey(carrier);
    }

    String getSpn(String carrier) {
        return mCarrierSpnMap.get(carrier);
    }

    private void loadSpnOverrides() {
        FileReader spnReader;

        File spnFile = new File(Environment.getRootDirectory(),
                PARTNER_SPN_OVERRIDE_PATH);
        File oemSpnFile = new File(Environment.getOemDirectory(),
                OEM_SPN_OVERRIDE_PATH);

        if (oemSpnFile.exists()) {
            // OEM image exist SPN xml, get the timestamp from OEM & System image for comparison.
            long oemSpnTime = oemSpnFile.lastModified();
            long sysSpnTime = spnFile.lastModified();
            Rlog.d(LOG_TAG, "SPN Timestamp: oemTime = " + oemSpnTime + " sysTime = " + sysSpnTime);

            // To get the newer version of SPN from OEM image
            if (oemSpnTime > sysSpnTime) {
                Rlog.d(LOG_TAG, "SPN in OEM image is newer than System image");
                spnFile = oemSpnFile;
            }
        } else {
            // No SPN in OEM image, so load it from system image.
            Rlog.d(LOG_TAG, "No SPN in OEM image = " + oemSpnFile.getPath() +
                " Load SPN from system image");
        }

        try {
            spnReader = new FileReader(spnFile);
        } catch (FileNotFoundException e) {
            Rlog.w(LOG_TAG, "Can not open " + spnFile.getAbsolutePath());
            return;
        }

        try {
            XmlPullParser parser = Xml.newPullParser();
            parser.setInput(spnReader);

            XmlUtils.beginDocument(parser, "spnOverrides");

            while (true) {
                XmlUtils.nextElement(parser);

                String name = parser.getName();
                if (!"spnOverride".equals(name)) {
                    break;
                }

                String numeric = parser.getAttributeValue(null, "numeric");
                String data    = parser.getAttributeValue(null, "spn");

                mCarrierSpnMap.put(numeric, data);
            }
            spnReader.close();
        } catch (XmlPullParserException e) {
            Rlog.w(LOG_TAG, "Exception in spn-conf parser " + e);
        } catch (IOException e) {
            Rlog.w(LOG_TAG, "Exception in spn-conf parser " + e);
        }
    }

}