hailushijie的专栏

转载请注明出处:

2,短彩信发送framework逻辑

相关文章:

————————————————————-

1、短信发送上层逻辑

3、短信发送framework层逻辑

————————————————————-

短信在SmsSingleRecipientSender.java中包装了SentIntents,以及DeliveryIntents,信息的内容在message中,信息的目的发送地址在mDest中,然后调用下面的代码进行信息的发送

smsManager.sendMultipartTextMessage(mDest, mServiceCenter, messages, sentIntents, deliveryIntents);smsMessager对应的类为:SmsManager.java

2.1 进入SmsManager.java

public void sendMultipartTextMessage(String destinationAddress, String scAddress, ArrayList<String> parts,ArrayList<PendingIntent> sentIntents, ArrayList<PendingIntent> deliveryIntents) {if (TextUtils.isEmpty(destinationAddress)) {throw new IllegalArgumentException("Invalid destinationAddress");}if (parts == null || parts.size() < 1) {throw new IllegalArgumentException("Invalid message body");}if (parts.size() > 1) {try {ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));if (iccISms != null) {iccISms.sendMultipartText(destinationAddress, scAddress, parts,sentIntents, deliveryIntents);}} catch (RemoteException ex) {// ignore it}} else {PendingIntent sentIntent = null;PendingIntent deliveryIntent = null;if (sentIntents != null && sentIntents.size() > 0) {sentIntent = sentIntents.get(0);}if (deliveryIntents != null && deliveryIntents.size() > 0) {deliveryIntent = deliveryIntents.get(0);}sendTextMessage(destinationAddress, scAddress, parts.get(0),sentIntent, deliveryIntent);}}在这个类中,主要是根据parts的数量,进行跨进程调用ISms服务。如果是多条信息,执行:iccISms.sendMultipartText(destinationAddress, scAddress, parts,sentIntents, deliveryIntents);

这里调用的ISms服务的sendMultipartText方法。

如果是单条信息,执行sendTextMessagepublic void sendTextMessage(String destinationAddress, String scAddress, String text,PendingIntent sentIntent, PendingIntent deliveryIntent) {if (TextUtils.isEmpty(destinationAddress)) {throw new IllegalArgumentException("Invalid destinationAddress");}if (TextUtils.isEmpty(text)) {throw new IllegalArgumentException("Invalid message body");}try {ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));if (iccISms != null) {iccISms.sendText(destinationAddress, scAddress, text, sentIntent, deliveryIntent);}} catch (RemoteException ex) {// ignore it}}同样的,要调用ISms服务。只不过方法变成了Isms服务的sendText方法

关于iSms服务的注册,它是在初始化phone进程时注册的

public IccSmsInterfaceManagerProxy(IccSmsInterfaceManagericcSmsInterfaceManager) {this.mIccSmsInterfaceManager = iccSmsInterfaceManager;if(ServiceManager.getService("isms") == null) {ServiceManager.addService("isms", this);}}然后我们进到IccSmsInterfaceManagerProxy.java中

2.2 IccSmsManagerProxy.java

public void sendText(String destAddr, String scAddr,String text, PendingIntent sentIntent, PendingIntent deliveryIntent) {mIccSmsInterfaceManager.sendText(destAddr, scAddr, text, sentIntent, deliveryIntent);}public void sendMultipartText(String destAddr, String scAddr,List<String> parts, List<PendingIntent> sentIntents,List<PendingIntent> deliveryIntents) throws android.os.RemoteException {mIccSmsInterfaceManager.sendMultipartText(destAddr, scAddr,parts, sentIntents, deliveryIntents);}代理类中进行实现

2.3 iccSmsManager.java

public void sendMultipartText(String destAddr, String scAddr, List<String> parts,List<PendingIntent> sentIntents, List<PendingIntent> deliveryIntents) {mPhone.getContext().enforceCallingPermission("android.permission.SEND_SMS","Sending SMS message");if (Log.isLoggable("SMS", Log.VERBOSE)) {int i = 0;for (String part : parts) {log("sendMultipartText: destAddr=" + destAddr + ", srAddr=" + scAddr +", part[" + (i++) + "]=" + part);}}mDispatcher.sendMultipartText(destAddr, scAddr, (ArrayList<String>) parts,(ArrayList<PendingIntent>) sentIntents, (ArrayList<PendingIntent>) deliveryIntents);} public void sendText(String destAddr, String scAddr,String text, PendingIntent sentIntent, PendingIntent deliveryIntent) {mPhone.getContext().enforceCallingOrSelfPermission("android.permission.SEND_SMS","Sending SMS message");if (Log.isLoggable("SMS", Log.VERBOSE)) {log("sendText: destAddr=" + destAddr + " scAddr=" + scAddr +" text=’"+ text + "’ sentIntent=" +sentIntent + " deliveryIntent=" + deliveryIntent);}mDispatcher.sendText(destAddr, scAddr, text, sentIntent, deliveryIntent);}最终他们都要调到mDispatcher的sendText或者sendMultipartText方法,mDispatcher的原型类:SMSDispatcher,它有两个子类,GsmSmsDispatcher.java以及CdmaSmsDispatcher.java上帝从不埋怨人们的愚昧,人们却埋怨上帝的不公

hailushijie的专栏

相关文章:

你感兴趣的文章:

标签云: