ImageVerifierCode 换一换
格式:DOCX , 页数:46 ,大小:31.13KB ,
资源ID:10518190      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/10518190.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(RIL短信接收和发送流程分析最新版android.docx)为本站会员(b****8)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

RIL短信接收和发送流程分析最新版android.docx

1、RIL短信接收和发送流程分析最新版android(RIL)短信接收和发送流程分析最新版(android ) 参考网站: 为了能更好的了解android接收短信的流程,我进行了更深入的分析,从RIL的通信架构来分析当接收到短信的整个流程。从frameword里的RIL.java(观察360的短信拦截和QQ管家的短信拦截,发现先安装的就能先拦截到的短信,然后中断广播,之后谁都不能获取到短信。从这里可以推出系统大概有一个广播表,同等级的按安装先后顺序排放。目前的方法是在应用层调用framework API进行控制的) 文件可以看出发送短信和接收短信是通过Receiver和Sender架构,发送短信主

2、要通过Sender框架,主要如下(图是从网上窃滴): 上层函数调用Command Interface将请求消息发送到sender架构,由该架构将请求发送到RILD的架构。补充发送的子类 class RILSender extends Handler implements Runnable public RILSender(Looper looper) super(looper); / Only allocated once byte dataLength = new byte4; /* Runnable implementation public void run() /setup if ne

3、eded /* Handler implementation Override public void handleMessage(Message msg) RILRequest rr = (RILRequest)(msg.obj); RILRequest req = null; switch (msg.what) case EVENT_SEND: /* * mRequestMessagePending+ already happened for every * EVENT_SEND, thus we must make sure * mRequestMessagePending- happe

4、ns once and only once */ boolean alreadySubtracted = false; try LocalSocket s; s = mSocket; if (s = null) rr.onError(RADIO_NOT_AVAILABLE, null); rr.release(); if (mRequestMessagesPending 0) mRequestMessagesPending-; alreadySubtracted = true; return; synchronized (mRequestsList) mRequestsList.add(rr)

5、; mRequestMessagesWaiting+; if (mRequestMessagesPending 0) mRequestMessagesPending-; alreadySubtracted = true; byte data; data = rr.mp.marshall(); rr.mp.recycle(); rr.mp = null; if (data.length RIL_MAX_COMMAND_BYTES) throw new RuntimeException( Parcel larger than max bytes allowed! + data.length); /

6、 parcel length in big endian dataLength0 = dataLength1 = 0; dataLength2 = (byte)(data.length 8) & 0xff); dataLength3 = (byte)(data.length) & 0xff); /Log.v(LOG_TAG, writing packet: + data.length + bytes); s.getOutputStream().write(dataLength); s.getOutputStream().write(data); catch (IOException ex) L

7、og.e(LOG_TAG, IOException, ex); req = findAndRemoveRequestFromList(rr.mSerial); / make sure this request has not already been handled, / eg, if RILReceiver cleared the list. if (req != null | !alreadySubtracted) rr.onError(RADIO_NOT_AVAILABLE, null); rr.release(); catch (RuntimeException exc) Log.e(

8、LOG_TAG, Uncaught exception , exc); req = findAndRemoveRequestFromList(rr.mSerial); / make sure this request has not already been handled, / eg, if RILReceiver cleared the list. if (req != null | !alreadySubtracted) rr.onError(GENERIC_FAILURE, null); rr.release(); finally / Note: We are Done only if

9、 there are no outstanding / requests or replies. Thus this code path will only release / the wake lock on errors. releaseWakeLockIfDone(); if (!alreadySubtracted & mRequestMessagesPending 0) mRequestMessagesPending-; break; case EVENT_WAKE_LOCK_TIMEOUT: / Havent heard back from the last request. Ass

