Android Tel 拨打电话及来电流程分析

打电话流程

接下来分析一下打电话的流程。输入电话号码的流程这里忽略。输入电话号码之后会点击拨打图标。之后就会走拨打电话的流程了。这部分是在packages/apps/Dialer/src/com/android/dialer/DialtactsActivity.java中实现的。
下面分析源码分析

    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.floating_action_button:
                if (mListsFragment.getCurrentTabIndex()
                        == ListsFragment.TAB_INDEX_ALL_CONTACTS && !mInRegularSearch) {
                    DialerUtils.startActivityWithErrorToast(
                            this,
                            IntentUtil.getNewContactIntent(),
                            R.string.add_contact_not_available);
                } else if (!mIsDialpadShown) {
                    mInCallDialpadUp = false;
                    showDialpadFragment(true);
                    mFloatingActionButton.setImageResource(R.drawable.fab_ic_call);
                    mFloatingActionButton.setVisibility(view.VISIBLE);
                    setConferenceDialButtonImage(false);
                    setConferenceDialButtonVisibility(true);
                } else {
                    //用户点击拨打键
                    mDialpadFragment.dialButtonPressed();
                }
                break;
          
        }
    }

上面就是click之后将会调用packages/apps/Dialer/src/com/android/dialer/dialpad/DialpadFragment.java

public void dialButtonPressed() {
        getView().performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);//按键反馈
handleDialButtonPressed();
}

private void handleDialButtonPressed() {

final Intent intent = CallUtil.getCallIntent(number);
if (!isDigitsShown && !PhoneNumberUtils.isEmergencyNumber(number)) {
	// must be dial conference add extra
	intent.putExtra(EXTRA_DIAL_CONFERENCE_URI, true);
}
	intent.putExtra(ADD_PARTICIPANT_KEY, mAddParticipant && isPhoneInUse());
	DialerUtils.startActivityWithErrorToast(getActivity(), intent);
	hideAndClearDialpad(false);
    }

之后就开始启动拨号的Activity
启动Activity代码如下:

packages/apps/Dialer/src/com/android/dialer/util/DialerUtils.java
    public static void startActivityWithErrorToast(Context context, Intent intent, int msgId) {
        try {
            if ((IntentUtil.CALL_ACTION.equals(intent.getAction())
                            && context instanceof Activity)) {
                final TelecomManager tm =
                        (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
                tm.placeCall(intent.getData(), intent.getExtras());
            } else {
                context.startActivity(intent);
            }
        } catch (ActivityNotFoundException e) {
            Toast.makeText(context, msgId, Toast.LENGTH_SHORT).show();
        }
    }

这里面有两种拨号的方式:1.直接调用TelecomManager进行呼叫;2,启动一个Activity显示拨号界面。
这里面有一个转换过程:public static final String CALL_ACTION = Intent.ACTION_CALL;
之后拨打电话的流程如下图:

UserCallActivity UserCallInt PrimaryCallReceiver CallIntentProcessor NewOutgoingCallI CallsManager Call CreateConnec ConnectionSe ConnectionService TelephonyConn Phone CallTracker RIL onCreate processIntent sendBroadcastToReceiver with KEY_IS_PRIVILEGED_DIALER onReceive processOutgoingCallIntent processIntent processIntent placeOutgoingCall startCreateConnection new process attemptNextPhoneAccount createConnection sendmessage(MSG_CREATE_CONNECTION) onCreateOutgoingConnection onCreateOutgoingConnection placeOutgoingConnection dial dial dial UserCallActivity UserCallInt PrimaryCallReceiver CallIntentProcessor NewOutgoingCallI CallsManager Call CreateConnec ConnectionSe ConnectionService TelephonyConn Phone CallTracker RIL

接收来电的处理过程

SubscriptionManager本身就是一个service
registerService(Context.TELEPHONY_SUBSCRIPTION_SERVICE, SubscriptionManager.class,)

PhoneApp TelephonyGlobals TelecomAcco SubscriptionManager TelephonyRegistry TelephonyManager new onCreate setupOnBoot addOnSubscriptionsChangedListener addOnSubscriptionsChangedListener listen listenForSubscriber PhoneApp TelephonyGlobals TelecomAcco SubscriptionManager TelephonyRegistry TelephonyManager

之后就开始监听消息。

TelephonyRegistry TelecomAccountReg TelecomAcco AccountEntry PstnIncoming Phone PstnPhoneCapab onSubscriptionsChanged setupAccounts new TelephonyConn ectionService new regist EVENT_NEW_RINGING_CONNECTION EVENT_CDMA_CALL_WAITING EVENT_UNKNOWN_CONNECTION new TelephonyRegistry TelecomAccountReg TelecomAcco AccountEntry PstnIncoming Phone PstnPhoneCapab

当有新的call之后处理

GsmCallTracker PhoneBase PstnIncoming TelecomManager TelecomServiceImpl CallIntentProcessor CallsManager Call CreateConnec ConnectionSer ConnectionSe Binder2 ServiceBind TelephonyConn ConnectionService notifyNewRingingConnectionP handleNewRingingConnection addNewIncomingCall addNewIncomingCall new Intent(TelecomManager.ACTION_INCOMING_CALL) processIncomingCallIntent processIncomingCallIntent new Call startCreateConnection process attemptNextPhoneAccount getService new ConnectionServiceWrapper createConnection bind new bindService onServiceConnected setServiceInterface addConnectionServiceAdapter MSG_ADD_CONNECTION_SERVICE_ADAPTER GsmCallTracker PhoneBase PstnIncoming TelecomManager TelecomServiceImpl CallIntentProcessor CallsManager Call CreateConnec ConnectionSer ConnectionSe Binder2 ServiceBind TelephonyConn ConnectionService

这里面需要注意,bind的Service为:TelephonyConnectionService

TelephonyConn ConnectionService ConnectionSe Call MSG_CREATE_CONNECTION createConnection onCreateUnknownConnection handleCreateConnectionComplete handleCreateConnectionSuccess TelephonyConn ConnectionService ConnectionSe Call

之后就是调用UI注册进来的listener用来更新UI了。

你可能感兴趣的:(android,Telephone)