本文基于Android 8.0
继续分析CallsManager.placeOutgoingCall
我们再次回到Telecom应用的拨号流程中, CallsManager分别调用startOutgoingCall和placeOutgoingCall。startOutgoingCalI方法将通过绑定服务和调用其服务接口,启动和更新Dialer应用中的InCallActivity,展示出通话界面;但拨号请求并未发送到BP Modem处理。 我们继续分析placeOutgoingCall的处理逻辑,其关键的调用过程是: sendNewOutgoingCallIntent ->
NewOutgoingCalllntentBroadcaster.processlntent -> mCallsManager.placeOutgoingCall -> call.startCreateConnection ->
CreateConnectionProcessor.process -> attemptNextPhoneAccount等一系列调用,这个流程相对简单,请读者自己去跟踪和分析。 我们重点关注一下 CreateConnectionProcessor类的attemptNextPhoneAccount方法,其关键逻辑详情如下:
// 又出现一个Service
mService = mRepository.getService(phoneAccount.getComponentName(),
phoneAccount.getUserHandle());
if (mService == null) {
attemptNextPhoneAccount();// 如Service未准备好,将递归调用,直到超过次数限制
} else {
mConnectionAttempt++;// 计数
mCall.setConnectionManagerPhoneAccount(attempt.connectionManagerPhoneAccount);
mCall.setTargetPhoneAccount(attempt.targetPhoneAccount);
mCall.setConnectionService(mService);// 更新Call对象相关信息
setTimeoutIfNeeded(mService, attempt);
mService.createConnection(mCall, this);// 创建Connection,我们推测一下会是什么样的连接呢?
}
在CreateConnectionProcessor类的attemptNextPhoneAccount方法中, mRepository.getService获取 mService ,此处又出现一个 Service ,而且通过它创建Connection ,它究竟是个什么服务呢?又将创建什么类型的Connection呢?
在CreateConnectionProcessor类中的定义是private ConnectionServiceWrapper mService,继续跟踪ConnectionServiceWrapper的CreateConnection方法,其核心逻辑简化后,如下所示:
public void createConnection(final Call call, final CreateConnectionResponse response) {
BindCallback callback = new BindCallback() {
@Override
public void onSuccess() {
...// 绑定服务成功后的处理逻辑
}
@Override
public void onFailure() {
...// 绑定服务失败后的处理逻辑