【私人备忘录】Android P 来电代码流程

一、RILD层:
Vendor Ril → ril_service.cpp(callStateChangedInd)(mRadioIndication->callStateChanged) → RadioIndication.java(callStateChanged)
备注:
1、ril_unsol_commands.h中定义: {RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED, radio::callStateChangedInd, WAKE_PARTIAL}, 
2、ril_service.cpp中struct RadioImpl : public V1_1::IRadio定义了所有接口
3、mRadioIndication是sp<IRadioIndication> mRadioIndication,RadioIndication.java实现IRadioIndication.stub

二、Telephony Frameworks:
RadioIndication.java(callStateChanged) → mRil.mCallStateRegistrants.notifyRegistrants(); → GsmCdmaCallTracker.handleMessage(case EVENT_CALL_STATE_CHANGE) → CallTracker.pollCallsWhenSafe(mCi.getCurrentCalls(mLastRelevantPoll)) → RIL.getCurrentCalls(radioProxy.getCurrentCalls(rr.mSerial)) → RadioResponse.responseCurrentCalls(sendMessageResponse(rr.mResult, dcCalls)) → msg.sendToTarget()(将返回值返回给当初的请求者,由请求者去决定如何处理) → GsmCdmaCallTracker.handleMessage(case EVENT_POLL_CALLS_RESULT) → handlePollCalls((AsyncResult)msg.obj)(mPhone.notifyNewRingingConnection(newRinging)) → Phone.notifyNewRingingConnectionP(mNewRingingConnectionRegistrants.notifyRegistrants(ar)) → PstnIncommingCallNotifier.handleMessage(case EVENT_NEW_RINGING_CONNECTION)
备注:
1、RIL.java中mRadioIndication = new RadioIndication(this);
2、callStateChanged中干了两件事:a、调用processIndication向底层发送确认收到消息;b、notifyRegistrant发出通知
3、mCallStateRegistrants在BaseCommands.java中定义,registerForCallStateChanged方法添加mCallStateRegistrants.add(r);GsmCdmaCallTracker注册了次接口(BascCommands,CommandsInterface也注册了但都是接口)
4、radioProxy向底层发起请求,等待modem返回结果给RIL层。在RIL.java中查找底层消息反馈的处理方法,发现有两个方法processRespose和processResponseDone,向上追溯发现其是在RadioResponse.java中的调用此方法。 responseCurrentCalls创建了DriverCall。
5、mLastRelevantPoll = obtainMessage(EVENT_POLL_CALLS_RESULT);
6、registerForNewRingingConnection在CallManager 和 PstnIncommingCallNotifier中注册了。CallManager在对此消息进行判断后,确认是否需要挂断,如果不需要则进一步通知此消息。所以其实还是 PstnIncommingCallNotifier 中处理此消息。 

三、Telephony Services:
PstnIncommingCallNotifier.handleMessage(case EVENT_NEW_RINGING_CONNECTION) → handleNewRingingConnection(sendIncommingCallIntent) → TelecomManager.addNewIncomingCall

四、Telecom Frameworks:
TelecomManager.addNewIncomingCall → getTelecomService().addNewIncomingCall → TelecomServiceImpl.addNewIncomingCall
备注:
1、getTelecomService()是ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE)),通过AIDL调用到TelecomServiceImpl

五、Telecom Services:
TelecomServiceImpl.addNewIncomingCall(mCallIntentProcessorAdapter.processIncomingCallIntent) → CallIntentProcessor.processIncomingCallIntent → CallsManager.processIncomingCallIntent(call.startCreateConnection(mPhoneAccountRegistrar)) → Call.startCreateConnection(mCreateConnectionProcessor.process()) → CreateConnectionProcessor.process(attemptNextPhoneAccount(mService.createConnection(mCall, CreateConnectionProcessor.this))) → ConnectionServiceWrapper.createConnection(mBinder.bind(callback, call)) → ServiceBinder.Binder2.bind(ServiceConnection connection = new ServiceBinderConnection(call)) → ServiceBinderConnection.onServiceConnected() 
1、onServiceConnected(setBinder(binder).setServiceInterface(binder)) → ConnectionServiceWrapper.setServiceInterface() → mServiceInterface = IConnectionService.Stub.asInterface(binder) 获取远程IConnectionService服务的aidl接口
2、onServiceConnected(handleSuccessfulConnection(callback.onSuccess())) → ConnectionServiceWrapper.createConnection(onSuccess(mServiceInterface.createConnection())) → ConnectionService.createConnection
备注:
1、 CallsManager.processIncomingCallIntent中创建了Call对象,初始化后创建连接
2、mService是mRepository.getService(phoneAccount.getComponentName(), phoneAccount.getUserHandle());是个ConnectionServiceWrapper对象
3、public class ConnectionServiceWrapper extends ServiceBinder 实际上就是一个包装了绑定远程服务的代理类,构造方法中ConnectionService.SERVICE_INTERFACE是“android.telecom.ConnectionService”
4、mService.createConnection开始,mBinder.bind(callback, call)该方法调用时会创建一个连接,封装了绑定远程服务的一些操作,若当前还未绑定服务,则直接调用bindService获取远程服务的aidl接口,成功获取到aidl接口后将其赋值给mServiceInterface,当绑定完成后会调用handleSuccessFulConnection方法,其回调了CallBack的onSuccess方法。至此就完成了服务的创建及连接。

