Android N撥打電話的流程

分類:編程 時間:2017-02-23

1. 從Dialer工程開始,DialtactsActivity中打開DialpadFragment界面,在DialpadFragment中實現OnClickListener的onClick()方法,根據點擊事件如果是撥號按鈕(R.id.dialpad_floating_action_button)則調用handleDialButtonPressed()方法,開啟撥號流程。
2. handleDialButtonPressed方法中首先判斷所撥打的號碼是否為空號,是否為禁止撥打的號碼,如果都不是則繼續調用DialerUtils中的startActivityWithErrorToast()方法將撥號的請求繼續往下傳遞,通過ContactsCommon中的TelecomManagerCompat類傳遞到telecomm(TelecomService)中的TelecomManager中。
3 .在TelecomManager中調用placeCall()方法,通過該方法遠程調用ITelecomService.aidl的方式調用TelecomServiceImpl(進入Telecom工程)中的placeCall()方法(ITelecomService的實現類為TelecomServiceImpl中的ITelecomService.Stub mBinderImpl)。
4. placeCall()方法中通過工廠模式生成UserCallIntentProcessor對象,通過調用UserCallIntentProcessor中的processIntent()方法向PrimaryCallReceiver發送請求通話的廣播(processIntent()—>processOutgoingCallIntent()–>sendBroadcastToReceiver())。
5. 在PrimaryCallReceiver的回調方法中獲取Telecomsystem實例,然後通過再獲取CallIntentProcessor實例,調用CallIntentProcessor中的processIntent()方法。
6. processIntent()方法中對unKnownCall和outgoingcall進行判斷,分別處理:

if (isUnknownCall) {
            processUnknownCallIntent(mCallsManager, intent);
        } else {
            processOutgoingCallIntent(mContext, mCallsManager, intent);
        }

processOutgoingCallIntent方法處理撥打正常號碼的流程。
7. processOutgoingCallIntent()方法中通過CallsManagerstartOutgoingCall()方法獲取Call實例(startOutgoingCal()l方法中同時對手機是單卡雙卡進行判斷):

// Send to CallsManager to ensure the InCallUI gets kicked off before the broadcast returns
        Call call = callsManager
                .startOutgoingCall(handle, phoneAccountHandle, clientExtras, initiatingUser);

如果call不為空,new一個NewOutgoingCallIntentBroadcaster對象,然後調用processIntent()方法。
8. processIntent()方法中對所撥打的號碼進行處理。如果不是緊急撥號或者語音撥號,則繼續調用broadcastIntent()方法,發生action為ACTION_NEW_OUTGOING_CALL的有序廣播到NewOutgoingCallBroadcastIntentReceiver
9. NewOutgoingCallBroadcastIntentReceiver中回調到CallsManager中的placeOutgoingCall()方法,該方法中繼續調用Call中的startCreateConnection()方法開始建立通話連接。
10. startCreateConnection()方法中生成CreateConnectionProcessor對象,然後調用process()方法。
11. process()方法中調用自身的attemptNextPhoneAccount()方法,此方法中通過ConnectionServiceWrapper實例調用createConnection()方法,createConnection()方法中通過IConnectionService.aidl遠程調用ConnectionService中的IConnectionService的實現類中的createConnection()方法,通過handler繼續傳遞MSG_CREATE_CONNECTION消息。在handler的處理消息的方法中調用ConnectionService的createConnection()方法(註意和IConnectionService的實現類中的createConnection()區分,此時有進入telecomm工程。)。
12. 判斷建立的連接是否為outgoingConnection:

Connection connection = isUnknown ? onCreateUnknownConnection(callManagerAccount, request)
                : isIncoming ? onCreateIncomingConnection(callManagerAccount, request)
                : onCreateOutgoingConnection(callManagerAccount, request);

在onCreateOutgoingConnection()方法中處理外撥電話的流程。
13. onCreateOutgoingConnection()方法中調用placeOutgoingConnection()方法,獲取GsmCdmaPhone的對象,通過dial()方法獲取連接。
14. 獲取mCT,創建RIL對象,通過RILSender發送消息,通過RILReceiver接收處理消息。
15. 如果通過成功則在CallsManager中的onSuccessfulOutgoingCall()方法中調用setCallState()方法生成通話記錄(setCallState()–>CallsManagerListener.onCallStateChanged()–>CallLogManager.onCallStateChanged()–>logCall()–>logCallAsync()–>LogCallAsyncTask)。


Tags:

文章來源:


ads
ads

相關文章
ads

相關文章

ad