美文网首页
android 6.0 ConnectionService

android 6.0 ConnectionService

作者: wbxjack | 来源:发表于2016-06-24 20:54 被阅读1110次

    分析Connection的创建

    MO的时候,CallIntentProcessor(packages/services/Telecomm/src/com/android/server/telecom/CallIntentProcessor.java)收到去电请求后,会调用CallsManager的startOutgoingCall生成一个Call对象,在其中会走前一篇(绑定InCallService)的逻辑,然后继续往下走,最终到CallsManager.placeOutgoingCall函数,里面通过call.startCreateConnection来创建Connection。最后走到ConnectionServiceWrapper.createConnection()从此走上ConnectionService相关之路。

    首先是通过ConnectionServiceWrapper来获得ConnectionService(frameworks/base/telecomm/java/android/telecom/ConnectionService.java),也就是在ConnectionServiceWrapper中通过bindService来和ConnectionService相连。事件上TelephonyConnectionService(packages/services/Telephony/src/com/android/services/telephony/TelephonyConnectionService.java)继承ConnectionService,最后连的是TelephonyConnectionService。
    并且,和InCallService类似,连接成功后,设置IConnectionServiceAdapter.Stub的一个adapter到ConnectionService,以完成双向调用。

     mServiceInterface.addConnectionServiceAdapter(adapter)
    

    最后存在了ConnectionServiceAdapter(frameworks/base/telecomm/java/android/telecom/ConnectionServiceAdapter.java)对象中。

    创建connection之前,把ConnectionServiceWrapper对象设置到Call对象中,这样,当有相关操作的时候(比如answer),会调用ConnectionServiceWrapper对象,最终会调用ConnectionService来传到framework下面去。

        if (mResponse != null && attempt != null) {
            Log.i(this, "Trying attempt %s", attempt);
            PhoneAccountHandle phoneAccount = attempt.connectionManagerPhoneAccount;
            ConnectionServiceWrapper service =
                    mRepository.getService(
                            phoneAccount.getComponentName(),
                            phoneAccount.getUserHandle());
            if (service == null) {
                Log.i(this, "Found no connection service for attempt %s", attempt);
                attemptNextPhoneAccount();
            } else {
                mCall.setConnectionManagerPhoneAccount(attempt.connectionManagerPhoneAccount);
                mCall.setTargetPhoneAccount(attempt.targetPhoneAccount);
                mCall.setConnectionService(service);
                setTimeoutIfNeeded(service, attempt);
    
                service.createConnection(mCall, new Response(service));
            }
        }
    

    走了一圈,最后到了ConnectionService.createConnection,里面根据是MO/MT调用了onCreateOutgoingConnection/onCreateInComingConnection,这里我们看onCreateOutgoingConnection,在这个里面创建最终的connection,并调用phone.dial()拨号,把命令发到RIL。

        com.android.internal.telephony.Connection originalConnection;
        try {
            if (isAddParticipant) {
                phone.addParticipant(number);
                return;
            } else {
                originalConnection = phone.dial(number, null, request.getVideoState(), bundle);
            }
        } catch (CallStateException e) {
    

    然后把dial生成的connection和service包里面的connection相关联。

      connection.setOriginalConnection(originalConnection);
    

    这样,当底层有电话状态变化的时候,会传到connection中,然后再传到call,最后到UI。

    相关文章

      网友评论

          本文标题:android 6.0 ConnectionService

          本文链接:https://www.haomeiwen.com/subject/kfoodttx.html