Android Telephony架构和流程
16lz
2021-01-23
在我的概念里,Telephony 是从 GsmcdmaPhone 这一对象开始往下算起,才算是 Telephony 层。实际上 Telephony 的概念,它还包括这三个部分,一直以为是 Call App 的模块:
- /packages/services/Telephony ==> TeleService.apk
- /packages/services/Telecomm ==> Telecomm.apk
- /frameworks/base/telecomm ==> Telecomm FW
上面这三个部分,都算是 Telephony;在这个概念里, Call App UI 才算是上层 app 模块。
- /packages/apps/Dialer/java/com/android/incallui ==> InCallUI
这篇文章,从框架上讲解一下这三个模块的关系,并整理一下来电的流程,熟悉他们的调用关系。
只谈框架流程,不聊具体细节。
架构
先上一张图,从大体上看他们的调用关系。
如上图所示,
- TeleService <==> Telephony Framework PhoneBase;TeleService 和 framework 进行交互;
- TelecommService/Telecomm FW <==> TeleService , TeleService 和 InCallUI 交互要经过 Telecomm 层;
- InCallUI <==> TelecommService/Telecomm FW 交互;
这就是基本的架构,要清楚知道交互消息是如何传输的, 看起来是 Telecomm 起着中间桥梁的作用。
Telephony 主要的类
TeleService 中的 TelephonyConnection 监听来自 PhoneBase 的 call 状态变化,并通过 connectionService 相关的类(ConnectionServiceWrapper) 向 Telecomm 传递状态信息;
Telecomm 到 InCallUI 的过程,则是由 CallsManager 向 InCallController 传递,最后通过 InCallServiceImpl 向 InCallUI 传递。
中间各层 call 的转化,需要经过 Telecom FW.
Telephony 中主要的 Service
- 开机加载 TelecommServiceImpl(TelecommManager), 创建 CallsManager 和 InCallController;同时创建 PhoneAccount,监听来电信息;
- 来电,创建 TelephonyConnectionService, 创建 TelephonyConnection 监听 Call 状态变化;
- CallsManager 回调 InCallController, 告知 InCallService, 最终更新到 InCallUI.
来电流程图
- CallsManager and IncallController create by telecom service when system boot up;
- TelecomAccountResigistry create PstnIncomingCallNotifer, and it register Notification to PhoneBase,including event(EVENT_NEW_RINGING_CONNECTION);
- PstnIncomingCallNotifier receive incoming call event, it will let TelecomServiceImpl call addNewIncomingCall functio;
- CallsManager create Call instance, and set itself as Call.Listener.
- CallsManager give Call the ConnectionServiceWrapper reference, so Call can access ConnectionService.
- Call request ConnectionService to createConnection then callback to CreateConnectionResponse.
- When CreateConnectionResponse call back, Call will let its listeners(CallsManager) know it.
- When something is changed from ConnectionService, Wrapper will receive the event and then tell to Call or CallsManager.
- after create connection successfully, CallsManager will call onSuccessIncomingCall(), then addCall();
- InCallController as listener will call onCallAdded(), and then InCallService addCall and enter InCallUI logic.
- TelephonyConnectionService get the orginalConnection(framework) first.
- Create GsmConnection/CdmaConnection depends on the phoneType.
- Each TelephonyConnection registerNotification to PhoneBase by themselves, listener to them.
- Some changed about PhoneBase, TelephonyConnection will receive and then broadcast to all listeners(ConnectionService).
- all the event will deliver by listener like: CallsManager ==> InCallController ==> InCallService ==> InCallUI;
更多相关文章
- Android 部分内容设置颜色、字体、超链接、图片
- (Android)处理图片成圆形
- Android P按键静音流程
- Android 架构篇----------Framework初识
- MixtureTextView 支持Android图文混排、文字环绕图片等效果
- MediaRecorder流程分析
- 穿针引线,帮你回忆, 汇总:Android系统启动流程 & 应用程序'进程'启