---
title: "Android RIL CDMA分支总结(1)"
author: "地球小野花"
date: "2011-05-16T21:36:16Z"
tags: []
categories: ["移动开发"]
slug: "android-ril-cdma-1"
draft: false
lastmod: "2011-05-16T21:36:16Z"
id: 1046238
url: "https://android-sz.iteye.com/blog/1046238"
---

Android RIL CDMA分支总结

 

1\. CDMA分支代码结构

代码结构如下:  
ril  
|-- include  
| \`-- telephony  
| |-- ril.h  
| \`-- ril\_cdma\_sms.h  
|-- libril  
| |-- ril.cpp  
| |-- ril\_commands.h  
| |-- ril\_event.cpp  
| |-- ril\_event.h  
| \`-- ril\_unsol\_commands.h  
|-- reference-cdma-sms  
| |-- reference-cdma-sms.c  
| \`-- reference-cdma-sms.h  
|-- reference-ril  
| |-- at\_tok.c  
| |-- at\_tok.h  
| |-- atchannel.c  
| |-- atchannel.h  
| |-- misc.c  
| |-- misc.h  
| \`-- reference-ril.c  
\`-- rild  
|-- radiooptions.c  
\`-- rild.c

 

reference-ril-&gt;libference-ril.so 主要负责modem通信（包含通话、上网、短信以及modem初始化功能等等）

 

rild -&gt; rild  rild守护进程，是整个android ril层的入口点。

 

libril -&gt; libril.so rild的共享库，驻留在rild中，完成和上层通信的工作，接受ril请求并传递给libreference-ril.so来通知modem，与此同时将其反馈回传给调用进程。

 

radiooptions -&gt; radiooptions  无线通信测试程序。

 

reference-cdma-sms -&gt; cdma模组特殊定义用于cdma（evdo）通信使用，主要定义短信接口（实现短息的编码解码工作）。

 

 

2.AT从界面到模组流程

 

通话外例：

 

按通话图标-&gt;&gt;

DialtactsActivity(4个Tab 分别由TwelveKeyDialer&lt;拨号&gt;、RecentCallsListActivity&lt;最近联系人&gt;，两个activity-alias DialtactsContactsEntryActivity&lt;联系人&gt;和DialtactsFavoritesEntryActivity&lt;收藏&gt;)

 

输入拨号号码

TwelveKeyDialer

 

        mehod: Onclick

        placecall()

            Intent intent =new Intent(Intent.ACTION\_CALL\_PRIVILEGED,

                       Uri.fromParts("tel",number,null));

                       intent.setFlags(Intent.FLAG\_ACTIVITY\_NEW\_TASK);

                       startActivity(intent);

启动拨号-&gt;&gt;&gt;&gt;&gt;&gt;

 

 

intert.ACTION\_CALL\_PRIVILEGED实际字符串为android.intent.action.CALL\_PRIVILEGED，通过查找知道了packegs/phone

下面的androidmanifest.xml中PrivilegedOutgoingCallBroadcaster activity-alias设置了intent-filter，所以需要找到其targetactivity为OutgoingCallBroadcaster。所以进入OutgoingCallBroadcaster的

  method:onCreate（）

  //如果为紧急号码马上启动intent.setClass(this, InCallScreen.class); startActivity(intent);

  Intent broadcastIntent = new Intent(Intent.ACTION\_NEW\_OUTGOING\_CALL);

        if (number != null) broadcastIntent.putExtra(Intent.EXTRA\_PHONE\_NUMBER, number);

        broadcastIntent.putExtra(EXTRA\_ALREADY\_CALLED, callNow);

        broadcastIntent.putExtra(EXTRA\_ORIGINAL\_URI, intent.getData().toString());

        if (LOGV) Log.v(TAG, "Broadcasting intent " + broadcastIntent + ".");

        sendOrderedBroadcast(broadcastIntent, PERMISSION, null, null,

                             Activity.RESULT\_OK, number, null);

   

 

 

Intent.ACTION\_NEW\_OUTGOING\_CALL实际字符串为android.intent.action.NEW\_OUTGOING\_CALL，通过查找知道了packegs/phone下面的androidmanifest.xml中OutgoingCallReceiver Receiver接收此intent消息。找到OutgoingCallReceiver，执行

mothod:onReceive()函数

  Intent newIntent = new Intent(Intent.ACTION\_CALL, uri);

        newIntent.putExtra(Intent.EXTRA\_PHONE\_NUMBER, number);

        newIntent.setClass(context, InCallScreen.class);

        newIntent.addFlags(Intent.FLAG\_ACTIVITY\_NEW\_TASK);

 

《整个流程》

mothod:onCreate(第一次)/onNewIntent(非第一次)

  internalResolveIntent

    placeCall(intent);

      PhoneUtils.placeCall(mPhone, number, intent.getData());

        phone.dial(number);

          mCT.dial(newDialString);

            dial(dialString, CommandsInterface.CLIR\_DEFAULT);

              cm.dial(pendingMO.address, clirMode, obtainCompleteMessage());//obtainCompleteMessage(EVENT\_OPERATION\_COMPLETE);

                send(rr);

                  msg = mSender.obtainMessage(EVENT\_SEND, rr);

                  acquireWakeLock();

                  msg.sendToTarget();

                RILSender.handleMessage()  //已经到系统java ril&lt;gsm &cdma&gt;处理部分

                  case EVENT\_SEND:

                    ...

                    s.getOutputStream().write(dataLength);                   

                    s.getOutputStream().write(data);//从这里流程跑到下面ril.cpp中监听部份

 

 

RIL层

 

rild守护进程 rild-&gt;main=&gt;RIL\_startEventLoop

      //建立事件循环线程

    ret = pthread\_create(&s\_tid\_dispatch, &attr, eventLoop, NULL);

      //注册进程唤醒事件回调

      ril\_event\_set (&s\_wakeupfd\_event, s\_fdWakeupRead, true,

                processWakeupCallback, NULL);

      rilEventAddWakeup (&s\_wakeupfd\_event);

      //建立事件循环

      ril\_event\_loop

        for (;;) {

          ...

          n = select(nfds, &rfds, NULL, NULL, ptv);

          // Check for timeouts

          processTimeouts();

          // Check for read-ready

          processReadReadies(&rfds, n);

          // Fire away

          firePending();

        }

 

       funcs = rilInit(&s\_rilEnv, argc, rilArgv);//实际是通过动态加载动态库的方式执行reference-ril.c中的RIL\_Init

 

    

      //单独启动一个线程读取串口数据

       ret = pthread\_create(&s\_tid\_mainloop, &attr, mainLoop, NULL);

       fd = open (s\_device\_path, O\_RDWR);//打开虚拟模组

       ret = at\_open(fd, onUnsolicited);  //设置模组主动上报

       ret = pthread\_create(&s\_tid\_reader, &attr, readerLoop, &attr);

       RIL\_requestTimedCallback(initializeCallback, NULL, &TIMEVAL\_0);

 

reference-ril.so 处理方式（rild动态加载libreference-ril.so库）

      (处理模型)

      &gt;static void request(x x x)

         switch(x)    //判断请求类型

              request\_dail //电话请求

                  function()  //请求处理函数AT指令

 

     设置事件回报//

 

参考文献：

[http://blog.csdn.net/basonjiang\_sz/archive/2011/03/17/6255881.aspx](http://blog.csdn.net/basonjiang_sz/archive/2011/03/17/6255881.aspx)

Android GSM驱动模块详细分析（作者：熊猫哥哥）