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