在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¬_restricted&trusted¬_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¬_restricted&trusted¬_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¬_restricted&trusted¬_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
Android6 0藍芽許可權申請及開啟藍芽
1 需要申請如下許可權 2 申請執行時許可權 檢查藍芽許可權 public void checkblepermission 1 else 2.1 重寫onrequestpermissionsresult,判斷使用者是否同意 override public void onrequestpermissi...
Android 6 0許可權管理
android 6.0在我們原有的androidmanifest.xml宣告許可權的基礎上,又新增了執行時許可權動態檢測,以下許可權都需要在執行時判斷 身體感測器 日曆攝像頭 通訊錄地理位置 麥克風 簡訊儲存空間 if contextcompat.checkselfpermission this,m...
Android6 0許可權適配
android6.0許可權適配 1.複寫activity onrequestpermissionsresult override public void onrequestpermissionsresult int requestcode,string permissions,int grantre...