远程来电流程分析---之二

本文详细解析了电信服务中连接创建的过程,包括ConnectionService的createConnection调用流程、ConnectionServiceAdapter的handleCreateConnectionComplete方法及TelephonyConnectionService的onCreateIncomingConnection方法等内容,并介绍了来电后的一般处理步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

2.4 services Telephony

ConnectionService的createConnection调用流程图如下,


方法代码如下,

1,首先根据电话的状态创建一个连接,

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

2,完成之后,回调ConnectionServiceAdapter的handleCreateConnectionComplete方法,

mAdapter.handleCreateConnectionComplete(callId, request,•••

其实,步骤2去电流程也会调用。

TelephonyConnectionService的onCreateIncomingConnection方法如下,

Connection connection = createConnectionFor(phone, originalConnection, false /* isOutgoing */,
     request.getAccountHandle());
if (connection == null) {
   return Connection.createCanceledConnection();
} else {
  return connection;
}

调用createConnectionFor构造一个连接,然后返回该连接。connection是指GsmConnection对象。

ConnectionServiceAdapter的handleCreateConnectionComplete方法如下,

void handleCreateConnectionComplete(String id, ConnectionRequest request,
            ParcelableConnection connection) {
   for (IConnectionServiceAdapter adapter : mAdapters) {
        try {
            adapter.handleCreateConnectionComplete(id, request, connection);
        } catch (RemoteException e) {
        }
   }
}

此处的IconnectionServiceAdapter对象是binder,指向ConnectionServiceWrapper的内部类Adapter, Adapter定义如下,

private final class Adapter extends IConnectionServiceAdapter.Stub {

Adapter的handleCreateConnectionComplete方法如下,

ConnectionServiceWrapper.this.handleCreateConnectionComplete(callId, request, connection);

直接调用ConnectionServiceWrapper的handleCreateConnectionComplete方法。

绕了这么一大圈,成功创建GsmConnection连接之后又回到了services telecom。

2.5 services telecom

ConnectionServiceWrapper的handleCreateConnectionComplete方法调用流程图如下,


ConnectionServiceWrapper的handleCreateConnectionSuccess方法如下,

if (mPendingResponses.containsKey(callId)) {
mPendingResponses.remove(callId).handleCreateConnectionSuccess(mCallIdMapper, connection);
}

调用CreateConnectionProcessor的handleCreateConnectionSuccess方法,

mResponse.handleCreateConnectionSuccess(idMapper, connection);
mResponse = null;

调用Call的handleCreateConnectionSuccess方法,该方法的逻辑如下,

if (mIsUnknown) {
    for (Listener l : mListeners) {
        l.onSuccessfulUnknownCall(this, getStateFromConnectionState(connection.getState()));
    }
} else if (mIsIncoming) {
mDirectToVoicemailQueryPending = true;
   mHandler.postDelayed(mDirectToVoicemailRunnable, Timeouts.getDirectToVoicemailMillis(
                    mContext.getContentResolver()));
} else {
   for (Listener l : mListeners) {
       l.onSuccessfulOutgoingCall(this, getStateFromConnectionState(connection.getState()));
   }
}

如果是未知call,回调监听器的onSuccessfulUnknownCall方法;

如果是来电,回调监听器的onSuccessfulIncomingCall方法;

如果是去电,回调监听器的onSuccessfulOutgoingCall方法;

CallsManager的addCall方法如下,

private void addCall(Call call) {
    Trace.beginSection("addCall");
    Log.v(this, "addCall(%s)", call);
    call.addListener(this);
    mCalls.add(call);

    // TODO: Update mForegroundCall prior to invoking
    // onCallAdded for calls which immediately take the foreground (like the first call).
    for (CallsManagerListener listener : mListeners) {
        if (Log.SYSTRACE_DEBUG) {
             Trace.beginSection(listener.getClass().toString() + " addCall");
        }
        listener.onCallAdded(call);//调用监听器的onCallAdded方法
        if (Log.SYSTRACE_DEBUG) {
            Trace.endSection();
        }
     }
     updateCallsManagerState();//更新状态
     Trace.endSection();
}

来电之后,一般会做2件事情,

1,铃声响起

2,启动来电界面。

调用Ringer的onCallAdded方法响铃;

调用InCallController的onCallAdded方法启动来电界面。

这2两个部分在后面的章节详细论述。

小结:

1,RIL和opt telephony phone进程利用通知机制进行通信,当电话的状态发生变化时,会查询当前的call。

2, servicesTelephony 到 services telecom通过binder服务进行通信。

3,然后services telecom 和 services Telephony之间建立一个通话连接。

4,最后services telecom通过监听回调的方式响铃和启动来电界面。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值