相对来电流程,去电流程是从下往上传递,来电流程从上往下传递。应用层对来电比较少,接收到来电信息从而进行铃声的响应和界面显示。在此简单分析下简单流程:

 

1、创建GsmPhone时,同时会创建GsmCallTracker():

public GSMPhone (Context context, CommandsInterface ci, PhoneNotifier notifier, boolean unitTestMode) {
        super(notifier, context, ci, unitTestMode);
           
        mCT = new GsmCallTracker(this);
}

2、GsmCallTracke注册EVENT_CALL_STATE_CHANGE:

GsmCallTracker (GSMPhone phone) {
        this.phone = phone;
        cm = phone.mCM;

        cm.registerForCallStateChanged(this, EVENT_CALL_STATE_CHANGE, null);

        cm.registerForOn(this, EVENT_RADIO_AVAILABLE, null);
        cm.registerForNotAvailable(this, EVENT_RADIO_NOT_AVAILABLE, null);
 }

3、首先RIL----RILReceiver线程读取rild传来的数据:

class RILReceiver implements Runnable {
      run( ){
           //部分省略..
           processResponse(p);
      }
}
private void processResponse (Parcel p) {
        int type;
        type = p.readInt();

        if (type == RESPONSE_UNSOLICITED) {
            processUnsolicited (p);
        } else if (type == RESPONSE_SOLICITED) {
            processSolicited (p);
        }
        releaseWakeLockIfDone();
 }

//接收RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED 消息,触发mCallStateRegistrants.
private void processUnsolicited (Parcel p) {
    
     try {switch(response) {
         //部分省略
         case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: ret =  responseVoid(p); break;
     }
}

4、GsmCallTracke处理EVENT_CALL_STATE_CHANG:

public void handleMessage (Message msg) {
      //部分省略...
      switch (msg.what) {
          case EVENT_CALL_STATE_CHANGE:
                pollCallsWhenSafe();
            break;
      }
}

5、调用CallTracker(抽象类)----- pollCallsWhenSafe()查询通话详情:

protected void pollCallsWhenSafe() {
        needsPoll = true;

        if (checkNoOperationsPending()) {
            lastRelevantPoll = obtainMessage(EVENT_POLL_CALLS_RESULT);
            cm.getCurrentCalls(lastRelevantPoll);
        }
 }

6、RIL.java ----- getCurrentCalls()获取当前电话:

public void getCurrentCalls (Message result) {
        RILRequest rr = RILRequest.obtain(RIL_REQUEST_GET_CURRENT_CALLS, result);

        if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));

        send(rr);
 }

7、RIL调用processSolicite处理RIL_REQUEST_GET_CURRENT_CALLS的返回结果:

private void processSolicited (Parcel p) {
      //部分省略...
      try {
           switch (rr.mRequest) {
                case RIL_REQUEST_GET_CURRENT_CALLS: ret =  responseCallList(p); break;
           }
      }
}

8、触发GsmCallTracke中handleMessag,处理事件EVENT_POLL_CALLS_RESUL:

public void handleMessage (Message msg) {
     switch (msg.what) {
        case EVENT_POLL_CALLS_RESULT:
                ar = (AsyncResult)msg.obj;

                if (msg == lastRelevantPoll) {
                    if (DBG_POLL) log(
                            "handle EVENT_POLL_CALL_RESULT: set needsPoll=F");
                    needsPoll = false;
                    lastRelevantPoll = null;

                   //调用此方法
                    handlePollCalls((AsyncResult)msg.obj);
                }
            break;
     }
}
//调用phone.notifyNewRingingConnection(newRinging);
protected void handlePollCalls(AsyncResult ar) {
    if (newRinging != null) {
            phone.notifyNewRingingConnection(newRinging);
    }
}

9、GSMPhone (继承PhoneBase )----- notifyNewRingingConnection():

void notifyNewRingingConnection(Connection c) {
        /* we'd love it if this was package-scoped*/
        super.notifyNewRingingConnectionP(c);
}

10、PhoneBase ----- notifyNewRingingConnectionP():

protected void notifyNewRingingConnectionP(Connection cn) {
        if (!mIsVoiceCapable)
            return;
        AsyncResult ar = new AsyncResult(null, cn, null);
        mNewRingingConnectionRegistrants.notifyRegistrants(ar);
 }

//以上都属于frameworks层

11、传递给 CallNotifier的 PHONE_INCOMING_RING:

@Override
 public void handleMessage(Message msg) {
        switch (msg.what) {
            case PHONE_INCOMING_RING:
                // repeat the ring when requested by the RIL, and when the user has NOT
                // specifically requested silence.
                if (msg.obj != null && ((AsyncResult) msg.obj).result != null) {
                    PhoneBase pb =  (PhoneBase)((AsyncResult)msg.obj).result;

                    if ((pb.getState() == Phone.State.RINGING)
                            && (mSilentRingerRequested == false)) {
                        if (DBG) log("RINGING... (PHONE_INCOMING_RING event)");
                        //响铃
                        mRinger.ring();
                    } else {
                        if (DBG) log("RING before NEW_RING, skipping");
                    }
                }
                break;
        }
}

    这是我对来电的基本流程理解,同时也查看许多文档结合代码跟踪,如哪里有错误或遗漏可提出来进行改进。

posted on 2013-09-05 16:03  羞涩的流氓  阅读(639)  评论(0编辑  收藏  举报