1. 点击发送按钮Src/com/android/mms/ui/ComposeMessageActivity.java
public void onClick(View v) {
if ((v == mSendButton) && isPreparedForSending()) {
confirmSendMessageIfNeeded(); //确认是否需要发送短信—-》
}
}
2.src/com/android/mms/ui/ComposeMessageActivity.java
private void confirmSendMessageIfNeeded() {
if (!isRecipientsEditorVisible()) { //编辑联系人不可见时,也就是给已存在会话的联系人发送短信时
sendMessage(true);
return;
}
boolean isMms = mWorkingMessage.requiresMms(); //是否需要以彩信形式发送
if (mRecipientsEditor.hasInvalidRecipient(isMms)) {//是否含有不合法的收件人
if (mRecipientsEditor.hasValidRecipient(isMms)) {//有合法的和不合法的,弹出尝试发送对话框
String title = getResourcesString(R.string.has_invalid_recipient,
mRecipientsEditor.formatInvalidNumbers(isMms));
new AlertDialog.Builder(this)
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle(title)
.setMessage(R.string.invalid_recipient_message)
.setPositiveButton(R.string.try_to_send,
newSendIgnoreInvalidRecipientListener())
.setNegativeButton(R.string.no, new CancelSendingListener())
.show();
} else {//如果全是不合法的联系人,提示不能发送信息
new AlertDialog.Builder(this)
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle(R.string.cannot_send_message)
.setMessage(R.string.cannot_send_message_reason)
.setPositiveButton(R.string.yes, new CancelSendingListener())
.show();
}
} else {//判断收件人没有问题,接着发送信息 --》
sendMessage(true);
}
}
3. src/com/android/mms/ui/ComposeMessageActivity.java
private void sendMessage(boolean bCheckEcmMode) {
Log.v(TAG, "sendMessage");
if (bCheckEcmMode) {
// TODO: expose this in telephony layer for SDK build
String inEcm = SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE); //判断电话是否处于紧急拨号模式,得到的inEcm一般为空
Log.v(TAG, "inEcm = " + inEcm);
if (Boolean.parseBoolean(inEcm)) {
try {
startActivityForResult(
new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS,null),
REQUEST_CODE_ECM_EXIT_DIALOG);
return;
} catch (ActivityNotFoundException e) {
// continue to send message
Log.e(TAG, "Cannot find EmergencyCallbackModeExitDialog", e);
}
}
}
if (!mSendingMessage) {
// send can change the recipients. Make sure we remove the listeners firstand then add
// them back once the recipient list has settled.
removeRecipientsListeners(); //取消对收件人的监听
mWorkingMessage.send(); //发送信息—-》
mSentMessage = true;
mSendingMessage = true;
addRecipientsListeners(); //重新添加收件人监听
}
// But bail out if we are supposed to exit after the message is sent.
if (mExitOnSent) {//如果mExitOnSent为true,信息发送完成后退出Activity
finish();
}
}
4. src/com/android/mms/data/WorkingMessage.java
/**
* Send this message over the network. Will call back with onMessageSent() once
* it has been dispatched to the telephonystack. This WorkingMessage object is
* no longer useful after this method hasbeen called.
*/
public void send() {
if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
LogTag.debug("send");
}
// Get ready to write to disk.
prepareForSave(true /* notify */);//主要做一下同步收件人和WorkingMessage,彩信时在准备其他一些东西
// We need the recipient list for both SMS and MMS.
final Conversation conv = mConversation;
String msgTxt = mText.toString();
Log.v(TAG, "msgText = " + msgTxt);
if (requiresMms()|| addressContainsEmailToMms(conv, msgTxt)) {
// Make local copies of the bits we need for sending a message,
// because we will be doing it off of the main thread, which will
// immediately continue on to resetting some of this state.
final Uri mmsUri = mMessageUri; //如果第一次发送,此时mmsUri为null,如果是重发,则是草稿箱的地址 mMessageUri =content://mms/drafts/1
final PduPersister persister = PduPersister.getPduPersister(mContext);
final SlideshowModel slideshow = mSlideshow;
final SendReq sendReq = makeSendReq(conv,mSubject);
// Do the dirty work of sending the message off of the main UI thread.
new Thread(new Runnable() {
public void run() {
// Make sure the text in slide 0 is no longer holding onto a reference to
// the text in the message text box.
slideshow.prepareForSend();
sendMmsWorker(conv, mmsUri, persister, slideshow, sendReq);
}
}).start();
}else {
// Same rules apply as above.
final String msgText = mText.toString();//取出短消息
Log.v(TAG, "msgText = " + msgText);
new Thread(new Runnable() {
public void run() {
preSendSmsWorker(conv, msgText);//发送信息--》
}
}).start();
}
// update the Recipient cache with the new to address, if it's different
RecipientIdCache.updateNumbers(conv.getThreadId(),conv.getRecipients());
// Mark the message as discarded because it is "off the market"after being sent.
mDiscarded = true;
}
5. src/com/android/mms/data/WorkingMessage.java
private void sendMmsWorker(Conversation conv, Uri mmsUri, PduPersisterpersister, SlideshowModel slideshow, SendReq sendReq) {
Log.v(TAG, "sendMmsWorker");
// If user tries to send the message, it's a signal the inputtedtext is what they wanted.
UserHappinessSignals.userAcceptedImeText(mContext);
// First make sure we don't have too many outstanding unsent message.
Cursor cursor = null;
try {
cursor = SqliteWrapper.query(mContext, mContentResolver,
Mms.Outbox.CONTENT_URI,MMS_OUTBOX_PROJECTION, null, null, null);
if (cursor != null) {//如果MMS_OUTBOX里有未发送的彩信,并且总的大小已经超过了彩信的最大限制,则取消此次发送,并存入草稿箱
Log.v(TAG, "query Mms.Outbox.CONTENT_URI is not empty");
long maxMessageSize = MmsConfig.getMaxSizeScaleForPendingMmsAllowed()*
MmsConfig.getMaxMessageSize();
Log.v(TAG, "MmsConfig.getMaxSizeScaleForPendingMmsAllowed() =" + MmsConfig.getMaxSizeScaleForPendingMmsAllowed());
Log.v(TAG, "MmsConfig.getMaxMessageSize()() = " + MmsConfig.getMaxMessageSize());
long totalPendingSize = 0;
while (cursor.moveToNext()) {
totalPendingSize +=cursor.getLong(MMS_MESSAGE_SIZE_INDEX);
Log.v(TAG, "totalPendingSize = " + totalPendingSize);
}
if (totalPendingSize >= maxMessageSize) {
unDiscard(); // itwasn't successfully sent. Allow it to be saved as a draft.
mStatusListener.onMaxPendingMessagesReached();
return;
}
}else{
Log.v(TAG, "query Mms.Outbox.CONTENT_URI is empty");
}
} finally {
if (cursor != null) {
cursor.close();
}
}
mStatusListener.onPreMessageSent();
// Make sure we are still using the correct thread ID for our
// recipient set.
long threadId = conv.ensureThreadId();
if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
LogTag.debug("sendMmsWorker: update draft MMS message " + mmsUri);
}
if (mmsUri == null) {//如果是首次发送,先把彩信保存入草稿箱
// Create a new MMS message if one hasn't been made yet.
Log.v(TAG, "mmsUri == null and startcreateDraftMmsMessage");
mmsUri = createDraftMmsMessage(persister,sendReq, slideshow);
} else {
// Otherwise, sync the MMS message in progress to disk.
Log.v(TAG, "mmsUri = " + mmsUri);
Log.v(TAG, "updateDraftMmsMessage");
updateDraftMmsMessage(mmsUri,persister, slideshow, sendReq);
}
// Be paranoid and clean any draft SMS up.
deleteDraftSmsMessage(threadId);
// Resize all the resizeable attachments (e.g. pictures) to fit
// in the remaining space in the slideshow.
int error = 0;
try {
slideshow.finalResize(mmsUri);
} catch (ExceedMessageSizeException e1) {
error = MESSAGE_SIZE_EXCEEDED;
} catch (MmsException e1) {
error = UNKNOWN_ERROR;
}
if (error != 0) {
markMmsMessageWithError(mmsUri);
mStatusListener.onAttachmentError(error);
return;
}
MessageSender sender = new MmsMessageSender(mContext, mmsUri,
slideshow.getCurrentMessageSize());
try {
if (!sender.sendMessage(threadId)) {
// The message was sent through SMS protocol, we should
// delete the copy which was previously saved in MMS drafts.
SqliteWrapper.delete(mContext, mContentResolver, mmsUri, null, null);
}
// Make sure this thread isn't over the limits in message count
Recycler.getMmsRecycler().deleteOldMessagesByThreadId(mContext, threadId);
} catch (Exception e) {
Log.e(TAG, "Failed to send message: " + mmsUri + ",threadId=" + threadId, e);
}
mStatusListener.onMessageSent();
}
6.src/com/android/mms/transaction/MmsMessageSender.java
public boolean sendMessage(long token) throws MmsException {
// Load the MMS from the message uri
PduPersister p = PduPersister.getPduPersister(mContext);
GenericPdu pdu = p.load(mMessageUri);
if (pdu.getMessageType() != PduHeaders.MESSAGE_TYPE_SEND_REQ){
throw new MmsException("Invalid message: " +pdu.getMessageType());
}
SendReq sendReq = (SendReq)pdu;
// Update headers.
updatePreferencesHeaders(sendReq);
// MessageClass.
sendReq.setMessageClass(DEFAULT_MESSAGE_CLASS.getBytes());
// Update the 'date' field of the message before sending it.
sendReq.setDate(System.currentTimeMillis()/ 1000L);
sendReq.setMessageSize(mMessageSize);
p.updateHeaders(mMessageUri, sendReq);
// Move the message into MMS Outbox
p.move(mMessageUri, Mms.Outbox.CONTENT_URI);
// Start MMS transaction service
SendingProgressTokenManager.put(ContentUris.parseId(mMessageUri), token);
mContext.startService(new Intent(mContext, TransactionService.class));
return true;
}
7.src/com/android/mms/transaction/TransactionService.java
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.v(TAG, "onStartCommand");
if (intent == null) {
return Service.START_NOT_STICKY;
}
mConnMgr = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
boolean noNetwork =!isNetworkAvailable();
if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
Log.v(TAG, "onStart: #" + startId + ": " + intent.getExtras() + " intent=" + intent);
Log.v(TAG, " networkAvailable=" + !noNetwork);
}
Log.v(TAG, "getAction is " + intent.getAction());
if (ACTION_ONALARM.equals(intent.getAction())|| (intent.getExtras() == null)) {
Log.v(TAG, "ACTION_ONALARM.equals(intent.getAction()) ||(intent.getExtras() == null)");
// Scan database to find all pending operations.
Cursor cursor = PduPersister.getPduPersister(this).getPendingMessages(
System.currentTimeMillis());
if (cursor != null) {
try {
int count = cursor.getCount();
if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
Log.v(TAG, "onStart: cursor.count=" + count);
}
if (count == 0) {
if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
Log.v(TAG, "onStart: no pending messages. Stoppingservice.");
}
RetryScheduler.setRetryAlarm(this);
stopSelfIfIdle(startId);
return Service.START_NOT_STICKY;
}
int columnIndexOfMsgId =cursor.getColumnIndexOrThrow(PendingMessages.MSG_ID);
int columnIndexOfMsgType =cursor.getColumnIndexOrThrow(
PendingMessages.MSG_TYPE);
if (noNetwork) {
// Make sure we register for connection state changes.
if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
Log.v(TAG, "onStart: registerForConnectionStateChanges");
}
MmsSystemEventReceiver.registerForConnectionStateChanges(
getApplicationContext());
}
while (cursor.moveToNext()) {
int msgType =cursor.getInt(columnIndexOfMsgType);
int transactionType =getTransactionType(msgType);
Log.v(TAG, "msgType = " + msgType);
Log.v(TAG, "transactionType = " + transactionType);
if (noNetwork) {
onNetworkUnavailable(startId, transactionType);
return Service.START_NOT_STICKY;
}
switch (transactionType){
case -1:
break;
case Transaction.RETRIEVE_TRANSACTION:
// If it's a transiently failed transaction,
// we should retry it in spite of current
// downloading mode.
int failureType =cursor.getInt(
cursor.getColumnIndexOrThrow(
PendingMessages.ERROR_TYPE));
if (!isTransientFailure(failureType)){
break;
}
// fall-through
default:
Uri uri =ContentUris.withAppendedId(
Mms.CONTENT_URI,
cursor.getLong(columnIndexOfMsgId));
TransactionBundle args = new TransactionBundle(
transactionType, uri.toString());
// FIXME: We use the same startId for all MMs.
launchTransaction(startId, args, false);
break;
}
}
} finally {
cursor.close();
}
} else {
if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
Log.v(TAG, "onStart: no pending messages. Stoppingservice.");
}
RetryScheduler.setRetryAlarm(this);
stopSelfIfIdle(startId);
}
} else {
if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
Log.v(TAG, "onStart: launch transaction...");
}
// For launching NotificationTransaction and test purpose.
TransactionBundle args = newTransactionBundle(intent.getExtras());
launchTransaction(startId, args,noNetwork);
}
return Service.START_NOT_STICKY;
}
8. src/com/android/mms/transaction/TransactionService.java
private void launchTransaction(int serviceId,TransactionBundle txnBundle, boolean noNetwork) {
Log.v(TAG, "launchTransaction");
if (noNetwork) {
Log.w(TAG, "launchTransaction: no network error!");
onNetworkUnavailable(serviceId,txnBundle.getTransactionType());
return;
}
Message msg = mServiceHandler.obtainMessage(EVENT_TRANSACTION_REQUEST);
msg.arg1 = serviceId;
msg.obj = txnBundle;
if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
Log.v(TAG, "launchTransaction: sending message " + msg);
}
mServiceHandler.sendMessage(msg);
}
9. src/com/android/mms/transaction/TransactionService.java
private final class ServiceHandler extends Handler {
public ServiceHandler(Looper looper) {
super(looper);
}
/**
* Handle incoming transactionrequests.
* The incoming requests are initiatedby the MMSC Server or by the
* MMS Client itself.
*/
@Override
public void handleMessage(Messagemsg) {
if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
Log.v(TAG, "Handling incoming message: " + msg);
}
Transaction transaction = null;
switch (msg.what) {
case EVENT_QUIT:
getLooper().quit();
return;
case EVENT_CONTINUE_MMS_CONNECTIVITY:
synchronized (mProcessing) {
if (mProcessing.isEmpty()) {
return;
}
}
if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
Log.v(TAG, "handle EVENT_CONTINUE_MMS_CONNECTIVITYevent...");
}
try {
int result =beginMmsConnectivity();
if (result != Phone.APN_ALREADY_ACTIVE){
Log.v(TAG, "Extending MMS connectivity returned " + result +
" instead of APN_ALREADY_ACTIVE");
// Just wait for connectivity startup without
// any newrequest of APN switch.
return;
}
} catch (IOException e) {
Log.w(TAG, "Attempt to extend use of MMS connectivityfailed");
return;
}
// Restart timer
sendMessageDelayed(obtainMessage(EVENT_CONTINUE_MMS_CONNECTIVITY),
APN_EXTENSION_WAIT);
return;
case EVENT_DATA_STATE_CHANGED:
/*
* If we are being informedthat connectivity has been established
* to allow MMS traffic,then proceed with processing the pending
* transaction, if any.
*/
if (mConnectivityListener == null) {
return;
}
NetworkInfo info = mConnectivityListener.getNetworkInfo();
if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
Log.v(TAG, "Handle DATA_STATE_CHANGED event: " + info);
}
// Check availability of the mobile network.
if ((info == null) || (info.getType() !=
ConnectivityManager.TYPE_MOBILE_MMS)) {
if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
Log.v(TAG, " type isnot TYPE_MOBILE_MMS, bail");
}
return;
}
if (!info.isConnected()) {
if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
Log.v(TAG, " TYPE_MOBILE_MMS not connected, bail");
}
return;
}
TransactionSettings settings = newTransactionSettings(
TransactionService.this,info.getExtraInfo());
// If this APN doesn't have an MMSC, wait for one that does.
if (TextUtils.isEmpty(settings.getMmscUrl())){
if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
Log.v(TAG, " empty MMSCurl, bail");
}
return;
}
// Set a timer to keep renewing our "lease" on the MMSconnection
sendMessageDelayed(obtainMessage(EVENT_CONTINUE_MMS_CONNECTIVITY),
APN_EXTENSION_WAIT);
processPendingTransaction(transaction, settings);
return;
case EVENT_TRANSACTION_REQUEST://响应请求
Log.v(TAG, "EVENT_TRANSACTION_REQUEST");
int serviceId = msg.arg1;
try {
TransactionBundle args= (TransactionBundle) msg.obj;
TransactionSettingstransactionSettings;
// Set the connection settings for this transaction.
// If these have not been set in args, load thedefault settings.
String mmsc =args.getMmscUrl();
if (mmsc != null) {
transactionSettings= new TransactionSettings(
mmsc,args.getProxyAddress(), args.getProxyPort());
} else {
transactionSettings= new TransactionSettings(
TransactionService.this, null);
}
int transactionType =args.getTransactionType();
Log.v(TAG, "transactionType = " + transactionType)
public void onClick(View v) {
if ((v == mSendButton) && isPreparedForSending()) {
confirmSendMessageIfNeeded(); //确认是否需要发送短信—-》
}
}
2.src/com/android/mms/ui/ComposeMessageActivity.java
private void confirmSendMessageIfNeeded() {
if (!isRecipientsEditorVisible()) { //编辑联系人不可见时,也就是给已存在会话的联系人发送短信时
sendMessage(true);
return;
}
boolean isMms = mWorkingMessage.requiresMms(); //是否需要以彩信形式发送
if (mRecipientsEditor.hasInvalidRecipient(isMms)) {//是否含有不合法的收件人
if (mRecipientsEditor.hasValidRecipient(isMms)) {//有合法的和不合法的,弹出尝试发送对话框
String title = getResourcesString(R.string.has_invalid_recipient,
mRecipientsEditor.formatInvalidNumbers(isMms));
new AlertDialog.Builder(this)
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle(title)
.setMessage(R.string.invalid_recipient_message)
.setPositiveButton(R.string.try_to_send,
newSendIgnoreInvalidRecipientListener())
.setNegativeButton(R.string.no, new CancelSendingListener())
.show();
} else {//如果全是不合法的联系人,提示不能发送信息
new AlertDialog.Builder(this)
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle(R.string.cannot_send_message)
.setMessage(R.string.cannot_send_message_reason)
.setPositiveButton(R.string.yes, new CancelSendingListener())
.show();
}
} else {//判断收件人没有问题,接着发送信息 --》
sendMessage(true);
}
}
3. src/com/android/mms/ui/ComposeMessageActivity.java
private void sendMessage(boolean bCheckEcmMode) {
Log.v(TAG, "sendMessage");
if (bCheckEcmMode) {
// TODO: expose this in telephony layer for SDK build
String inEcm = SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE); //判断电话是否处于紧急拨号模式,得到的inEcm一般为空
Log.v(TAG, "inEcm = " + inEcm);
if (Boolean.parseBoolean(inEcm)) {
try {
startActivityForResult(
new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS,null),
REQUEST_CODE_ECM_EXIT_DIALOG);
return;
} catch (ActivityNotFoundException e) {
// continue to send message
Log.e(TAG, "Cannot find EmergencyCallbackModeExitDialog", e);
}
}
}
if (!mSendingMessage) {
// send can change the recipients. Make sure we remove the listeners firstand then add
// them back once the recipient list has settled.
removeRecipientsListeners(); //取消对收件人的监听
mWorkingMessage.send(); //发送信息—-》
mSentMessage = true;
mSendingMessage = true;
addRecipientsListeners(); //重新添加收件人监听
}
// But bail out if we are supposed to exit after the message is sent.
if (mExitOnSent) {//如果mExitOnSent为true,信息发送完成后退出Activity
finish();
}
}
4. src/com/android/mms/data/WorkingMessage.java
/**
* Send this message over the network. Will call back with onMessageSent() once
* it has been dispatched to the telephonystack. This WorkingMessage object is
* no longer useful after this method hasbeen called.
*/
public void send() {
if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
LogTag.debug("send");
}
// Get ready to write to disk.
prepareForSave(true /* notify */);//主要做一下同步收件人和WorkingMessage,彩信时在准备其他一些东西
// We need the recipient list for both SMS and MMS.
final Conversation conv = mConversation;
String msgTxt = mText.toString();
Log.v(TAG, "msgText = " + msgTxt);
if (requiresMms()|| addressContainsEmailToMms(conv, msgTxt)) {
// Make local copies of the bits we need for sending a message,
// because we will be doing it off of the main thread, which will
// immediately continue on to resetting some of this state.
final Uri mmsUri = mMessageUri; //如果第一次发送,此时mmsUri为null,如果是重发,则是草稿箱的地址 mMessageUri =content://mms/drafts/1
final PduPersister persister = PduPersister.getPduPersister(mContext);
final SlideshowModel slideshow = mSlideshow;
final SendReq sendReq = makeSendReq(conv,mSubject);
// Do the dirty work of sending the message off of the main UI thread.
new Thread(new Runnable() {
public void run() {
// Make sure the text in slide 0 is no longer holding onto a reference to
// the text in the message text box.
slideshow.prepareForSend();
sendMmsWorker(conv, mmsUri, persister, slideshow, sendReq);
}
}).start();
}else {
// Same rules apply as above.
final String msgText = mText.toString();//取出短消息
Log.v(TAG, "msgText = " + msgText);
new Thread(new Runnable() {
public void run() {
preSendSmsWorker(conv, msgText);//发送信息--》
}
}).start();
}
// update the Recipient cache with the new to address, if it's different
RecipientIdCache.updateNumbers(conv.getThreadId(),conv.getRecipients());
// Mark the message as discarded because it is "off the market"after being sent.
mDiscarded = true;
}
5. src/com/android/mms/data/WorkingMessage.java
private void sendMmsWorker(Conversation conv, Uri mmsUri, PduPersisterpersister, SlideshowModel slideshow, SendReq sendReq) {
Log.v(TAG, "sendMmsWorker");
// If user tries to send the message, it's a signal the inputtedtext is what they wanted.
UserHappinessSignals.userAcceptedImeText(mContext);
// First make sure we don't have too many outstanding unsent message.
Cursor cursor = null;
try {
cursor = SqliteWrapper.query(mContext, mContentResolver,
Mms.Outbox.CONTENT_URI,MMS_OUTBOX_PROJECTION, null, null, null);
if (cursor != null) {//如果MMS_OUTBOX里有未发送的彩信,并且总的大小已经超过了彩信的最大限制,则取消此次发送,并存入草稿箱
Log.v(TAG, "query Mms.Outbox.CONTENT_URI is not empty");
long maxMessageSize = MmsConfig.getMaxSizeScaleForPendingMmsAllowed()*
MmsConfig.getMaxMessageSize();
Log.v(TAG, "MmsConfig.getMaxSizeScaleForPendingMmsAllowed() =" + MmsConfig.getMaxSizeScaleForPendingMmsAllowed());
Log.v(TAG, "MmsConfig.getMaxMessageSize()() = " + MmsConfig.getMaxMessageSize());
long totalPendingSize = 0;
while (cursor.moveToNext()) {
totalPendingSize +=cursor.getLong(MMS_MESSAGE_SIZE_INDEX);
Log.v(TAG, "totalPendingSize = " + totalPendingSize);
}
if (totalPendingSize >= maxMessageSize) {
unDiscard(); // itwasn't successfully sent. Allow it to be saved as a draft.
mStatusListener.onMaxPendingMessagesReached();
return;
}
}else{
Log.v(TAG, "query Mms.Outbox.CONTENT_URI is empty");
}
} finally {
if (cursor != null) {
cursor.close();
}
}
mStatusListener.onPreMessageSent();
// Make sure we are still using the correct thread ID for our
// recipient set.
long threadId = conv.ensureThreadId();
if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
LogTag.debug("sendMmsWorker: update draft MMS message " + mmsUri);
}
if (mmsUri == null) {//如果是首次发送,先把彩信保存入草稿箱
// Create a new MMS message if one hasn't been made yet.
Log.v(TAG, "mmsUri == null and startcreateDraftMmsMessage");
mmsUri = createDraftMmsMessage(persister,sendReq, slideshow);
} else {
// Otherwise, sync the MMS message in progress to disk.
Log.v(TAG, "mmsUri = " + mmsUri);
Log.v(TAG, "updateDraftMmsMessage");
updateDraftMmsMessage(mmsUri,persister, slideshow, sendReq);
}
// Be paranoid and clean any draft SMS up.
deleteDraftSmsMessage(threadId);
// Resize all the resizeable attachments (e.g. pictures) to fit
// in the remaining space in the slideshow.
int error = 0;
try {
slideshow.finalResize(mmsUri);
} catch (ExceedMessageSizeException e1) {
error = MESSAGE_SIZE_EXCEEDED;
} catch (MmsException e1) {
error = UNKNOWN_ERROR;
}
if (error != 0) {
markMmsMessageWithError(mmsUri);
mStatusListener.onAttachmentError(error);
return;
}
MessageSender sender = new MmsMessageSender(mContext, mmsUri,
slideshow.getCurrentMessageSize());
try {
if (!sender.sendMessage(threadId)) {
// The message was sent through SMS protocol, we should
// delete the copy which was previously saved in MMS drafts.
SqliteWrapper.delete(mContext, mContentResolver, mmsUri, null, null);
}
// Make sure this thread isn't over the limits in message count
Recycler.getMmsRecycler().deleteOldMessagesByThreadId(mContext, threadId);
} catch (Exception e) {
Log.e(TAG, "Failed to send message: " + mmsUri + ",threadId=" + threadId, e);
}
mStatusListener.onMessageSent();
}
6.src/com/android/mms/transaction/MmsMessageSender.java
public boolean sendMessage(long token) throws MmsException {
// Load the MMS from the message uri
PduPersister p = PduPersister.getPduPersister(mContext);
GenericPdu pdu = p.load(mMessageUri);
if (pdu.getMessageType() != PduHeaders.MESSAGE_TYPE_SEND_REQ){
throw new MmsException("Invalid message: " +pdu.getMessageType());
}
SendReq sendReq = (SendReq)pdu;
// Update headers.
updatePreferencesHeaders(sendReq);
// MessageClass.
sendReq.setMessageClass(DEFAULT_MESSAGE_CLASS.getBytes());
// Update the 'date' field of the message before sending it.
sendReq.setDate(System.currentTimeMillis()/ 1000L);
sendReq.setMessageSize(mMessageSize);
p.updateHeaders(mMessageUri, sendReq);
// Move the message into MMS Outbox
p.move(mMessageUri, Mms.Outbox.CONTENT_URI);
// Start MMS transaction service
SendingProgressTokenManager.put(ContentUris.parseId(mMessageUri), token);
mContext.startService(new Intent(mContext, TransactionService.class));
return true;
}
7.src/com/android/mms/transaction/TransactionService.java
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.v(TAG, "onStartCommand");
if (intent == null) {
return Service.START_NOT_STICKY;
}
mConnMgr = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
boolean noNetwork =!isNetworkAvailable();
if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
Log.v(TAG, "onStart: #" + startId + ": " + intent.getExtras() + " intent=" + intent);
Log.v(TAG, " networkAvailable=" + !noNetwork);
}
Log.v(TAG, "getAction is " + intent.getAction());
if (ACTION_ONALARM.equals(intent.getAction())|| (intent.getExtras() == null)) {
Log.v(TAG, "ACTION_ONALARM.equals(intent.getAction()) ||(intent.getExtras() == null)");
// Scan database to find all pending operations.
Cursor cursor = PduPersister.getPduPersister(this).getPendingMessages(
System.currentTimeMillis());
if (cursor != null) {
try {
int count = cursor.getCount();
if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
Log.v(TAG, "onStart: cursor.count=" + count);
}
if (count == 0) {
if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
Log.v(TAG, "onStart: no pending messages. Stoppingservice.");
}
RetryScheduler.setRetryAlarm(this);
stopSelfIfIdle(startId);
return Service.START_NOT_STICKY;
}
int columnIndexOfMsgId =cursor.getColumnIndexOrThrow(PendingMessages.MSG_ID);
int columnIndexOfMsgType =cursor.getColumnIndexOrThrow(
PendingMessages.MSG_TYPE);
if (noNetwork) {
// Make sure we register for connection state changes.
if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
Log.v(TAG, "onStart: registerForConnectionStateChanges");
}
MmsSystemEventReceiver.registerForConnectionStateChanges(
getApplicationContext());
}
while (cursor.moveToNext()) {
int msgType =cursor.getInt(columnIndexOfMsgType);
int transactionType =getTransactionType(msgType);
Log.v(TAG, "msgType = " + msgType);
Log.v(TAG, "transactionType = " + transactionType);
if (noNetwork) {
onNetworkUnavailable(startId, transactionType);
return Service.START_NOT_STICKY;
}
switch (transactionType){
case -1:
break;
case Transaction.RETRIEVE_TRANSACTION:
// If it's a transiently failed transaction,
// we should retry it in spite of current
// downloading mode.
int failureType =cursor.getInt(
cursor.getColumnIndexOrThrow(
PendingMessages.ERROR_TYPE));
if (!isTransientFailure(failureType)){
break;
}
// fall-through
default:
Uri uri =ContentUris.withAppendedId(
Mms.CONTENT_URI,
cursor.getLong(columnIndexOfMsgId));
TransactionBundle args = new TransactionBundle(
transactionType, uri.toString());
// FIXME: We use the same startId for all MMs.
launchTransaction(startId, args, false);
break;
}
}
} finally {
cursor.close();
}
} else {
if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
Log.v(TAG, "onStart: no pending messages. Stoppingservice.");
}
RetryScheduler.setRetryAlarm(this);
stopSelfIfIdle(startId);
}
} else {
if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
Log.v(TAG, "onStart: launch transaction...");
}
// For launching NotificationTransaction and test purpose.
TransactionBundle args = newTransactionBundle(intent.getExtras());
launchTransaction(startId, args,noNetwork);
}
return Service.START_NOT_STICKY;
}
8. src/com/android/mms/transaction/TransactionService.java
private void launchTransaction(int serviceId,TransactionBundle txnBundle, boolean noNetwork) {
Log.v(TAG, "launchTransaction");
if (noNetwork) {
Log.w(TAG, "launchTransaction: no network error!");
onNetworkUnavailable(serviceId,txnBundle.getTransactionType());
return;
}
Message msg = mServiceHandler.obtainMessage(EVENT_TRANSACTION_REQUEST);
msg.arg1 = serviceId;
msg.obj = txnBundle;
if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
Log.v(TAG, "launchTransaction: sending message " + msg);
}
mServiceHandler.sendMessage(msg);
}
9. src/com/android/mms/transaction/TransactionService.java
private final class ServiceHandler extends Handler {
public ServiceHandler(Looper looper) {
super(looper);
}
/**
* Handle incoming transactionrequests.
* The incoming requests are initiatedby the MMSC Server or by the
* MMS Client itself.
*/
@Override
public void handleMessage(Messagemsg) {
if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
Log.v(TAG, "Handling incoming message: " + msg);
}
Transaction transaction = null;
switch (msg.what) {
case EVENT_QUIT:
getLooper().quit();
return;
case EVENT_CONTINUE_MMS_CONNECTIVITY:
synchronized (mProcessing) {
if (mProcessing.isEmpty()) {
return;
}
}
if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
Log.v(TAG, "handle EVENT_CONTINUE_MMS_CONNECTIVITYevent...");
}
try {
int result =beginMmsConnectivity();
if (result != Phone.APN_ALREADY_ACTIVE){
Log.v(TAG, "Extending MMS connectivity returned " + result +
" instead of APN_ALREADY_ACTIVE");
// Just wait for connectivity startup without
// any newrequest of APN switch.
return;
}
} catch (IOException e) {
Log.w(TAG, "Attempt to extend use of MMS connectivityfailed");
return;
}
// Restart timer
sendMessageDelayed(obtainMessage(EVENT_CONTINUE_MMS_CONNECTIVITY),
APN_EXTENSION_WAIT);
return;
case EVENT_DATA_STATE_CHANGED:
/*
* If we are being informedthat connectivity has been established
* to allow MMS traffic,then proceed with processing the pending
* transaction, if any.
*/
if (mConnectivityListener == null) {
return;
}
NetworkInfo info = mConnectivityListener.getNetworkInfo();
if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
Log.v(TAG, "Handle DATA_STATE_CHANGED event: " + info);
}
// Check availability of the mobile network.
if ((info == null) || (info.getType() !=
ConnectivityManager.TYPE_MOBILE_MMS)) {
if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
Log.v(TAG, " type isnot TYPE_MOBILE_MMS, bail");
}
return;
}
if (!info.isConnected()) {
if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
Log.v(TAG, " TYPE_MOBILE_MMS not connected, bail");
}
return;
}
TransactionSettings settings = newTransactionSettings(
TransactionService.this,info.getExtraInfo());
// If this APN doesn't have an MMSC, wait for one that does.
if (TextUtils.isEmpty(settings.getMmscUrl())){
if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
Log.v(TAG, " empty MMSCurl, bail");
}
return;
}
// Set a timer to keep renewing our "lease" on the MMSconnection
sendMessageDelayed(obtainMessage(EVENT_CONTINUE_MMS_CONNECTIVITY),
APN_EXTENSION_WAIT);
processPendingTransaction(transaction, settings);
return;
case EVENT_TRANSACTION_REQUEST://响应请求
Log.v(TAG, "EVENT_TRANSACTION_REQUEST");
int serviceId = msg.arg1;
try {
TransactionBundle args= (TransactionBundle) msg.obj;
TransactionSettingstransactionSettings;
// Set the connection settings for this transaction.
// If these have not been set in args, load thedefault settings.
String mmsc =args.getMmscUrl();
if (mmsc != null) {
transactionSettings= new TransactionSettings(
mmsc,args.getProxyAddress(), args.getProxyPort());
} else {
transactionSettings= new TransactionSettings(
TransactionService.this, null);
}
int transactionType =args.getTransactionType();
Log.v(TAG, "transactionType = " + transactionType)
发表评论
-
ActivityGroup 替代tabActivity
2013-12-26 16:43 2539转载自http://www.cnblogs.com/answe ... -
Android实战技巧:为从右向左语言定义复杂字串
2013-09-04 17:37 1140我们所使用的语言,无论是中文还是英语, ... -
Android 5种方式存储数据:
2013-05-08 17:17 1098Android 提供了5种方式存储数据: --使用Shared ... -
widget的设计与应用
2013-02-02 16:27 9301.AppWidgetProviderInfo对象 ... -
Android系统主题设计和实现
2012-12-11 14:09 1481转自:http://www.apkbus.com/ ... -
Android实现DES对字符串加密
2012-09-02 14:15 17155import java.io.Unsuppor ... -
android综合
2012-08-02 16:25 15891 ,手动设置横竖屏 TestA ... -
onSaveInstanceState
2012-08-01 17:40 718@Override //存储 public void onSa ... -
处理多个Activity
2012-07-20 09:40 707public class LifecycleManager ... -
bitmap 和drawable 互相转换
2012-07-19 13:37 648// bitmap to drawable; Drawable ... -
设置壁纸的三种方法
2012-07-19 11:46 25221111111111111111111111111111111 ... -
sqlite数据库处理时间问题 和 日期时间函数
2012-06-27 10:36 22840首先,sqlite数据库在时间 ... -
app缓存管理
2012-06-27 10:25 1052无论大型或小型应用, ... -
Uri、UriMatcher、ContentUris类使用介绍&&Android应用间数据共享之ContentProvider
2012-05-24 15:50 4424Android应用开发中我们会经常用Uri进行数据的处理,下面 ... -
getWidth()为0
2012-04-12 10:06 2008一般在刚开始开发android时,会犯一个错误,即在View的 ... -
自定义View 及使用
2012-04-05 14:08 769可能是一直都在做Web的富客户端开发的缘故吧,在接触Andro ... -
搜索手机联系人所有字段
2012-03-28 15:54 1442想取手机联系人的有效字段,但是苦于找不到API表示的字段变量, ... -
Andoid2.X各字段意义
2012-03-28 14:59 1250ContactsContract.Contacts.TIMES ... -
SMS发送流程
2012-03-20 18:07 1256发短信流程: 1 afterTextChanged{mWork ... -
Android telephony MMS 学习笔记
2012-03-14 13:32 2883转载 http://blog.csdn.net/tjy1985 ...
相关推荐
Android MMS 发送流程分析 Android 操作系统中,MMS 发送流程是一个复杂的过程,涉及到多个组件和类的交互。在本文中,我们将对 Android 2.2 版本中的 MMS 发送流程进行详细的分析。 点击发送按钮 在 ...
以下是从提供的文件【MMS发送流程代码版android.pdf】中提取的关于MMS发送流程的关键知识点: 1. **发送按钮触发**: 当用户点击发送按钮时,该操作在`src/com/android/mms/ui/ComposeMessageActivity.java`中的`...
以下是对MMS发送流程的详细解析,基于提供的代码片段: 1. **发送触发**: 当用户在MMS应用中点击“发送”按钮时,触发发送流程。这个过程在`ComposeMessageActivity.java`中的`onClick()`方法内开始。当`...
MMS发送流程(代码版)android.doc
彩信发送流程
在 Messaging 应用层,MMS 彩信发送流程主要涉及到以下几个组件: 1. 短信/彩信会话列表界面(ConversationListActivity):该组件负责展示短信/彩信的会话列表,提供了用户与其他人的对话记录。 2. 短信/彩信编辑...
MMS发送流程** 1) 用户在MMS应用中创建包含多媒体内容的消息。 2) 应用将内容编码为MIME格式,并构建MMS请求。 3) 请求通过HTTP/HTTPS发送到MMSC。 4) MMSC验证发送者的身份和接收者的信息。 5) 如果接收者也使用...
6. **MMS发送流程** 发送MMS时,MmsService首先创建MMS消息对象,然后通过WAP Push技术将消息封装成二进制数据,通过网络发送。接收方的设备会监听WAP Push服务,接收到MMS通知后,再通过MmsService和Mms类进行...
5. **MMS发送流程**:发送MMS时,手机会通过WAP连接将消息发送到MMS代理服务器,该服务器负责转发到收件人的MMS用户代理。过程中可能涉及HTTP或WSP(WAP Session Protocol)协议。 6. **MMS接收流程**:当接收到MMS...
二、MMS发送流程 1. 用户在MmsApp中创建并编辑MMS消息。 2. 应用通过ContentProvider将消息内容保存到数据库。 3. 发送Intent启动MmsService,传递消息ID和服务URL等信息。 4. MmsService使用HTTP/HTTPS通过WAP ...
虽然源码未经过完整调试,但通过这些文件我们可以了解MMS发送的基本流程:从用户界面接收到发送指令,通过SerialPort.cpp建立网络连接,然后使用Ip.cpp和Protocol_PPP.cpp处理IP层和PPP层的通信,接着构建SMIL内容,...
2. **MMS发送流程** - 用户在MMS应用中创建并编辑彩信。 - 应用通过`MMSC`组件与服务器建立连接,上传多媒体内容。 - `MMSC`将多媒体内容转化为WAP Push格式,并通过SMS发送彩信通知,包含MMS的URL。 - 收件人的...
MMS发送接收流程协议分析,以及在Android中的相关实现
#### 一、Android MMS发送流程概述 MMS发送主要涉及以下几个关键步骤: 1. **消息线程创建**:首先需要为发送的MMS消息创建一个消息线程ID。 2. **消息发送处理**:接下来通过`MmsMessageSender`类进行具体的消息...
MMS(Multimedia Messaging Service)即多媒体信息服务,是一种在移动网络中发送和接收包含文本、图像、音频、视频等多媒体内容的消息服务。与传统的SMS短信相比,MMS提供了更为丰富的信息传递方式。 **1. MMS业务...
在Android MMS专题中,我们探讨的是信息发送流程,这一过程涉及到多个组件和步骤,确保信息能够成功地从用户界面传递到接收者。以下是对这一过程的详细解析: 首先,当用户在MMS应用程序中创建并发送信息时,信息会...