10、ume were / not getting a response and release the wake lock. synchronized (mWakeLock) if (mWakeLock.isHeld() / The timer of WAKE_LOCK_TIMEOUT is reset with each / new send request. So when WAKE_LOCK_TIMEOUT occurs / all requests in mRequestList already waited at / least DEFAULT_WAKE_LOCK_TIMEOUT but

11、 no response. / Reset mRequestMessagesWaiting to enable / releaseWakeLockIfDone(). / / Note: Keep mRequestList so that delayed response / can still be handled when response finally comes. if (mRequestMessagesWaiting != 0) Log.d(LOG_TAG, NOTE: mReqWaiting is NOT 0 but + mRequestMessagesWaiting + at T

12、IMEOUT, reset! + There still msg waitng for response); mRequestMessagesWaiting = 0; if (RILJ_LOGD) synchronized (mRequestsList) int count = mRequestsList.size(); Log.d(LOG_TAG, WAKE_LOCK_TIMEOUT + mRequestList= + count); for (int i = 0; i 0 & retryCount 8) Log.i (LOG_TAG, Couldnt find + rilSocket +

13、socket; retrying after timeout); try Thread.sleep(SOCKET_OPEN_RETRY_MILLIS); catch (InterruptedException er) retryCount+; continue; retryCount = 0; mSocket = s; Log.i(LOG_TAG, Connected to + rilSocket + socket); int length = 0; try InputStream is = mSocket.getInputStream(); for (;) Parcel p; length

14、= readRilMessage(is, buffer); if (length 0) / End-of-stream reached break; p = Parcel.obtain(); p.unmarshall(buffer, 0, length); p.setDataPosition(0); /Log.v(LOG_TAG, Read packet: + length + bytes); processResponse(p); p.recycle(); catch (java.io.IOException ex) Log.i(LOG_TAG, + rilSocket + socket c

15、losed, ex); catch (Throwable tr) Log.e(LOG_TAG, Uncaught exception read length= + length + Exception: + tr.toString(); Log.i(LOG_TAG, Disconnected from + rilSocket + socket); setRadioState (RadioState.RADIO_UNAVAILABLE); try mSocket.close(); catch (IOException ex) mSocket = null; RILRequest.resetSer

16、ial(); / Clear request list on close clearRequestsList(RADIO_NOT_AVAILABLE, false); catch (Throwable tr) Log.e(LOG_TAG,Uncaught exception, tr); /* Were disconnected so we dont know the ril version */ notifyRegistrantsRilConnectionChanged(-1); 因此从代码可以看出获取到短信消息后经过一系列地分析然后提交给processResponse(p); 方法处理,处理

17、过程中会有两种response,一种是主动上报,比如网络状态,短信,来电等都不需要经过请求,用unsolicited词语专门描述,另一种才是真正意义上的response,也就是命令的响应用solicited描述。那接收短信就是属于unsolicited,跳到processUnsolicited (Parcel p)方法,查看该方法可得出会继续触发以下方法mSMSRegistrant.notifyRegistrant(new AsyncResult(null, sms, null);追溯该方法对象的创建,最后发现该方法设置handler的源头是在:SMSDispatcher类里 该类做了一件重要

18、的事:给Command Interface设置handler的处理方法,就是当接收到短信后触发mSMSRegistrant.notifyRegistrant(new AsyncResult(null, sms, null);方法,然后回调调用之前传入的handler,接着在handler里面处理短信消息。mCm.setOnNewSMS(this, EVENT_NEW_SMS, null);mCm.setOnSmsStatus(this, EVENT_NEW_SMS_STATUS_REPORT, null);mCm.setOnIccSmsFull(this, EVENT_ICC_FULL, nu

19、ll);mCm.registerForOn(this, EVENT_RADIO_ON, null);handler处理接收到的短信消息:Override public void handleMessage(Message msg) AsyncResult ar; switch (msg.what) case EVENT_NEW_SMS: / A new SMS has been received by the device if (Config.LOGD) Log.d(TAG, New SMS Message Received); SmsMessage sms; ar = (AsyncResu

20、lt) msg.obj; if (ar.exception != null) Log.e(TAG, Exception processing incoming SMS. Exception: + ar.exception); return; sms = (SmsMessage) ar.result; try int result = dispatchMessage(sms.mWrappedSmsMessage); if (result != Activity.RESULT_OK) / RESULT_OK means that message was broadcast for app(s) t

21、o / handle. / Any other result, we should ack here. boolean handled = (result = Intents.RESULT_SMS_HANDLED); notifyAndAcknowledgeLastIncomingSms(handled, result, null); catch (RuntimeException ex) Log.e(TAG, Exception dispatching message, ex); notifyAndAcknowledgeLastIncomingSms(false, Intents.RESULT_SMS_GENERIC_ERROR, null); break; int result = dispatchMessage(sms.mWrappedSmsMessage); 该段会通过子类(GsmSMSDispatcher)的dispatchMessage方法处理。经一系列的判断处理最后普通短信将交给dispatchPdus(pdus);这个方法处理。protected void

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1