1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 package org.marre.sms;
36
37 import java.util.Iterator;
38 import java.util.LinkedList;
39
40 /***
41 * Represents a "Message Waiting" sms.
42 *
43 * As described in TS 23.040-650 section 9.2.3.24.2 "Special SMS Message Indication".
44 *
45 * On a Sony-Ericsson T610 these messages can be used to display different types of icons in the
46 * notification bar.
47 *
48 * @author Markus Eriksson
49 * @version $Id: SmsMsgWaitingMessage.java,v 1.2 2005/05/12 07:50:16 c95men Exp $
50 */
51 public class SmsMsgWaitingMessage extends SmsTextMessage
52 {
53 /*** Message waiting type : VOICE */
54 public static final int TYPE_VOICE = 0;
55 /*** Message waiting type : FAX */
56 public static final int TYPE_FAX = 1;
57 /*** Message waiting type : EMAIL */
58 public static final int TYPE_EMAIL = 2;
59 /*** Message waiting type : VIDEO */
60 public static final int TYPE_VIDEO = 3;
61
62 private static final int OPT_PROFILE_MASK = 0x03;
63 /*** Profile ID 1. (Default) */
64 public static final int OPT_PROFILE_ID_1 = 0x00;
65 /*** Profile ID 2. */
66 public static final int OPT_PROFILE_ID_2 = 0x01;
67 /*** Profile ID 3. */
68 public static final int OPT_PROFILE_ID_3 = 0x02;
69 /*** Profile ID 4. */
70 public static final int OPT_PROFILE_ID_4 = 0x03;
71
72 /*** Store message in the phone memory. */
73 public static final int OPT_STORE_MSG = 0x04;
74
75 /***
76 * Represents one message waiting udh.
77 */
78 private class MsgWaiting
79 {
80 int type;
81 int count;
82 int options;
83
84 private MsgWaiting(int type, int count, int options)
85 {
86 this.type = type;
87 this.count = count;
88 this.options = options;
89 }
90 }
91
92 /***
93 * List of MsgWaiting "objects".
94 */
95 protected LinkedList messages_ = new LinkedList();
96
97 /***
98 * Creates an empty message.
99 */
100 public SmsMsgWaitingMessage()
101 {
102 this("", SmsDcs.ALPHABET_8BIT);
103 }
104
105 /***
106 * Creates an message with the supplied text (GSM charset).
107 *
108 * @param text Description of this message.
109 */
110 public SmsMsgWaitingMessage(String text)
111 {
112 this(text, SmsDcs.ALPHABET_GSM);
113 }
114
115 /***
116 * Creates an message with the supplied text and alphabet.
117 *
118 * @param text Description of this message
119 * @param alphabet Alphabet to use. Valid values are SmsDcs.ALPHABET_*.
120 */
121 public SmsMsgWaitingMessage(String text, int alphabet)
122 {
123 super(text, SmsDcs.getGeneralDataCodingDcs(alphabet, SmsDcs.MSG_CLASS_UNKNOWN));
124 }
125
126 /***
127 * Adds a message waiting.
128 *
129 * @param type Type of message that is waiting. Can be any of TYPE_*.
130 * @param count Number of messages waiting for retrieval.
131 */
132 public void addMsgWaiting(int type, int count)
133 {
134 addMsgWaiting(type, count, 0);
135 }
136
137 /***
138 * Adds a message waiting.
139 *
140 * @param type Type of message that is waiting. Can be any of TYPE_*.
141 * @param count Number of messages waiting for retrieval.
142 * @param options Bitfield of OPT_ options.
143 */
144 public void addMsgWaiting(int type, int count, int options)
145 {
146
147 switch (type)
148 {
149 case TYPE_VOICE:
150 case TYPE_FAX:
151 case TYPE_EMAIL:
152 case TYPE_VIDEO:
153
154 break;
155
156 default:
157 throw new IllegalArgumentException("Invalid type.");
158 }
159
160
161 if (count > 255)
162 {
163 count = 255;
164 }
165
166 messages_.add(new MsgWaiting(type, count, options));
167 }
168
169 /***
170 * Creates a "Message waiting" UDH element using UDH_IEI_SPECIAL_MESSAGE.
171 * <p>
172 * If more than one type of message is required to be indicated within
173 * one SMS message, then multiple "Message waiting" UDH elements must
174 * be used.
175 * <p>
176 * <b>Special handling in concatenated messages:</b><br>
177 * <i>
178 * "In the case where this IEI is to be used in a concatenated SM then the
179 * IEI, its associated IEI length and IEI data shall be contained in the
180 * first segment of the concatenated SM. The IEI, its associated IEI length
181 * and IEI data should also be contained in every subsequent segment of the
182 * concatenated SM although this is not mandatory. However, in the case
183 * where these elements are not contained in every subsequent segment of
184 * the concatenated SM and where an out of sequence segment delivery
185 * occurs or where the first segment is not delivered then processing
186 * difficulties may arise at the receiving entity which may result in
187 * the concatenated SM being totally or partially discarded."
188 * </i>
189 *
190 * @param msgWaiting The MsgWaiting to convert
191 * @return A SmsUdhElement
192 */
193 protected SmsUdhElement getMessageWaitingUdh(MsgWaiting msgWaiting)
194 {
195 byte[] udh = new byte[2];
196
197
198
199 switch (msgWaiting.type)
200 {
201 case TYPE_VOICE: udh[0] = 0x00; break;
202 case TYPE_FAX: udh[0] = 0x01; break;
203 case TYPE_EMAIL: udh[0] = 0x02; break;
204 case TYPE_VIDEO: udh[0] = 0x07; break;
205
206 default:
207 throw new RuntimeException("Invalid message type.");
208 }
209
210
211 switch (msgWaiting.options & OPT_PROFILE_MASK)
212 {
213 case OPT_PROFILE_ID_1: udh[0] |= 0x00; break;
214 case OPT_PROFILE_ID_2: udh[0] |= 0x20; break;
215 case OPT_PROFILE_ID_3: udh[0] |= 0x40; break;
216 case OPT_PROFILE_ID_4: udh[0] |= 0x60; break;
217
218 default:
219 throw new RuntimeException("Invalid option.");
220 }
221
222
223 if ((msgWaiting.options & OPT_STORE_MSG) != 0)
224 {
225 udh[0] |= (byte) (0x80);
226 }
227
228
229 udh[1] = (byte) (msgWaiting.count & 0xff);
230
231 return new SmsUdhElement(SmsConstants.UDH_IEI_SPECIAL_MESSAGE, udh);
232 }
233
234 /***
235 * Builds a udh element for this message.
236 *
237 * @see org.marre.sms.SmsTextMessage#getUdhElements()
238 */
239 public SmsUdhElement[] getUdhElements()
240 {
241 SmsUdhElement udhElements[] = null;
242 int msgCount = messages_.size();
243
244 if (msgCount > 0)
245 {
246 udhElements = new SmsUdhElement[messages_.size()];
247 int i = 0;
248
249 for(Iterator j = messages_.iterator(); j.hasNext(); i++)
250 {
251 MsgWaiting msgWaiting = (MsgWaiting) j.next();
252 udhElements[i] = getMessageWaitingUdh(msgWaiting);
253 }
254
255 }
256
257 return udhElements;
258 }
259 }