Android 系统电话管理机制一

[来源] 达内    [编辑] 达内   [时间]2012-09-17

电话管理是Android 系统支持的重要的业务之一,提供接听电话,收发短信、电话薄、网络事件监听、读取用户信息等功能。

电话管理是 Android  系统支持的重要的业务之一,提供接听电话,收发短信、电话薄、网络事件监听、读取用户信息等功能。

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">          从下到上可以分为四层:硬件驱动层、RIL daemon层、 Telephony 框架实现层、 PHONE应用层,下层为上层提供服务,每层之间采用不同的通讯方式交互。RIL daemon 层实现为单独的一个开机启动的进程(rild命令),通过AT命令硬件驱动层交互, Telephony  JAVA框架实现层包括一个RIL抽象层, RIL 抽象层中通过一个本地socketRIL daemon层(rild )交互,PHONE 应用层通过BINDER机制与Telephony框架交互。

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">          本文主要分析框架层相关的主要类的结构。

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">  Telephony框架

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">          Telephony框架系统类图如下图:

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">          

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">          Telephony框架层为应用层和框架层的其它服务提供Telephony 服务,提供了如下几个服务:PhoneInterfaceManager 服务,是ITelephony接口的桩实现,IccSmsInterfaceManager 短消息服务,是 Isms接口的桩实现;IccPhoneBookInterfaceManager电话本服务,是IIccPhoneBook接口的桩实现; PhoneSubInfo提供用户信息读取服务,是IPhoneSubInfo接口的桩实现;TelephonyRegistry 提供应用层的消息登记服务,是ITelephonyRegistry接口的桩实现。

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">        应用程序通过以下几个客户端对象使用Telephony框架提供的服务。

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">        应用程序可以在SmsManager单例对象(通过SmsManager类的 getDefault函数返回 SmsManager单例对象)中访问IccSmsInterfaceManager服务,用来收发短信。

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">        通过IccProvider一个内容提供对象提供对IccPhoneBookInterfaceManager 服务的访问,读取和管理电话本。 

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">        通过TelephonyManager对象提供对PhoneSubInfoPhoneInterfaceManager TelephonyRegistry服务的访问,TelephonyManager对象通过getSubscriberInfo函数获得PhoneSubInfo 服务的远程访问代理对象。通过getITelephony函数获得PhoneInterfaceManager 的远程访问代理对象。提供一个对象全局sRegistry(指向TelephonyRegistry 服务的远程访问代理对象)访问TelephonyRegistry服务。

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">          TelephonyManager通过这三个接口函数提供对外的TelephonyAPI,因此应用程序可以通过  TelephonyManager 对象提供的TelephonyAPI访问这些服务,使用Telephony框架层提供的接口功能。

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">          TelephonyManager对象本身通过Context对象调用getSystemService(Context.TELEPHONY_SERVICE) 函数返回, TelephonyManager对象是一个单例对象。

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">          PhoneInterfaceManager服务在默认电话应用的PhoneApp对象中采用单例模式进行初始化(PhoneApp 对象本身也是单例对象),和PhoneApp对象公用一个进程,PhoneInterfaceManager 为框架层的其它服务提供Telephony API  服务,并通过TelephonyManager对象(通过getITelephony函数获得ITelephony 接口)为其它应用提供服务。PhoneInterfaceManager通过PhoneAppCallManagerPhone对象实现相应功能。CallManager是一个单例对象,CallManager 对象提供 CALL控制以及登记通知等功能。

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">          Phone对象是整个Telephony服务的核心,主要的Telephony 服务(IccSmsInterfaceManagerIccPhoneBookInterfaceManagerPhoneSubInfo )及数据连接功能都通过具体的Phone对象提供,具体的Phone对象包括CDMAPhone CDMALTEPhoneGSMPhoneSipPhone

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">          PhoneBase抽象类是这些具体Phone对象的共同的基类,本身一个Handler 类,用来提供Phone 接口的基实现,PhoneBase通过CommandsInterface接口与RIL daemon 层交互,实现短消息提交、数据连接控制、ICC 信息读取等Telephony 基类功能。PhoneBase包含SMSDispatcherDataConnectionTracker IccFileHandlerIccRecordsIccCard等几个抽象类成员,并通过这些抽象类成员提供某一方面功能的基类实现。

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">          SMSDispatcher DataConnectionTracker IccFileHandlerIccRecords抽象类也是派生自Handler类,因此都能够向RIL 发送命令,接收和处理RIL发来的事件和命令应答。PhoneBase包括一个PhoneNotifier 接口, Phone对象本身及内部对象可以通过PhoneNotifier接口向应用发送Telephony事件通知。

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">          CDMAPhoneGSMPhoneCDMALTEPhone三个具体的Phone 对象在默认的PhoneApp应用中调用PhoneFactorymakeDefaultPhone 函数根据不同的网络模式进行单例实例化,并封装进一个统一的PhoneProxy代理对象中。

