一 初始化

手机开机初始化调用GSMPhone 构造函数。

GSMPhone (Context context, CommandsInterface ci, PhoneNotifier notifier, boolean unitTestMode)

创建 mSMS = new GsmSMSDispatcher(this);

该类继承于SMSDispatcher。类SMSDispatcher中构造函数中初始化了 短信的消息

mCm.setOnNewSMS(this, EVENT_NEW_SMS, null);

mCm.setOnSmsStatus(this, EVENT_NEW_SMS_STATUS_REPORT, null);

mCm.setOnIccSmsFull(this, EVENT_ICC_FULL, null);

handleMessage定义了sms的消息处理函数

public void handleMessage(Message msg) {

……

case EVENT_NEW_SMS:

……

}

mSimSmsIntManager = new SimSmsInterfaceManager(this);

SimSmsInterfaceManager继承于IccSmsInterfaceManager 为Isms.stub的实现类.

在IccSmsInterfaceManager 类实现了 Isms.adil. 中定义的方法,以实现远程调用。

二 短信发送

短信发送调用接口

SmsManager sms = SmsManager.getDefault();

sms.sendTextMessage(string1, null, string2, p, null);

sendTextMessage 调用 sendRawPdu。

在sendRawPdu中 创建了

ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));

通过aidl接口,实例化 IccSmsInterfaceManager. 调用 smsDispatcher.java中

protected void sendRawPdu(byte[] smsc, byte[] pdu, PendingIntent sentIntent,

PendingIntent deliveryIntent) 函数。

而后通过stub 接口调用sendSMS 接口。

RIL.java 中 sendSMS

public void

sendSMS (String smscPDU, String pdu, Message result) {

RILRequest rr

= RILRequest.obtain(RIL_REQUEST_SEND_SMS, result);

…..

send(rr);

}

发送 RIL_REQUEST_SEND_SMS 的 Request 请求到rild层。

Rild与modem之间联系与其它应用类似,不再重复。

三 短信的接收

Modem 与rild之间不再重复。从ril层中收到消息开始。

Ril.java中 rilReceiver 收到信短信消息processResponse(p); 收到短信属于主动上报

调用processUnsolicited函数。

private void processUnsolicited (Parcel p) {

………

case RIL_UNSOL_RESPONSE_NEW_SMS: ret = responseString(p); break;

…….

switch(response) {

case RIL_UNSOL_RESPONSE_NEW_SMS: {

…….

SmsMessage sms;

…….

sms = SmsMessage.newFromCMT(a);

if (mSMSRegistrant != null) {

mSMSRegistrant

.notifyRegistrant(new AsyncResult(null, sms, null));

}

break;

}

…….

}

mSMSRegistrant 调用到Registrant.java文件中notifyRegistrant方法。

internalNotifyRegistrant 调用sendMessage 方法。

public void notifyRegistrant(AsyncResult ar)

{

internalNotifyRegistrant (ar.result, ar.exception);

}

internalNotifyRegistrant 收到消息后将消息发送到消息队列。

/*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);

}

}

sendMessage 依次调用Handler.java 文件中 sendMessage->sendMessageDelayed-> sendMessageAtTime 在 sendMessageAtTime中将该短信消息加入到 消息队列中。

sent = queue.enqueueMessage(msg, uptimeMillis);

public boolean sendMessageAtTime(Message msg, long uptimeMillis)

{

boolean sent = false;

MessageQueue queue = mQueue;

if (queue != null) {

msg.target = this;

sent = queue.enqueueMessage(msg, uptimeMillis);

}

else {

RuntimeException e = new RuntimeException(

this + " sendMessageAtTime() called with no mQueue");

Log.w("Looper", e.getMessage(), e);

}

return sent;

}

Looper.java 中loop方法。用于将消息队列中消息dispatch出去。
public static final void loop() {

Looper me = myLooper();

MessageQueue queue = me.mQueue;

while (true) {

Message msg = queue.next(); // might block

//if (!me.mRun) {

// break;

//}

if (msg != null) {

if (msg.target == null) {

// No target is a magic identifier for the quit message.

return;

}

if (me.mLogging!= null) me.mLogging.println(

">>>>> Dispatching to " + msg.target + " "

+ msg.callback + ": " + msg.what

);

msg.target.dispatchMessage(msg);

if (me.mLogging!= null) me.mLogging.println(

"<<<<< Finished to " + msg.target + " "

+ msg.callback);

msg.recycle();

}

}

}

dispatchMessage函数调用当前handle的消息处理函数。

public void dispatchMessage(Message msg) {

if (msg.callback != null) {

handleCallback(msg);

} else {

if (mCallback != null) {

if (mCallback.handleMessage(msg)) {

return;

}

}

handleMessage(msg);

}

}

调用到smsDispatcher.java中

public void handleMessage(Message msg) {

AsyncResult ar;

switch (msg.what) {

case EVENT_NEW_SMS:

………

}

}

从而实现了对新收到的短信的处理。

更多相关文章

  1. [置顶] Android服务器推送之GCM
  2. ServiceManager & SystemService
  3. Qt example之Joke for Android( make for my honey)
  4. ExpandableListActivity 使用
  5. Android(安卓)Camera调用流程
  6. Android(安卓)JNI开发摘录(二)之JNI数组处理
  7. Android(安卓)使用Instrumentation进行界面的单元测试
  8. Android分享小程序并且互跳(小程序回到APP、APP跳转小程序)
  9. Android通知系统

随机推荐

  1. android 监听应用前后台运行状态
  2. android4.4.2 bluetooth解析(二)
  3. android ADB 详解
  4. Android自带音频均衡器MusicFx分析
  5. android同一个程序中使用多个地图出现混
  6. Android关闭JIT的方法
  7. Android学习笔记_布局文件属性的说明
  8. Java EE 6 SDK+Eclipse JEE+Android(安卓
  9. Android Choreographer 源码笔记
  10. 调用系统计算器 android(适用于不同品牌)