Android Telephony MMS Learning Notes

Source: Internet
Author: User

This article mainly from the following aspects to learn MMS processing in the Android system: MMS initialization, MMS send, MMS receive (including push MMS receive and extract MMS content from mmsc), MMS storage/deletion and other data operations.

Android MMS Basics Point

First, MMS overview

MMS is a message service developed on the basis of short message service, which can be used for transmitting multimedia information such as text, picture, animation, audio and video. MMS uses "Storage and forwarding" technology, user-created information can be automatically and quickly transmitted between the mobile phone and mobile, the transmission of information is still based on the receiver's mobile phone number, the information will be stored in the Multimedia Message Center (MMSC), when the receiver is shut down or temporarily out of service, until it can be correctly delivered. The MMS Messaging service requires a WAP gateway, a data transmission network such as a circuit-switched network, GPRS or WCDMA network, and a multimedia Message center (MMSC). At present, MMS service is mainly based on WAP, with short message notification, from MMS mobile phone automatically to the Multimedia Message Center (MMSC) to extract to achieve.

In Android, MMS main processing is in the app layer, in the framework layer mainly involved in the MMS PDU packet parsing processing and sending and receiving MMS when the network processing.

MMS uses classes from the Telephony Framework section for more information, refer to the Android_telephony_framework series documentation.

Second, MMS related service
1. Transactionservice
Mainly through the corresponding transaction to handle the MMS send, receive and other requests. The transactionservice contains a Servicehandler handler inner class for handling MMS corresponding events.

Third, MMS related receiver
1. Pushreceiver
Accept Intent.wap_push_received_action and start Transactionservice to pass the corresponding PUSH data.
2. Mmssystemeventreceiver
Accept Mms.Intents.CONTENT_CHANGED_ACTION, telephonyintents.action_any_data_connection_state_changed and Intent.action_ Boot_completed.

Iv. MMS Related Handler
1. Smsdispatcher
For the handling of Sms/mms escalation events, it has two subclasses: Gsmsmsdispatcher and Cdmasmsdispatcher, Cdmaphone classes for Gsmphone and handler, respectively.
2. wappushoversms
Although the Wappushoversms class does not inherit from the handler class, its function is actually a handler class, it is implemented by Smsdispatcher dispatch method. The purpose of this class is to send the received push PDU packet through the intent mode to receiver processing of the application module.

V. MMS RELATED Transaction
1. Transaction
Inherits from the observable class, which is an abstract class of notificationtransaction, Readrectransaction, Retrievetransaction, and Sendtransaction.
2. Notificationtransaction
Inherits from the transaction class and implements the Runnable interface. The notifications (m-notification.ind) message that mainly processes MMS, which is the push MMS notification message. Main functions:
1) Determine whether you need to download MMS content from MMSc immediately according to 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 processing, notify Transactionservice to do the corresponding treatment.
3.ReadRecTransaction
Inherits from the transaction class and implements the Runnable interface. Read report notifications (M-read-rec.ind), which mainly handles MMS. Main functions:
1) Loads The Read report indication from storage (Outbox). The Read report indication PDU is removed from the 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 to extract MMS (m-retrieve.conf) from the 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. The main processing is to send 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.

Vi. MMS Related Provider

File

Class/Interface Name

Super class/implementation interface

Description

Telephonyprovider.java

Telephonyprovider

ContentProvider

Access encapsulation of APN, Proxy and other information

Mmsprovider.java

Mmsprovider

ContentProvider

Access to MMS

Mmssmsprovider.java

Mmssmsprovider

ContentProvider

Provides unified read for MMS and SMS and does not support write operations

Vii. MMS related classes in the framework

Package or Category

Path

Description

Com.google.android.mms

Frameworks\base\core\java\com\google\android\mms

Common content type classes for MMS PDU packages and exception handling classes for MMS

Com.google.android.mms.pdu

Frameworks\base\core\java\com\google\android\mms\pdu

The Analytic processing class of MMS PDU package

Com.google.android.mms.util

Frameworks\base\core\java\com\google\android\mms\util

Storage classes for PDU packages

Android.provider

Frameworks\base\core\java\android\provider

The data encapsulation class required for 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

Super class/implementation interface

Description

Contenttype.java

ContentType

Defines the supported element types for the content portion of the PDU package, including the supported image, audio types

Invalidheadervalueexception.java

Invalidheadervalueexception

Mmsexception

Exception handling for PDU header, thrown when header value is invalid

Mmsexception.java

Mmsexception

Exception

MMS Exception Interface Class

Com.google.android.mms.pdu

File

Class/Interface Name

Super class/implementation interface

Description

Acknowledgeind.java

Acknowledgeind

Genericpdu

M-acknowledge.ind PDU, confirmation message sent to MMSc by recipient

Base64.java

Base64

Parsing and processing of Base64 characters

Charactersets.java

Charactersets

MMS Encoding Type

Deliveryind.java

Deliveryind