< table width="721" cellspacing="0" cellpadding="0" border="1" style="margin: 0px auto; border: 1px solid rgb(192, 192, 192); border-collapse: collapse; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 19px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">

            sCommandsInterface = new RIL(context, networkMode, cdmaSubscription);

                int phoneType = getPhoneType(networkMode);

                if (phoneType == Phone.PHONE_TYPE_GSM) {

                    sProxyPhone = new PhoneProxy(new GSMPhone(context,

                            sCommandsInterface, sPhoneNotifier));

                } else if (phoneType == Phone.PHONE_TYPE_CDMA) {

                    switch (BaseCommands.getLteOnCdmaModeStatic()) {

                        case Phone.LTE_ON_CDMA_TRUE:

                        sProxyPhone = new PhoneProxy(new CDMALTEPhone(context,

                                sCommandsInterface, sPhoneNotifier));

                            break;

                        case Phone.LTE_ON_CDMA_FALSE:

                        default:

                            sProxyPhone = new PhoneProxy(new CDMAPhone(context,

                                    sCommandsInterface, sPhoneNotifier));

                            break;

                    }

                }

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">          PhoneProxy内部的对象成员mActivePhone指向代理的实际Phone 对象。PhoneProxy 代理对象实现了Phone接口,使应用能够使用统一的PhoneProxy对象控制操作具体类型的 Phone 对象,而不用关心它们之间的差异(代理模式的采用),应用程序通过PhoneFactorygetDefaultPhone 函数返回统一的PhoneProxy代理对象来访问不同的Phone对象。

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">       因为Telephony框架层支持不同的网络类型的Telephony实现( CDMAGSM ),因此Telephony框架层普遍使用代理模式来对应用提供统一的服务接口。如PhoneProxy 代理对象内部还封装了IccSmsInterfaceManagerIccPhoneBookInterfaceManagerPhoneSubInfo 三个服务的代理对象,通过代理对象提供对这三个服务的操作控制。

< table width="744" cellspacing="0" cellpadding="0" border="1" style="margin: 0px auto; border: 1px solid rgb(192, 192, 192); border-collapse: collapse; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 19px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">

  public PhoneProxy(Phone phone) {

        mActivePhone = phone;

        mIccSmsInterfaceManagerProxy = new IccSmsInterfaceManagerProxy(

                phone.getIccSmsInterfaceManager());

        mIccPhoneBookInterfaceManagerProxy = new IccPhoneBookInterfaceManagerProxy(

                phone.getIccPhoneBookInterfaceManager());

        mPhoneSubInfoProxy = new PhoneSubInfoProxy(phone.getPhoneSubInfo());

        mCommandsInterface = ((PhoneBase)mActivePhone).mCM;

    }

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">        另外CommandsInterface接口的具体实现对象RILPhoneNotifier 接口的具体实现对象 DefaultPhoneNotifier也是在PhoneFactorymakeDefaultPhone中进行单例实例化。

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">           CDMAPhoneGSMPhone对象直接派生自PhoneBase ,提供Phone 接口的具体实现,GSMPhoneGSM电话的JAVA 框架层实现,CDMAPhoneCDMA电话的JAVA框架层实现。

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">           CDMAPhoneGSMPhone对象实例化时除实例化基对象PhoneBase 内部抽象对象(SMSDispatcherDataConnectionTrackerIccFileHandlerIccRecords IccCard)的具体类外,还实例化用于具体电话对象的Telephony服务(IccSmsInterfaceManager IccPhoneBookInterfaceManagerPhoneSubInfo三个服务或者服务的派生类)。

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">  GSMPhone

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">         如下是GSMPhone对象的相关类图。

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">        

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">          SMSDispatcher DataConnectionTracker IccFileHandlerIccRecordsIccCard等抽象类对应GSMPhone 对象中的派生类分别为 GsmSMSDispatcher(提供GSM模式的短消息发送和接收提交功能)、GsmDataConnectionTracker (提供 GSM模式的数据连接管理功能)、SIMFileHandler(提供SIM File处理)、SIMRecords (提供SIM信息记录功能)、SimCard(提供SIM CARD功能);

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">          IccSmsInterfaceManagerIccPhoneBookInterfaceManagerPhoneSubInfo 服务在GSMPhone 对象中实现的具体的服务类为 SimSmsInterfaceManager    SimPhoneBookInterfaceManagerPhoneSubInfo;这些对象和服务都在CDMAPhone对象实例化进行实例化。

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">       另外GSMPhone对象在实例化时还实例化GsmCallTracker(提供GSM 模式的CALL 管理)、GsmServiceStateTracker(提供GSM模式的服务状态管理)、CatService 对象(提供STK服务)。

