Android telephony MMS Study Notes

Source: Internet
Author: User
Document directory
  • Basic processing of Android MMS

This article mainly describes how to process MMs in the Android system from the following aspects: MMS initialization, MMS sending, and MMS receiving (including pushing MMS receiving and extracting MMS content from mmsc) and MMS storage/deletion.

Basic knowledge of Android MMS

I. MMS Overview

MMS is a messaging service developed on the basis of the Short Message Service. It can be used to transmit texts, images, animations, audios, videos, and other multimedia information. MMS uses the "Storage and forwarding" technology, and the information created by the user can be automatically and quickly transmitted between the mobile phone and the mobile phone; the information is still transmitted Based on the mobile phone number of the recipient; when the receiver is shut down or is temporarily out of service, the information will be stored in the multimedia message center (mmsc) until it can be delivered correctly. The MMS Message Service requires a WAP Gateway, a data transmission network such as a circuit switching network, GPRS or WCDMA network, and a multimedia message center (mmsc ). Currently, the MMS service is mainly carried by WAP and notified by short messages, which are automatically extracted from the MMS mobile phone to the multimedia message center (mmsc.

In Android, the main processing of MMS is at the app layer. The framework layer mainly involves the parsing and processing of mms pdu packets and the network processing for sending and receiving MMS packets.

MMS uses the Telephony framework class. For more information, see the android_telephony_framework series documentation.

Ii. MMS Related Services
1. transactionservice
It mainly uses the corresponding transaction to process requests such as sending and receiving MMs. Transactionservice contains a servicehandler handler internal class for processing MMS related events.

3. MMS-related referers
1. pushreceiver
Accept intent. wap_push_received_action and start transactionservice to transmit the corresponding push data.
2. mmssystemeventreceiver
Accept mms. intents. content_changed_action, telephonyintents. action_any_data_connection_state_changed, and intent. action_boot_completed.

4. Handler related to MMS
1. smsdispatcher
The processing of SMS/MMS reporting events has two sub-classes: gsmsmsdispatcher and cdmasmsdispatcher, which are the handler classes of gsmphone and cdmaphone respectively.
2. wappushoversms
Although the wappushoversms class does not inherit from the handler class, its function is actually a handler class, which is implemented through the dispatch method of smsdispatcher. This class is used to send the received push PDU packets to the receiver of the application module in intent mode.

5. MMS-related transaction
1. Transaction
It is inherited from the observable class and is an abstract class of icationicationtransaction, readrectransaction, retrievetransaction, and sendtransaction.
2. icationicationtransaction
Inherits from the transaction class and implements the runnable interface. The main processing MMS notifications (M-Notification.ind) messages, that is, push MMS notification messages. Main functions:
1) determine whether to download MMS content from mmsc immediately based on the downloadmanager. mautodownload status.
2) Send a GET request to mmsc
3) Get M-Retrieve.conf data and parse
4) Save the received MMs to inbox
5) delete M-Notification.ind Information
6) Send the M-NotifyResp.ind to mmsc
7) after the processing is complete, notify transactionservice to handle the problem accordingly.
3. readrectransaction
Inherits from the transaction class and implements the runnable interface. Read report specifications (M-read-rec.ind) for MMS ). Main functions:
1) loads the Read report indication from storage (outbox). Read report indication PDU is retrieved from mmssms. DB.
2) packs M-read-rec.ind and sends it.
3) notifies the transactionservice about succesful completion.
4. retrievetransaction
Inherits from the transaction class and implements the runnable interface. The main processing is extracting MMS (M-Retrieve.conf) from mmsc ). Main functions:
1) sends a GET request to the mmsc Server
2) retrieves the binary M-Retrieve.conf data and parses it.
3) persists the retrieve multimedia message.
4) determines whether an acknowledgement is required.
5) creates appropriate M-Acknowledge.ind and sends it to mmsc server.
6) notifies the transactionservice about succesful completion.
5. sendtransaction
Inherits from the transaction class and implements the runnable interface. Mainly handle sending MMS to mmsc (M-Send.req ). Main functions:
1) loads the multimedia message from storage (outbox ).
2) packs M-Send.req and sends it.
3) retrieves confirmation data from the server (M-Send.conf ).
4) parses confirmation message and handles it.
5) moves sent multimedia message from outbox to sent.
6) notifies the transactionservice about successful completion.

