1 /* 2 * Copyright (c) 2008-2009, Motorola, Inc. 3 * 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are met: 8 * 9 * - Redistributions of source code must retain the above copyright notice, 10 * this list of conditions and the following disclaimer. 11 * 12 * - Redistributions in binary form must reproduce the above copyright notice, 13 * this list of conditions and the following disclaimer in the documentation 14 * and/or other materials provided with the distribution. 15 * 16 * - Neither the name of the Motorola, Inc. nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 package com.android.obex; 34 35 /** 36 * Represents an Application Parameter header for OBEX as defined by the IrDA specification. 37 */ 38 public final class ApplicationParameter { 39 40 private byte[] mArray; 41 42 private int mLength; 43 44 private int mMaxLength = 1000; 45 46 /** 47 * Possible values for the tag field in the Application Parameter header. 48 */ 49 public static class TRIPLET_TAGID { 50 public static final byte ORDER_TAGID = 0x01; 51 52 public static final byte SEARCH_VALUE_TAGID = 0x02; 53 54 public static final byte SEARCH_ATTRIBUTE_TAGID = 0x03; 55 56 // if equals to "0", PSE only reply number of contacts 57 public static final byte MAXLISTCOUNT_TAGID = 0x04; 58 59 public static final byte LISTSTARTOFFSET_TAGID = 0x05; 60 61 public static final byte PROPERTY_SELECTOR_TAGID = 0x06; 62 63 public static final byte FORMAT_TAGID = 0x07; 64 65 // only used if max list count = 0 66 public static final byte PHONEBOOKSIZE_TAGID = 0x08; 67 68 // only used in "mch" in response 69 public static final byte NEWMISSEDCALLS_TAGID = 0x09; 70 71 public static final byte SUPPORTEDFEATURE_TAGID = 0x10; 72 73 public static final byte PRIMARYVERSIONCOUNTER_TAGID = 0x0A; 74 75 public static final byte SECONDARYVERSIONCOUNTER_TAGID = 0x0B; 76 77 public static final byte VCARDSELECTOR_TAGID = 0x0C; 78 79 public static final byte DATABASEIDENTIFIER_TAGID = 0x0D; 80 81 public static final byte VCARDSELECTOROPERATOR_TAGID = 0x0E; 82 83 public static final byte RESET_NEW_MISSED_CALLS_TAGID = 0x0F; 84 } 85 86 /** 87 * Possible values for the value field in the Application Parameter header. 88 */ 89 public static class TRIPLET_VALUE { 90 public static class ORDER { 91 public static final byte ORDER_BY_INDEX = 0x00; 92 93 public static final byte ORDER_BY_ALPHANUMERIC = 0x01; 94 95 public static final byte ORDER_BY_PHONETIC = 0x02; 96 } 97 98 public static class SEARCHATTRIBUTE { 99 public static final byte SEARCH_BY_NAME = 0x00; 100 101 public static final byte SEARCH_BY_NUMBER = 0x01; 102 103 public static final byte SEARCH_BY_SOUND = 0x02; 104 } 105 106 public static class FORMAT { 107 public static final byte VCARD_VERSION_21 = 0x00; 108 109 public static final byte VCARD_VERSION_30 = 0x01; 110 } 111 } 112 113 /** 114 * Possible values for the length field in the Application Parameter header. 115 */ 116 public static class TRIPLET_LENGTH { 117 public static final byte ORDER_LENGTH = 1; 118 119 public static final byte SEARCH_ATTRIBUTE_LENGTH = 1; 120 121 public static final byte MAXLISTCOUNT_LENGTH = 2; 122 123 public static final byte LISTSTARTOFFSET_LENGTH = 2; 124 125 public static final byte PROPERTY_SELECTOR_LENGTH = 8; 126 127 public static final byte FORMAT_LENGTH = 1; 128 129 public static final byte PHONEBOOKSIZE_LENGTH = 2; 130 131 public static final byte NEWMISSEDCALLS_LENGTH = 1; 132 133 public static final byte SUPPORTEDFEATURE_LENGTH = 4; 134 135 public static final byte PRIMARYVERSIONCOUNTER_LENGTH = 16; 136 137 public static final byte SECONDARYVERSIONCOUNTER_LENGTH = 16; 138 139 public static final byte VCARDSELECTOR_LENGTH = 8; 140 141 public static final byte DATABASEIDENTIFIER_LENGTH = 16; 142 143 public static final byte VCARDSELECTOROPERATOR_LENGTH = 1; 144 145 public static final byte RESETNEWMISSEDCALLS_LENGTH = 1; 146 } 147 148 /** 149 * Constructs an ApplicationParameter header 150 */ ApplicationParameter()151 public ApplicationParameter() { 152 mArray = new byte[mMaxLength]; 153 mLength = 0; 154 } 155 156 /** 157 * Adds a triplet of tag, length, and value to this application parameter header as per the 158 * IrDA specifications. 159 * 160 * @param tag one of {@link TRIPLET_TAGID} 161 * @param len one of {@link TRIPLET_LENGTH} 162 * @param value is the value required for the supplied tag 163 */ addTriplet(byte tag, byte len, byte[] value)164 public void addTriplet(byte tag, byte len, byte[] value) { 165 if ((mLength + len + 2) > mMaxLength) { 166 byte[] array_tmp = new byte[mLength + 4 * len]; 167 System.arraycopy(mArray, 0, array_tmp, 0, mLength); 168 mArray = array_tmp; 169 mMaxLength = mLength + 4 * len; 170 } 171 mArray[mLength++] = tag; 172 mArray[mLength++] = len; 173 System.arraycopy(value, 0, mArray, mLength, len); 174 mLength += len; 175 } 176 177 /** 178 * Gets the application parameter header as a byte array. 179 * 180 * @return a byte array representing the application parameter header 181 */ getHeader()182 public byte[] getHeader() { 183 byte[] para = new byte[mLength]; 184 System.arraycopy(mArray, 0, para, 0, mLength); 185 return para; 186 } 187 } 188