Detailed analysis of the sending process of short messages:
1. interface function called by upper-Layer Development: smsmanager. getdefault (). sendtextmessage ()
Function implementation:
Public 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"); // register the service in the binder and call the underlying interface through iccisms
If (iccisms! = NULL ){
Iccisms. sendtext (destinationaddress, scaddress, text, sentintent, deliveryintent); // call the underlying function
}
} Catch (RemoteException ex ){
// Ignore it
}
}
2. Processing sendtext in isms
I found two functions in isms. java. Why are there two functions?
One of them is iccisms. sendtext.
The other is: proxy: sendtext
You can see that we want the first one at a glance. But when we look at the first function, we find that it is not implemented... Why? At this time, we need to talk about a mechanism: binder, which is a zombie here. The interface provided here is the interface of the binder client. The specific implementation is in the service of the binder.
3. Find the sendtext implemented in the binder Service
Sendtext is in the smsdispatcher. Java file, but its implementation is in the smsdispatcher. Java or cdmasmsdispatcher. Java file.
Protected void sendtext (string destaddr, string scaddr, string text,
Pendingintent sentintent, pendingintent deliveryintent)
{
Smsmessage. submitpdu PDU = smsmessage. getsubmitpdu (
Scaddr, destaddr, text, (deliveryintent! = NULL ));
Sendrawpdu (PDU. encodedscaddress, PDU. encodedmessage, sentintent, deliveryintent );
}
4. The sendrawpdu function is returned to the smsdispatcher. Java file,
Protected void sendrawpdu (byte [] SMSC, byte [] PDU, pendingintent sentintent,
Pendingintent deliveryintent)
{
If (PDU = NULL)
{
If (sentintent! = NULL)
{
Try
{
Sentintent. Send (result_error_null_pdu );
} Catch (canceledexception ex ){}
}
Return;
}
Hashmap <string, Object> map = new hashmap <string, Object> ();
Map. Put ("SMSC", SMSC );
Map. Put ("PDU", PDU );
Smstracker tracker = new smstracker (MAP, sentintent,
Deliveryintent );
Int Ss = mphone. getservicestate (). getstate ();
If (SS! = Servicestate. state_in_service ){
Handlenotinservice (SS, tracker );
} Else {
String appname = getappnamebyintent (sentintent );
If (mcounter. Check (appname, single_part_sms )){
Sendsms (tracker );
} Else {
Sendmessage (obtainmessage (event_post_alert, tracker ));
}
}
}
5. sendsms sees that this function is not far from actually working. This function ran to the gsmsmsdispatcher. Java or cdmasmsdispatcher. Java file, indicating that there are still some differences between the implementation methods of the two networks.
Protected void sendsms (smstracker tracker ){
Hashmap map = tracker. mdata;
Byte SMSC [] = (byte []) map. Get ("SMSC ");
Byte PDU [] = (byte []) map. Get ("PDU ");
Message reply = obtainmessage (event_send_sms_complete, tracker );
MCM. sendsms (iccutils. bytestohexstring (SMSC ),
Iccutils. bytestohexstring (PDU), reply );
}
It is worth mentioning that the member variable of MCM is declared as commandsinterface (how to run such a thing ?) This is the interface layer of the RIL layer, which provides the RIL implementation function.
Here we can go through the RIL mechanism and find the desired function implementation. Commandsinterface. Java only provides interfaces, which are implemented in RIL. java.
6. sendsms this function is in RIL. Java to see how it is implemented. (What is this? I don't understand it)
Public void
Sendsms (string smscpdu, string PDU, message result ){
Rilrequest rr
= Rilrequest. Obtain (ril_request_send_sms, result );
Rr. MP. writeint (2 );
Rr. MP. writestring (smscpdu );
Rr. MP. writestring (PDU );
If (rilj_logd) riljlog (RR. serialstring () + ">" + requesttostring (RR. mrequest ));
Send (RR );
}
RIL. the implementation method in Java is basically like sending (RR), which is actually the RIL mechanism. java is actually a proxy of rild. He is responsible for sending messages to rild and notifying him to perform specific operations.
7. Check who has handled the ril_request_send_sms message to know who is working.
Onrequest
This function is used to process messages. The corresponding case ril_request_send_sms will call the corresponding function requestsendsms (data, datalen, t );
8. Let's look at how to edit the request to the AT command and send it to the CP layer. This is the true meaning of RIL. There is no need to write it again.