Genericpdu

M-delivery.ind pdu,mmsc delivery report sent to Sender

Multimediamessagepdu.java

Multimediamessagepdu

Genericpdu

Multimedia message Pdu,mms PDU entity class

Notificationind.java

Notificationind

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 send confirmation message returned to Sender

Pdubody.java

Pdubody

Handling PDU Body Parts

Pducomposer.java

Pducomposer

The corresponding MMS PDU package is composed of the relevant data.

Pduheaders.java

Pduheaders

Parsing the MMS PDU header

Pduparser.java

Pduparser

MMS PDU Packet Parsing portal class

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

 

SQLite wrapper class, Provides handling of objects of the corresponding ContentProvider class by Contentresolver objects

Android.provider

File

Class/Interface Name

Super class/implementation interface

Description

Telephony.java

Telephony

Provide the data and operations needed with SMS/MMS provider, including corresponding Content_uri and some other data

Com.google.android.mms.utilcom.google.android.mms.util

The classes under these two packages are primarily intended to operate on the network side. For the time being, there is not much to know.

Android MMS Basic Processing

The following processing takes Gsmphone as an example.

First, MMS initialization
MMS initialization is basically consistent with SMS, but registers some events, such as Event_new_sms and Event_new_sms_status_report, in the process of Phoneapp initialization. In the Android platform, MMS initialization is not the operation of information data, Android is sqlite3 as a storage mechanism, and MMS-related data are stored in the Mmssms.db file, this file will be present in the phone for a long time, will not be deleted. The operation of MMS is directly to the operation of the MMSSMS.DB database, so there is no corresponding processing of MMS data in the initialization section. The following is a detailed description of the relationship between MMS initialization classes and the event registration process:
1. Create an instance of Gsmsmsdispatcher in the Gsmphone constructor msms:msms = new Gsmsmsdispatcher (this);
2. Call the Gsmsmsdispatcher constructor, execute super (phone), and because Gsmsmsdispatcher inherits from the Smsdispatcher class, the Smsdispatcher constructor is actually implemented.
3. In the Smsdispatcher constructor, execute the following statement:
MCm = PHONE.MCM;//MCM is an object of the Commandsinterface interface class
...............
Mcm.setonnewsms (this, event_new_sms, null);
...............
An instance msmsregistrant of the registrant class is created in the Setonnewsms method of the Commandsinterface class to hold Smsdispatcher handler objects, event_new_sms events, When a new message is escalated, the Smsdispatcher handler object is acquired through the Msmsregistrant object, and the Event_new_ SMS events and corresponding data are handled by the Handlemessage method sent to the Smsdispatcher class through the messaging mechanism and the handler processing mechanism.

Second, MMS receive

1. Push MMS Receive
MMS notification messages are delivered in the form of a short message PDU packet (M-notification.ind PDU). The specific processing flow in Android is as follows:
1) When a new message comes in, the reader thread of Atchannel calls the onunsolicited () function to handle it.
2) the onunsolicited () function calls the Ril_onunsolicitedresponse () function and passes in the Ril_unsol_response_new_sms value and the corresponding data.
3) Ril_onunsolicitedresponse () calls the Sendresponse () function to pass data to the Ril.java layer through the socket (socket name: Socket_name_ril).
4) The RIL Java layer reads data from the socket through the Rilreceiver receiver, calls the ProcessResponse () method in the Ril class after processing, and ProcessResponse () method calls 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); Resolve PDU packages based on SMS protocol
if (msmsregistrant! = null) {
Msmsregistrant.notifyregistrant (new AsyncResult (NULL, SMS, NULL));
}
Break
Where Msmsregistrant instances are created at initialization time, where Smsdispatcher handler objects and Event_new_sms event information are stored. The Event_new_sms event is then passed to the Smsdispatcher handler class processing through the message messaging mechanism and the handler processing mechanism.
6) Smsdispatcher handler receives the Event_new_sms event, calls the Handlemessage () method processing, and the Handlemessage () method calls its subclass DispatchMessage () method.
7) in DispatchMessage (), according to the Smsheader.portaddrs (Port_wap_push = 2948) address to determine whether the PUSH information.
8) Call the DISPATCHWAPPDU () method of the Wappushoversms class.
9) Use the Wsptypedecoder class instance to parse the push information and determine whether it is MMS push information based on the content type.
10) Call the Dispatchwappdu_mms () method to broadcast the send intent through the dispatch () method of the Smsdispatcher class. Wap_push_received_action.
One) Pushreceiver receives the intent, initiates Receivepushtas and executes the Doinbackground () method.
12) in the Doinbackground () method, resolve the corresponding PDU package through the Pduparser class object, and then execute the following code:
Case Message_type_notification_ind: {
Notificationind Nind = (notificationind) PDU;
if (!isduplicatenotification (Mcontext, Nind)) {
Uri uri = p.persist (PDU, Inbox.content_uri); MMS push information is stored in Inbox.
Intent svc = new Intent (Mcontext, transactionservice.class);//intent starts with Transactionservice.
Svc.putextra (Transactionbundle.uri, uri.tostring ());
Svc.putextra (Transactionbundle.transaction_type,
transaction.notification_transaction);//transaction type: notification_transaction
Mcontext.startservice (SVC);//Start Transactionservice Service
}
OnStart () call Launchtransaction () method in the Transactionservice class
The Launchtransaction () method is passed to the Servicehandler event_transaction_request event.
The Handlemessage () method of the Servicehandler class handles the Event_transaction_request event, depending on the type of TRANSACTION notification_transaction, Create an instance of the Notificationtransaction class and remove the PDU package from the mmssms.db based on the URI.
16) Call the Processtransaction (transaction) method, and in the Processtransaction () method, execute the following code:
int connectivityresult = beginmmsconnectivity ();//data connection through the Beginmmsconnectivity function.
if (Connectivityresult = = phone.apn_request_started) {//If the apn_request_started result is returned, the data connection is connected, waiting to return Event_ Data_state_changed Events
Mpending.add (transaction);//put transaction into the waiting queue
return true; Return, wait for the Event_data_state_changed event to continue processing
}
Transaction.attach (Transactionservice.this); Because both the transaction class and the Transactionservice class inherit from the observable class, this is for the transaction class's subclasses to notify Transactionservice of the corresponding processing results after processing is complete.
Transaction.process (); Enter the Notificationtransaction class to process and create a new thread to handle the transaction.
17) Please refer to the notificationtransaction instructions in the MMS related transaction for the following processing.

