一、拨号流程总结

  • DialpadFragment提供用户拨号的交互界面
  • CallIntentBuilder创建拨号请求的intent对象
  • TelecomManager继续传递拨号请求intent对象 40.1

二、ITelecomService接收拨号请求服务

  • /packages/services/Telecomm/src/com/android/server/telecom这个代码库编译出来就是Telecom.apk Android应用程序,后面统一称为Telecom应用
        <service android:name=".components.TelecomService"
                android:singleUser="true"
                android:process="system">
            <intent-filter>
                <action android:name="android.telecom.ITelecomService" />
            </intent-filter>
        </service>
  • 指定进程为system,也就是这个服务将会运行在system_server系统,唯一的action为android.telecom.ITelecomService.

注意:Dialer应用的com.android.dialer进程提供用户拨号界面并且响应用户的拨号请求,把拨号请求包装成action为Intent.ACTION_CALL的intent对象,通过调用ITelecomService提供的placeCall接口,将拨号请求intent发送给了Telelcom应用(system_server进程),完成了第一次跨进程的服务调用。

  • 看一下TelecomServiceImpl.java文件中的placeCall方法
public void placeCall(Uri handle, Bundle extras, String callingPackage) {
            try {
                Log.startSession("TSI.pC");
                enforceCallingPackage(callingPackage);

                PhoneAccountHandle phoneAccountHandle = null;
                if (extras != null) {
                    phoneAccountHandle = extras.getParcelable(
                            TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE);
                    if (extras.containsKey(TelecomManager.EXTRA_IS_HANDOVER)) {
                        // This extra is for Telecom use only so should never be passed in.
                        extras.remove(TelecomManager.EXTRA_IS_HANDOVER);
                    }
                }
                boolean isSelfManaged = phoneAccountHandle != null &&
                        isSelfManagedConnectionService(phoneAccountHandle);
                if (isSelfManaged) {
                    mContext.enforceCallingOrSelfPermission(Manifest.permission.MANAGE_OWN_CALLS,
                            "Self-managed ConnectionServices require MANAGE_OWN_CALLS permission.");

                    if (!callingPackage.equals(
                            phoneAccountHandle.getComponentName().getPackageName())
                            && !canCallPhone(callingPackage,
                            "CALL_PHONE permission required to place calls.")) {
                        // The caller is not allowed to place calls, so we want to ensure that it
                        // can only place calls through itself.
                        throw new SecurityException("Self-managed ConnectionServices can only "
                                + "place calls through their own ConnectionService.");
                    }
                } else if (!canCallPhone(callingPackage, "placeCall")) {
                    throw new SecurityException("Package " + callingPackage
                            + " is not allowed to place phone calls");
                }

三、源码:

posted on 2021-04-29 00:38  心悦君兮君不知-睿  阅读(442)  评论(0编辑  收藏  举报