我已经从下载了master分支的整个源代码
https://android.googlesource.com/platform/frameworks/base/+/master,并试图破译传入调用中的事件链。

我假设ACTION_ANSWER Intent 已启动,但除此之外,不知道在此之前或之后会发生什么。

有人可以帮忙吗?

最佳答案

让我们从CallNotifier开始:



该处理程序响应的消息之一是:CallStateMonitor.PHONE_NEW_RINGING_CONNECTION:

case CallStateMonitor.PHONE_NEW_RINGING_CONNECTION:
    log("RINGING... (new)");
    onNewRingingConnection((AsyncResult) msg.obj);
    mSilentRingerRequested = false;
    break;
onNewRingingConnection(AsyncResult)最终(通常在通常情况下)调用ringAndNotifyOfIncomingCall(Connection c):
private void ringAndNotifyOfIncomingCall(Connection c) {
    if (PhoneUtils.isRealIncomingCall(c.getState())) {
        mRinger.ring();
    } else {
        if (VDBG) log("- starting call waiting tone...");
            if (mCallWaitingTonePlayer == null) {
                mCallWaitingTonePlayer = new InCallTonePlayer(
                                         InCallTonePlayer.TONE_CALL_WAITING);
                mCallWaitingTonePlayer.start();
            }
    }

    // CallModeler.onNewRingingConnection(Connection)
    mCallModeler.onNewRingingConnection(c);
}
CallModeler.onNewRingingConnection(Connection)(Link)通知附加的监听器:
for (int i = 0; i < mListeners.size(); ++i) {
    mListeners.get(i).onIncoming(call);
}

这些监听器实现CallModeler.Listener接口(interface)。 CallHandlerServiceProxy就是这样的监听器,它的onIncoming(Call)回调触发CallHandlerServiceProxy.processIncoming(Call):
private void processIncoming(Call call) {
    ....
    // ICallHandlerService
    mCallHandlerServiceGuarded.onIncoming(call,
                   RejectWithTextMessageManager.loadCannedResponses());
    ....
}

CallHandlerService定义了ICallHandlerService.Stub成员,其onIncoming(Call, List<String>)方法如下所示:
@Override
public void onIncoming(Call call, List<String> textResponses) {
    ....
    mMainHandler.sendMessage(mMainHandler.obtainMessage(
                   ON_UPDATE_CALL_WITH_TEXT_RESPONSES, incomingCall));
    ....
}

这是mMainHandler处理个案ON_UPDATE_CALL_WITH_TEXT_RESPONSES的方式:
case ON_UPDATE_CALL_WITH_TEXT_RESPONSES:
    AbstractMap.SimpleEntry<Call, List<String>> entry
                   = (AbstractMap.SimpleEntry<Call, List<String>>) msg.obj;
    Log.i(TAG, "ON_INCOMING_CALL: " + entry.getKey());

    // CallList
    mCallList.onIncoming(entry.getKey(), entry.getValue());
    break;

CallList保留实现CallList.Listener的监听器列表,并从其onIncomingCall(Call)方法中触发其CallList.onIncoming(Call, List<String>)事件。

现在,让我们看一看InCallPresenter:


InCallPresenter实现CallList.Listener接口(interface),并负责启动InCallActivity,该InCallPresenter.startOrFinishUi(InCallState)为所有与电话相关的操作提供UI。以下注释(取自ojit_code)将上述事件链汇集到一起:
/* A new Incoming call means that the user needs to be notified of the
   the call (since it wasn't them who initiated it).  We do this
   through full  screen notifications and happens indirectly through {@link
   StatusBarListener}. The process for incoming calls is as follows:

   1) CallList          - Announces existence of new INCOMING call
   2) InCallPresenter   - Gets announcement and calculates that the new
                          InCallState should be set to INCOMING.
   3) InCallPresenter   - This method is called to see if we need to
                          start or finish the app given the new state.
   4) StatusBarNotifier - Listens to InCallState changes. InCallPresenter
                          calls StatusBarNotifier explicitly to issue a
                          FullScreen Notification that will either start the
                          InCallActivity or show the user a top-level
                          notification dialog if the user is in
                          an immersive app. That notification can also start
                          the InCallActivity.
   5) InCallActivity    - Main activity starts up and at the end of its
                          onCreate will call InCallPresenter::setActivity()
                          to let the presenter know that start-up is complete.
                  [ AND NOW YOU'RE IN THE CALL. voila! ] */

我希望这能回答您的问题,或者至少可以告诉您在哪里看。随时纠正我忽略/误解的任何内容。

关于android - 来电时在系统级别会发生什么?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21054077/

10-09 04:42