The transmission of information, for MMS applications is mainly in the information database to create and maintain a record of information, the real sending process to the bottom (frameworks layer) function to deal with.
Generally speaking, when the information is created, there are usually three places for information, one is to give up the information, that is, the user does not want this information, once selected, the information will not be saved; The second place is to save the draft; The last place to go is to send this message.
When you click on the Send, the UI layer will not change, the UI layer to listen to the various classes responsible for sending the callback information and database changes to update the UI. Information sent the first stop is workingmessage, it will first deal with the relevant content of information, such as refreshing the recipient (Sync Recipients) to ensure that all legal addressee, the attachment (slideshow) into a can send MMS attachment PDU (sendreq), Makesendreq. Then, for different types of information (SMS, MMS) call different processing classes to deal with. The process of processing is similar, is to first put the message in a queue, and then start the appropriate service to deal with. The service maintains information queues, and then processes each information. SMS is sent by the Smsmanager in frameworks, and MMS is sent via HTTP protocol.
SMS Send
After Workingmessage get a message to send, do a simple processing (refresh the recipient), and then the SMS and MMS color to take different processing process. For SMS, Workingmessage will not do anything other than refresh the contact, it will create Smsmessagesender and call its SendMessage () method to send the information, the relevant parameter delivery address (is a semicolon-delimited string of characters), The information content and the ID of the dialog (thread ID) are passed in the constructed Smsmessagesender object, and the SendMessage () method is called directly after the construction completes, and then Smsmessagesender handles everything.
Before handing in Smsmessagesender, Workingmessage recalls the UI once to let the UI refresh the recipient edit box and the information text input box.
The main task of Smsmessagesender is to the information to be divided by the recipient, that is to say, the message is to send a letter to each recipient, although you may only edit a text message, but when the recipient of more than one, it becomes a number of text messages, you will send more than a message, Send a text message to each recipient. Therefore, the first task of Smsmessagesender is to analyze the addressee's address, get the number of the addressee, and then put the information in the queue to be sent by each recipient. This is a message sent to the queue, the number of SMS is the number of people who receive the letter. In fact, Smsmessagesender's work is only that, when the information is put into the sending queue is written into the database, and then the state of the information is being sent, it will send intent invoke Smsreceiverservice to process the queue, its work is completed, SendMessage () also returned to this. After Smsmessagesender's SendMessage () is returned, Workingmessage will again call back the UI interface, because the text message has been written to the database, so the UI refreshes the list of messages, showing just the text, when the status should be in the process of being sent, Because it was received from the queue to be sent. Since then, the delivery process of the class will not directly communicate with the UI, send service Smsreceiverservice, etc. will directly update the status of the text messages in the database, and the UI will listen to the changes in the database, once the information data changes, the UI will refresh the list of messages, update the status, such as sending the sent into the sent, or indicating the delivery failure, and these states are sent to the service update.
Smsreceiverservice, do not be the name of the Tiger Live, it is not only responsible for receiving information, it is a short message (SMS) processing service, responsible for the sending and receiving of SMS, send short message instructions (action_send_ message), then reads the first SMS from the queue, creates the Smssinglerecipientsender object, passes in the recipient address, the message content, the URI of the ThreadID and the message, and calls its SendMessage () to send the message.
Smssinglerecipientsender will call the Smsmanager method Dividemessage () to divide the text into several parts that fit to send, because the information may be too long to be sent at once, so it needs to be divided into several sections to send. It will also move the message to Outbox. The two pendingintent are then created for each part of the partition, and the two pendingintent are used for the bottom, one for broadcasting when the text message is sent out, and the other for broadcasting when the message has been received by the addressee. So the function of two broadcasts is that one can be used to identify messages that have been sent and the other to be served as notifications. The last call Smsmanager.sendmultiparttextmessage to the bottom to send text messages.
Instead of listening to send_message_action and message_sent_action, Smsreceiverservice is listening to the two broadcast events by Smsreceiver, The two events are then transmitted to the Smsreceiverservice for processing through StartService.
Information has been sent to broadcast and messages have been delivered to broadcast by Smsreceiverservice monitoring and Messagestatusreceiver respectively. When they receive the broadcast, they get a detailed send and delivery status from the intent, and then update the status of the information in the database, and the UI updates the UI when it finds a change in the database.
At this point, a text message sent to complete.
MMS Send
MMS send process and SMS is not exactly the same, workingmessage refresh the recipient, generate MMS can send Pdu-sendreq, and then will write MMS to the database, the Sendreq will be sent to the database, and then read out from the database sendreq, and identifies it as a draft, and then constructs the Mmsmessagesender, passing in the URI of the recipient and MMS, and letting it send. The UI is also invoked again during this period to initialize the recipient edit box and information edit box.
Mmsmessagesender from the database to read the MMS sent Pdu-sendreq,google built-in package com.google.android.mms.*, which encapsulates all the methods to operate the PDU, This includes writing the PDU to the database (Pdupersister.persist ()) and reading the Build PDU (Pdupersister.load ()) from the database. Then according to the current MMS configuration and other information to update sendreq, such as setting expiration,priority,date and size, the MMS moved to Outbox, and then start Transactionservice to process MMS. SendMessage () returned to this. Workingmessage will back up the UI interface again, because the multimedia message is already in the database, so the UI refreshes the information list to show just the MMS, at which point the status should be being sent.
Transactionservice, and SMS Smsreceiverservice similar, is responsible for processing MMS services, can send, receive and so on. For Transactionservice, all the processes that need to be processed, whether sent or received, are a transaction. It has two queues inside, one that is currently being processed (processing) and one that is transaction (pending) transaction. It maintains these two queues, checks the network connections, opens the MMS network connection, prepares and examines the environment, and then takes the first one from the queue to be processed, puts it in the queue being processed, and processes the transaction, which is called transaction.process ().
Send MMS is a sendtransaction, its process () method is responsible for sending MMS, it will create a separate thread to do so does not block transactionservice, processing services can be processed to other transaction. It will first remove the MMS pdu,m-send.req from the Database (sendreq), update some fields, such as date, and then call the method SENDPDU in its parent class Transaction.java to send the Sendreq out SENDPDU () Returns the result sent (send confirmation). TRANSACTION.SENDPDU () will set up the network first, then directly call the Httpconnection () method in Httputils, send the MMS with HTTP, At the same time get the return message (Response) to sendtransaction. Sendtransaction checks the results of the send, returns the results (send confirmation), analyzes the status and updates to the database (for example, sending failed or sent successfully). The UI will monitor the status changes and update the information list.
To this end, a MMS is sent.
As mentioned earlier, Transactionsettings is a related configuration information for a process that contains MMSC (multimedia message Service Center), proxy, and ProxyPort. This information, especially for sending and receiving, is very important. Because of the mobile phone information, not the mobile phone directly to the recipient of the phone, but directly to the service center, followed by the service center to send information to the corresponding recipient of the phone. For MMS is also the case, httputils through the HTTP protocol to send MMS to MMSC, it is a URL, and then for the sender, MMS sent out, MMS Service Center (MMSC) will handle the next send process, service center is related to mobile phone operations, It is provided by the operator. For MMS to send MMS, is not deliberately specified transactionsettings, meaning that it does not specify MMSC and proxy, then Transactionservice will use the system default MMSC, Proxy as Transcationsetting,mmsc,proxy and proxyport need to be queried from the telephony database, which is related to the APN settings of specific handsets and specific operators. So, if you want to change the configuration information for MMS, you can only change the APN system settings to complete.
And the message sent does not involve SMSC (SMS Service center), because the frameworks in the tool has been encapsulated Smsmanager provides a number of ways to send text messages, it may be to deal with SMSC related things.
Summary, you can see that the database plays an important role in the process of sending information, when the information left the editor immediately written to the database, the sending process of each class is the first load from the database information, and then do the appropriate processing, and then write back to the database or update the state, And then to the next process to deal with. The so-called pending message queue does not have the corresponding data structure, they are the information in the database and the state is to be sent. So the information is written to the database after it leaves the editor, only the state has been changing, from send to sent, or send failed, or if the telephony service is not available to be sent, but for the UI page may not be so many states, it may only show sent, sent and sent failed.