2424import android .util .Config ;
2525import android .util .Log ;
2626
27-
2827/**
2928 * WAP push handler class.
3029 *
@@ -59,7 +58,7 @@ public WapPushOverSms(Phone phone, SMSDispatcher smsDispatcher) {
5958 */
6059 public int dispatchWapPdu (byte [] pdu ) {
6160
62- if (Config .LOGD ) Log .d (LOG_TAG , "Rx: " + IccUtils .bytesToHexString (pdu ));
61+ if (Config .DEBUG ) Log .d (LOG_TAG , "Rx: " + IccUtils .bytesToHexString (pdu ));
6362
6463 int index = 0 ;
6564 int transactionId = pdu [index ++] & 0xFF ;
@@ -68,7 +67,7 @@ public int dispatchWapPdu(byte[] pdu) {
6867
6968 if ((pduType != WspTypeDecoder .PDU_TYPE_PUSH ) &&
7069 (pduType != WspTypeDecoder .PDU_TYPE_CONFIRMED_PUSH )) {
71- if (Config .LOGD ) Log .w (LOG_TAG , "Received non-PUSH WAP PDU. Type = " + pduType );
70+ if (Config .DEBUG ) Log .w (LOG_TAG , "Received non-PUSH WAP PDU. Type = " + pduType );
7271 return Intents .RESULT_SMS_HANDLED ;
7372 }
7473
@@ -81,7 +80,7 @@ public int dispatchWapPdu(byte[] pdu) {
8180 * So it will be encoded in no more than 5 octets.
8281 */
8382 if (pduDecoder .decodeUintvarInteger (index ) == false ) {
84- if (Config .LOGD ) Log .w (LOG_TAG , "Received PDU. Header Length error." );
83+ if (Config .DEBUG ) Log .w (LOG_TAG , "Received PDU. Header Length error." );
8584 return Intents .RESULT_SMS_GENERIC_ERROR ;
8685 }
8786 headerLength = (int )pduDecoder .getValue32 ();
@@ -102,136 +101,44 @@ public int dispatchWapPdu(byte[] pdu) {
102101 * Length = Uintvar-integer
103102 */
104103 if (pduDecoder .decodeContentType (index ) == false ) {
105- if (Config .LOGD ) Log .w (LOG_TAG , "Received PDU. Header Content-Type error." );
104+ if (Config .DEBUG ) Log .w (LOG_TAG , "Received PDU. Header Content-Type error." );
106105 return Intents .RESULT_SMS_GENERIC_ERROR ;
107106 }
108- int binaryContentType ;
107+
109108 String mimeType = pduDecoder .getValueString ();
110- if (mimeType == null ) {
111- binaryContentType = (int )pduDecoder .getValue32 ();
112- // TODO we should have more generic way to map binaryContentType code to mimeType.
113- switch (binaryContentType ) {
114- case WspTypeDecoder .CONTENT_TYPE_B_DRM_RIGHTS_XML :
115- mimeType = WspTypeDecoder .CONTENT_MIME_TYPE_B_DRM_RIGHTS_XML ;
116- break ;
117- case WspTypeDecoder .CONTENT_TYPE_B_DRM_RIGHTS_WBXML :
118- mimeType = WspTypeDecoder .CONTENT_MIME_TYPE_B_DRM_RIGHTS_WBXML ;
119- break ;
120- case WspTypeDecoder .CONTENT_TYPE_B_PUSH_SI :
121- mimeType = WspTypeDecoder .CONTENT_MIME_TYPE_B_PUSH_SI ;
122- break ;
123- case WspTypeDecoder .CONTENT_TYPE_B_PUSH_SL :
124- mimeType = WspTypeDecoder .CONTENT_MIME_TYPE_B_PUSH_SL ;
125- break ;
126- case WspTypeDecoder .CONTENT_TYPE_B_PUSH_CO :
127- mimeType = WspTypeDecoder .CONTENT_MIME_TYPE_B_PUSH_CO ;
128- break ;
129- case WspTypeDecoder .CONTENT_TYPE_B_MMS :
130- mimeType = WspTypeDecoder .CONTENT_MIME_TYPE_B_MMS ;
131- break ;
132- case WspTypeDecoder .CONTENT_TYPE_B_VND_DOCOMO_PF :
133- mimeType = WspTypeDecoder .CONTENT_MIME_TYPE_B_VND_DOCOMO_PF ;
134- break ;
135- default :
136- if (Config .LOGD ) {
137- Log .w (LOG_TAG ,
138- "Received PDU. Unsupported Content-Type = " + binaryContentType );
139- }
140- return Intents .RESULT_SMS_HANDLED ;
141- }
142- } else {
143- if (mimeType .equals (WspTypeDecoder .CONTENT_MIME_TYPE_B_DRM_RIGHTS_XML )) {
144- binaryContentType = WspTypeDecoder .CONTENT_TYPE_B_DRM_RIGHTS_XML ;
145- } else if (mimeType .equals (WspTypeDecoder .CONTENT_MIME_TYPE_B_DRM_RIGHTS_WBXML )) {
146- binaryContentType = WspTypeDecoder .CONTENT_TYPE_B_DRM_RIGHTS_WBXML ;
147- } else if (mimeType .equals (WspTypeDecoder .CONTENT_MIME_TYPE_B_PUSH_SI )) {
148- binaryContentType = WspTypeDecoder .CONTENT_TYPE_B_PUSH_SI ;
149- } else if (mimeType .equals (WspTypeDecoder .CONTENT_MIME_TYPE_B_PUSH_SL )) {
150- binaryContentType = WspTypeDecoder .CONTENT_TYPE_B_PUSH_SL ;
151- } else if (mimeType .equals (WspTypeDecoder .CONTENT_MIME_TYPE_B_PUSH_CO )) {
152- binaryContentType = WspTypeDecoder .CONTENT_TYPE_B_PUSH_CO ;
153- } else if (mimeType .equals (WspTypeDecoder .CONTENT_MIME_TYPE_B_MMS )) {
154- binaryContentType = WspTypeDecoder .CONTENT_TYPE_B_MMS ;
155- } else if (mimeType .equals (WspTypeDecoder .CONTENT_MIME_TYPE_B_VND_DOCOMO_PF )) {
156- binaryContentType = WspTypeDecoder .CONTENT_TYPE_B_VND_DOCOMO_PF ;
157- } else {
158- if (Config .LOGD ) Log .w (LOG_TAG , "Received PDU. Unknown Content-Type = " + mimeType );
159- return Intents .RESULT_SMS_HANDLED ;
160- }
161- }
162- index += pduDecoder .getDecodedDataLength ();
163109
164- boolean dispatchedByApplication = false ;
165- switch (binaryContentType ) {
166- case WspTypeDecoder .CONTENT_TYPE_B_PUSH_CO :
167- dispatchWapPdu_PushCO (pdu , transactionId , pduType , headerStartIndex , headerLength );
168- dispatchedByApplication = true ;
169- break ;
170- case WspTypeDecoder .CONTENT_TYPE_B_MMS :
171- dispatchWapPdu_MMS (pdu , transactionId , pduType , headerStartIndex , headerLength );
172- dispatchedByApplication = true ;
173- break ;
174- default :
175- break ;
176- }
177- if (dispatchedByApplication == false ) {
178- dispatchWapPdu_default (pdu , transactionId , pduType , mimeType ,
179- headerStartIndex , headerLength );
180- }
181- return Activity .RESULT_OK ;
182- }
110+ index += pduDecoder .getDecodedDataLength ();
183111
184- private void dispatchWapPdu_default (byte [] pdu , int transactionId , int pduType ,
185- String mimeType , int headerStartIndex , int headerLength ) {
186112 byte [] header = new byte [headerLength ];
187113 System .arraycopy (pdu , headerStartIndex , header , 0 , header .length );
188- int dataIndex = headerStartIndex + headerLength ;
189- byte [] data ;
190114
191- data = new byte [pdu . length - dataIndex ] ;
192- System . arraycopy ( pdu , dataIndex , data , 0 , data . length ) ;
115+ byte [] intentData ;
116+ String permission ;
193117
194- Intent intent = new Intent (Intents .WAP_PUSH_RECEIVED_ACTION );
195- intent .setType (mimeType );
196- intent .putExtra ("transactionId" , transactionId );
197- intent .putExtra ("pduType" , pduType );
198- intent .putExtra ("header" , header );
199- intent .putExtra ("data" , data );
200-
201- mSmsDispatcher .dispatch (intent , "android.permission.RECEIVE_WAP_PUSH" );
202- }
118+ if (mimeType .equals (WspTypeDecoder .CONTENT_TYPE_B_PUSH_CO )) {
119+ intentData = pdu ;
120+ } else {
121+ int dataIndex = headerStartIndex + headerLength ;
122+ intentData = new byte [pdu .length - dataIndex ];
123+ System .arraycopy (pdu , dataIndex , intentData , 0 , intentData .length );
124+ }
203125
204- private void dispatchWapPdu_PushCO (byte [] pdu , int transactionId , int pduType ,
205- int headerStartIndex , int headerLength ) {
206- byte [] header = new byte [headerLength ];
207- System .arraycopy (pdu , headerStartIndex , header , 0 , header .length );
126+ if (mimeType .equals (WspTypeDecoder .CONTENT_TYPE_B_MMS )) {
127+ permission = "android.permission.RECEIVE_MMS" ;
128+ } else {
129+ permission = "android.permission.RECEIVE_WAP_PUSH" ;
130+ }
208131
209132 Intent intent = new Intent (Intents .WAP_PUSH_RECEIVED_ACTION );
210- intent .setType (WspTypeDecoder . CONTENT_MIME_TYPE_B_PUSH_CO );
133+ intent .setType (mimeType );
211134 intent .putExtra ("transactionId" , transactionId );
212135 intent .putExtra ("pduType" , pduType );
213136 intent .putExtra ("header" , header );
214- intent .putExtra ("data" , pdu );
137+ intent .putExtra ("data" , intentData );
138+ intent .putExtra ("contentTypeParameters" , pduDecoder .getContentParameters ());
215139
216- mSmsDispatcher .dispatch (intent , "android.permission.RECEIVE_WAP_PUSH" );
217- }
140+ mSmsDispatcher .dispatch (intent , permission );
218141
219- private void dispatchWapPdu_MMS (byte [] pdu , int transactionId , int pduType ,
220- int headerStartIndex , int headerLength ) {
221- byte [] header = new byte [headerLength ];
222- System .arraycopy (pdu , headerStartIndex , header , 0 , header .length );
223- int dataIndex = headerStartIndex + headerLength ;
224- byte [] data = new byte [pdu .length - dataIndex ];
225- System .arraycopy (pdu , dataIndex , data , 0 , data .length );
226-
227- Intent intent = new Intent (Intents .WAP_PUSH_RECEIVED_ACTION );
228- intent .setType (WspTypeDecoder .CONTENT_MIME_TYPE_B_MMS );
229- intent .putExtra ("transactionId" , transactionId );
230- intent .putExtra ("pduType" , pduType );
231- intent .putExtra ("header" , header );
232- intent .putExtra ("data" , data );
233-
234- mSmsDispatcher .dispatch (intent , "android.permission.RECEIVE_MMS" );
142+ return Activity .RESULT_OK ;
235143 }
236- }
237-
144+ }
0 commit comments