拨号时获取双卡状态及飞行模式判断(设置)

源码在:CallController.java中,以下是截取紧急拨号获取SIM1或SIM2以及另一张卡是否正在拨打电话的判断代码。


  /* below are added by mediatek .inc */
    private CallStatusCode checkIfOkToInitiateOutgoingCall(int state, int slot) {
        log("checkIfOkToInitiateOutgoingCall, state = " + state + " slot = " + slot);
        if(slot == -1)
            return checkIfOkToInitiateOutgoingCall(state);

        GeminiPhone phone = (GeminiPhone) PhoneApp.getInstance().phone;
        if(slot == Phone.GEMINI_SIM_1) {
            if(phone.getStateGemini(Phone.GEMINI_SIM_2) != Phone.State.IDLE)
                return CallStatusCode.CALL_FAILED;
        } else {
            if(phone.getStateGemini(Phone.GEMINI_SIM_1) != Phone.State.IDLE)
                return CallStatusCode.CALL_FAILED;
        }

        final int realState = phone.getServiceStateGemini(slot).getState();
        log("realState = " + realState);
        return checkIfOkToInitiateOutgoingCall(realState);
    }

    int pickBestSlotForEmergencyCall() {
        log("pickBestSlotForEmergencyCall");
        int slot = Phone.GEMINI_SIM_1;

        GeminiPhone phone = (GeminiPhone) PhoneApp.getInstance().phone;
        boolean radioOn0 = phone.isRadioOnGemini(Phone.GEMINI_SIM_1);
        boolean radioOn1 = phone.isRadioOnGemini(Phone.GEMINI_SIM_2);
        log("radioOn0 = " + radioOn0 + " radioOn1 = " + radioOn1);

        if(radioOn0 && radioOn1) {
            // if both radio are power on
            // use the one in service
            if(phone.getStateGemini(Phone.GEMINI_SIM_2) != Phone.State.IDLE)
                slot = Phone.GEMINI_SIM_2;
            else if(phone.getStateGemini(Phone.GEMINI_SIM_1) != Phone.State.IDLE)
                slot = Phone.GEMINI_SIM_1;
            else {
                final int state0 = phone.getServiceStateGemini(Phone.GEMINI_SIM_1).getState();
                final int state1 = phone.getServiceStateGemini(Phone.GEMINI_SIM_2).getState();
                log("service state0 = " + state0 + " state1 = " + state1);

                if(state0 == ServiceState.STATE_OUT_OF_SERVICE && state1 == ServiceState.STATE_IN_SERVICE)
                    slot = Phone.GEMINI_SIM_2;
                if(state1 == ServiceState.STATE_OUT_OF_SERVICE && state0 == ServiceState.STATE_IN_SERVICE)
                    slot = Phone.GEMINI_SIM_1;
            }
        } else if(radioOn0) {
            slot = Phone.GEMINI_SIM_1;
        } else if(radioOn1){
            slot = Phone.GEMINI_SIM_2;
        }

        return slot;
    }


以下为飞行模式判断及退出飞行模式:EmergencyCallHelper.java

 /**
     * Attempt to power on the radio (i.e. take the device out
     * of airplane mode.)
     *
     * Additionally, start listening for service state changes;
     * we'll eventually get an onServiceStateChanged() callback
     * when the radio successfully comes up.
     */
    private void powerOnRadio() {
        if (DBG)
            log("- powerOnRadio()...");

        // We're about to turn on the radio, so arrange to be notified
        // when the sequence is complete.
        registerForServiceStateChanged();

        // If airplane mode is on, we turn it off the same way that the
        // Settings activity turns it off.
        int dualSimMode = 0;
        boolean bOffAirplaneMode = false;
        if (FeatureOption.MTK_GEMINI_SUPPORT)
            dualSimMode = Settings.System.getInt(mApp.getContentResolver(),
                    Settings.System.DUAL_SIM_MODE_SETTING,
                    Settings.System.DUAL_SIM_MODE_SETTING_DEFAULT);

        if (DBG) Log.d(TAG, "dualSimMode = " + dualSimMode);
        if (Settings.System.getInt(mApp.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) > 0) {
            if (DBG) log("==> Turning off airplane mode...");

            // Change the system setting
            Settings.System.putInt(mApp.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0);

            // Post the intent
            Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
            intent.putExtra("state", false);
            mApp.sendBroadcast(intent);
            bOffAirplaneMode = true;
        } else if (!FeatureOption.MTK_GEMINI_SUPPORT) {
            // Otherwise, for some strange reason the radio is off
            // (even though the Settings database doesn't think we're
            // in airplane mode.) In this case just turn the radio
            // back on.
            if (DBG) log("==> (Apparently) not in airplane mode; manually powering radio on...");
            mPhone.setRadioPower(true);
        }
        if (FeatureOption.MTK_GEMINI_SUPPORT
                && (!bOffAirplaneMode || (bOffAirplaneMode && needSetDualSimMode(dualSimMode)))) {
            int mode = getProperDualSimMode();
            Settings.System.putInt(mApp.getContentResolver(),
                    Settings.System.DUAL_SIM_MODE_SETTING, mode);
            final Intent intent = new Intent(Intent.ACTION_DUAL_SIM_MODE_CHANGED);
            intent.putExtra(Intent.EXTRA_DUAL_SIM_MODE, mode);
            mApp.sendBroadcast(intent);
        }
    }



阅读更多

没有更多推荐了,返回首页