【私人备忘录】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,然后上层就可以无法无天了!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值