Android 6.0 自动开启移动数据流程


  在M版本,触发建立默认的数据连接的机制跟以前的版本有比较大的变化,本文主要介绍触发建立数据连接的开始阶段,而建立data call的过程跟之前是一样的,只要条件准备好了发起就可以了。



step 1:在ConnectivityService构造的时候就创建了一个默认的default Request,mDefaultRequest


网络工厂连接上以后,就请求网络连接

step 2:在ConnectivityService:handleAsyncChannelHalfConnect里,如果已经连接到网络工厂,就把网络请求发到对应的网络工厂

在日志里会打印出下面的消息

01-12 14:55:53.066 D/ConnectivityService( 1170): NetworkFactory connected
01-12 14:55:53.066 D/ConnectivityService( 1170): send CMD_REQUEST_NETWORK


接着是网络工厂处理请求CMD_REQUEST_NETWORK

step 3:NetworkFactory:handleAddRequest进行处理,调用evalRequest来判断是开启网络,还是释放网络,如果开启则调用needNetworkFor,如果是释放则调用releaseNetworkFor

现在先关注移动网络开启数据的,由于移动网络的网络工厂是TelephonyNetworkFactory,在dctController里定义的

step 4:TelephonyNetworkFactory:needNetworkFor

检查sub id是否符合,还有apn是否支持,如果符合条件,则调用requestNetwork

对应的log

01-12 14:55:59.236 D/QtiDctController( 3208): [TNF 2147483643]Cellular needs Network for NetworkRequest [ id=1, legacyType=-1, [ Capabilities: INTERNET&NOT_RESTRICTED&TRUSTED&NOT_VPN] ]

step 5:DctController:request

把请求加入到队列mRequestInfos中,紧接着调processRequests来处理队列中的请求


step 6:QtiDctController:onProcessRequest

根据请求判断是否需要切DDS,需要的话调用handleDdsSwitch

01-12 14:56:03.496 D/QtiDctController( 3208): getTopPriorityRequestPhoneId = 1, priority = 0
01-12 14:56:03.496 D/QtiDctController( 3208): phoneId = 1
01-12 14:56:03.496 D/QtiDctController( 3208): activePhoneId = -1
01-12 14:56:03.496 D/QtiDctController( 3208): ddsPhoneId = 1
01-12 14:56:03.496 D/QtiDctController( 3208): maxDataCap = -1
01-12 14:56:03.496 D/QtiDctController( 3208): Modem is DSDS-Data capable.
01-12 14:56:03.496 D/QtiDctController( 3208): ON_DEMAND_REQ_DSDS

step 7: qtiDctController:handleDdsSwitch

根据情况是要关闭当前的数据,还是开始建立连接,关闭调用doDisconnectAll,建立连接调doConnect

01-12 14:56:03.496 D/QtiDctController( 3208): doConnect phoneId = 1

step 8:qtiDctController:doConnect

调用informDdsToRil通知底层默认的dds,然后通过DcSwitchAsyncChannel的connect发送请求REQ_CONNECT

状态的的跳转过程如下:IdleState->AttachingState->AttachedState->DetachingState->IdleState

在AttachingState会调用setDataAllowed为true,DetachingState会setDataAllowed为false

setDataAllowed会把某个phone的ps变为attached,从而触发建立data call

12-31 16:37:44.635 D/DcSwitchSM( 5990): [DcSwitchStateMachine-1] IdleState: REQ_CONNECT, apnRequest=[ request=NetworkRequest [ id=8, legacyType=2, [ Transports: CELLULAR Capabilities: MMS&NOT_RESTRICTED&TRUSTED&NOT_VPN Specifier: <2>] ], executed=false, priority=4]
12-31 16:37:44.635 D/DcSwitchSM( 5990): [DcSwitchStateMachine-1] AttachingState: enter
12-31 16:37:44.635 D/DcSwitchSM( 5990): [DcSwitchStateMachine-1] AttachingState executeAll due to autoAttach
12-31 16:37:44.635 D/DcSwitchSM( 5990): [DcSwitchStateMachine-1] AttachingState: REQ_CONNECT, apnRequest=[ request=NetworkRequest [ id=8, legacyType=2, [ Transports: CELLULAR Capabilities: MMS&NOT_RESTRICTED&TRUSTED&NOT_VPN Specifier: <2>] ], executed=false, priority=4]
12-31 16:37:48.385 D/DcSwitchSM( 5990): [DcSwitchStateMachine-1] AttachingState: EVENT_DATA_ATTACHED
12-31 16:37:48.385 D/DcSwitchSM( 5990): [DcSwitchStateMachine-1] AttachedState: enter
12-31 16:37:52.165 D/DcSwitchSM( 5990): [DcSwitchStateMachine-1] AttachedState: REQ_DISCONNECT_ALL
12-31 16:37:52.165 D/DcSwitchSM( 5990): [DcSwitchStateMachine-1] DetachingState: enter
12-31 16:37:52.935 D/DcSwitchSM( 5990): [DcSwitchStateMachine-1] DetachingState: EVENT_DATA_DETACHED
12-31 16:37:52.935 D/DcSwitchSM( 5990): [DcSwitchStateMachine-1] IdleState: enter

你可能感兴趣的:(Android相关)