1 /*
2  * Copyright (C) 2007 Esmertec AG.
3  * Copyright (C) 2007 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.os.Build;
22 
23 import com.google.android.mms.InvalidHeaderValueException;
24 
25 /**
26  * Multimedia message PDU.
27  */
28 public class MultimediaMessagePdu extends GenericPdu{
29     /**
30      * The body.
31      */
32     private PduBody mMessageBody;
33 
34     /**
35      * Constructor.
36      */
37     @UnsupportedAppUsage
MultimediaMessagePdu()38     public MultimediaMessagePdu() {
39         super();
40     }
41 
42     /**
43      * Constructor.
44      *
45      * @param header the header of this PDU
46      * @param body the body of this PDU
47      */
48     @UnsupportedAppUsage
MultimediaMessagePdu(PduHeaders header, PduBody body)49     public MultimediaMessagePdu(PduHeaders header, PduBody body) {
50         super(header);
51         mMessageBody = body;
52     }
53 
54     /**
55      * Constructor with given headers.
56      *
57      * @param headers Headers for this PDU.
58      */
MultimediaMessagePdu(PduHeaders headers)59     MultimediaMessagePdu(PduHeaders headers) {
60         super(headers);
61     }
62 
63     /**
64      * Get body of the PDU.
65      *
66      * @return the body
67      */
68     @UnsupportedAppUsage
getBody()69     public PduBody getBody() {
70         return mMessageBody;
71     }
72 
73     /**
74      * Set body of the PDU.
75      *
76      * @param body the body
77      */
78     @UnsupportedAppUsage
setBody(PduBody body)79     public void setBody(PduBody body) {
80         mMessageBody = body;
81     }
82 
83     /**
84      * Get subject.
85      *
86      * @return the value
87      */
88     @UnsupportedAppUsage
getSubject()89     public EncodedStringValue getSubject() {
90         return mPduHeaders.getEncodedStringValue(PduHeaders.SUBJECT);
91     }
92 
93     /**
94      * Set subject.
95      *
96      * @param value the value
97      * @throws NullPointerException if the value is null.
98      */
99     @UnsupportedAppUsage
setSubject(EncodedStringValue value)100     public void setSubject(EncodedStringValue value) {
101         mPduHeaders.setEncodedStringValue(value, PduHeaders.SUBJECT);
102     }
103 
104     /**
105      * Get To value.
106      *
107      * @return the value
108      */
109     @UnsupportedAppUsage
getTo()110     public EncodedStringValue[] getTo() {
111         return mPduHeaders.getEncodedStringValues(PduHeaders.TO);
112     }
113 
114     /**
115      * Add a "To" value.
116      *
117      * @param value the value
118      * @throws NullPointerException if the value is null.
119      */
120     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
addTo(EncodedStringValue value)121     public void addTo(EncodedStringValue value) {
122         mPduHeaders.appendEncodedStringValue(value, PduHeaders.TO);
123     }
124 
125     /**
126      * Get X-Mms-Priority value.
127      *
128      * @return the value
129      */
130     @UnsupportedAppUsage
getPriority()131     public int getPriority() {
132         return mPduHeaders.getOctet(PduHeaders.PRIORITY);
133     }
134 
135     /**
136      * Set X-Mms-Priority value.
137      *
138      * @param value the value
139      * @throws InvalidHeaderValueException if the value is invalid.
140      */
141     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
setPriority(int value)142     public void setPriority(int value) throws InvalidHeaderValueException {
143         mPduHeaders.setOctet(value, PduHeaders.PRIORITY);
144     }
145 
146     /**
147      * Get Date value.
148      *
149      * @return the value
150      */
151     @UnsupportedAppUsage
getDate()152     public long getDate() {
153         return mPduHeaders.getLongInteger(PduHeaders.DATE);
154     }
155 
156     /**
157      * Set Date value in seconds.
158      *
159      * @param value the value
160      */
161     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
setDate(long value)162     public void setDate(long value) {
163         mPduHeaders.setLongInteger(value, PduHeaders.DATE);
164     }
165 }
166