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