1 /*
2  * Copyright (C) 2007-2008 Esmertec AG.
3  * Copyright (C) 2007-2008 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 package com.android.messaging.mmslib.pdu;
19 
20 import android.util.Log;
21 
22 import com.android.messaging.mmslib.InvalidHeaderValueException;
23 
24 public class SendReq extends MultimediaMessagePdu {
25     private static final String TAG = "SendReq";
26 
SendReq()27     public SendReq() {
28         super();
29 
30         try {
31             setMessageType(PduHeaders.MESSAGE_TYPE_SEND_REQ);
32             setMmsVersion(PduHeaders.CURRENT_MMS_VERSION);
33             // TODO: Content-type must be decided according to whether
34             // SMIL part present.
35             setContentType("application/vnd.wap.multipart.related".getBytes());
36             setFrom(new EncodedStringValue(PduHeaders.FROM_INSERT_ADDRESS_TOKEN_STR.getBytes()));
37             setTransactionId(generateTransactionId());
38         } catch (InvalidHeaderValueException e) {
39             // Impossible to reach here since all headers we set above are valid.
40             Log.e(TAG, "Unexpected InvalidHeaderValueException.", e);
41             throw new RuntimeException(e);
42         }
43     }
44 
generateTransactionId()45     private byte[] generateTransactionId() {
46         String transactionId = "T" + Long.toHexString(System.currentTimeMillis());
47         return transactionId.getBytes();
48     }
49 
50     /**
51      * Constructor, used when composing a M-Send.req pdu.
52      *
53      * @param contentType   the content type value
54      * @param from          the from value
55      * @param mmsVersion    current viersion of mms
56      * @param transactionId the transaction-id value
57      * @throws InvalidHeaderValueException if parameters are invalid.
58      *                                     NullPointerException if contentType, form or
59      *                                     transactionId is null.
60      */
SendReq(byte[] contentType, EncodedStringValue from, int mmsVersion, byte[] transactionId)61     public SendReq(byte[] contentType,
62             EncodedStringValue from,
63             int mmsVersion,
64             byte[] transactionId) throws InvalidHeaderValueException {
65         super();
66         setMessageType(PduHeaders.MESSAGE_TYPE_SEND_REQ);
67         setContentType(contentType);
68         setFrom(from);
69         setMmsVersion(mmsVersion);
70         setTransactionId(transactionId);
71     }
72 
73     /**
74      * Constructor with given headers.
75      *
76      * @param headers Headers for this PDU.
77      */
SendReq(PduHeaders headers)78     SendReq(PduHeaders headers) {
79         super(headers);
80     }
81 
82     /**
83      * Constructor with given headers and body
84      *
85      * @param headers Headers for this PDU.
86      * @param body    Body of this PDu.
87      */
SendReq(PduHeaders headers, PduBody body)88     SendReq(PduHeaders headers, PduBody body) {
89         super(headers, body);
90     }
91 
92     /**
93      * Get Bcc value.
94      *
95      * @return the value
96      */
getBcc()97     public EncodedStringValue[] getBcc() {
98         return mPduHeaders.getEncodedStringValues(PduHeaders.BCC);
99     }
100 
101     /**
102      * Add a "BCC" value.
103      *
104      * @param value the value
105      * @throws NullPointerException if the value is null.
106      */
addBcc(EncodedStringValue value)107     public void addBcc(EncodedStringValue value) {
108         mPduHeaders.appendEncodedStringValue(value, PduHeaders.BCC);
109     }
110 
111     /**
112      * Set "BCC" value.
113      *
114      * @param value the value
115      * @throws NullPointerException if the value is null.
116      */
setBcc(EncodedStringValue[] value)117     public void setBcc(EncodedStringValue[] value) {
118         mPduHeaders.setEncodedStringValues(value, PduHeaders.BCC);
119     }
120 
121     /**
122      * Get CC value.
123      *
124      * @return the value
125      */
getCc()126     public EncodedStringValue[] getCc() {
127         return mPduHeaders.getEncodedStringValues(PduHeaders.CC);
128     }
129 
130     /**
131      * Add a "CC" value.
132      *
133      * @param value the value
134      * @throws NullPointerException if the value is null.
135      */
addCc(EncodedStringValue value)136     public void addCc(EncodedStringValue value) {
137         mPduHeaders.appendEncodedStringValue(value, PduHeaders.CC);
138     }
139 
140     /**
141      * Set "CC" value.
142      *
143      * @param value the value
144      * @throws NullPointerException if the value is null.
145      */
setCc(EncodedStringValue[] value)146     public void setCc(EncodedStringValue[] value) {
147         mPduHeaders.setEncodedStringValues(value, PduHeaders.CC);
148     }
149 
150     /**
151      * Get Content-type value.
152      *
153      * @return the value
154      */
getContentType()155     public byte[] getContentType() {
156         return mPduHeaders.getTextString(PduHeaders.CONTENT_TYPE);
157     }
158 
159     /**
160      * Set Content-type value.
161      *
162      * @param value the value
163      * @throws NullPointerException if the value is null.
164      */
setContentType(byte[] value)165     public void setContentType(byte[] value) {
166         mPduHeaders.setTextString(value, PduHeaders.CONTENT_TYPE);
167     }
168 
169     /**
170      * Get X-Mms-Delivery-Report value.
171      *
172      * @return the value
173      */
getDeliveryReport()174     public int getDeliveryReport() {
175         return mPduHeaders.getOctet(PduHeaders.DELIVERY_REPORT);
176     }
177 
178     /**
179      * Set X-Mms-Delivery-Report value.
180      *
181      * @param value the value
182      * @throws InvalidHeaderValueException if the value is invalid.
183      */
setDeliveryReport(int value)184     public void setDeliveryReport(int value) throws InvalidHeaderValueException {
185         mPduHeaders.setOctet(value, PduHeaders.DELIVERY_REPORT);
186     }
187 
188     /**
189      * Get X-Mms-Expiry value.
190      *
191      * Expiry-value = Value-length
192      *      (Absolute-token Date-value | Relative-token Delta-seconds-value)
193      *
194      * @return the value
195      */
getExpiry()196     public long getExpiry() {
197         return mPduHeaders.getLongInteger(PduHeaders.EXPIRY);
198     }
199 
200     /**
201      * Set X-Mms-Expiry value.
202      *
203      * @param value the value
204      */
setExpiry(long value)205     public void setExpiry(long value) {
206         mPduHeaders.setLongInteger(value, PduHeaders.EXPIRY);
207     }
208 
209     /**
210      * Get X-Mms-MessageSize value.
211      *
212      * Expiry-value = size of message
213      *
214      * @return the value
215      */
getMessageSize()216     public long getMessageSize() {
217         return mPduHeaders.getLongInteger(PduHeaders.MESSAGE_SIZE);
218     }
219 
220     /**
221      * Set X-Mms-MessageSize value.
222      *
223      * @param value the value
224      */
setMessageSize(long value)225     public void setMessageSize(long value) {
226         mPduHeaders.setLongInteger(value, PduHeaders.MESSAGE_SIZE);
227     }
228 
229     /**
230      * Get X-Mms-Message-Class value.
231      * Message-class-value = Class-identifier | Token-text
232      * Class-identifier = Personal | Advertisement | Informational | Auto
233      *
234      * @return the value
235      */
getMessageClass()236     public byte[] getMessageClass() {
237         return mPduHeaders.getTextString(PduHeaders.MESSAGE_CLASS);
238     }
239 
240     /**
241      * Set X-Mms-Message-Class value.
242      *
243      * @param value the value
244      * @throws NullPointerException if the value is null.
245      */
setMessageClass(byte[] value)246     public void setMessageClass(byte[] value) {
247         mPduHeaders.setTextString(value, PduHeaders.MESSAGE_CLASS);
248     }
249 
250     /**
251      * Get X-Mms-Read-Report value.
252      *
253      * @return the value
254      */
getReadReport()255     public int getReadReport() {
256         return mPduHeaders.getOctet(PduHeaders.READ_REPORT);
257     }
258 
259     /**
260      * Set X-Mms-Read-Report value.
261      *
262      * @param value the value
263      * @throws InvalidHeaderValueException if the value is invalid.
264      */
setReadReport(int value)265     public void setReadReport(int value) throws InvalidHeaderValueException {
266         mPduHeaders.setOctet(value, PduHeaders.READ_REPORT);
267     }
268 
269     /**
270      * Set "To" value.
271      *
272      * @param value the value
273      * @throws NullPointerException if the value is null.
274      */
setTo(EncodedStringValue[] value)275     public void setTo(EncodedStringValue[] value) {
276         mPduHeaders.setEncodedStringValues(value, PduHeaders.TO);
277     }
278 
279     /**
280      * Get X-Mms-Transaction-Id field value.
281      *
282      * @return the X-Mms-Report-Allowed value
283      */
getTransactionId()284     public byte[] getTransactionId() {
285         return mPduHeaders.getTextString(PduHeaders.TRANSACTION_ID);
286     }
287 
288     /**
289      * Set X-Mms-Transaction-Id field value.
290      *
291      * @param value the value
292      * @throws NullPointerException if the value is null.
293      */
setTransactionId(byte[] value)294     public void setTransactionId(byte[] value) {
295         mPduHeaders.setTextString(value, PduHeaders.TRANSACTION_ID);
296     }
297 
298     /*
299      * Optional, not supported header fields:
300      *
301      *     public byte getAdaptationAllowed() {return 0};
302      *     public void setAdaptationAllowed(btye value) {};
303      *
304      *     public byte[] getApplicId() {return null;}
305      *     public void setApplicId(byte[] value) {}
306      *
307      *     public byte[] getAuxApplicId() {return null;}
308      *     public void getAuxApplicId(byte[] value) {}
309      *
310      *     public byte getContentClass() {return 0x00;}
311      *     public void setApplicId(byte value) {}
312      *
313      *     public long getDeliveryTime() {return 0};
314      *     public void setDeliveryTime(long value) {};
315      *
316      *     public byte getDrmContent() {return 0x00;}
317      *     public void setDrmContent(byte value) {}
318      *
319      *     public MmFlagsValue getMmFlags() {return null;}
320      *     public void setMmFlags(MmFlagsValue value) {}
321      *
322      *     public MmStateValue getMmState() {return null;}
323      *     public void getMmState(MmStateValue value) {}
324      *
325      *     public byte[] getReplyApplicId() {return 0x00;}
326      *     public void setReplyApplicId(byte[] value) {}
327      *
328      *     public byte getReplyCharging() {return 0x00;}
329      *     public void setReplyCharging(byte value) {}
330      *
331      *     public byte getReplyChargingDeadline() {return 0x00;}
332      *     public void setReplyChargingDeadline(byte value) {}
333      *
334      *     public byte[] getReplyChargingId() {return 0x00;}
335      *     public void setReplyChargingId(byte[] value) {}
336      *
337      *     public long getReplyChargingSize() {return 0;}
338      *     public void setReplyChargingSize(long value) {}
339      *
340      *     public byte[] getReplyApplicId() {return 0x00;}
341      *     public void setReplyApplicId(byte[] value) {}
342      *
343      *     public byte getStore() {return 0x00;}
344      *     public void setStore(byte value) {}
345      */
346 }
347