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 javax.obex;
34 
35 /**
36  * @hide
37  */
38 public final class ApplicationParameter {
39 
40     private byte[] mArray;
41 
42     private int mLength;
43 
44     private int mMaxLength = 1000;
45 
46     public static class TRIPLET_TAGID {
47         public static final byte ORDER_TAGID = 0x01;
48 
49         public static final byte SEARCH_VALUE_TAGID = 0x02;
50 
51         public static final byte SEARCH_ATTRIBUTE_TAGID = 0x03;
52 
53         // if equals to "0", PSE only reply number of contacts
54         public static final byte MAXLISTCOUNT_TAGID = 0x04;
55 
56         public static final byte LISTSTARTOFFSET_TAGID = 0x05;
57 
58         public static final byte PROPERTY_SELECTOR_TAGID = 0x06;
59 
60         public static final byte FORMAT_TAGID = 0x07;
61 
62         // only used if max list count = 0
63         public static final byte PHONEBOOKSIZE_TAGID = 0x08;
64 
65         // only used in "mch" in response
66         public static final byte NEWMISSEDCALLS_TAGID = 0x09;
67 
68         public static final byte SUPPORTEDFEATURE_TAGID = 0x10;
69 
70         public static final byte PRIMARYVERSIONCOUNTER_TAGID = 0x0A;
71 
72         public static final byte SECONDARYVERSIONCOUNTER_TAGID = 0x0B;
73 
74         public static final byte VCARDSELECTOR_TAGID = 0x0C;
75 
76         public static final byte DATABASEIDENTIFIER_TAGID = 0x0D;
77 
78         public static final byte VCARDSELECTOROPERATOR_TAGID = 0x0E;
79 
80         public static final byte RESET_NEW_MISSED_CALLS_TAGID = 0x0F;
81     }
82 
83     public static class TRIPLET_VALUE {
84         public static class ORDER {
85             public static final byte ORDER_BY_INDEX = 0x00;
86 
87             public static final byte ORDER_BY_ALPHANUMERIC = 0x01;
88 
89             public static final byte ORDER_BY_PHONETIC = 0x02;
90         }
91 
92         public static class SEARCHATTRIBUTE {
93             public static final byte SEARCH_BY_NAME = 0x00;
94 
95             public static final byte SEARCH_BY_NUMBER = 0x01;
96 
97             public static final byte SEARCH_BY_SOUND = 0x02;
98         }
99 
100         public static class FORMAT {
101             public static final byte VCARD_VERSION_21 = 0x00;
102 
103             public static final byte VCARD_VERSION_30 = 0x01;
104         }
105     }
106 
107     public static class TRIPLET_LENGTH {
108         public static final byte ORDER_LENGTH = 1;
109 
110         public static final byte SEARCH_ATTRIBUTE_LENGTH = 1;
111 
112         public static final byte MAXLISTCOUNT_LENGTH = 2;
113 
114         public static final byte LISTSTARTOFFSET_LENGTH = 2;
115 
116         public static final byte PROPERTY_SELECTOR_LENGTH = 8;
117 
118         public static final byte FORMAT_LENGTH = 1;
119 
120         public static final byte PHONEBOOKSIZE_LENGTH = 2;
121 
122         public static final byte NEWMISSEDCALLS_LENGTH = 1;
123 
124         public static final byte SUPPORTEDFEATURE_LENGTH = 4;
125 
126         public static final byte PRIMARYVERSIONCOUNTER_LENGTH = 16;
127 
128         public static final byte SECONDARYVERSIONCOUNTER_LENGTH = 16;
129 
130         public static final byte VCARDSELECTOR_LENGTH = 8;
131 
132         public static final byte DATABASEIDENTIFIER_LENGTH = 16;
133 
134         public static final byte VCARDSELECTOROPERATOR_LENGTH = 1;
135 
136         public static final byte RESETNEWMISSEDCALLS_LENGTH = 1;
137     }
138 
ApplicationParameter()139     public ApplicationParameter() {
140         mArray = new byte[mMaxLength];
141         mLength = 0;
142     }
143 
addAPPHeader(byte tag, byte len, byte[] value)144     public void addAPPHeader(byte tag, byte len, byte[] value) {
145         if ((mLength + len + 2) > mMaxLength) {
146             byte[] array_tmp = new byte[mLength + 4 * len];
147             System.arraycopy(mArray, 0, array_tmp, 0, mLength);
148             mArray = array_tmp;
149             mMaxLength = mLength + 4 * len;
150         }
151         mArray[mLength++] = tag;
152         mArray[mLength++] = len;
153         System.arraycopy(value, 0, mArray, mLength, len);
154         mLength += len;
155     }
156 
getAPPparam()157     public byte[] getAPPparam() {
158         byte[] para = new byte[mLength];
159         System.arraycopy(mArray, 0, para, 0, mLength);
160         return para;
161     }
162 }
163