【私人备忘录】Android P 网络变化代码流程

一、RILD层:
Vendor Ril → ril_service.cpp(networkStateChangedInd)(mRadioIndication->networkStateChanged) → RadioIndication.java(networkStateChanged)
备注:
1、ril_unsol_commands.h中定义: {RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, radio::networkStateChangedInd, WAKE_PARTIAL},
2、ril_service.cpp中struct RadioImpl : public V1_1::IRadio定义了所有接口
3、mRadioIndication是sp<IRadioIndication> mRadioIndication,RadioIndication.java实现IRadioIndication.stub

二、Telephony Frameworks:
RadioIndication.java(networkStateChanged) → mRil.mNetworkStateRegistrants.notifyRegistrants() → CellularNetworkService(case NETWORK_REGISTRATION_STATE_CHANGED).notifyNetworkRegistrationStateChanged → NetworkService(case NETWORK_SERVICE_INDICATION_NETWORK_STATE_CHANGED).notifyStateChangedToCallbacks → callback.onNetworkStateChanged() → ServiceStateTracker(case EVENT_NETWORK_STATE_CHANGED).pollState → ServiceStateTracker.handlePollStateResult → ServiceStateTracker.pollStateDone(mPhone.notifyServiceStateChanged(mPhone.getServiceState())) → GsmCdmaPhone.notifyServiceStateChanged → Phone.notifyServiceStateChangedP()
1、mServiceStateRegistrants.notifyRegistrants(ar);跟下代码会发现影响一般
2、mNotifier.notifyServiceState(this) → DefaultPhoneNotifier.notifyServiceState(mRegistry.notifyServiceStateForPhoneId(phoneId, subId, ss)) → TelephonyRegistry.notifyServiceStateForPhoneId(r.callback.onServiceStateChanged(makeServiceState(state)))
备注:
1、callback是registerForNetworkRegistrationStateChanged方法中添加,这个方法在NetworkRegistrationManager的onServiceConnected中通过AIDL调用,由其中的NetworkRegStateCallback定义可知,onNetworkStateChanged是mRegStateChangeRegistrants.notifyRegistrants(),mRegStateChangeRegistrants是registerForNetworkRegistrationStateChanged中添加,此方法是ServiceStateTracker中调用mRegStateManagers.get(transportType).registerForNetworkRegistrationStateChanged( this, EVENT_NETWORK_STATE_CHANGED, null)
2、pollState中获取运营商(EVENT_POLL_STATE_OPERATOR)、获取PS状态(EVENT_POLL_STATE_GPRS)、获取CS状态(EVENT_POLL_STATE_REGISTRATION)、获取网络模式(EVENT_POLL_STATE_NETWORK_SELECTION_MODE)然后到ServiceStateTracker,这个方法很长,具体就是根据查询结果来给mNewSS赋值。
3、pollStateDone中各种通知网络状态有变,我们看关键的mPhone.notifyServiceStateChanged

三、上层:
我们来看看r.callback.onServiceStateChanged中的r是add函数添加来的,add由listen和addOnSubscriptionsChangedListener调用,addOnSubscriptionsChangedListener看起来就是卡变化的时候触发的,看下listen由另一个listen和listenForSubscriber方法调用,listenForSubscriber方法由TelephonyManager中调用,所以上层应用可以通过TelephonyManager来注册。比如MobileNetworkPreferenceController,然后上层就可以无法无天了!

发布了15 篇原创文章 · 获赞 107 · 访问量 19万+

猜你喜欢

转载自blog.csdn.net/llleahdizon/article/details/89673724
今日推荐