Android连载40-ITelecomService详解

一、拨号流程总结

  • 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");
                }

三、源码:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值