android4.0来电过程(RIL Framework Java部分)

   1.RILReceiver 接收到unsolicited message RIL_UNSOL_CALL_RING,处理该消息
     if (mRingRegistrant != null) {
                    mRingRegistrant.notifyRegistrant(
                            new AsyncResult (null, ret, null));
                }
   2.经分析mRingRegistrant,是由 PhoneBase 在其构造函数中构造的。
       protected PhoneBase(PhoneNotifier notifier, Context context, CommandsInterface ci,
            boolean unitTestMode) {
        .....
        mCM.setOnCallRing(this, EVENT_CALL_RING, null);
        .....
       }
   3.那么消息就传递给 PhoneBase的EVENT_CALL_RING,处理该消息,调用 PhoneBase的notifyIncommingRing
      case EVENT_CALL_RING:
                Log.e("LUSHUAITEST","phone base event call ring");
                Log.d(LOG_TAG, "Event EVENT_CALL_RING Received state=" + getState());
                ar = (AsyncResult)msg.obj;
                if (ar.exception == null) {
                    Phone.State state = getState();
                    if ((!mDoesRilSendMultipleCallRing)
                            && ((state == Phone.State.RINGING) || (state == Phone.State.IDLE))) {
                        mCallRingContinueToken += 1;
                        sendIncomingCallRingNotification(mCallRingContinueToken);
                    } else {
                        notifyIncomingRing();
                    }
                }
                break;

            case EVENT_CALL_RING_CONTINUE:
                Log.d(LOG_TAG, "Event _CONTINUE Received stat=" + getState());
                if (getState() == Phone.State.RINGING) {
                    sendIncomingCallRingNotification(msg.arg1);
                }
         break;
    private void sendIncomingCallRingNotification(int token) {
        if (mIsVoiceCapable && !mDoesRilSendMultipleCallRing &&
                (token == mCallRingContinueToken)) {
            Log.d(LOG_TAG, "Sending notifyIncomingRing");
            notifyIncomingRing();
            sendMessageDelayed(
                    obtainMessage(EVENT_CALL_RING_CONTINUE, token, 0), mCallRingDelay);
        } else {
            Log.d(LOG_TAG, "Ignoring ring notification request,"
                    + " mDoesRilSendMultipleCallRing=" + mDoesRilSendMultipleCallRing
                    + " token=" + token
                    + " mCallRingContinueToken=" + mCallRingContinueToken
                    + " mIsVoiceCapable=" + mIsVoiceCapable);
        }
    }
     private void notifyIncomingRing() {
        Log.e("LUSHUAITEST","notify incomingring");
        if (!mIsVoiceCapable)
            return;
        AsyncResult ar = new AsyncResult(null, this, null);
        mIncomingRingRegistrants.notifyRegistrants(ar);
    }
    sendIncomingCallRingNotification 使来电不断的响铃,直到用户接听电话。
    
  4. 经分析PhoneBase的mIncomingRingRegistrants是 由 CallManager 的registerForPhoneStates 方法中构造的。
    private void registerForPhoneStates(Phone phone) {
        ...
        phone.registerForIncomingRing(mHandler, EVENT_INCOMING_RING, null);
        ...
    }
  5.那么消息就传递到 CallManager 的 EVENT_INCOMING_RING,处理该消息
    case EVENT_INCOMING_RING:
                    if (VDBG) Log.d(LOG_TAG, " handleMessage (EVENT_INCOMING_RING)");
                    // The event may come from RIL who's not aware of an ongoing fg call
                    if (!hasActiveFgCall()) {
                        mIncomingRingRegistrants.notifyRegistrants((AsyncResult) msg.obj);
                    }
                    break;
   6. 经分析 CallManager的 mIncomingRingRegistrants,是由 CallNotifier的  registerForNotifications 构造的。
    private void registerForNotifications() {
        ...
        mCM.registerForIncomingRing(this, PHONE_INCOMING_RING, null);
        ...
    }
   7.消息就传递给 CallNotifier的 PHONE_INCOMING_RING,处理该消息
      case PHONE_INCOMING_RING:
                // repeat the ring when requested by the RIL, and when the user has NOT
                // specifically requested silence.
                Log.e("LUSHUAITEST","phone  incoming ring");
                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;
       来电铃声响起。
   8. RILReceiver 接收到unsolicited message RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED,处理该消息
       case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED:
                if (RILJ_LOGD) unsljLog(response);
                Log.e("LUSHUAITEST","call state changed");
                mCallStateRegistrants
                    .notifyRegistrants(new AsyncResult(null, null, null));
            break;
   9.经分析 mCallStateRegistrants是由 GsmCallTracker 构造的
      GsmCallTracker (GSMPhone phone) {
        ...
        cm = phone.mCM;

        cm.registerForCallStateChanged(this, EVENT_CALL_STATE_CHANGE, null);
        ...
    }
    10.消息就传递给 GsmCallTracker 的 EVENT_CALL_STATE_CHANGE,处理该消息
    protected void pollCallsWhenSafe() {
        needsPoll = true;
        Log.e("LUSHUAITEST","poll Call When Safe");
        if (checkNoOperationsPending()) {
            lastRelevantPoll = obtainMessage(EVENT_POLL_CALLS_RESULT);
            cm.getCurrentCalls(lastRelevantPoll);
        }
    }
   11.向RIL请求 RIL_REQUEST_GET_CURRENT_CALLS,将返回结果 交给 GsmCallTracker的 EVENT_POLL_CALLS_RESULT 事件处理
   RIL的
    getCurrentCalls (Message result) {
        RILRequest rr = RILRequest.obtain(RIL_REQUEST_GET_CURRENT_CALLS, result);
        Log.e("LUSHUAITEST","get currentCalls");
        if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));

        send(rr);
    }
   12.从RILReceiver 中获取 对 RIL_REQUEST_GET_CURRENT_CALLS的响应。
   13.   if (rr.mResult != null) {
            AsyncResult.forMessage(rr.mResult, ret, null);
            rr.mResult.sendToTarget();
        }

        rr.release();
   14.响应结果交给  GsmCallTracker的 EVENT_POLL_CALLS_RESULT 事件处理
    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;
                    Log.e("LUSHUAITEST","get currentCalls return result handle poll calls");
                    handlePollCalls((AsyncResult)msg.obj);
                }
            break;

   15.
   handlePollCalls(AsyncResult ar) {
    ...
    if (newRinging != null) {
            phone.notifyNewRingingConnection(newRinging);
        }
    ...
   }
   16.调用PhoneBase 的 notifyNewRingingConnectionP
    protected void notifyNewRingingConnectionP(Connection cn) {
        if (!mIsVoiceCapable)
            return;
        AsyncResult ar = new AsyncResult(null, cn, null);
        mNewRingingConnectionRegistrants.notifyRegistrants(ar);
    }
  17.经分析 mNewRingingConnectionRegistrants是由 CallManager的registerForPhoneStates构造,消息传递给 EVENT_NEW_RINGING_CONNECTION
   private void registerForPhoneStates(Phone phone) {
        ...
        phone.registerForNewRingingConnection(mHandler, EVENT_NEW_RINGING_CONNECTION, null);
       ...
   }
  18.CallManager的EVENT_NEW_RINGING_CONNECTION,处理消息,
    case EVENT_NEW_RINGING_CONNECTION:
                    if (VDBG) Log.d(LOG_TAG, " handleMessage (EVENT_NEW_RINGING_CONNECTION)");
                    if (getActiveFgCallState().isDialing() || hasMoreThanOneRingingCall()) {
                        Connection c = (Connection) ((AsyncResult) msg.obj).result;
                        try {
                            Log.d(LOG_TAG, "silently drop incoming call: " + c.getCall());
                            c.getCall().hangup();
                        } catch (CallStateException e) {
                            Log.w(LOG_TAG, "new ringing connection", e);
                        }
                    } else {
                        mNewRingingConnectionRegistrants.notifyRegistrants((AsyncResult) msg.obj);
                    }
                    break;
  19.经分析 mNewRingingConnectionRegistrants 是由CallNotifier 的 registerForNotifications构造,消息传递给 PHONE_NEW_RINGING_CONNECTION
    private void registerForNotifications() {
        mCM.registerForNewRingingConnection(this, PHONE_NEW_RINGING_CONNECTION, null);
    ...
   }
  20.CallNotifier 的 PHONE_NEW_RINGING_CONNECTION,处理消息。
       case PHONE_NEW_RINGING_CONNECTION:
                log("RINGING... (new)");
                onNewRingingConnection((AsyncResult) msg.obj);
                mSilentRingerRequested = false;
                break;
  21,开始查询来电号码的信息,并显示 来电画面。
    if (DBG) log("- updating notification from showIncomingCall()...");
        mApplication.notificationMgr.updateNotificationAndLaunchIncomingCallUi();
  }
 
 

    

    


 

  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值