MMS发送流程android
Android2.2packages/apps/Mms
1.点击发送按钮Src/com/android/mms/ui/
publicvoidonClick(Viewv){
if((v==mSendButton)&&isPreparedForSending()){
confirmSendMessageIfNeeded();//确认是否需要发送短信—-》
}
}
/com/android/mms/ui/
privatevoidconfirmSendMessageIfNeeded(){
if(!isRecipientsEditorVisible()){//编辑联系人不可见时,也就是给已存在会话的联
系人发送短信时
ndMessage(true);
return;
}
booleanisMms=esMms();//是否需要以彩信形式发送
if(alidRecipient(isMms)){//是否含有不合法的收件
人
if(idRecipient(isMms)){//有合法的与不合法的,弹出尝
试发送对话框
Stringtitle=getResourcesString(_invalid_recipient,
InvalidNumbers(isMms));
r(this)
.tIcon(_dialog_alert)
.tTitle(title)
.tMessage(d_recipient_message)
.tPositiveButton(_to_nd,
newSendIgnoreInvalidRecipientListener())
.tNegativeButton(,newCancelSendingListener())
.show();
}el{//假如全是不合法的联系人,提示不能发送信息
r(this)
.tIcon(_dialog_alert)
.tTitle(_nd_message)
.tMessage(_nd_message_reason)
.tPositiveButton(,newCancelSendingListener())
.show();
}
}el{//推断收件人没有问题,接着发送信息--》
ndMessage(true);
}
}
/com/android/mms/ui/
privatevoidndMessage(booleanbCheckEcmMode){
Log.v(TAG,"ndMessage");
if(bCheckEcmMode){
//TODO:expothisintelephonylayerforSDKbuild
StringinEcm=
(TY_INECM_MODE);//推断电话是否处于紧急拨
号模式,得到的inEcm通常为空
Log.v(TAG,"inEcm="+inEcm);
if(oolean(inEcm)){
try{
startActivityForResult(
new
Intent(_SHOW_NOTICE_ECM_BLOCK_OTHERS,null),
REQUEST_CODE_ECM_EXIT_DIALOG);
return;
}catch(ActivityNotFoundExceptione){
//continuetondmessage
Log.e(TAG,"CannotfindEmergencyCallbackModeExitDialog",e);
}
}
}
if(!mSendingMessage){
//reweremovethelistenersfirstand
thenadd
//thembackoncetherecipientlisthasttled.
removeRecipientsListeners();//取消对收件人的监听
();//发送信息—-》
mSentMessage=true;
mSendingMessage=true;
addRecipientsListeners();//重新添加收件人监听
}
//Butbailoutifwearesuppodtoexitafterthemessageisnt.
if(mExitOnSent){//假如mExitOnSent为true,信息发送完成后退出Activity
finish();
}
}
/com/android/mms/data/
/**
*llbackwithonMessageSent()once
*rkingMessageobjectis
*nolongerufulafterthismethodhasbeencalled.
*/
publicvoidnd(){
if(able(CTION,E)){
("nd");
}
//Getreadytowritetodisk.
prepareForSave(true/*notify*/);//要紧做一下同步收件人与WorkingMessage,彩信时在
准备其他一些东西
//WeneedtherecipientlistforbothSMSandMMS.
finalConversationconv=mConversation;
StringmsgTxt=ng();
Log.v(TAG,"msgText="+msgTxt);
if(requiresMms()||addressContainsEmailToMms(conv,msgTxt)){
//Makelocalcopiesofthebitsweneedforndingamessage,
//becauwewillbedoingitoffofthemainthread,whichwill
//immediatelycontinueontorettingsomeofthisstate.
finalUrimmsUri=mMessageUri;//假如第一次发送,如今mmsUri为null,假如是
重发,则是草稿箱的地址mMessageUri=content://mms/drafts/1
finalPduPersisterpersister=Persister(mContext);
finalSlideshowModelslideshow=mSlideshow;
finalSendReqndReq=makeSendReq(conv,mSubject);
//DothedirtyworkofndingthemessageoffofthemainUIthread.
newThread(newRunnable(){
publicvoidrun(){
//Makesurethetextinslide0isnolongerholdingontoa
referenceto
//thetextinthemessagetextbox.
eForSend();
ndMmsWorker(conv,mmsUri,persister,slideshow,ndReq);
}
}).start();
}el{
//Samerulesapplyasabove.
finalStringmsgText=ng();//取出短消息
Log.v(TAG,"msgText="+msgText);
newThread(newRunnable(){
publicvoidrun(){
preSendSmsWorker(conv,msgText);//发送信息--》
}
}).start();
}
//updatetheRecipientcachewiththenewtoaddress,ifit'sdifferent
Numbers(eadId(),ipients());
//Markthemessageasdiscardedbecauitis"offthemarket"afterbeingnt.
mDiscarded=true;
}
/com/android/mms/data/
privatevoidndMmsWorker(Conversationconv,UrimmsUri,PduPersisterpersister,
SlideshowModelslideshow,SendReqndReq){
Log.v(TAG,"ndMmsWorker");
//Ifurtriestondthemessage,it'sasignaltheinputtedtextiswhatthey
wanted.
ceptedImeText(mContext);
//Firstmakesurewedon'thavetoomanyoutstandingunntmessage.
Cursorcursor=null;
try{
cursor=(mContext,mContentResolver,
T_URI,MMS_OUTBOX_PROJECTION,null,null,null);
if(cursor!=null){//假如MMS_OUTBOX里有未发送的彩信,同时总的大小已经超过了
彩信的最大限制,则取消此次发送,并存入草稿箱
Log.v(TAG,"T_URIisnotempty");
longmaxMessageSize=SizeScaleForPendingMmsAllowed()*
MessageSize();
Log.v(TAG,"SizeScaleForPendingMmsAllowed()="+
SizeScaleForPendingMmsAllowed());
Log.v(TAG,"MessageSize()()="+
MessageSize());
longtotalPendingSize=0;
while(Next()){
totalPendingSize+=g(MMS_MESSAGE_SIZE_INDEX);
Log.v(TAG,"totalPendingSize="+totalPendingSize);
}
if(totalPendingSize>=maxMessageSize){
unDiscard();//itwasn'ttobesaved
asadraft.
endingMessagesReached();
return;
}
}el{
Log.v(TAG,"T_URIimpty");
}
}finally{
if(cursor!=null){
();
}
}
essageSent();
//MakesurewearestillusingthecorrectthreadIDforour
//recipientt.
longthreadId=ThreadId();
if(able(,E)){
("ndMmsWorker:updatedraftMMSmessage"+mmsUri);
}
if(mmsUri==null){//假如是首次发送,先把彩信储存入草稿箱
//CreateanewMMSmessageifonehasn'tbeenmadeyet.
Log.v(TAG,"mmsUri==nullandstartcreateDraftMmsMessage");
mmsUri=createDraftMmsMessage(persister,ndReq,slideshow);
}el{
//Otherwi,synctheMMSmessageinprogresstodisk.
Log.v(TAG,"mmsUri="+mmsUri);
Log.v(TAG,"updateDraftMmsMessage");
updateDraftMmsMessage(mmsUri,persister,slideshow,ndReq);
}
//BeparanoidandcleananydraftSMSup.
deleteDraftSmsMessage(threadId);
//Resizealltheresizeableattachments(es)tofit
//intheremainingspaceintheslideshow.
interror=0;
try{
esize(mmsUri);
}catch(ExceedMessageSizeExceptione1){
error=MESSAGE_SIZE_EXCEEDED;
}catch(MmsExceptione1){
error=UNKNOWN_ERROR;
}
if(error!=0){
markMmsMessageWithError(mmsUri);
chmentError(error);
return;
}
MessageSendernder=newMmsMessageSender(mContext,mmsUri,
rentMessageSize());
try{
if(!ssage(threadId)){
//ThemessagewasntthroughSMSprotocol,weshould
//deletethecopywhichwaspreviouslysavedinMMSdrafts.
(mContext,mContentResolver,mmsUri,null,null);
}
//Makesurethisthreadisn'toverthelimitsinmessagecount
Recycler().deleteOldMessagesByThreadId(mContext,threadId);
}catch(Exceptione){
Log.e(TAG,"Failedtondmessage:"+mmsUri+",threadId="+threadId,e);
}
ageSent();
}
/com/android/mms/transaction/
publicbooleanndMessage(longtoken)throwsMmsException{
//LoadtheMMSfromthemessageuri
PduPersisterp=Persister(mContext);
GenericPdupdu=(mMessageUri);
if(sageType()!=E_TYPE_SEND_REQ){
thrownewMmsException("Invalidmessage:"+sageType());
}
SendReqndReq=(SendReq)pdu;
//Updateheaders.
updatePreferencesHeaders(ndReq);
//MessageClass.
sageClass(DEFAULT_MESSAGE_es());
//Updatethe'date'fieldofthemessagebeforendingit.
e(tTimeMillis()/1000L);
sageSize(mMessageSize);
Headers(mMessageUri,ndReq);
//MovethemessageintoMMSOutbox
(mMessageUri,T_URI);
//StartMMStransactionrvice
(d(mMessageUri),token);
ervice(newIntent(mContext,));
returntrue;
}
/com/android/mms/transaction/
@Override
publicintonStartCommand(Intentintent,intflags,intstartId){
Log.v(TAG,"onStartCommand");
if(intent==null){
_NOT_STICKY;
}
mConnMgr=(ConnectivityManager)getSystemService(TIVITY_SERVICE);
booleannoNetwork=!isNetworkAvailable();
if(able(CTION,E)){
Log.v(TAG,"onStart:#"+startId+":"+ras()+"intent="+
intent);
Log.v(TAG,"networkAvailable="+!noNetwork);
}
Log.v(TAG,"getActionis"+ion());
if(ACTION_(ion())||(ras()==null)){
Log.v(TAG,"ACTION_(ion())||(ras()==
null)");
//Scandatabatofindallpendingoperations.
Cursorcursor=Persister(this).getPendingMessages(
tTimeMillis());
if(cursor!=null){
try{
intcount=nt();
if(able(CTION,E)){
Log.v(TAG,"onStart:="+count);
}
if(count==0){
if(able(CTION,E)){
Log.v(TAG,"onStart:nopendingmessages.
Stoppingrvice.");
}
ryAlarm(this);
stopSelfIfIdle(startId);
_NOT_STICKY;
}
intcolumnIndexOfMsgId
=umnIndexOrThrow(_ID);
intcolumnIndexOfMsgType=umnIndexOrThrow(
_TYPE);
if(noNetwork){
//Makesureweregisterforconnectionstatechanges.
if(able(CTION,E)){
Log.v(TAG,"onStart:registerForConnectionStateChanges");
}
erForConnectionStateChanges(
getApplicationContext());
}
while(Next()){
intmsgType=(columnIndexOfMsgType);
inttransactionType=getTransactionType(msgType);
Log.v(TAG,"msgType="+msgType);
Log.v(TAG,"transactionType="+transactionType);
if(noNetwork){
onNetworkUnavailable(startId,transactionType);
_NOT_STICKY;
}
switch(transactionType){
ca-1:
break;
VE_TRANSACTION:
//Ifit'satransientlyfailedtransaction,
//weshouldretryitinspiteofcurrent
//downloadingmode.
intfailureType=(
umnIndexOrThrow(
_TYPE));
if(!isTransientFailure(failureType)){
break;
}
//fall-through
default:
Uriuri=pendedId(
T_URI,
g(columnIndexOfMsgId));
TransactionBundleargs=newTransactionBundle(
transactionType,ng());
//FIXME:WeuthesamestartIdforallMMs.
launchTransaction(startId,args,fal);
break;
}
}
}finally{
();
}
}el{
if(able(CTION,E)){
Log.v(TAG,"onStart:ngrvice.");
}
ryAlarm(this);
stopSelfIfIdle(startId);
}
}el{
if(able(CTION,E)){
Log.v(TAG,"onStart:launchtransaction...");
}
//ForlaunchingNotificationTransactionandtestpurpo.
TransactionBundleargs=newTransactionBundle(ras());
launchTransaction(startId,args,noNetwork);
}
_NOT_STICKY;
}
/com/android/mms/transaction/
privatevoidlaunchTransaction(intrviceId,TransactionBundletxnBundle,booleannoNetwork)
{
Log.v(TAG,"launchTransaction");
if(noNetwork){
Log.w(TAG,"launchTransaction:nonetworkerror!");
onNetworkUnavailable(rviceId,nsactionType());
return;
}
Messagemsg=Message(EVENT_TRANSACTION_REQUEST);
1=rviceId;
=txnBundle;
if(able(CTION,E)){
Log.v(TAG,"launchTransaction:ndingmessage"+msg);
}
ssage(msg);
}
/com/android/mms/transaction/
privatefinalclassServiceHandlerextendsHandler{
publicServiceHandler(Looperlooper){
super(looper);
}
/**
*Handleincomingtransactionrequests.
*TheincomingrequestsareinitiatedbytheMMSCServerorbythe
*MMSClientitlf.
*/
@Override
publicvoidhandleMessage(Messagemsg){
if(able(CTION,E)){
Log.v(TAG,"Handlingincomingmessage:"+msg);
}
Transactiontransaction=null;
switch(){
caEVENT_QUIT:
getLooper().quit();
return;
caEVENT_CONTINUE_MMS_CONNECTIVITY:
synchronized(mProcessing){
if(y()){
return;
}
}
if(able(CTION,E)){
Log.v(TAG,"handleEVENT_CONTINUE_MMS_CONNECTIVITYevent...");
}
try{
intresult=beginMmsConnectivity();
if(result!=_ALREADY_ACTIVE){
Log.v(TAG,"ExtendingMMSconnectivityreturned"+result
+
"insteadofAPN_ALREADY_ACTIVE");
//Justwaitforconnectivitystartupwithout
//anynewrequestofAPNswitch.
return;
}
}catch(IOExceptione){
Log.w(TAG,"AttempttoextenduofMMSconnectivityfailed");
return;
}
//Restarttimer
ndMessageDelayed(obtainMessage(EVENT_CONTINUE_MMS_CONNECTIVITY),
APN_EXTENSION_WAIT);
return;
caEVENT_DATA_STATE_CHANGED:
/*
*Ifwearebeinginformedthatconnectivityhasbeenestablished
*toallowMMStraffic,thenproceedwithprocessingthepending
*transaction,ifany.
*/
if(mConnectivityListener==null){
return;
}
NetworkInfoinfo=workInfo();
if(able(CTION,E)){
Log.v(TAG,"HandleDATA_STATE_CHANGEDevent:"+info);
}
//Checkavailabilityofthemobilenetwork.
if((info==null)||(e()!=
_MOBILE_MMS)){
if(able(CTION,E)){
Log.v(TAG,"typeisnotTYPE_MOBILE_MMS,bail");
}
return;
}
if(!ected()){
if(able(CTION,E)){
Log.v(TAG,"TYPE_MOBILE_MMSnotconnected,bail");
}
return;
}
TransactionSettingsttings=newTransactionSettings(
,raInfo());
//IfthisAPNdoesn'thaveanMMSC,waitforonethatdoes.
if(y(cUrl())){
if(able(CTION,E)){
Log.v(TAG,"emptyMMSCurl,bail");
}
return;
}
//Setatimertokeeprenewingour"lea"ontheMMSconnection
ndMessageDelayed(obtainMessage(EVENT_CONTINUE_MMS_CONNECTIVITY),
APN_EXTENSION_WAIT);
processPendingTransaction(transaction,ttings);
return;
caEVENT_TRANSACTION_REQUEST://响应请求
Log.v(TAG,"EVENT_TRANSACTION_REQUEST");
intrviceId=1;
try{
TransactionBundleargs=(TransactionBundle);
TransactionSettingstransactionSettings;
//Settheconnectionttingsforthistransaction.
//Ifthehavenotbeentinargs,loadthedefaultttings.
Stringmmsc=cUrl();
if(mmsc!=null){
transactionSettings=newTransactionSettings(
mmsc,xyAddress(),xyPort());
}el{
transactionSettings=newTransactionSettings(
,null);
}
inttransactionType=nsactionType();
Log.v(TAG,"transactionType="+transactionType);
if(able(CTION,E)){
Log.v(TAG,"handle
EVENT_TRANSACTION_REQUEST:transactionType="+
transactionType);
}
//Createappropriatetransaction
switch(transactionType){
CATION_TRANSACTION:
Stringuri=();
if(uri!=null){
transaction=newNotificationTransaction(
,rviceId,
transactionSettings,uri);
}el{
//Nowit'sonlyudfortestpurpo.
byte[]pushData=hData();
PduParrparr=newPduParr(pushData);
GenericPduind=();
inttype=
E_TYPE_NOTIFICATION_IND;
if((ind!=null)&&(sageType()==type))
{
transaction=newNotificationTransaction(
,rviceId,
transactionSettings,(NotificationInd)
ind);
}el{
Log.e(TAG,"InvalidPUSHdata.");
transaction=null;
return;
}
}
break;
VE_TRANSACTION:
transaction=newRetrieveTransaction(
,rviceId,
transactionSettings,());
break;
_TRANSACTION://根据transactiontype响
应发送彩信
Log.v(TAG,"_TRANSACTION");
transaction=newSendTransaction(
,rviceId,
transactionSettings,());
break;
C_TRANSACTION:
transaction=newReadRecTransaction(
,rviceId,
transactionSettings,());
break;
default:
Log.w(TAG,"Invalidtransactiontype:"+rviceId);
transaction=null;
return;
}
if(!processTransaction(transaction)){
transaction=null;
return;
}
if(able(CTION,E)){
Log.v(TAG,"Startedprocessingofincomingmessage:"+
msg);
}
}catch(Exceptionex){
Log.w(TAG,"Exceptionoccurredwhilehandlingmessage:"+msg,
ex);
if(transaction!=null){
try{
();
if(ns(transaction)){
synchronized(mProcessing){
(transaction);
}
}
}catch(Throwablet){
Log.e(TAG,"UnexpectedThrowable.",t);
}finally{
//Settransactiontonulltoallowstoppingthe
//transactionrvice.
transaction=null;
}
}
}finally{
if(transaction==null){
if(able(CTION,E)){
Log.v(TAG,"nglf:"+
rviceId);
}
endMmsConnectivity();
stopSelf(rviceId);
}
}
return;
caEVENT_HANDLE_NEXT_PENDING_TRANSACTION:
processPendingTransaction(transaction,(TransactionSettings));
return;
default:
Log.w(TAG,"what="+);
return;
}
}
/com/android/mms/transaction/
/**
*Internalmethodtobeginprocessingatransaction.
*@tbe{@codenull}.
*@return{@codetrue}ifprocesshasbegunorwillbegin.{@codefal}
*ifthetransactionshouldbediscarded.
*@throwsIOExceptionifconnectivityforMMStrafficcouldnotbe
*established.
*/
privatebooleanprocessTransaction(Transactiontransaction)throwsIOException{
//Checkiftransactionalreadyprocessing
Log.v(TAG,"processTransaction");
synchronized(mProcessing){
for(Transactiont:mPending){
if(valent(transaction)){
if(able(CTION,E)){
Log.v(TAG,"Transactionalreadypending:"+
viceId());
}
returntrue;
}
}
for(Transactiont:mProcessing){
if(valent(transaction)){
if(able(CTION,E)){
Log.v(TAG,"Duplicatedtransaction:"+
viceId());
}
returntrue;
}
}
/*
*Makesurethatthenetworkconnectivitynecessary
*not,weneed
*todeferprocessingthetransactionuntil
*connectivityistablished.
*/
if(able(CTION,E)){
Log.v(TAG,"processTransaction:callbeginMmsConnectivity...");
}
intconnectivityResult=beginMmsConnectivity();
if(connectivityResult==_REQUEST_STARTED){
(transaction);
if(able(CTION,E)){
Log.v(TAG,"processTransaction:connResult=APN_REQUEST_STARTED,"
+
"defertransactionpendingMMSconnectivity");
}
returntrue;
}
if(able(CTION,E)){
Log.v(TAG,"Addingtransactionto'mProcessing'list:"+
transaction);
}
(transaction);
}
//Setatimertokeeprenewingour"lea"ontheMMSconnection
ndMessageDelayed(obtainMessage(EVENT_CONTINUE_MMS_CONNECTIVITY),
APN_EXTENSION_WAIT);
if(able(CTION,E)){
Log.v(TAG,"processTransaction:startingtransaction"+transaction);
}
//Attachtotransactionandprocessit
();
s();
returntrue;
}
/com/android/mms/transaction/
@Override
publicvoidprocess(){
Log.v(TAG,"process");
mThread=newThread(this);
();
}
/com/android/mms/transaction/
publicvoidrun(){
Log.v(TAG,"run()");
try{
RateControllerrateCtlr=tance();
if(tSurpasd()&&!wedByUr()){
Log.e(TAG,"Sendingratelimitsurpasd.");
return;
}
//moutbox
PduPersisterpersister=Persister(mContext);
SendReqndReq=(SendReq)(mSendReqURI);
//Updatethe'date'fieldofthePDUrightbeforendingit.
longdate=tTimeMillis()/1000L;
e(date);
//Persistthenewdatevalueintodataba.
ContentValuesvalues=newContentValues(1);
(,date);
(mContext,tentResolver(),
mSendReqURI,values,null,null);
//fixbug2100169:inrtthe'from'addressperspec
StringlineNumber=alNumber();
if(!y(lineNumber)){
m(newEncodedStringValue(lineNumber));
}
//,ndit,retrieveconfirmationdata,andparit
longtokenKey=d(mSendReqURI);
byte[]respon=ndPdu((tokenKey),
newPduCompor(mContext,ndReq).make());//发送
彩信
(tokenKey);
if(able(CTION,E)){
StringrespStr=newString(respon);
Log.d(TAG,"[SendTransaction]run:ndmmsmsg("+mId+"),resp="+
respStr);
}
SendConfconf=(SendConf)newPduParr(respon).par();
if(conf==null){
Log.e(TAG,"ceived.");
}
//CheckwhethertherespondingTransaction-IDisconsistent
//withthentone.
byte[]reqId=nsactionId();
byte[]confId=nsactionId();
if(!(reqId,confId)){
Log.e(TAG,"InconsistentTransaction-ID:req="
+newString(reqId)+",conf="+newString(confId));
return;
}
//Fromnowon,wewon'to
//d,wejustsavesomeinterestingfields
//.
values=newContentValues(2);
intrespStatus=ponStatus();
(SE_STATUS,respStatus);
if(respStatus!=SE_STATUS_OK){
(mContext,tentResolver(),
mSendReqURI,values,null,null);
Log.e(TAG,"Serverreturnedanerrorcode:"+respStatus);
return;
}
StringmessageId=tring(sageId());
(E_ID,messageId);
(mContext,tentResolver(),
mSendReqURI,values,null,null);
//mOutboxintoSent.
Uriuri=(mSendReqURI,T_URI);
te(S);
tentUri(uri);
}catch(Throwablet){
Log.e(TAG,ckTraceString(t));
}finally{
if(te()!=S){
te();
tentUri(mSendReqURI);
Log.e(TAG,"Deliveryfailed.");
}
notifyObrvers();
}
}
/com/android/mms/transaction/
/**
*AcommonmethodtondaPDUtoMMSC.
*
*@paramtokenThetokentoidentifythendingprogress.
*@parampduAbytearraywhichcontainsthedataofthePDU.
*@returnAbytearraywhichcontainstherespondata.
*@throwsIOExceptionifanyerroroccurredonnetworkinterfaceor
*/
protectedbyte[]ndPdu(longtoken,byte[]pdu)throwsIOException{
returnndPdu(token,pdu,cUrl());
}
/com/android/mms/transaction/
protectedbyte[]ndPdu(longtoken,byte[]pdu,StringmmscUrl)throwsIOException{
ensureRouteToHost(mmscUrl,mTransactionSettings);
mContext,token,
mmscUrl,
ySet(),
xyAddress(),
xyPort());//通过网络发送彩信,AP层的最后实现
}
本文发布于:2023-03-09 17:26:30,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/1678353991195761.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:彩信怎么发.doc
本文 PDF 下载地址:彩信怎么发.pdf
留言与评论(共有 0 条评论) |