The message sending process of the confirmsendmessageifneeded part in composemessageactivity. The validation of the recipient's validity is the main factor, and then the sendmessage method is used for sending.
Composemessageactivity. sendmessage
It can be seen that in this method, the main task is to confirm the validity of the mobile phone status. Finally, the workingmessage sending method is called to send information.
Workingmessage. Send
We can see that different methods are called to process messages of different types in this method. And some brief preprocessing of MMS.
Text message section:
Workingmessage. presendsmsworker
As shown in, this is the process for sending text messages. This method involves a lot of things. The workingmessage in the original composemessage can be updated because it has been transferred to a new thread to send messages using workingmessage. Check whether the session exists. If not, create a new session.
Next, serialize the receiver and call sendsmsworker. Create an smsmessagesender and store the message in the sending Queue (set the type field to 6 ). Send a notification to smsreceiver.
Smsreceiver calls smsreceiverservice to send the first text message in the queue.
Before sending the message, you must divide the text message into several blocks Based on the phone card to ensure that the size of each block does not exceed the limit of the card. In the sentintent of the last text message after segmentation, set extra_message_sent_send_next to true. In this way, after the SMS is successfully sent, the handlesmssent method of smsreceiverservice is called to send the first message in the queue.
Then, specify an sentintent for each part. After sending the message, modify its status. If a report is required, a deliveryintent is also specified for processing the message report. Both intents will be encapsulated in smstracker. After the message is sent successfully, it will be taken out in handlesendcomplete of smsdispatcher. The sentintent is executed immediately and the message status is changed to sent. The deliveryintent is added to the deliverypendinglist and executed only after the message report is received (the specific code is in different dispatcher ).
After sending the message, you must process the SMS ceiling, message display list, and draft.
Processing after smsreceiverservice. handlesmssent message is sent
After the sentintent is executed, the message mailbox is updated based on different results.
Messagestatusreceiver message report
When you need to receive the report, the report will be retrieved from deliverypendinglist in smsdispatcher based on different types of mobile phones and the corresponding deliveryintent will be executed.
Smsreceiverservice. handlesmsreceived receives text messages
When the rilreceiver receives a message, it will be passed up from RIL. The intent calls privilegedsmsreceiver through the dispatchpdus method of smsdispatcher.
MMS part:
Workingmessage. sendmmsworker
We can see that the process of sending MMS messages is similar to that of sending SMS messages. You must reset the workingmessage to obtain the actual threadid. To delete unnecessary information after sending, call the onmessagesent of composemessageactivity. Only MMS does not create a method similar to presendsmsworker, but stores all content in sendmmsworker for processing. At the same time, the location for deleting a draft is also different.
Transactionservice. onstartcommand
Different from the text message, MMS is sent over the network.
During each call, all the MMS messages to be sent before the current time are extracted. Then, it encapsulates its Uri and transactiontype into transactionbundle and passes it to servicehandler. Set the type to event_transaction_request. Create a sendtransaction object in servicehandler. Then, call the processtransaction method to determine which queue the sendtransaction object is to be sent based on whether the current transaction is in the queue and the current connection status, mprocessing is sending ). At the same time, use the sendmessagedelayed method to send a message marked as event_continue_mms_connectivity to maintain the connection.
Then, put transactionservice into the observer list of the transaction object to continue sending the MMS message to be sent after the object is successfully sent.
Next, use the sendtransaction run method to obtain the specified MMS from the database, construct sendreq, and send the encoded MMS through httputils. Based on the sending result, choose whether to save the error status to the database, or convert the MMS to the sent box and notify transactionservice to process the MMS to be sent.
Transactionservice. Update
After this method is executed, remove the transaction from the mprocessing list. If the mpending is not empty, the MMS is in the basic processing but not sent status. Therefore, call mservicehandler and set event_handle_next_pending_transaction for processing. Extracts the first one from the mpending queue and submits it to processtransaction. As mentioned earlier, all transactions that call processtransaction will be added to the mprocessing queue, and after the transaction is sent successfully, the observer will be notified again, then, call the update method of transactionservice to continue sending information in the mpending queue. Therefore, MMS messages in the mpending queue are automatically sent in order.
Then, use notification to notify users of successfully sent messages (including unread messages and message reports ). And send the broadcast of Android. Intent. Action. transaction_completed_action (currently This broadcast is not accepted, it should be a broadcast provided to support application developers ).
Pushreceiver
The application layer of Android MMS Reception starts with pushreceiver. After onreceive is called, enable the screen to light for 5 seconds, create a receivepushtask and use its execute method. Receivepushtask is an asynctask that implements the doinbackground method. After the intent is passed in, the data is converted to genericpdu in doinbackground, and different operations are performed based on the message type.
If a report is sent or read, save it to the database.
If it is a MMS notification, if it already exists, it will not be processed. Otherwise, it will be stored in the database. Start transactionservice for processing.
In transactionservice, mservicehandler is called. The general process is the same as that when MMS is sent, but icationicationtransaction is created here.
If Automatic download or data transmission is not enabled, only mmsc is notified. Otherwise, download the corresponding MMS, delete the MMS notification, notify mmsc, delete the MMS that exceed the capacity limit, and notify transactionservice to process the remaining MMs.
Author haliluya4