android的收彩信通知的過程解析

這裏對froyo(非標準)裏mms模塊收彩信的函數調用關係進行一點解說。這裏只說的是收到彩信,但是還沒有下載(設爲手工下載)
首先,mms是通過WAPPUSH實現的,具體在com.android.internal.telephony包裏的WapPushOverSms類。
這個類裏除了構造函數,另一個public的就是dispatchWapPdu()了

仔細查看下,就會找到dispatchWapPdu_MMS()這個函數

  1. private void dispatchWapPdu_MMS(byte[] pduint transactionIdint pduType,
  2.                                     int headerStartIndexint headerLength) {
  3.         byte[] header = new byte[headerLength];
  4.         System.arraycopy(pduheaderStartIndexheader0header.length);
  5.         int dataIndex = headerStartIndex + headerLength;
  6.         byte[] data = new byte[pdu.length - dataIndex];
  7.         System.arraycopy(pdudataIndexdata0data.length);
  8.  
  9.         Intent intent = new Intent(Intents.WAP_PUSH_RECEIVED_ACTION);
  10.         intent.setType(WspTypeDecoder.CONTENT_MIME_TYPE_B_MMS);
  11.         intent.putExtra("transactionId"transactionId);
  12.         intent.putExtra("pduType"pduType);
  13.         intent.putExtra("header"header);
  14.         intent.putExtra("data"data);
  15.        
  16.         mSmsDispatcher.dispatch(intent"android.permission.RECEIVE_MMS");
  17.     }

注意別混了, mSmsDispatcher.dispatch的第二個參數不是action的意思,而是權限,實際這個intent的action就是Intents.WAP_PUSH_RECEIVED_ACTION

然後,mms包(com.android.mms.transaction)下的onReceive會得到這個intent,進行處理
在這個onReceive裏,會調用內部類去執行:

  1. new ReceivePushTask(context).execute(intent);

在這個內部類的doInBackground方法裏,則會再繼續根據pdu類型,來判斷如何處理

  1. Uri uri = p.persist(pduInbox.CONTENT_URIphoneId);
  2.                             // Start service to finish the notification transaction.
  3.                             Intent svc = new Intent(mContextTransactionService.class);
  4.                             svc.putExtra(TransactionBundle.URIuri.toString());
  5.                             svc.putExtra(TransactionBundle.TRANSACTION_TYPE,
  6.                                     Transaction.NOTIFICATION_TRANSACTION);
  7.                             mContext.startService(svc);

在TransactionService裏,實際上會最終調用NotificationTransaction

  1. int type = PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND;
  2.                                     if ((ind != null) && (ind.getMessageType() == type)) {
  3.                                         transaction = new NotificationTransaction(
  4.                                                 TransactionService.thisserviceId,
  5.                                                 transactionSettings(NotificationInd) ind,phoneId);
  6.                                     }

在NotificationTransaction裏,則會完成Notification事務

  1. // Don't try to download when data is suspended, as it will fail, so defer download
  2.             if (!autoDownload || dataSuspended) {
  3.                 downloadManager.markState(mUriDownloadManager.STATE_UNSTARTED);
  4.                 sendNotifyRespInd(status);
  5.                 return;
  6.             }

到這裏(sendNotifyRespInd),這個事務應該算結束了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章