- 浏览: 436203 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
weiwu83:
为什么我在手机内访问127.0.0.1访问不了呀
NanoHttpd 构建android 手机端的HttpServer -
jiae:
为啥我的插入语句乱码? 但是可以插入数据库 然后复制你 ...
SQLite3 在应用启动时初始化数据 -
lichenxiao77:
...
android 连接远程数据库 -
林源滔:
为什么我make clobber之后第一次执行make 可以。 ...
No rule to make target `out/target/common/obj/JAVA_LIBRARIES/bouncycastle_in -
cn23snyga:
new String(str.getBytes("I ...
android 平台上SQLite3中文乱码 --我的小bug
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);
if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
Log.v(TAG, "handle EVENT_TRANSACTION_REQUEST:transactionType=" +
transactionType);
}
// Create appropriate transaction
switch (transactionType){
case Transaction.NOTIFICATION_TRANSACTION:
String uri =args.getUri();
if (uri != null) {
transaction= new NotificationTransaction(
TransactionService.this, serviceId,
transactionSettings, uri);
} else {
// Now it's only used for test purpose.
byte[] pushData =args.getPushData();
PduParserparser = new PduParser(pushData);
GenericPdu ind= parser.parse();
int type = PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND;
if ((ind != null) &&(ind.getMessageType() == type)) {
transaction = newNotificationTransaction(
TransactionService.this, serviceId,
transactionSettings, (NotificationInd) ind);
} else {
Log.e(TAG, "Invalid PUSH data.");
transaction = null;
return;
}
}
break;
case Transaction.RETRIEVE_TRANSACTION:
transaction = newRetrieveTransaction(
TransactionService.this, serviceId,
transactionSettings, args.getUri());
break;
case Transaction.SEND_TRANSACTION://根据transactiontype响应发送彩信
Log.v(TAG, "Transaction.SEND_TRANSACTION");
transaction = new SendTransaction(
TransactionService.this, serviceId,
transactionSettings, args.getUri());
break;
case Transaction.READREC_TRANSACTION:
transaction = newReadRecTransaction(
TransactionService.this, serviceId,
transactionSettings, args.getUri());
break;
default:
Log.w(TAG, "Invalidtransaction type: " + serviceId);
transaction = null;
return;
}
if (!processTransaction(transaction)) {
transaction = null;
return;
}
if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
Log.v(TAG, "Started processing of incoming message: " + msg);
}
} catch (Exception ex) {
Log.w(TAG, "Exception occurred while handling message: " + msg, ex);
if (transaction != null) {
try {
transaction.detach(TransactionService.this);
if (mProcessing.contains(transaction)){
synchronized (mProcessing) {
mProcessing.remove(transaction);
}
}
} catch (Throwable t) {
Log.e(TAG, "Unexpected Throwable.", t);
} finally {
// Set transaction to null to allow stopping the
// transaction service.
transaction = null;
}
}
} finally {
if (transaction == null) {
if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
Log.v(TAG, "Transaction was null. Stopping self: " + serviceId);
}
endMmsConnectivity();
stopSelf(serviceId);
}
}
return;
case EVENT_HANDLE_NEXT_PENDING_TRANSACTION:
processPendingTransaction(transaction, (TransactionSettings) msg.obj);
return;
default:
Log.w(TAG, "what=" + msg.what);
return;
}
}
10. src/com/android/mms/transaction/TransactionService.java
/**
* Internal method to begin processinga transaction.
* @param transaction the transaction. Must not be{@code null}.
* @return {@code true} if process hasbegun or will begin. {@code false}
* if the transaction should bediscarded.
* @throws IOException if connectivityfor MMS traffic could not be
* established.
*/
private boolean processTransaction(Transaction transaction) throws IOException {
// Check if transaction already processing
Log.v(TAG, "processTransaction");
synchronized (mProcessing) {
for (Transaction t : mPending) {
if (t.isEquivalent(transaction)) {
if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
Log.v(TAG, "Transaction already pending: " +
transaction.getServiceId());
}
return true;
}
}
for (Transaction t : mProcessing) {
if (t.isEquivalent(transaction)) {
if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
Log.v(TAG, "Duplicated transaction: " + transaction.getServiceId());
}
return true;
}
}
/*
* Make sure that the networkconnectivity necessary
* for MMS traffic is enabled.If it is not, we need
* to defer processing thetransaction until
* connectivity is established.
*/
if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
Log.v(TAG, "processTransaction: callbeginMmsConnectivity...");
}
int connectivityResult = beginMmsConnectivity();
if (connectivityResult == Phone.APN_REQUEST_STARTED){
mPending.add(transaction);
if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
Log.v(TAG, "processTransaction: connResult=APN_REQUEST_STARTED," +
"defer transaction pending MMS connectivity");
}
return true;
}
if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
Log.v(TAG, "Adding transaction to 'mProcessing' list: " + transaction);
}
mProcessing.add(transaction);
}
// Set a timer to keep renewing our "lease" on the MMSconnection
sendMessageDelayed(obtainMessage(EVENT_CONTINUE_MMS_CONNECTIVITY),
APN_EXTENSION_WAIT);
if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
Log.v(TAG, "processTransaction: starting transaction " + transaction);
}
// Attach to transaction and process it
transaction.attach(TransactionService.this);
transaction.process();
return true;
}
11.src/com/android/mms/transaction/SendTransaction.java
@Override
public void process() {
Log.v(TAG, "process");
mThread = new Thread(this);
mThread.start();
}
12. src/com/android/mms/transaction/SendTransaction.java
public void run() {
Log.v(TAG, "run()");
try {
RateController rateCtlr =RateController.getInstance();
if (rateCtlr.isLimitSurpassed() &&!rateCtlr.isAllowedByUser()) {
Log.e(TAG, "Sending rate limit surpassed.");
return;
}
// Load M-Send.req from outbox
PduPersister persister = PduPersister.getPduPersister(mContext);
SendReq sendReq = (SendReq)persister.load(mSendReqURI);
// Update the 'date' field of the PDU right before sending it.
long date = System.currentTimeMillis() /1000L;
sendReq.setDate(date);
// Persist the new date value into database.
ContentValues values = new ContentValues(1);
values.put(Mms.DATE, date);
SqliteWrapper.update(mContext, mContext.getContentResolver(),
mSendReqURI, values, null, null);
// fix bug 2100169: insert the 'from' address per spec
String lineNumber = MessageUtils.getLocalNumber();
if (!TextUtils.isEmpty(lineNumber)) {
sendReq.setFrom(new EncodedStringValue(lineNumber));
}
// Pack M-Send.req, send it, retrieve confirmation data, and parse it
long tokenKey = ContentUris.parseId(mSendReqURI);
byte[] response = sendPdu(SendingProgressTokenManager.get(tokenKey),
new PduComposer(mContext,sendReq).make());//发送彩信
SendingProgressTokenManager.remove(tokenKey);
if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
String respStr = new String(response);
Log.d(TAG, "[SendTransaction] run: send mms msg (" + mId + "),resp=" + respStr);
}
SendConf conf = (SendConf)new PduParser(response).parse();
if (conf == null) {
Log.e(TAG, "No M-Send.conf received.");
}
// Check whether the responding Transaction-ID is consistent
// with the sent one.
byte[] reqId = sendReq.getTransactionId();
byte[] confId = conf.getTransactionId();
if (!Arrays.equals(reqId, confId)) {
Log.e(TAG, "Inconsistent Transaction-ID: req="
+ new String(reqId) + ", conf=" + new String(confId));
return;
}
// From now on, we won't save the whole M-Send.conf into
// our database. Instead, we just save some interesting fields
// into the related M-Send.req.
values = new ContentValues(2);
int respStatus = conf.getResponseStatus();
values.put(Mms.RESPONSE_STATUS,respStatus);
if (respStatus != PduHeaders.RESPONSE_STATUS_OK){
SqliteWrapper.update(mContext, mContext.getContentResolver(),
mSendReqURI, values, null, null);
Log.e(TAG, "Server returned an error code: " + respStatus);
return;
}
String messageId = PduPersister.toIsoString(conf.getMessageId());
values.put(Mms.MESSAGE_ID,messageId);
SqliteWrapper.update(mContext, mContext.getContentResolver(),
mSendReqURI, values, null, null);
// Move M-Send.req from Outbox into Sent.
Uri uri = persister.move(mSendReqURI, Sent.CONTENT_URI);
mTransactionState.setState(TransactionState.SUCCESS);
mTransactionState.setContentUri(uri);
} catch (Throwable t) {
Log.e(TAG, Log.getStackTraceString(t));
} finally {
if (mTransactionState.getState() != TransactionState.SUCCESS) {
mTransactionState.setState(TransactionState.FAILED);
mTransactionState.setContentUri(mSendReqURI);
Log.e(TAG, "Delivery failed.");
}
notifyObservers();
}
}
13.src/com/android/mms/transaction/Transaction.java
/**
* A common method to send a PDU to MMSC.
*
* @param token The token to identify the sendingprogress.
* @param pdu A byte array which contains the dataof the PDU.
* @return A byte array which containsthe response data.
* If an HTTP error code is returned, an IOException will be thrown.
* @throws IOException if any erroroccurred on network interface or
* an HTTP error code(>=400) returned from the server.
*/
protected byte[] sendPdu(long token, byte[]pdu) throws IOException {
return sendPdu(token, pdu, mTransactionSettings.getMmscUrl());
}
14. src/com/android/mms/transaction/Transaction.java
protected byte[] sendPdu(long token, byte[] pdu, StringmmscUrl) throws IOException {
ensureRouteToHost(mmscUrl, mTransactionSettings);
return HttpUtils.httpConnection(
mContext, token,
mmscUrl,
pdu, HttpUtils.HTTP_POST_METHOD,
mTransactionSettings.isProxySet(),
mTransactionSettings.getProxyAddress(),
mTransactionSettings.getProxyPort());//通过网络发送彩信,AP层的最后实现
}
发表评论
-
Android.mk文件解析
2016-01-27 14:01 939以 tools/tradefederation/Androi ... -
NanoHttpd 构建android 手机端的HttpServer
2015-10-20 16:24 2948NanoHttpd是Github上的一个开源项目, 通过下载 ... -
permission denial : android.permission.INTERACT_ACROSS_USERS_FULL
2015-08-05 16:50 5047在android5.0上运行 Runtime.getRun ... -
android getprop() 和 java System.getPropety()
2015-06-04 14:39 63591 System.getPropety()是java中的方 ... -
android cts测试相关
2015-05-27 17:38 0example: -
android uiautomator 相关
2015-05-15 16:53 16951 Runtime.getRuntime().exec 启 ... -
android UI test Espresso
2015-04-10 18:31 1204google android UI测试工具 espresso ... -
android 安全(转)
2014-12-26 12:37 722一 如何不被反编译解析1防止反编译工具的反编译 查看 ... -
nexus related
2014-12-17 15:29 7411 nexus drivers https://deve ... -
git related
2014-12-17 15:24 9671 see all detailed git info ... -
ubuntu android studio 配置和使用
2014-12-10 17:34 3627Ubuntu 64位,Android studio 的安装, ... -
eclipse+ADT+android配置相关
2014-12-05 16:40 14531 eclipse 过旧时,ant 运行不了,会报sdk. ... -
anroid 开发小知识点
2014-10-09 09:52 8241 1)代码 获取APK安装路径和包名 L ... -
androird 内存泄露 浅析
2013-06-19 17:52 1449主要是记录工作中出 ... -
mms 相关链接
2013-03-15 13:53 1396http://blog.chinaunix.net/uid ... -
java层堆栈调用的打印
2012-12-26 15:14 44721. 在指定的函数内打印相关java调用 Log.d ... -
mms 数据包相关
2012-11-26 14:51 22721 抓包 adb shell tcpdump -i any ... -
sms AT指令返回错误代码: CMS errors & CME errors 的区别!
2012-10-26 18:35 12027CMS的是短信中心的返回错误。 CME 是设备返 ... -
sms 发送 radio log
2012-10-26 17:25 4074发送短信:radio.log 关键字 :SEND_SMS ... -
SQLite --函数
2012-09-03 18:22 1988一、日期和时间函数:原文地址SQLite主要支持以下 ...
相关推荐
Android MMS 发送流程分析 Android 操作系统中,MMS 发送流程是一个复杂的过程,涉及到多个组件和类的交互。在本文中,我们将对 Android 2.2 版本中的 MMS 发送流程进行详细的分析。 点击发送按钮 在 ...
在 Messaging 应用层,MMS 彩信发送流程主要涉及到以下几个组件: 1. 短信/彩信会话列表界面(ConversationListActivity):该组件负责展示短信/彩信的会话列表,提供了用户与其他人的对话记录。 2. 短信/彩信编辑...
以上就是Android MMS发送流程的核心步骤,涉及到了用户交互、数据验证、网络通信以及错误处理等多个方面。每个环节都是确保MMS服务正常运行的关键组成部分。在实际开发中,开发者需要考虑多种情况,以保证在各种环境...
#### 一、Android MMS发送流程概述 MMS发送主要涉及以下几个关键步骤: 1. **消息线程创建**:首先需要为发送的MMS消息创建一个消息线程ID。 2. **消息发送处理**:接下来通过`MmsMessageSender`类进行具体的消息...
以下是从提供的文件【MMS发送流程代码版android.pdf】中提取的关于MMS发送流程的关键知识点: 1. **发送按钮触发**: 当用户点击发送按钮时,该操作在`src/com/android/mms/ui/ComposeMessageActivity.java`中的`...
MMS发送流程(代码版)android.doc
MMS发送接收流程协议分析,以及在Android中的相关实现
在Android MMS专题中,我们探讨的是信息发送流程,这一过程涉及到多个组件和步骤,确保信息能够成功地从用户界面传递到接收者。以下是对这一过程的详细解析: 首先,当用户在MMS应用程序中创建并发送信息时,信息会...
虽然源码未经过完整调试,但通过这些文件我们可以了解MMS发送的基本流程:从用户界面接收到发送指令,通过SerialPort.cpp建立网络连接,然后使用Ip.cpp和Protocol_PPP.cpp处理IP层和PPP层的通信,接着构建SMIL内容,...
MMS发送流程** 1) 用户在MMS应用中创建包含多媒体内容的消息。 2) 应用将内容编码为MIME格式,并构建MMS请求。 3) 请求通过HTTP/HTTPS发送到MMSC。 4) MMSC验证发送者的身份和接收者的信息。 5) 如果接收者也使用...
MMS(Multimedia Messaging Service)即多媒体信息服务,是一种在移动网络中发送和接收包含文本、图像、音频、视频等多媒体内容的消息服务。与传统的SMS短信相比,MMS提供了更为丰富的信息传递方式。 **1. MMS业务...
最简单的android彩信发送代码。适合学习彩信发送流程。 事实上android中的Mms模块中,对这个流程进行了很少的封装,这里就是将其简化,帮助初学者了解流程。
两者在Android系统中都由`SmsManager`管理,但发送MMS的流程比发送SMS复杂,涉及到更多的数据处理和网络交互。 9. **安全与隐私**:处理MMS时,开发者需要注意用户隐私和数据安全,如正确处理敏感信息,避免信息...
例如,发送MMS的意图可能会触发服务端的处理流程。 - **Content Provider**:提供对MMS和SMS数据的统一访问接口,允许其他应用通过URI查询和修改MMS信息。 - **BroadcastReceiver**:监听系统事件,如网络状态变化...
二、MMS发送流程 1. 用户在MmsApp中创建并编辑MMS消息。 2. 应用通过ContentProvider将消息内容保存到数据库。 3. 发送Intent启动MmsService,传递消息ID和服务URL等信息。 4. MmsService使用HTTP/HTTPS通过WAP ...