Android 电话通知机制原理分析

上传人:nbwa****ajie 文档编号:49062170 上传时间:2018-07-23 格式:PPTX 页数:11 大小:56.95KB
返回 下载 相关 举报
Android 电话通知机制原理分析_第1页
第1页 / 共11页
Android 电话通知机制原理分析_第2页
第2页 / 共11页
Android 电话通知机制原理分析_第3页
第3页 / 共11页
Android 电话通知机制原理分析_第4页
第4页 / 共11页
Android 电话通知机制原理分析_第5页
第5页 / 共11页
点击查看更多>>
资源描述

《Android 电话通知机制原理分析》由会员分享,可在线阅读,更多相关《Android 电话通知机制原理分析(11页珍藏版)》请在金锄头文库上搜索。

1、Android 电话通知机制原理分析概述 电话中如何注册通知 通知机制数据结构分析 底层通知机制分析 典型流程通知机制分析电话中如何注册通知 在InCallScreen中注册 InScreen.java: onCreate()-registerForPhoneStates()- mCM.registerForPreciseCallStateChanged(mHandler,PHON E_STATE_CHANGED, null); 调用时机:设备启动后第一次拨打电话或者接到电话 时。 在CallNitifier中注册 PhoneApp.java: onCreate() - notifier =

2、new CallNotifier(this, phone, ringer, mBtHandsfree, new CallLogAsync(); CallNotifier.java: 构造函数中-registerForNotifications()- mCM.registerForNewRingingConnection(this, PHONE_NEW_RINGING_CONNECTION, null); 设备启动时自动注册电话中如何注册通知CallManager 中如何注册通知 PhoneApp.java, onCreate()-mCM = CallManager.getInstance();

3、mCM.registerPhone(phone); CallManager.java: registerPhone()- registerForPhoneStates(basePhone)- phone.registerForNewRingingConnection(mHandler, EVENT_NEW_RINGING_CONNECTION, null); CallManager 中的注册函数说明:registerForCallWaiting、 registerForInCallVoicePrivacyOff、 registerForNewRingingConnection、register

4、ForDisconnect 等大概有10多个注册函数是用来供InCallScreen 和 CallNotifier 调用来注册相应的通知。 这两套注册函数的区别:电话中如何注册通知 CallManager 中如何注册通知1和2中调用的注册函数是CallManager通过调用PhoneBase类 的注册函数来实现的。他的用途是让底层上报通知到 CallManager. 3中实现的注册函数是CallManager实现了供InCallScreen 和 CallNotifier调用的。也就是说,当CallManager收到底层的事 件通知后,根据上面调用的情况,决定将哪个事件通知给 InCallScr

5、een 或者 CallNotifier.电话中如何注册通知 Phone 中如何注册通知 实现了registerForCallWaiting、 registerForInCallVoicePrivacyOff、 registerForNewRingingConnection、registerForDisconnect 等大概有10多个注册函数是用来供CallManager调用实现 注册相应的通知。 在GsmPhone的构造函数中调用了 mCM.registerForAvailable(this, EVENT_RADIO_AVAILABLE,null);mSIMRecords.registerFo

6、rRe cordsLoaded(this, EVENT_SIM_RECORDS_LOADED, null); mCM.registerForOffOrNotAvailable(this,EVENT_RADIO_OFF _OR_NOT_AVAILABLE, null);mCM.registerForOn(this, EVENT_RADIO_ON, null); 此处的mCM正是 CommandInterface接口的实现类RIL的实例。可以认为这 个类是java 框架中电话通知的发起的源头。通知机制数据结构分析 通知实现函数源码分析:各个类中的实现都很类似,因此只copy了CallManager

7、中的 registerForDisconnect 作为示例进行分析。 public void registerForDisconnect(Handler h, int what, Objectobj ) mDisconnectRegistrants.addUnique(h, what, obj); protected final RegistrantList mDisconnectRegistrants = new RegistrantList(); 每一个register函数都有一个相对应的unregister函数和一 个notify函数。或者在handleMessage函数中直接处理。Re

8、gistrantList 源码public class RegistrantList ArrayList registrants = new ArrayList(); / of Registrantpublic synchronized voidaddUnique(Handler h, int what, Object obj)/ if the handler is already in the registrant list, remove itremove(h);add(new Registrant(h, what, obj); private synchronized voidinter

9、nalNotifyRegistrants (Object result, Throwable exception)for (int i = 0, s = registrants.size(); i s ; i+) Registrant r = (Registrant) registrants.get(i);r.internalNotifyRegistrant(result, exception); Registrant 源码public class Registrant public Registrant(Handler h, int what, Object obj)refH = new W

10、eakReference(h);this.what = what;userObj = obj;/*package*/ void internalNotifyRegistrant (Object result, Throwable exception)Handler h = getHandler();if (h = null) clear(); else Message msg = Message.obtain();msg.what = what;msg.obj = new AsyncResult(userObj, result, exception);h.sendMessage(msg);We

11、akReference refH;int what;Object userObj; 通知机制数据结构分析 从对前面的源码分析可知,当调用每个notify 函数或者类似下面的直接调用时,最终会调 用到register函数中指定的Message handle 的 sendMessage 函数。 mDisconnectRegistrants.notifyRegistrants(Asyn cResult) msg.obj);底层通知机制分析 根据上面的分析,我们可以得出如下的流程CallNotifilerInCallScreenCallManagerPhoneRILprocessResponse: notify to phone/callManagerhandleMessage: notify to callManagerhandleMessage: notify to CallNotifier and InCallScreenhandleMessagehandleMessage

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 其它办公文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号