Android 开机SIM卡变更提示信息始终为卡1的问题解析

在高通平台上,更换SIM卡后开机会有一个提示信息。

在双卡项目上遇到了这样一个问题,当用户只插入一张卡2时,开机SIM变更提示显示为卡1。

如图所示:



这里主要是分析为什么这个SIM卡信息会显示错误,所以不赘述弹出过程,直奔主题:

vendor/qcom/proprietary/qrdplus/Extension/apps/PhoneFeatures/src/com/android/phonefeature/simdetector/MSimStateService.java

    protected void alertSIMChanged() {
        mSimDetectorApp.onSimChangedNotified();
        saveSubscriptions();

        SpannableStringBuilder spanStrBuilderSIMInfo = getSIMInfo();
        // BEGIN: Modified by Tony at 2014-01-21 for 0024804
        AlertDialog dialog = null;
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        // AlertDialog dialog = builder.setTitle(R.string.sim_info).setMessage(spanStrBuilderSIMInfo)
        //         .setNegativeButton(R.string.close, this)
        //         .setPositiveButton(R.string.change, this).create();
        if ("msm8610_t7_j930_cu".equals(SystemProperties.get("ro.product.name"))) {
            dialog = builder.setTitle(R.string.config_sub_title).setMessage(R.string.new_cards_available)
                    .setNegativeButton(R.string.close, this)
                    .setPositiveButton(R.string.ok, this).create();
        } else {
            dialog = builder.setTitle(R.string.sim_info).setMessage(spanStrBuilderSIMInfo)
                    .setNegativeButton(R.string.close, this)
                    .setPositiveButton(R.string.change, this).create();
        }
        // END:   Modified by Tony at 2014-01-21
        dialog.getWindow().setType(
                WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
        dialog.show();
    }

alertSIMChanged()这个方法就是弹出提示框的方法,我们主要关注的是它的信息,来看getSIMInfo()。

   private SpannableStringBuilder getSIMInfo() {
        final TypedArray icons = this.getResources().obtainTypedArray(
                com.android.internal.R.array.sim_icons);

        ConnectivityManager connService = (ConnectivityManager)
                getSystemService(Context.CONNECTIVITY_SERVICE);
        boolean mobileDataEnabled = connService.getMobileDataEnabled();

        String mobileDataState = mobileDataEnabled ? getString(R.string.mobile_data_on)
                : getString(R.string.mobile_data_off);
        final int dataSub = MSimPhoneFactory.getDataSubscription();

        String html = getString(R.string.new_sim_detected) + "<br>" +
                getString(R.string.mobile_data) + getString(R.string.slot) + (dataSub + 1) +
                " <img src=‘data‘/> " + getString(R.string.carrier_name) + "<br>" +
                getString(R.string.mobile_data) + mobileDataState;

        SpannableStringBuilder spannableStringBuilder = (SpannableStringBuilder) Html.fromHtml(
                html, new ImageGetter() {

                    public Drawable getDrawable(String source) {
                        Drawable drawable = null;
                        if (source.equals(DATA_OPTION)) {
                            drawable = icons.getDrawable(dataSub);
                            drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
                                    drawable.getIntrinsicHeight());
                        }

                        return drawable;
                    }
                }, null);

        return spannableStringBuilder;
    }

String类型的html变量就是将要显示的内容。

final int dataSub = MSimPhoneFactory.getDataSubscription();
dataSub + 1 就是显示的(卡)1或者2 (加1是因为代码中获取到的卡1为0,卡2为1)

那么就是这里获取的值出错了,继续往下跟。

frameworks/opt/telephony-msim/frameworks/src/com/codeaurora/internal/telephony/MSimPhoneFactory.java

    public static int getDataSubscription() {
        int subscription = 0;

        try {
            subscription = Settings.Global.getInt(sContext.getContentResolver(),
                    Settings.Global.MULTI_SIM_DATA_CALL_SUBSCRIPTION);
        } catch (SettingNotFoundException snfe) {
            Rlog.e(LOG_TAG, "Settings Exception Reading Dual Sim Data Call Values");
        }

        if (subscription < 0 || subscription >= MSimTelephonyManager.getDefault().getPhoneCount()) {
            Rlog.i(LOG_TAG, "Subscription is invalid..." + subscription + " Set to 0");
            subscription = 0;
            setDataSubscription(subscription);
        }

        return subscription;
    }

也就是说subscription始终返回的是0,仔细一看这个逻辑就有问题了。

如果subscription = Settings.Global.getInt(sContext.getContentResolver(), Settings.Global.MULTI_SIM_DATA_CALL_SUBSCRIPTION);获取到的是0,或者下面的这个判断可以通过的话那么将始终返回0。

但是卡1(0代表卡1)不一定是可用的(没有插卡),这种返回将导致开篇指出的提示信息有误。

提供一种解决思路:

    public static int getDataSubscription() {
        int subscription = 0;

        try {
            subscription = Settings.Global.getInt(sContext.getContentResolver(),
                    Settings.Global.MULTI_SIM_DATA_CALL_SUBSCRIPTION);
        } catch (SettingNotFoundException snfe) {
            Rlog.e(LOG_TAG, "Settings Exception Reading Dual Sim Data Call Values");
        }

        // BEGIN: Modified by Tony at 2014-03-22 for 0028503
        //if (subscription < 0 || subscription >= MSimTelephonyManager.getDefault().getPhoneCount()) {
        //    Rlog.i(LOG_TAG, "Subscription is invalid..." + subscription + " Set to 0");
        //    subscription = 0;
        //    setDataSubscription(subscription);
        //}
        boolean isHasSUB1 = MSimTelephonyManager.getDefault().hasIccCard(MSimConstants.SUB1);
        boolean isHasSUB2 = MSimTelephonyManager.getDefault().hasIccCard(MSimConstants.SUB2);
        boolean isHasDataSubscription = MSimTelephonyManager.getDefault().hasIccCard(subscription);
        if (subscription < 0 || subscription >= MSimTelephonyManager.getDefault().getPhoneCount() || !isHasDataSubscription) {
            int currentSubscription = 0;
            if (isHasSUB1) {
                currentSubscription = MSimConstants.SUB1;
            } else if (isHasSUB2) {
                currentSubscription = MSimConstants.SUB2;
            }

            if (currentSubscription != subscription) {
                subscription = currentSubscription;
                setDataSubscription(subscription);
            }
        }
        // END:   Modified by Tony at 2014-03-22

        return subscription;
    }

对卡槽1、卡槽2和获取到的subscription进行判断是否插入SIM卡,如果获取到的subscription卡槽没有插入SIM卡(还有其他两个条件)则对其进行重置操作。

如果卡槽1插入了SIM卡则优先设置使用卡1数据流量并返回,若卡槽1未插卡,则判断卡2,都没有插卡则默认返回卡1(没关系的,都不插卡不会有弹出提示框)。


仅供参考,如有更好的思路请留言。相互学习,谢谢。

Android 开机SIM卡变更提示信息始终为卡1的问题解析,,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。