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