6. MMS related providers

File

Class/Interface Name

Superclass/implementation Interface

Description

Telephonyprovider. Java

Telephonyprovider

Contentprovider

Access and encapsulation of information such as APN and proxy

Mmsprovider. Java

Mmsprovider

Contentprovider

MMS access

Mmssmsprovider. Java

Mmssmsprovider

Contentprovider

Provides unified reading of MMS and SMS, and does not support write operations

7. MMS related classes in the framework

Package or category

Path

Description

Com. Google. Android. MMS

Frameworks \ base \ core \ Java \ com \ google \ Android \ MMS

General content type class of the mms pdu package and MMS exception handling class

Com. Google. Android. mms. PDU

Frameworks \ base \ core \ Java \ com \ google \ Android \ MMS \ PDU

Parsing and processing of mms pdu packets

Com. Google. Android. mms. util

Frameworks \ base \ core \ Java \ com \ google \ Android \ MMS \ util

Storage Class of PDU package

Android. Provider

Frameworks \ base \ core \ Java \ Android \ provider

Data encapsulation class required by the corresponding provider

Android.net

Frameworks \ base \ core \ Java \ Android \ net

 

Android.net. HTTP

Frameworks \ base \ core \ Java \ Android \ net \ HTTP

 

Com. Google. Android. MMS

File

Class/Interface Name

Superclass/implementation Interface

Description

Contenttype. Java

Contenttype

 

Defines the supported Element Types of the PDU Package content, including the supported image and audio types

Invalidheadervalueexception. Java

Invalidheadervalueexception

Mmsexception

Exception Handling for PDU headers. thrown when the header value is invalid

Mmsexception. Java

Mmsexception

Exception

MMS exception Interface Class

Com. Google. Android. mms. PDU

File

Class/Interface Name

Superclass/implementation Interface

Description

Acknowledgeind. Java

Acknowledgeind

Genericpdu

M-Acknowledge.ind PDU, the validation message sent by the recipient to mmsc

Base64.java

Base64

 

Base64 Character Parsing

Charactersets. Java

Charactersets

 

MMS encoding type

Deliveryind. Java

Deliveryind

Genericpdu

Delivery report sent by M-Delivery.Ind PDU, mmsc to the sender

Multimediamessagepdu. Java

Multimediamessagepdu

Genericpdu

Multimedia Message PDU, mms pdu entity class

Notificationind. Java

Icationicationind

Genericpdu

M-Notification.ind PDU, MMS push notification message PDU

Notifyrespind. Java

Notifyrespind

Genericpdu

M-NofifyResp.ind PDU, return notification response to mmsc

Sendconf. Java

Sendconf

Genericpdu

M-Send.conf PDU, mmsc returns the send confirmation message to the sender

Pdubody. Java

Pdubody

 

Processing PDU body

Pducomposer. Java

Pducomposer

 

Make the corresponding data into the corresponding mms pdu package

Pduheaders. Java

Pduheaders

 

Parse MMS pdu header

Pduparser. Java

Pduparser

 

Mms pdu package resolution entry

Pdupersister. Java

Pdupersister

 

Mms pdu storage management class

Retrieveconf. Java

Retrieveconf

Multimediamessagepdu

M-Retrive.conf PDU

Sendreq. Java

Sendreq

Multimediamessagepdu

M-Send.req PDU

Com. Google. Android. mms. util

File

Class/Interface Name

Superclass/implementation Interface

Description

Abstractcache. Java

Abstractcache

 

Cache processing abstract class

Pducache. Java

Pducache

Abstractcache

PDU Cache

Pducacheentry. Java

Pducacheentry

 

PDU cache entry

Sqlitewrapper. Java

Sqlitewrapper

 

The Wrapper class of SQLite provides processing for the objects of the corresponding contentprovider class through the contentresolver object

Android. Provider

File

Class/Interface Name

Superclass/implementation Interface

Description

Telephony. Java

Telephony

 

Provides the data and operations required by the SMS/MMS provider, including the corresponding content_uri and other data.

Com. Google. Android. mms. utilcom. Google. Android. mms. util

The classes under these two packages are mainly used to operate the network. I do not know much about this.

 

Basic processing of Android MMS