六、Telecom Frameworks:
ConnectionService.createConnection(mHandler.obtainMessage(MSG_CREATE_CONNECTION, args).sendToTarget()) → mHandler(case MSG_CREATE_CONNECTION(createConnection())) → onCreateIncomingConnection(空实现,找子类) → TelephonyConnectionService.onCreateIncomingConnection
备注:
1、ConnectionService.createConnection是protected IBinder mBinder = new IConnectionService.Stub()中实现的方法,之前mServiceInterface调用AIDL过来的。

七、Telephony Services:
TelephonyConnectionService.onCreateIncomingConnection(createConnectionFor()) → 返回需要的connection → createConnection(handleCreateConnectionComplete)

八、Telecom Frameworks:
createConnection(handleCreateConnectionComplete) → IConnectionServiceAdapter.handleCreateConnectionComplete → ConnectionServiceWrapper.this.handleCreateConnectionComplete()
备注:
1、ConnectionServiceWrapper中实现了private final class Adapter extends IConnectionServiceAdapter.Stub

九、Telecom Services:
ConnectionServiceWrapper.this.handleCreateConnectionComplete() → CreateConnectionProcessor.hanleCreateConnectionSuccess(mCallResponse.handleCreateConnectionSuccess(idMapper, connection)) → Call.handleCreateConnectionSuccess(l.onSuccessfulIncomingCall(this)) → CallsManager.onSuccessfulIncomingCall(new IncomingCallFilter()) → IncomingCallFilter.performFiltering(mListener.onCallFilteringComplete(mCall, mResult)) → CallsManager.onCallFilteringComplete(addCall(incomingCall)) → listener.onCallAdded(call) → InCallController.OnCallAdded(inCallService.addCall(parcelableCall)) → InCallService(InCallServiceBinder extends IInCallService.Stub)
备注:
1、handleCreateConnectionComplete中,mPendingResponses是hashMap容器,每次在 createConnection 的时候会将对象加入该容器,如果此时connection还未断开的,会移除此connection,调用hanleCreateConnectionSuccess方法。往上追溯createConnection跟踪到mService.createConnection(mCall, this); CreateConnectionProcessor.java会把自身传入,发现该类也实现了 CreateConnectionResponse ,所以这里的 handleCreateConnectionSuccess 调用的是这个类里面的方法。 
2、CallsManager.onSuccessfulIncomingCall中用了迭代器模式一个来电触发三个对象的处理,最后创建一个IncomingCallFilter并调用performFiltering。
3、performFiltering方法中如果没有超时则在异步查询结束后,会通过回调方法将CallFilterResult传回onCallFilteringComplete。
4、listener.onCallAdded(call)是CallsManager构造函数初始化的时候添加了一些列观察者,还有就是通过addListener去添加的。这里我们继续跟进mInCallController

十、Telecom Frameworks:
InCallService.addCall(case MSG_ADD_CALL) → Phone.internalAddCall(fireCallAdded(call)) → InCallService.onCallAdded() → InCallServiceImpl.onCallAdded()

十一、Dialer:
InCallServiceImpl.onCallAdded()就已经到了上层了,随便怎么玩了

扫描二维码关注公众号,回复: 9078698 查看本文章
发布了15 篇原创文章 · 获赞 107 · 访问量 19万+

猜你喜欢

转载自blog.csdn.net/llleahdizon/article/details/89640367
今日推荐