Andriod messaging: Radio Interface layer


Android SDK provides apis for sending sms and receiving SMS
The two primary classes as part of  android.telephony package used for developing SMS application are
1)SMSManager
2)SMSMessage

SMS Send :

SMSManager class has api sendTextMessage(String destination_Address,String service_center address,String message,
PendingIntent sentIntent,Pending deliveryIntent)

destination_Address
:  MDN no of sms receiver
Service_center_address :The service center address is retrieved from SIM.If null,sms packet will be routed to default MSC
Message :text message to send.

PendingIntent

Pending Intent (android.app.PendingIntent)
Android has provided PendingIntent class which defines an intent and the components which can handle the intent to perform specific task.
The sent pendingIntent,sendIntent which is called  from telephonic framework when sms is sent.
SMS is sent when sms packet is received by SMSC.

Delivery Intent :

The pendingIntent deliveryIntent defines an the application component which is fired when telephoy framework broadcast the delivery status of message. The SMSC forwards the message to SMS receiver .When it receives ack from sms receiver,it sends special message called Status report. This is sent only when sender has requested for delivery report.The particular field has to be set in SMS pdu packet. When telephony framework receives the status report message,it broadcast the sms delivery status.
The delivery intent is null if user has not enabled message delivery option in Message setting.

For example
SMSManager sm=sms.getDefault();
sm.sendTextMessage(” 944437890″,NULL,”hello”,si,di);

The instance of sent penidingIntent,si is obtained by
PendingIntent si = PendingIntent.getBroadcast(context, 0, new Intent(“SMS_SENT_ACTION), 0);

The above argumented context must register broadcast receiver  sentIntent :
context.registerReceiver(sentIntent,new IntentFilter(“SMS_SENT_ACTION”);

By registering broadcast receiver,the sentIntent receiver is called when sms sent event is dispatched by SMSDispacther of Telephony Framework. through si.send() call.

BroadcastReceiver sentIntent =new BroadcastReceiver(
public void OnReceive(Intent intent)
{
switch(intet.resultCode)
{
case :A\ctivity.OK :
“sms sent successfully ,move to sent folder with sent status”
case : SMSManager.RESULT_ERROR_GENERIC_FAILURE :
“sms failed ”
case :SMSManager.RESULT_ERROR_NO_SERVICW
“push the message in the sms queue database,message will be sent when network service will be available,move to outbox”
}  } );

The Application sends next message when the sent intent of previous message is arrived.Each typed message is queued in sms database.The next message from the top of the queue is taken when sent event of previous message is processed.This way messages are sent sequentially.

The delivery Intent di is obtained by
PendingIntent deliveredPI = PendingIntent.getBroadcast(context, 0, new Intent(“SMS_DELIVERED_ACTION), 0);
Like sentIntent,the context has to register broadcast receiver,which be would handled when sms application receives the delivery of the message from framework
through delivery intent
The telephony intent broadcast with the deliveryIntent’s intent and the receiver deliveryIntent is triggered.

context.registerReceiver(deliveryIntent,new IntentFilter(“SMS_DELIVERED_ACTION)
BroadcastReceiver deliveryIntent =new BroadcastReceiver(
{
public void onReceiver(Intent intent)
{
if(getResultCode==Activity.OK)
“sms delivered update the status of sms to delivered in the sent folder”
}});

SMS Framework :SMS Apis,sendtextMessage calls SMS framework classes.The main class is SMSDispatcher which handles incoming and outgoing sms transaction and interacts with application through intent.The sms framework can send sms over CS(circuit switched) or PS(packet switch) network

For CS,framework will make RIL request to RIL(radio interface layer) layer of android telephony,RIL layer sends request to MODEM.MODEM route sms packet in form of data burst message to Base station.

For PS,Framework dispatch pdu to SIP stack ,which forms SIP(session initiation protocol) packet  and send to registered SIP server. The SMS framework is part of phone process and it is initialized on bootup. SMS framework forms transport layer sms pdu from the input parameters ,destination_no,message,sent intent,delivery intent.

The pdu is formed as per 3gpp2 sms Specification for sms over CDMA channel and 3gpp spec for sms to be sent over GSM based channel.

SMS RECEIVE :

Whenever phone boots up,the smsDispatcher(part of phone process),registers itself as handler to RIL(radio interface layer)
Whenever RIL receives unsolicited sms receive command from MODEM,it calls the sms handler with NEW_SMS_RECEIVE event and
smsDispatcher post the sms receive event to SMS application. The SMS application receives the new sms intent from framework and intent data contains SMS pdu which is byte array. The application creates android.telephony.SMSMessage object from received pdu through SDK class

SMSMesssage msg=SMSMessage.creatFromPdu(pdu)
The message display to display on UI can be obtained from msg Object as

String text=msg.getDisplayMessageBody()
String origination_no = msg.getDisplayOriginatingAddress()

The application should include the required permissions android.permission.SEND_SMS and android.permission.RECEIVE_SMS in sms application’s android.manifest file.

About Author

Jainendra Kumar is Android developer. He has rich experience in developing commercial Android application. He received B.E (Gold Medalist) from BIT Mesra and M.S from BITS Pilani.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s