The following process uses gsmphone as an example.

1. MMS Initialization
The initialization of MMS is basically the same as that of SMS. It only registers some events during the phoneapp initialization process, such as event_new_sms and event_new_sms_status_report. On the Android platform, there is no information data operation during MMS initialization. Android uses sqlite3 as the storage mechanism, and all MMS-related data is stored in mmssms. DB files are stored on mobile phones for a long time and will not be deleted. The operation on MMS is directly performed on the mmssms. DB database, so the MMS data is not processed in the initialization part. The following describes in detail the relationship between classes during MMS initialization and the event registration process:
1. Create the gsmsmsdispatcher instance msms: msms = new gsmsmsdispatcher (this) in the gsmphone constructor );
2. Call the gsmsmsdispatcher constructor and execute super (phone). Because the gsmsmsdispatcher inherits from the smsdispatcher class, the smsdispatcher constructor is actually implemented.
3. Execute the following statement in the smsdispatcher constructor:
MCM = phone. MCM; // MCM is the object of the commandsinterface interface class.
...............
MCM. setonnewsms (this, event_new_sms, null );
...............
In the setonnewsms method of the commandsinterface class, the registrant instance msmsregistrant is created to save the smsdispatcher handler object and event_new_sms event. When a new message is reported, the smsdispatcher handler object is obtained through the dispatch object, the event_new_sms event and corresponding data are sent to the handlemessage method of the smsdispatcher class through the message mechanism and handler processing mechanism.

Ii. MMS reception

1. Push MMS reception
The MMS notification message is passed in the form of a short message PDU package (M-Notification.ind PDU ). The specific process in Android is as follows:
1) when there is new information, the reader thread of the atchannel will call the onunsolicited () function for processing.
2) The onunsolicited () function calls the ril_onunsolicitedresponse () function and passes in the ril_unsol_response_new_sms value and corresponding data.
3) ril_onunsolicitedresponse () calls the sendresponse () function and transmits data to the RIL. Java layer through socket (socket name: socket_name_ril.
4) The RIL Java layer reads data from the socket through the rilreceiver receiver, and calls the processresponse () method in the RIL class after processing. The processresponse () method calls the processunsolicited () method.
5) in the processunsolicited () method, execute the following statement:
Case ril_unsol_response_new_sms :{
If (rilj_logd) unsljlog (response );
String a [] = new string [2];
A [1] = (string) ret;
Smsmessage SMS;
SMS = smsmessage. newfromcmt (a); // parse the PDU package based on the SMS Protocol
If (msmsregistrant! = NULL ){
Msmsregistrant. policyregistrant (New asyncresult (null, SMS, null ));
}
Break;
The msmsregistrant instance was created during initialization, and contains the smsdispatcher handler object and event_new_sms event information. Then, the event_new_sms event is passed to the smsdispatcher handler class for processing through the message mechanism and handler processing mechanism.
6) The smsdispatcher handler receives the event_new_sms event and calls the handlemessage () method for processing. The handlemessage () method calls its subclass dispatchmessage () method.
7) in dispatchmessage (), determine whether the push information is based on the smsheader. portaddrs (port_wap_push = 2948) address.
8) Call the dispatchwappdu () method of the wappushoversms class.
9) use the wsptypedecoder class instance to parse the push information and determine whether the push information is MMS based on the content type.
10) Call the dispatchwappdu_mms () method to broadcast and send intent. wap_push_received_action through the dispatch () method of the smsdispatcher class.
11) pushreceiver receives the intent, starts receivepushtas, and executes the doinbackground () method.
12) in the doinbackground () method, parse the corresponding PDU package through the pduparser class object, and then execute the following code:
Case message_type_icationication_ind :{
Notificationind nind = (notificationind) PDU;
If (! Isduplicatenotification (mcontext, nind )){
Uri uri = P. persist (PDU, inbox. content_uri); // The MMS push information is stored in inbox.
Intent SVC = new intent (mcontext, transactionservice. Class); // intent starts transactionservice.
SVC. putextra (transactionbundle. Uri, Uri. tostring ());
SVC. putextra (transactionbundle. transaction_type,
Transaction. icationication_transaction); // transaction type: icationication_transaction
Mcontext. startservice (SVC); // start the transactionservice
}
13) onstart () in the transactionservice class calls the launchtransaction () method
14) The launchtransaction () method is passed to the servicehandler event_transaction_request event.
15) The handlemessage () method of the servicehandler class processes the event_transaction_request event, creates icationicationtransaction class instances based on the transaction type, and extracts the PDU package from mmssms. DB according to the URI.
16) Call the processtransaction (transaction) method and execute the following code in the processtransaction () method:
Int connectivityresult = beginmmsconnectivity (); // perform data connection through the beginmmsconnectivity function.
If (connectivityresult = phone. apn_request_started) {// If the apn_request_started result is returned, the data connection is being connected and the event event_data_state_changed is returned.
Mpending. Add (transaction); // put transaction in the waiting queue
Return true; // return. Wait until the event_data_state_changed event is processed.
}
Transaction. attach (transactionservice. this); // because both the transaction class and transactionservice class inherit from the observable class, this is to notify transactionservice of the corresponding processing result after the transaction class is processed.
Transaction. Process (); // enter the notificationtransaction class for processing, and create a new thread to process the transaction.
17) See icationicationtransaction in MMS-related transaction.

