Android切换系统语言状态栏运营商不改变

frameworks/base/telephony/java/android/telephony/SubscriptionManager

 /**
     * Set display name by simInfo index
     * @param displayName the display name of SIM card
     * @param subId the unique SubscriptionInfo index in database
     * @return the number of records updated
     * @hide
     */
    public int setDisplayName(String displayName, int subId) {
        return setDisplayName(displayName, subId, NAME_SOURCE_UNDEFINDED);
    }

    public int setDisplayName(String displayName, int subId, long nameSource) {
        if (VDBG) {
            logd("[setDisplayName]+  displayName:" + displayName + " subId:" + subId
                    + " nameSource:" + nameSource);
        }
        if (!isValidSubscriptionId(subId)) {
            // MTK-START
            //logd("[setDisplayName]- fail");
            logd("[setDisplayName]- fail, subId = " + subId);
            // MTK-END
            return -1;
        }

        int result = 0;

        try {
            ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub"));
            if (iSub != null) {
                result = iSub.setDisplayNameUsingSrc(displayName, subId, nameSource); //SubscriptionController
            }
        } catch (RemoteException ex) {
            // ignore it
        }

        return result;

    }
setDisplayName由SubscriptionInfoUpdater里的handleSimLoaded调用
public class SubscriptionInfoUpdater extends Handler {


    case SIM_LOADED:
                    handleSimLoaded(mUserObj.slotId);
                    break;

    private void handleSimLoaded(int slotId) {

    mSubscriptionManager.setDisplayName(nameToSet, subId);

运营商的名称最后由TelephonyManager里面更新的
 /**
     * Returns the Service Provider Name (SPN).
     *
     * @hide
     */
    public String getSimOperatorNameForPhone(int phoneId) {
         return getTelephonyProperty(phoneId,
                TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA, "");
    }
    

/**
     * Returns the Service Provider Name (SPN).
     * <p>
     * Availability: SIM state must be {@link #SIM_STATE_READY}
     *
     * @see #getSimState
     *
     * @param subId for which SimOperatorName is returned
     * @hide
     */
    public String getSimOperatorNameForSubscription(int subId) {
        int phoneId = SubscriptionManager.getPhoneId(subId);
        return getSimOperatorNameForPhone(phoneId);
    }

    /**
     * Gets the telephony property.
     *
     * @hide
     */
    public static String getTelephonyProperty(int phoneId, String property, String defaultVal) {
        String propVal = null;
        String prop = SystemProperties.get(property);
        Rlog.d(TAG, "getTelephonyProperty prop value= " + prop);
        if ((prop != null) && (prop.length() > 0)) {
            String values[] = prop.split(",");
            if ((phoneId >= 0) && (phoneId < values.length) && (values[phoneId] != null)) {
                propVal = values[phoneId];
            }
        }
        return propVal == null ? defaultVal : "6666666";
    }

上面是流程,在SubscriptionInfoUpdater里面有一个广播更新状态以及解决方案

在构造方法里面注册

  IntentFilter intentFilter = new IntentFilter(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
        intentFilter.addAction(IccCardProxy.ACTION_INTERNAL_SIM_STATE_CHANGED);
        // MTK-START
        intentFilter.addAction("android.intent.action.ACTION_SHUTDOWN_IPO");
        intentFilter.addAction(TelephonyIntents.ACTION_COMMON_SLOT_NO_CHANGED);
        intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED); // add by larry
        if ("OP09".equals(SystemProperties.get("ro.operator.optr"))
                && ("SEGDEFAULT".equals(SystemProperties.get("ro.operator.seg"))
                    || "SEGC".equals(SystemProperties.get("ro.operator.seg")))) {
            intentFilter.addAction(Intent.ACTION_LOCALE_CHANGED);
        }

 

 private final BroadcastReceiver sReceiver = new  BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            logd("[Receiver]+");
            String action = intent.getAction();
            logd("Action: " + action);


            if (!action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED) &&
                !action.equals(IccCardProxy.ACTION_INTERNAL_SIM_STATE_CHANGED) &&
                // MTK-START
                !action.equals("android.intent.action.ACTION_SHUTDOWN_IPO") &&
                !action.equals(TelephonyIntents.ACTION_COMMON_SLOT_NO_CHANGED) &&
                !action.equals(Intent.ACTION_CONFIGURATION_CHANGED) && // add by larry
                !action.equals(Intent.ACTION_LOCALE_CHANGED)) {
                // MTK-END
                return;
            }

   .........

 } else if (action.equals(Intent.ACTION_LOCALE_CHANGED) ||action.equals(Intent.ACTION_CONFIGURATION_CHANGED) ){ // modify by larry
                int[] subIdList = mSubscriptionManager.getActiveSubscriptionIdList();
                for (int subId : subIdList) {
                    updateSubName(subId);
                }
            } 
   private void updateSubName(int subId) {
        SubscriptionInfo subInfo =
                mSubscriptionManager.getSubscriptionInfo(subId);
        if (subInfo != null
                && subInfo.getNameSource() != SubscriptionManager.NAME_SOURCE_USER_INPUT) {
            SpnOverride spnOverride = SpnOverride.getInstance();
            String nameToSet;
            String carrierName = TelephonyManager.getDefault().getSimOperator(subId);
            int slotId = SubscriptionManager.getSlotId(subId);
            logd("updateSubName, carrierName = " + carrierName + ", subId = " + subId);
            if (SubscriptionManager.isValidSlotId(slotId)) {
                if (spnOverride.containsCarrierEx(carrierName)) {
                    nameToSet = spnOverride.lookupOperatorName(subId, carrierName,
                        true, mContext);
                    logd("SPN found, name = " + nameToSet);
                } else {
                    nameToSet = "CARD " + Integer.toString(slotId + 1);
                    logd("SPN not found, set name to " + nameToSet);
                }
                mSubscriptionManager.setDisplayName(nameToSet, subId);
            }
        }
    }

 最后就调用到mSubscriptionManager.setDisplayName(nameToSet, subId);


总结:其实就是一个监听语言改变的广播然后进行更新语言


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值