Skip to content

Commit c979071

Browse files
author
Dan Griffin
committed
Enhance WspTypeDecoder to decode Content Type Parameters
This patch enables WspTypeDecoder to correctly parse content type parameters as described in the Wap230 WSP specifications (wap-230-wsp-20010705-a section 8.4.2.24) which are then passed on as part of the WAP_PUSH intent notification. It also recognises all Well Known WSP Content types, and simplifies their retrieval (i.e. a well known content type will always be available through the WspTypeDecoder.getValueString() method). Change-Id: I0eb3f9ac287aa7cb53312777c4be54b1939fa857
1 parent 4506c62 commit c979071

File tree

4 files changed

+1269
-192
lines changed

4 files changed

+1269
-192
lines changed

core/java/android/provider/Telephony.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -562,15 +562,24 @@ public static final class Intents {
562562
* values:</p>
563563
*
564564
* <ul>
565-
* <li><em>transactionId (Integer)</em> - The WAP transaction
566-
* ID</li>
565+
* <li><em>transactionId (Integer)</em> - The WAP transaction ID</li>
567566
* <li><em>pduType (Integer)</em> - The WAP PDU type</li>
568567
* <li><em>header (byte[])</em> - The header of the message</li>
569568
* <li><em>data (byte[])</em> - The data payload of the message</li>
569+
* <li><em>contentTypeParameters (HashMap&lt;String,String&gt;)</em>
570+
* - Any parameters associated with the content type
571+
* (decoded from the WSP Content-Type header)</li>
570572
* </ul>
571573
*
572574
* <p>If a BroadcastReceiver encounters an error while processing
573575
* this intent it should set the result code appropriately.</p>
576+
*
577+
* <p>The contentTypeParameters extra value is map of content parameters keyed by
578+
* their names.</p>
579+
*
580+
* <p>If any unassigned well-known parameters are encountered, the key of the map will
581+
* be 'unassigned/0x...', where '...' is the hex value of the unassigned parameter. If
582+
* a parameter has No-Value the value in the map will be null.</p>
574583
*/
575584
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
576585
public static final String WAP_PUSH_RECEIVED_ACTION =
@@ -583,7 +592,7 @@ public static final class Intents {
583592
*/
584593
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
585594
public static final String SIM_FULL_ACTION =
586-
"android.provider.Telephony.SIM_FULL";
595+
"android.provider.Telephony.SIM_FULL";
587596

588597
/**
589598
* Broadcast Action: An incoming SMS has been rejected by the

telephony/java/com/android/internal/telephony/WapPushOverSms.java

Lines changed: 26 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import android.util.Config;
2525
import 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

Comments
 (0)