< table width="732" cellspacing="0" cellpadding="0" border="1" style="margin: 0px auto; border: 1px solid rgb(192, 192, 192); border-collapse: collapse; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 19px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">

        mCT = new GsmCallTracker(this);

        mSST = new GsmServiceStateTracker (this);

        mSMS = new GsmSMSDispatcher(this, mSmsStorageMonitor, mSmsUsageMonitor);

        mIccFileHandler = new SIMFileHandler(this);

        mIccRecords = new SIMRecords(this);

        mDataConnectionTracker = new GsmDataConnectionTracker (this);

        mIccCard = new SimCard(this);

        if (!unitTestMode) {

            mSimPhoneBookIntManager = new SimPhoneBookInterfaceManager(this);

            mSimSmsIntManager = new SimSmsInterfaceManager(this, mSMS);

            mSubInfo = new PhoneSubInfo(this);

        }

        mStkService = CatService.getInstance(mCM, mIccRecords, mContext, mIccFileHandler, mIccCard);

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">          GSMCallTrackerAndroid的通话管理层,GsmCallTracker 派生自Handler 的虚拟类CallTrackerGsmServiceStateTracker派生自Handler 的虚拟类 ServiceStateTracker

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">          GsmCallTrackerGsmServiceStateTracker对象分别提供Call 状态( 共有IDLE, ACTIVE, HOLDING, DIALING, ALERTING, INCOMING, WAITING, DISCONNECTED, DISCONNECTING九种状态) ServiceState (共有STATE_IN_SERVICESTATE_OUT_OF_SERVICESTATE_EMERGENCY_ONLY STATE_POWER_OFF四种状态)的跟踪和管理,能够提供向RIL层发送请求,接收和处理RIL 层发来的命令响应事件及其它主动通知事件,如振铃等CALL相关事件及Service状态事件。

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">          GsmCallTracker对象中还提供有三个GsmCall对象(派生自抽象类Call ):ringingCall (用来管理处于INCOMINGWAITING状态的通话)、foregroundCall (用来管理处于DAILINGALERTINGACTIVE 状态的通话)、backgroundCall (用来管理HOLD的通话)。

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">           每个GsmCall可以同时有几路connection ,因此GsmCall 对象内部包含一个Connection类型的ArrayList对象,用来维护每个CALL 拥有的connection,一个Call最大允许有5 connections

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">          另外GSMCallTracker还包含一个GsmConnection 类型(派生自抽象类Connection)的数组对象Connections,用来维护所有的现行的通话的列表, GSMCallTracker 对象最大可维护7路通话。

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">          GsmConnection对象中有个成员变量:GsmCall parent,这个成员变量是用来表示该connection 是属于哪个 Call的,一个Call可以有多个Connection,但一个Connection 只能属于一个Call

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">          GsmServiceStateTracker对象中除了包括ServiceState状态信息外,还包括SignalStrength 信号强度等信息。

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">          GsmServiceStateTracker对象还维护GSM CELL位置信息, 因此包含两个GsmCellLocation 对象成员cellLoc(当前位置) , newCellLoc( 新位置  )

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">          GsmCallTrackerGsmServiceStateTracker维护的状态和位置信息都通过RILRIL daemon 获得,因此两个对象都包括一个指向RILCommandsInterface对象。

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">         CatService对象实现STK服务, 也是一个Handler对象,并实现AppInterface 接口。CatService 对象能够与RILSTK应用交互:可以实现向RIL发送 Envelop 命令,以及RIL接收STK 事件,解析事件流(包括Proactive Command ,从STK应用接收命令执行结果编码后发给RILCatService 对象采用一个RilMessageDecoder状态机解析RIL发来的STK事件流。

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">  CDMAPhone

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">       如下是CDMAPhone对象的相关类图。

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">        

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">          SMSDispatcher DataConnectionTracker IccFileHandlerIccRecordsIccCard等抽象类对应的CDMAPhone 对象中的派生类为CdmaSMSDispatcherCdmaDataConnectionTrackerRuimFileHandlerRuimRecordsRuimCard

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">          IccSmsInterfaceManagerIccPhoneBookInterfaceManagerPhoneSubInfo 服务在CDMAPhone 对象中实现的派生类服务为 RuimSmsInterfaceManager    RuimPhoneBookInterfaceManagerPhoneSubInfo;这些对象和服务都在CDMAPhone对象实例化进行实例化。

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">       另外CDMAPhone对象在实例化时还实例化CdmaCallTracker CdmaServiceStateTracker CatService对象。以及一个EriManager对象用来加载ERI文件及管理CDMA漫游信息。

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 

