您的位置:首页 > 其它

ServiceStateTracker与RIL对象的交互

2015-03-19 10:06 786 查看

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);
}
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