Step 1:注册监听事件
GsmServiceStateTracker(CdmaServiceStateTracker) 在构造函数就会通过registerForVoiceNetworkStateChanged 注册网络状态的变化监听,处理事件为EVENT_NETWORK_STATE_CHANGED
Step 2:modem主动上报
01-25 10:13:56.717 D/RILJ ( 3636): [UNSL]< UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED [SUB0]
Ril.java的processUnsolicited处理主动上报事件的,对应的事件为RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED
Step 3:处理主动上报
GsmServiceStateTracker收到EVENT_NETWORK_STATE_CHANGED就会调用PollState来获取状态
01-25 10:13:56.727 D/RILJ ( 3636): [5596]> OPERATOR [SUB0] 获取运营商
01-25 10:13:56.727 D/RILJ ( 3636): [5597]> DATA_REGISTRATION_STATE [SUB0] 获取PS状态
01-25 10:13:56.727 D/RILJ ( 3636): [5598]> VOICE_REGISTRATION_STATE [SUB0] 获取CS状态
01-25 10:13:56.727 D/RILJ ( 3636): [5599]> QUERY_NETWORK_SELECTION_MODE [SUB0] 获取网络模式
01-25 10:13:56.737 D/RILJ ( 3636): [5597]< DATA_REGISTRATION_STATE {1, null, 0037ac1f, 14, null, 20, 4118, 470, 3648543, null, null} [SUB0]
01-25 10:13:56.747 D/RILJ ( 3636): [5596]< OPERATOR {CHN-UNICOM, UNICOM, 46001} [SUB0]
01-25 10:13:56.757 D/RILJ ( 3636): [5598]< VOICE_REGISTRATION_STATE {1, 1016, 0037ac1f, 14, null, null, null, 0, null, null, 1, null, null, 0, null} [SUB0]
01-25 10:13:56.757 D/RILJ ( 3636): [5599]< QUERY_NETWORK_SELECTION_MODE {0} [SUB0]
等4个请求都返回了,调用pollStateDone来进行状态的上报,这里有一个mPollingContext,在向底层发请求会递增,,底层返回能递减,等于0就认为返回完成。
Step 4: 上报状态
在GsmServiceStateTracker:pollStateDone
01-25 10:13:56.767 D/QtiGsmSST( 3636): [GsmSST] Poll ServiceState done: oldSS=[0 0 voice home data home CHN-UNICOM UNICOM 46001 CHN-UNICOM UNICOM 46001 LTE LTE CSS not supported -1 -1 RoamInd=-1 DefRoamInd=-1 EmergOnly=false IsDataRoamingFromRegistration=false] newSS=[0 0 voice home data home CHN-UNICOM UNICOM 46001 CHN-UNICOM UNICOM 46001 LTE LTE CSS not supported -1 -1 RoamInd=-1 DefRoamInd=-1 EmergOnly=false IsDataRoamingFromRegistration=false] oldMaxDataCalls=20 mNewMaxDataCalls=20 oldReasonDataDenied=-1 mNewReasonDataDenied=-1
下一步调用GsmPhone的notifyServiceStateChanged
下一步调用PhoneBase:notifyServiceStateChangedP
下一步调用DefaultPhoneNotifier:notifyServiceState
下一步调用TelephonyRegistry:notifyServiceStateForPhoneId,这里就会调用应用注册的回调函数onServiceStateChanged