Android Telephony 分析[PART IV]

Open telephony packages:

frameworks/base/telephony/java/android/telephony

      

TelephonyManager provides a way for 3rd application  interacting with internal telephony packages.

Class Overview (from android sdk document)

Provides access to information about the telephony services on the device. Applications can use the methods in this class to determine telephony services and states, as well as to access some types of subscriber information. Applications can also register a listener to receive notification of telephony state changes.

You do not instantiate this class directly; instead, you retrieve a reference to an instance throughContext.getSystemService(Context.TELEPHONY_SERVICE).

Note that access to some telephony information is permission-protected. Your application cannot access the protected information unless it has the appropriate permissions declared in its manifest file. Where permissions apply, they are noted in the the methods through which you access the protected information.


[原创]Android Telephony 分析[PART IV] - 〇〇柒 - 朝阳光出发

  这个 详细 一下, 这个 演示 第三方 用, P hone S ervic e 及T elephony 关系。

第一条主线,TelephonyManager上半部分PhoneApp一个非常特殊app,通过调用PhoneFactory'创建一个Telephony(Internal),同时第三方application暴露接口,通过TelephonyManager调用,TelephonyManager通过ITelephonyandroid的AIDL机制)获得PhoneInterfaceManager远程对象然后第三方application通过这个远程对象调用service方法这里调用两个独立进程之间进行如果不清楚aidl可以3rd application直接调用了PhoneInterfaceManager方法,实际上需要通过TelephonyManager才能调用


第二条主线,TelephonyManager右半部分,TelephonyRegistry,顾名思义,什么东西注册,这种注册一般都是为了实现回调功能这个类主要作用就是第三方Appnew 的PhoneStateListener需要监听动作通过调用TelephonyManager注册到TelephonyRegistry,底层状态变化通知GSMPhone时,GSMPhone的DefaultPhoneNotifier通知TelephonyRegistry,然后注册到TelephonyRegistry的PhoneStateListener监听事件会被触发(此时TelephonyRegistry还会发个boardCast),然后回调上层APP复写方法。

(要理清关系的最好办法就是结合图阅读源码,那样会有更深的理解)

如果上面机制看不懂也没关系,作为SDK开发只要知道以下部分行,


If we want to track telephony state in 3rd application:

 We should  retrive  an instance of  TelephonyManager  and get Phone service.      //needed
2  Implement a  PhoneStateListener  what you want to listen.                                         //not needed
3  You can also register a  BroadCastReceiver  to receive broadcast if you want.       //not needed
4  Don’t forget add permission in manifest file.                                                                //needed

Take Settings as example to show how to achieve these.

packages/apps/Settings/src/com/android/settings/deviceinfo/ Status.java

111     private TelephonyManager mTelephonyManager;

       

169     private PhoneStateListener mPhoneStateListener = new PhoneStateListener() {

170         @Override

171         public void onDataConnectionStateChanged(int state) {

               UpdateDataState();  //you can override with your own code here

       

178     protected void onCreate(Bundle icicle) {            

184         mTelephonyManager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);

268     protected void onResume() {

278             mTelephonyManager.listen(mPhoneStateListener,

279                       PhoneStateListener.LISTEN_DATA_CONNECTION_STATE);

337     private void updateDataState() {

338         int state = mTelephonyManager.getDataState();

341         switch (state) {



部分内容参考了http://wenku.baidu.com/view/49699c4f2e3f5727a5e96266.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值