分析Connection的創建
MO的時候,CallIntentProcessor(packages/services/Telecomm/src/com/android/server/telecom/CallIntentProcessor.java)收到去電請求后,會調用CallsManager的startOutgoingCall生成一個Call對象,在其中會走前一篇(綁定InCallService)的邏輯,然后繼續往下走,最終到CallsManager.placeOutgoingCall函數,里面通過call.startCreateConnection來創建Connection。最后走到ConnectionServiceWrapper.createConnection()從此走上ConnectionService相關之路。
首先是通過ConnectionServiceWrapper來獲得ConnectionService(frameworks/base/telecomm/java/android/telecom/ConnectionService.java),也就是在ConnectionServiceWrapper中通過bindService來和ConnectionService相連。事件上TelephonyConnectionService(packages/services/Telephony/src/com/android/services/telephony/TelephonyConnectionService.java)繼承ConnectionService,最后連的是TelephonyConnectionService。
并且,和InCallService類似,連接成功后,設置IConnectionServiceAdapter.Stub的一個adapter到ConnectionService,以完成雙向調用。
mServiceInterface.addConnectionServiceAdapter(adapter)
最后存在了ConnectionServiceAdapter(frameworks/base/telecomm/java/android/telecom/ConnectionServiceAdapter.java)對象中。
創建connection之前,把ConnectionServiceWrapper對象設置到Call對象中,這樣,當有相關操作的時候(比如answer),會調用ConnectionServiceWrapper對象,最終會調用ConnectionService來傳到framework下面去。
if (mResponse != null && attempt != null) {
Log.i(this, "Trying attempt %s", attempt);
PhoneAccountHandle phoneAccount = attempt.connectionManagerPhoneAccount;
ConnectionServiceWrapper service =
mRepository.getService(
phoneAccount.getComponentName(),
phoneAccount.getUserHandle());
if (service == null) {
Log.i(this, "Found no connection service for attempt %s", attempt);
attemptNextPhoneAccount();
} else {
mCall.setConnectionManagerPhoneAccount(attempt.connectionManagerPhoneAccount);
mCall.setTargetPhoneAccount(attempt.targetPhoneAccount);
mCall.setConnectionService(service);
setTimeoutIfNeeded(service, attempt);
service.createConnection(mCall, new Response(service));
}
}
走了一圈,最后到了ConnectionService.createConnection,里面根據是MO/MT調用了onCreateOutgoingConnection/onCreateInComingConnection,這里我們看onCreateOutgoingConnection,在這個里面創建最終的connection,并調用phone.dial()撥號,把命令發到RIL。
com.android.internal.telephony.Connection originalConnection;
try {
if (isAddParticipant) {
phone.addParticipant(number);
return;
} else {
originalConnection = phone.dial(number, null, request.getVideoState(), bundle);
}
} catch (CallStateException e) {
然后把dial生成的connection和service包里面的connection相關聯。
connection.setOriginalConnection(originalConnection);
這樣,當底層有電話狀態變化的時候,會傳到connection中,然后再傳到call,最后到UI。