2. Extracting MMS from MMSc
Depending on the value of the mautodownload variable in the Downloadmanager class, there are two situations in which MMS is extracted from mmsc:
1) If Mautodownload is true, which allows automatic extraction, the MMS message is extracted from mmsc when the indication notification comes up. Even if the processing is done in notificationtransaction. Please refer to the notificationtransaction instructions in MMS related transaction for details.
2) Otherwise, it is necessary to manually extract from the MMSc. This is handled as follows: The UI layer starts Transactionservice and passes in the transaction.retrieve_transaction type. The other process flows refer to steps 13th through 17th in the first (push MMS receive), except that the corresponding transaction is retrievetransaction, not notificationtransaction.

Third, MMS send
The sending action of MMS is triggered by the UI, and is mainly handled by the Sendmmsworker () method in the Composemessageactivity class. The specific processing flow is as follows:
1. In the Sendmmsworker () method, create the Mmsmessagesender class instance sender and call the SendMessage () method in the Mmsmessagesender class.
2. Remove the corresponding PDU data from the mmssms.db, move the information to the Outbox (formerly stored under draft), and start the Transactionservice service for transaction processing.
3. Processed through Transactionservice processing into the run () method of the Sendtransaction class. Please refer to the sendtransaction instructions in MMS related transaction for detailed processing.

Iv. data operations such as MMS storage/deletion
The storage of MMS information is based on SQLite3, and its mmssms.db database will exist after the first creation, which makes the storage processing of MMS much simpler, just execute the corresponding SQL statement.
The content part of MMS is stored in file, and is not placed in the MMSSMS.DB database, the following tables are stored in the database:
Static final String TABLE_PDU = "PDU";//pdu table with related information
Static final String table_addr = "ADDR";//mms sender/recipient address related tables
Static final String Table_part = "part"; Body can be divided into several parts, a table that stores part-related information, through which the part information can be taken from the file to the corresponding content section
Static final String table_rate = "rate"; Sent_time Information Sheet
Static final String table_drm = "DRM";
The above tables only store some relevant information, through which they can get the basic information of the corresponding MMS, and can read from the file to the corresponding MMS body.
The understanding of MMS storage mechanism is mainly the understanding of content provider mechanism, the content provider mechanism mainly involves the following classes:

File

Class/Interface Name

Super class/implementation interface

Description

Sqlitedatabase.java

Sqlitedatabase

Sqliteclosable

Sqllite Database Implementation Class

Sqliteopenhelper.java

Sqliteopenhelper

Helper classes for managing database Create, open, close, Get,upgrade, and version information

Contentprovider.java

ContentProvider

Enables different applications to access the database

Contentresolver.java

Contentresolver

The ContentProvider package class, which provides a unified provider to application, ContentProvider obtains the corresponding ContentProvider object based on the URI.

Sqlitewrapper.java

Sqlitewrapper

Package class for the Contentresolver class provided to application

MMS corresponding Database class: see MMS related provider and telephony, Mmssmsdatabasehelper

Five MMS parameter settings
The parameter setting of MMS is also operated by SQLite3 database, its content provider class: Telephonyprovider, its Databasehelper class is its inner class. Telephonyprovider corresponds to Content_uri in the carriers inner class of the telephony class.
The MMS parameter settings are mainly operated in the setting module.

Android Telephony MMS Learning Notes

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.