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