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); } }
相关文章推荐
- Android Application-Telephony-RIL 4 TelephonyManager to GSMServiceStateTracker
- Android4.4 Telephony流程分析——GsmServiceStateTracker管理网络服务状态
- 第三章:通话连接的作用以及建立过程之四GsmCallTracker.java与RIL.java交互完成物理拨号
- 关于ServiceStateTracker.java中setPowerStateToDesired函数的疑问
- android telephony模块——serviceStateTracker
- Telephony状态维护—ServiceStateTracker
- 对 ASP.NET 中 ViewState 对象的荒谬认识
- 没有启动 ASP.NET State service错误的解决方法
- inter-portlet communication ,portlet之间的交互通讯,Transient State Management
- ASP.NET状态管理 APPlication,Session,Cookie和ViewState等对象用法和区别
- ASP.NET Application,Session,Cookie和ViewState等对象用法和区别 (转)
- State 引入一组表示对象状态的类,然后,把与状态相关的代码逻辑分配到这些类中
- Application、Session、Cookie、ViewState和Cache等对象保存信息的区别
- 当会话状态模式为“StateServer”或“SQLServer”时,不允许使用无法序列化的对象或 MarshalByRef 对象
- 没有启动 ASP.NET State service错误的解决方法
- flash和javascript交互时 出现“对象不支持此属性或方法”错误的解决方法
- 使用APPlication,Session,Cookie和ViewState等对象保存信息的区别是什么?
- BT源代码学习心得(七):跟踪服务器(Tracker)的代码分析(HTTP协议处理对象)
- BT源代码学习心得(七):跟踪服务器(Tracker)的代码分析(HTTP协议处理对象)
- Mediator 用一个中介者对象来封装一系列的对象交互。中介者使各个对象不需要显式的相互作用,从而使其耦合松散,而且可以独立地改变它们之间的交互。