Android Tel 拨打电话及来电流程分析
16lz
2021-01-23
打电话流程
接下来分析一下打电话的流程。输入电话号码的流程这里忽略。输入电话号码之后会点击拨打图标。之后就会走拨打电话的流程了。这部分是在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 extraintent.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;
之后拨打电话的流程如下图:
接收来电的处理过程
SubscriptionManager本身就是一个service
registerService(Context.TELEPHONY_SUBSCRIPTION_SERVICE, SubscriptionManager.class,)
之后就开始监听消息。
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应用程序创建Surface过程源码分析
- 【 Android 10 四大组件 】系列 -- Activity 的 "启动流程"
- Android启动流程分析(九) 解析init.rc的service
- Android应用程序安装过程浅析
- android APK签名过程之CERT.RSA分析
- android 入门学习笔记 判断网页地址 邮箱 电话号码 符合要求的加
- 【高通SDM660平台 Android 10.0】(18) --- Camera start_session
- android通过查询电话号码获取联系人头像