2. Extract MMS from mmsc
According to the value of the mautodownload variable in the downloadmanager class, there are two scenarios for extracting MMS from mmsc:
1) if mautodownload is true, that is, automatic extraction is allowed, MMS information is extracted from mmsc when the indication notification comes up. Even in icationicationtransaction. For details, refer to icationicationtransaction description in MMS-related transaction.
2) Otherwise, you need to manually extract from mmsc. The specific process is as follows: at this time, the UI Layer starts transactionservice and passes in the transaction. retrieve_transaction type. For other processing procedures, see steps 13th to 17th in the first (push MMS receive), except that the corresponding transaction is retrievetransaction rather than icationicationtransaction.

3. Send by MMS
The sending action of MMS is triggered by the UI, mainly by the sendmmsworker () method in the composemessageactivity class. The specific process is as follows:
1. In the sendmmsworker () method, create an mmsmessagesender class instance sender and call the sendmessage () method in the mmsmessagesender class.
2. Extract the corresponding PDU data from mmssms. DB, move the information to outbox (previously stored in draft), and then start the transactionservice for transaction processing.
3. transactionservice is used to process the sendtransaction class run () method. For details, refer to sendtransaction description in MMS transaction.

4. MMS storage/deletion and other data operations
The storage of MMS information is based on sqlite3 and its mmssms. the database will always exist after the first creation, which makes it much easier to store mms. You only need to execute the corresponding SQL statement.
The content in MMS is stored in the file and not in the mmssms. DB database. The database stores the following tables:
Static final string table_pdu = "PDU"; // table of PDU-related information
Static final string table_addr = "ADDR"; // table related to the MMS sender/recipient address
Static final string table_part = "part"; // the body may be divided into several parts. The table that stores the part-related information can obtain the corresponding content from the file.
Static final string table_rate = "rate"; // sent_time information table
Static final string table_drm = "DRM ";
The above tables only store some related information. Through these tables, you can obtain the basic MMS information and read the corresponding MMS body from the file.
The understanding of the MMS storage mechanism mainly refers to the understanding of the content provider mechanism. The content provider mechanism mainly involves the following categories:

File

Class/Interface Name

Superclass/implementation Interface

Description

Sqlitedatabase. Java

Sqlitedatabase

Sqliteclosable

Sqllite database implementation class

Sqliteopenhelper. Java

Sqliteopenhelper

 

Auxiliary classes for managing database create, open, close, get, upgrade, and version information

Contentprovider. Java

Contentprovider

 

Allows different applications to access databases.

Contentresolver. Java

Contentresolver

 

The contentprovider encapsulation class that provides a unified access interface to the application. The contentprovider obtains the corresponding contentprovider object based on the URI.

Sqlitewrapper. Java

Sqlitewrapper

 

Encapsulation class of the contentresolver class provided to the application

Database classes for MMS: see MMS related providers and telephony and mmssmsdatabasehelper.

5. MMS parameter settings
MMS parameter settings are also performed through the sqlite3 database. Its content provider class is telephonyprovider, and its databasehelper class is its internal class. The content_uri of telephonyprovider is in the carriers internal class of telephony.
MMS parameter settings are mainly performed in the setting module.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.