< table width="732" cellspacing="0" cellpadding="0" border="1" style="margin: 0px auto; border: 1px solid rgb(192, 192, 192); border-collapse: collapse; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 19px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">

public CDMAPhone(Context context, CommandsInterface ci, PhoneNotifier notifier,

            boolean unitTestMode) {

        super(notifier, context, ci, unitTestMode);

        initSstIcc();

        init(context, notifier);

    }

 

    protected void initSstIcc() {

        mSST = new CdmaServiceStateTracker(this);

        mIccRecords = new RuimRecords(this);

        mIccCard = new RuimCard(this, LOG_TAG, DBG);

        mIccFileHandler = new RuimFileHandler(this);

    }

 

    protected void init(Context context, PhoneNotifier notifier) {

        mCM.setPhoneType(Phone.PHONE_TYPE_CDMA);

        mCT = new CdmaCallTracker(this);

        mSMS = new CdmaSMSDispatcher(this, mSmsStorageMonitor, mSmsUsageMonitor);

        mDataConnectionTracker = new CdmaDataConnectionTracker (this);

        mRuimPhoneBookInterfaceManager = new RuimPhoneBookInterfaceManager(this);

        mRuimSmsInterfaceManager = new RuimSmsInterfaceManager(this, mSMS);

        mSubInfo = new PhoneSubInfo(this);

        mEriManager = new EriManager(this, context, EriManager.ERI_FROM_XML);

        mCcatService = CatService.getInstance(mCM, mIccRecords, mContext,

                mIccFileHandler, mIccCard);

 

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); "> 

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">          CdmaCallTracker提供CDMA电话的通话管理功能,提供CDMA Call 事件的处理,CdmaCallTracker 派生自Handler的虚拟类CallTracker,用来管理CALL 通话。和GsmCallTracker相同,CdmaCallTracker对象中也提供有三个CdmaCall 类型的Call 对象:ringingCallforegroundCallbackgroundCall

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">       每个CdmaCall也包含一个Connection类型的ArrayList 对象,用来维护每个CALL 拥有的connection,但一个CdmaCall最大只允许有1 connection。同样CdmaCallTracker也包含一个CdmaConnection类型的数组对象Connections ,用来维护所有的现行的通话的列表,但Cdma最大也只允许1路现行通话。

< p style="line-height: 19px; margin: 5px auto; text-indent: 0px; color: rgb(75, 75, 75); font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); ">         CdmaServiceStateTracker派生自Handler的虚拟类ServiceStateTracker ,提供CdmaService 状态的管理。 CdmaServiceStateTracker对象也维护CELL 位置信息, 因此和GsmServiceStateTracker相同包含两个CdmaCellLocation对象成员cellLoc( 记录CELL当前位置) , newCellLoc(记录CELL 新的位置  ),用来记录CELL位置信息。

资源下载