ServiceStateTracker与RIL对象的交互

ServiceStateTracker通过被动接收RIL上报和主动发起服务状态控制请求与RIL进行交互。当RIL上报EVENT_SIM_READY时,ServiceStateTracker的pollState方法被调用,发起多个请求并处理响应结果,更新网络状态。同时,ServiceStateTracker可通过setRadioPower方法控制无线通信模块的开启和关闭。

ServiceStateTracker与RIL对象的交互

两种方式:

  • ServiceStateTracker对象主动发起的
  • ServiceStateTracker对象被动接收的

1.被动接收RIL上报

  • ServiceStateTracker对象和Phone对象有相同的生命周期,在建立时会调用RIL对象的registerForXXX和setOnXXX方法,完成7种类型注册:

        //ServiceStateTracker
        mCi.setOnSignalStrengthUpdate(this, EVENT_SIGNAL_STRENGTH_UPDATE, null);
        mCi.registerForCellInfoList(this, EVENT_UNSOL_CELL_INFO_LIST, null);

 
 
 
        //GsmServiceStateTracker       
        mCi.registerForAvailable(this, EVENT_RADIO_AVAILABLE, null);
        mCi.registerForRadioStateChanged(this, EVENT_RADIO_STATE_CHANGED, null);
        mCi.registerForVoiceNetworkStateChanged(this, EVENT_NETWORK_STATE_CHANGED, null);
        mCi.setOnNITZTime(this, EVENT_NITZ_TIME, null);
        mCi.setOnRestrictedStateChanged(this, EVENT_RESTRICTED_STATE_CHANGED, null);
        mIccRecords.registerForRecordsLoaded(this, EVENT_SIM_RECORDS_LOADED, null);
        mUiccApplcation.registerForReady(this, EVENT_SIM_READY, null);
 

  • 注册网络成功后RIL会发出EVENT_SIM_READY消息,ServiceStateTracker的handleMessage接收,接着调用 pollState方法:

            case EVENT_SIM_READY:
                // Set the network type, in case the radio does not restore it.
                // mCi.setCurrentPreferredNetworkType();

                boolean skipRestoringSelection = mPhone.getContext().getResources().getBoolean(
                        com.android.internal.R.bool.skip_restoring_network_selection);

                if (!skipRestoringSelection) {
                    // restore the previous network selection.
                    mPhone.restoreSavedNetworkSelection(null);
                }
                pollState();
                // Signal strength polling stops when radio is off
                queueNextSignalStrengthPoll();
                break;

  • pollState方法首先判断radio是否可用,然后会连续向RIL发出4个请求:

<pre name="code" class="java">                mPollingContext[0]++;
mCi.getOperator( obtainMessage( EVENT_POLL_STATE_OPERATOR, mPollingContext)); mPollingContext[0]++; mCi.getDataRegistrationState( obtainMessage( EVENT_POLL_STATE_GPRS, mPollingContext)); mPollingContext[0]++; mCi.getVoiceRegistrationState( obtainMessage( EVENT_POLL_STATE_REGISTRATION, mPollingContext)); mPollingContext[0]++; mCi.getNetworkSelectionMode( obtainMessage( EVENT_POLL_STATE_NETWORK_SELECTION_MODE, mPollingContext));

 

  • 会向MODEM发出对应的AT指令,handleMessage接受返回的结果,然后都会调用handlePollStateResult方法:

            case EVENT_POLL_STATE_REGISTRATION:
            case EVENT_POLL_STATE_GPRS:
            case EVENT_POLL_STATE_OPERATOR:
            case EVENT_POLL_STATE_NETWORK_SELECTION_MODE:
                ar = (AsyncResult) msg.obj;

                handlePollStateResult(msg.what, ar);
                break;

  • 在handlePollStateResult方法中会具体处理4种消息,主要是更新mNewSS(ServiceState)对象和mNewXXX对象的一些属性,最终调用pollStateDone方法,跟新属性,如果网络基本信息或状态改变了,发起对应的handler消息。

2.向服务对象主动发起服务状态控制请求:

主要通过setRadioPower方法,打开关闭radio无线通信模块。

    @Override
    protected void setPowerStateToDesired() {

        if (mAlarmSwitch) {
            if(DBG) log("mAlarmSwitch == true");
            Context context = mPhone.getContext();
            AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
            am.cancel(mRadioOffIntent);
            mAlarmSwitch = false;
        }

        // If we want it on and it's off, turn it on
        if (mDesiredPowerState
                && mCi.getRadioState() == CommandsInterface.RadioState.RADIO_OFF) {
            mCi.setRadioPower(true, null);
        } else if (!mDesiredPowerState && mCi.getRadioState().isOn()) {
            // If it's on and available and we want it off gracefully
            if (mPowerOffDelayNeed) {
                if (mImsRegistrationOnOff && !mAlarmSwitch) {
                    if(DBG) log("mImsRegistrationOnOff == true");
                    Context context = mPhone.getContext();
                    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

                    Intent intent = new Intent(ACTION_RADIO_OFF);
                    mRadioOffIntent = PendingIntent.getBroadcast(context, 0, intent, 0);

                    mAlarmSwitch = true;
                    if (DBG) log("Alarm setting");
                    am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
                            SystemClock.elapsedRealtime() + 3000, mRadioOffIntent);
                } else {
                    DcTrackerBase dcTracker = mPhone.mDcTracker;
                    powerOffRadioSafely(dcTracker);
                }
            } else {
                DcTrackerBase dcTracker = mPhone.mDcTracker;
                powerOffRadioSafely(dcTracker);
            }
        } else if (mDeviceShuttingDown && mCi.getRadioState().isAvailable()) {
            mCi.requestShutdown(null);
        }
    }



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值