1/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.cellbroadcastreceiver.tests;
18
19import android.app.Activity;
20import android.content.Intent;
21import android.provider.Telephony.Sms.Intents;
22import android.telephony.SmsCbLocation;
23import android.telephony.SmsCbMessage;
24import android.util.Log;
25
26import com.android.internal.telephony.EncodeException;
27import com.android.internal.telephony.GsmAlphabet;
28import com.android.internal.telephony.IccUtils;
29import com.android.internal.telephony.gsm.GsmSmsCbMessage;
30
31import java.io.UnsupportedEncodingException;
32
33/**
34 * Send test messages.
35 */
36public class SendTestMessages {
37
38    private static String TAG = "SendTestMessages";
39
40    private static final int DCS_7BIT_ENGLISH = 0x01;
41    private static final int DCS_16BIT_UCS2 = 0x48;
42
43    /* ETWS Test message including header */
44    private static final byte[] etwsMessageNormal = IccUtils.hexStringToBytes("000011001101" +
45            "0D0A5BAE57CE770C531790E85C716CBF3044573065B930675730" +
46            "9707767A751F30025F37304463FA308C306B5099304830664E0B30553044FF086C178C615E81FF09" +
47            "0000000000000000000000000000");
48
49    private static final byte[] etwsMessageCancel = IccUtils.hexStringToBytes("000011001101" +
50            "0D0A5148307B3069002800310030003A0035" +
51            "00320029306E7DCA602557309707901F5831309253D66D883057307E3059FF086C178C615E81FF09" +
52            "00000000000000000000000000000000000000000000");
53
54    private static final byte[] etwsMessageTest = IccUtils.hexStringToBytes("000011031101" +
55            "0D0A5BAE57CE770C531790E85C716CBF3044" +
56            "573065B9306757309707300263FA308C306B5099304830664E0B30553044FF086C178C615E81FF09" +
57            "00000000000000000000000000000000000000000000");
58
59    private static final byte[] gsm7BitTest = {
60            (byte)0xC0, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x40, (byte)0x11, (byte)0x41,
61            (byte)0xD0, (byte)0x71, (byte)0xDA, (byte)0x04, (byte)0x91, (byte)0xCB, (byte)0xE6,
62            (byte)0x70, (byte)0x9D, (byte)0x4D, (byte)0x07, (byte)0x85, (byte)0xD9, (byte)0x70,
63            (byte)0x74, (byte)0x58, (byte)0x5C, (byte)0xA6, (byte)0x83, (byte)0xDA, (byte)0xE5,
64            (byte)0xF9, (byte)0x3C, (byte)0x7C, (byte)0x2E, (byte)0x83, (byte)0xEE, (byte)0x69,
65            (byte)0x3A, (byte)0x1A, (byte)0x34, (byte)0x0E, (byte)0xCB, (byte)0xE5, (byte)0xE9,
66            (byte)0xF0, (byte)0xB9, (byte)0x0C, (byte)0x92, (byte)0x97, (byte)0xE9, (byte)0x75,
67            (byte)0xB9, (byte)0x1B, (byte)0x04, (byte)0x0F, (byte)0x93, (byte)0xC9, (byte)0x69,
68            (byte)0xF7, (byte)0xB9, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
69            (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
70            (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
71            (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
72            (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x00
73    };
74
75    private static final byte[] gsm7BitTestUmts = {
76            (byte)0x01, (byte)0x00, (byte)0x01, (byte)0xC0, (byte)0x00, (byte)0x40,
77
78            (byte)0x01,
79
80            (byte)0x41, (byte)0xD0, (byte)0x71, (byte)0xDA, (byte)0x04, (byte)0x91,
81            (byte)0xCB, (byte)0xE6, (byte)0x70, (byte)0x9D, (byte)0x4D, (byte)0x07,
82            (byte)0x85, (byte)0xD9, (byte)0x70, (byte)0x74, (byte)0x58, (byte)0x5C,
83            (byte)0xA6, (byte)0x83, (byte)0xDA, (byte)0xE5, (byte)0xF9, (byte)0x3C,
84            (byte)0x7C, (byte)0x2E, (byte)0x83, (byte)0xEE, (byte)0x69, (byte)0x3A,
85            (byte)0x1A, (byte)0x34, (byte)0x0E, (byte)0xCB, (byte)0xE5, (byte)0xE9,
86            (byte)0xF0, (byte)0xB9, (byte)0x0C, (byte)0x92, (byte)0x97, (byte)0xE9,
87            (byte)0x75, (byte)0xB9, (byte)0x1B, (byte)0x04, (byte)0x0F, (byte)0x93,
88            (byte)0xC9, (byte)0x69, (byte)0xF7, (byte)0xB9, (byte)0xD1, (byte)0x68,
89            (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1,
90            (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3,
91            (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46,
92            (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
93            (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x00,
94
95            (byte)0x34
96    };
97
98    private static final byte[] gsm7BitTestMultipageUmts = {
99            (byte)0x01, (byte)0x00, (byte)0x01, (byte)0xC0, (byte)0x00, (byte)0x40,
100
101            (byte)0x02,
102
103            (byte)0xC6, (byte)0xB4, (byte)0x7C, (byte)0x4E, (byte)0x07, (byte)0xC1,
104            (byte)0xC3, (byte)0xE7, (byte)0xF2, (byte)0xAA, (byte)0xD1, (byte)0x68,
105            (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1,
106            (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3,
107            (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46,
108            (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
109            (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A,
110            (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34,
111            (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68,
112            (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1,
113            (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3,
114            (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46,
115            (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
116            (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x00,
117
118            (byte)0x0A,
119
120            (byte)0xD3, (byte)0xF2, (byte)0xF8, (byte)0xED, (byte)0x26, (byte)0x83,
121            (byte)0xE0, (byte)0xE1, (byte)0x73, (byte)0xB9, (byte)0xD1, (byte)0x68,
122            (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1,
123            (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3,
124            (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46,
125            (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
126            (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A,
127            (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34,
128            (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68,
129            (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1,
130            (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3,
131            (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46,
132            (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
133            (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x00,
134
135            (byte)0x0A
136    };
137
138    private static final byte[] gsm7BitTestMultipage1 = {
139            (byte)0x01, (byte)0x00, (byte)0x01, (byte)0xC0, (byte)0x00, (byte)0x40,
140            (byte)0xC6, (byte)0xB4, (byte)0x7C, (byte)0x4E, (byte)0x07, (byte)0xC1,
141            (byte)0xC3, (byte)0xE7, (byte)0xF2, (byte)0xAA, (byte)0xD1, (byte)0x68,
142            (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1,
143            (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3,
144            (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46,
145            (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
146            (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A,
147            (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34,
148            (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68,
149            (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1,
150            (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3,
151            (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46,
152            (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
153            (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x00
154    };
155
156    private static final byte[] gsm7BitTestMultipage2 = {
157            (byte)0x01, (byte)0x00, (byte)0x01, (byte)0xC0, (byte)0x00, (byte)0x40,
158            (byte)0xD3, (byte)0xF2, (byte)0xF8, (byte)0xED, (byte)0x26, (byte)0x83,
159            (byte)0xE0, (byte)0xE1, (byte)0x73, (byte)0xB9, (byte)0xD1, (byte)0x68,
160            (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1,
161            (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3,
162            (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46,
163            (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
164            (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A,
165            (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34,
166            (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68,
167            (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1,
168            (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3,
169            (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46,
170            (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
171            (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x00
172    };
173
174    private static final byte[] gsm7BitTestNoPadding = {
175            (byte)0xC0, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x40, (byte)0x11, (byte)0x41,
176            (byte)0xD0, (byte)0x71, (byte)0xDA, (byte)0x04, (byte)0x91, (byte)0xCB, (byte)0xE6,
177            (byte)0x70, (byte)0x9D, (byte)0x4D, (byte)0x07, (byte)0x85, (byte)0xD9, (byte)0x70,
178            (byte)0x74, (byte)0x58, (byte)0x5C, (byte)0xA6, (byte)0x83, (byte)0xDA, (byte)0xE5,
179            (byte)0xF9, (byte)0x3C, (byte)0x7C, (byte)0x2E, (byte)0x83, (byte)0xC4, (byte)0xE5,
180            (byte)0xB4, (byte)0xFB, (byte)0x0C, (byte)0x2A, (byte)0xE3, (byte)0xC3, (byte)0x63,
181            (byte)0x3A, (byte)0x3B, (byte)0x0F, (byte)0xCA, (byte)0xCD, (byte)0x40, (byte)0x63,
182            (byte)0x74, (byte)0x58, (byte)0x1E, (byte)0x1E, (byte)0xD3, (byte)0xCB, (byte)0xF2,
183            (byte)0x39, (byte)0x88, (byte)0xFD, (byte)0x76, (byte)0x9F, (byte)0x59, (byte)0xA0,
184            (byte)0x76, (byte)0x39, (byte)0xEC, (byte)0x4E, (byte)0xBB, (byte)0xCF, (byte)0x20,
185            (byte)0x3A, (byte)0xBA, (byte)0x2C, (byte)0x2F, (byte)0x83, (byte)0xD2, (byte)0x73,
186            (byte)0x90, (byte)0xFB, (byte)0x0D, (byte)0x82, (byte)0x87, (byte)0xC9, (byte)0xE4,
187            (byte)0xB4, (byte)0xFB, (byte)0x1C, (byte)0x02
188    };
189
190    private static final byte[] gsm7BitTestNoPaddingUmts = {
191            (byte)0x01, (byte)0x00, (byte)0x01, (byte)0xC0, (byte)0x00, (byte)0x40,
192
193            (byte)0x01,
194
195            (byte)0x41, (byte)0xD0, (byte)0x71, (byte)0xDA, (byte)0x04, (byte)0x91,
196            (byte)0xCB, (byte)0xE6, (byte)0x70, (byte)0x9D, (byte)0x4D, (byte)0x07,
197            (byte)0x85, (byte)0xD9, (byte)0x70, (byte)0x74, (byte)0x58, (byte)0x5C,
198            (byte)0xA6, (byte)0x83, (byte)0xDA, (byte)0xE5, (byte)0xF9, (byte)0x3C,
199            (byte)0x7C, (byte)0x2E, (byte)0x83, (byte)0xC4, (byte)0xE5, (byte)0xB4,
200            (byte)0xFB, (byte)0x0C, (byte)0x2A, (byte)0xE3, (byte)0xC3, (byte)0x63,
201            (byte)0x3A, (byte)0x3B, (byte)0x0F, (byte)0xCA, (byte)0xCD, (byte)0x40,
202            (byte)0x63, (byte)0x74, (byte)0x58, (byte)0x1E, (byte)0x1E, (byte)0xD3,
203            (byte)0xCB, (byte)0xF2, (byte)0x39, (byte)0x88, (byte)0xFD, (byte)0x76,
204            (byte)0x9F, (byte)0x59, (byte)0xA0, (byte)0x76, (byte)0x39, (byte)0xEC,
205            (byte)0x4E, (byte)0xBB, (byte)0xCF, (byte)0x20, (byte)0x3A, (byte)0xBA,
206            (byte)0x2C, (byte)0x2F, (byte)0x83, (byte)0xD2, (byte)0x73, (byte)0x90,
207            (byte)0xFB, (byte)0x0D, (byte)0x82, (byte)0x87, (byte)0xC9, (byte)0xE4,
208            (byte)0xB4, (byte)0xFB, (byte)0x1C, (byte)0x02,
209
210            (byte)0x52
211    };
212
213    private static final byte[] gsm7BitTestWithLanguage = {
214            (byte)0xC0, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x04, (byte)0x11, (byte)0x41,
215            (byte)0xD0, (byte)0x71, (byte)0xDA, (byte)0x04, (byte)0x91, (byte)0xCB, (byte)0xE6,
216            (byte)0x70, (byte)0x9D, (byte)0x4D, (byte)0x07, (byte)0x85, (byte)0xD9, (byte)0x70,
217            (byte)0x74, (byte)0x58, (byte)0x5C, (byte)0xA6, (byte)0x83, (byte)0xDA, (byte)0xE5,
218            (byte)0xF9, (byte)0x3C, (byte)0x7C, (byte)0x2E, (byte)0x83, (byte)0xEE, (byte)0x69,
219            (byte)0x3A, (byte)0x1A, (byte)0x34, (byte)0x0E, (byte)0xCB, (byte)0xE5, (byte)0xE9,
220            (byte)0xF0, (byte)0xB9, (byte)0x0C, (byte)0x92, (byte)0x97, (byte)0xE9, (byte)0x75,
221            (byte)0xB9, (byte)0x1B, (byte)0x04, (byte)0x0F, (byte)0x93, (byte)0xC9, (byte)0x69,
222            (byte)0xF7, (byte)0xB9, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
223            (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
224            (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
225            (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
226            (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x00
227    };
228
229    private static final byte[] gsm7BitTestWithLanguageInBody = {
230            (byte)0xC0, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x10, (byte)0x11, (byte)0x73,
231            (byte)0x7B, (byte)0x23, (byte)0x08, (byte)0x3A, (byte)0x4E, (byte)0x9B, (byte)0x20,
232            (byte)0x72, (byte)0xD9, (byte)0x1C, (byte)0xAE, (byte)0xB3, (byte)0xE9, (byte)0xA0,
233            (byte)0x30, (byte)0x1B, (byte)0x8E, (byte)0x0E, (byte)0x8B, (byte)0xCB, (byte)0x74,
234            (byte)0x50, (byte)0xBB, (byte)0x3C, (byte)0x9F, (byte)0x87, (byte)0xCF, (byte)0x65,
235            (byte)0xD0, (byte)0x3D, (byte)0x4D, (byte)0x47, (byte)0x83, (byte)0xC6, (byte)0x61,
236            (byte)0xB9, (byte)0x3C, (byte)0x1D, (byte)0x3E, (byte)0x97, (byte)0x41, (byte)0xF2,
237            (byte)0x32, (byte)0xBD, (byte)0x2E, (byte)0x77, (byte)0x83, (byte)0xE0, (byte)0x61,
238            (byte)0x32, (byte)0x39, (byte)0xED, (byte)0x3E, (byte)0x37, (byte)0x1A, (byte)0x8D,
239            (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
240            (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
241            (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
242            (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x00
243    };
244
245    private static final byte[] gsm7BitTestWithLanguageInBodyUmts = {
246            (byte)0x01, (byte)0x00, (byte)0x01, (byte)0xC0, (byte)0x00, (byte)0x10,
247
248            (byte)0x01,
249
250            (byte)0x73, (byte)0x7B, (byte)0x23, (byte)0x08, (byte)0x3A, (byte)0x4E,
251            (byte)0x9B, (byte)0x20, (byte)0x72, (byte)0xD9, (byte)0x1C, (byte)0xAE,
252            (byte)0xB3, (byte)0xE9, (byte)0xA0, (byte)0x30, (byte)0x1B, (byte)0x8E,
253            (byte)0x0E, (byte)0x8B, (byte)0xCB, (byte)0x74, (byte)0x50, (byte)0xBB,
254            (byte)0x3C, (byte)0x9F, (byte)0x87, (byte)0xCF, (byte)0x65, (byte)0xD0,
255            (byte)0x3D, (byte)0x4D, (byte)0x47, (byte)0x83, (byte)0xC6, (byte)0x61,
256            (byte)0xB9, (byte)0x3C, (byte)0x1D, (byte)0x3E, (byte)0x97, (byte)0x41,
257            (byte)0xF2, (byte)0x32, (byte)0xBD, (byte)0x2E, (byte)0x77, (byte)0x83,
258            (byte)0xE0, (byte)0x61, (byte)0x32, (byte)0x39, (byte)0xED, (byte)0x3E,
259            (byte)0x37, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1,
260            (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3,
261            (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46,
262            (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
263            (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x00,
264
265            (byte)0x37
266    };
267
268    private static final byte[] gsmUcs2Test = {
269            (byte)0xC0, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x48, (byte)0x11, (byte)0x00,
270            (byte)0x41, (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x55, (byte)0x00, (byte)0x43,
271            (byte)0x00, (byte)0x53, (byte)0x00, (byte)0x32, (byte)0x00, (byte)0x20, (byte)0x00,
272            (byte)0x6D, (byte)0x00, (byte)0x65, (byte)0x00, (byte)0x73, (byte)0x00, (byte)0x73,
273            (byte)0x00, (byte)0x61, (byte)0x00, (byte)0x67, (byte)0x00, (byte)0x65, (byte)0x00,
274            (byte)0x20, (byte)0x00, (byte)0x63, (byte)0x00, (byte)0x6F, (byte)0x00, (byte)0x6E,
275            (byte)0x00, (byte)0x74, (byte)0x00, (byte)0x61, (byte)0x00, (byte)0x69, (byte)0x00,
276            (byte)0x6E, (byte)0x00, (byte)0x69, (byte)0x00, (byte)0x6E, (byte)0x00, (byte)0x67,
277            (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x61, (byte)0x00, (byte)0x20, (byte)0x04,
278            (byte)0x34, (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x63, (byte)0x00, (byte)0x68,
279            (byte)0x00, (byte)0x61, (byte)0x00, (byte)0x72, (byte)0x00, (byte)0x61, (byte)0x00,
280            (byte)0x63, (byte)0x00, (byte)0x74, (byte)0x00, (byte)0x65, (byte)0x00, (byte)0x72,
281            (byte)0x00, (byte)0x0D, (byte)0x00, (byte)0x0D
282    };
283
284    private static final byte[] gsmUcs2TestUmts = {
285            (byte)0x01, (byte)0x00, (byte)0x01, (byte)0xC0, (byte)0x00, (byte)0x48,
286
287            (byte)0x01,
288
289            (byte)0x00, (byte)0x41, (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x55,
290            (byte)0x00, (byte)0x43, (byte)0x00, (byte)0x53, (byte)0x00, (byte)0x32,
291            (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x6D, (byte)0x00, (byte)0x65,
292            (byte)0x00, (byte)0x73, (byte)0x00, (byte)0x73, (byte)0x00, (byte)0x61,
293            (byte)0x00, (byte)0x67, (byte)0x00, (byte)0x65, (byte)0x00, (byte)0x20,
294            (byte)0x00, (byte)0x63, (byte)0x00, (byte)0x6F, (byte)0x00, (byte)0x6E,
295            (byte)0x00, (byte)0x74, (byte)0x00, (byte)0x61, (byte)0x00, (byte)0x69,
296            (byte)0x00, (byte)0x6E, (byte)0x00, (byte)0x69, (byte)0x00, (byte)0x6E,
297            (byte)0x00, (byte)0x67, (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x61,
298            (byte)0x00, (byte)0x20, (byte)0x04, (byte)0x34, (byte)0x00, (byte)0x20,
299            (byte)0x00, (byte)0x63, (byte)0x00, (byte)0x68, (byte)0x00, (byte)0x61,
300            (byte)0x00, (byte)0x72, (byte)0x00, (byte)0x61, (byte)0x00, (byte)0x63,
301            (byte)0x00, (byte)0x74, (byte)0x00, (byte)0x65, (byte)0x00, (byte)0x72,
302            (byte)0x00, (byte)0x0D, (byte)0x00, (byte)0x0D,
303
304            (byte)0x4E
305    };
306
307    private static final byte[] gsmUcs2TestMultipageUmts = {
308            (byte)0x01, (byte)0x00, (byte)0x01, (byte)0xC0, (byte)0x00, (byte)0x48,
309
310            (byte)0x02,
311
312            (byte)0x00, (byte)0x41, (byte)0x00, (byte)0x41, (byte)0x00, (byte)0x41,
313            (byte)0x00, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
314            (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
315            (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
316            (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
317            (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
318            (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
319            (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
320            (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
321            (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
322            (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
323            (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
324            (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
325            (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
326
327            (byte)0x06,
328
329            (byte)0x00, (byte)0x42, (byte)0x00, (byte)0x42, (byte)0x00, (byte)0x42,
330            (byte)0x00, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
331            (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
332            (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
333            (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
334            (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
335            (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
336            (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
337            (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
338            (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
339            (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
340            (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
341            (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
342            (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
343
344            (byte)0x06
345    };
346
347    private static final byte[] gsmUcs2TestWithLanguageInBody = {
348            (byte)0xC0, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x11, (byte)0x11, (byte)0x78,
349            (byte)0x3C, (byte)0x00, (byte)0x41, (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x55,
350            (byte)0x00, (byte)0x43, (byte)0x00, (byte)0x53, (byte)0x00, (byte)0x32, (byte)0x00,
351            (byte)0x20, (byte)0x00, (byte)0x6D, (byte)0x00, (byte)0x65, (byte)0x00, (byte)0x73,
352            (byte)0x00, (byte)0x73, (byte)0x00, (byte)0x61, (byte)0x00, (byte)0x67, (byte)0x00,
353            (byte)0x65, (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x63, (byte)0x00, (byte)0x6F,
354            (byte)0x00, (byte)0x6E, (byte)0x00, (byte)0x74, (byte)0x00, (byte)0x61, (byte)0x00,
355            (byte)0x69, (byte)0x00, (byte)0x6E, (byte)0x00, (byte)0x69, (byte)0x00, (byte)0x6E,
356            (byte)0x00, (byte)0x67, (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x61, (byte)0x00,
357            (byte)0x20, (byte)0x04, (byte)0x34, (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x63,
358            (byte)0x00, (byte)0x68, (byte)0x00, (byte)0x61, (byte)0x00, (byte)0x72, (byte)0x00,
359            (byte)0x61, (byte)0x00, (byte)0x63, (byte)0x00, (byte)0x74, (byte)0x00, (byte)0x65,
360            (byte)0x00, (byte)0x72, (byte)0x00, (byte)0x0D
361    };
362
363    private static final byte[] gsmUcs2TestWithLanguageInBodyUmts = {
364            (byte)0x01, (byte)0x00, (byte)0x01, (byte)0xC0, (byte)0x00, (byte)0x11,
365
366            (byte)0x01,
367
368            (byte)0x78, (byte)0x3C, (byte)0x00, (byte)0x41, (byte)0x00, (byte)0x20,
369            (byte)0x00, (byte)0x55, (byte)0x00, (byte)0x43, (byte)0x00, (byte)0x53,
370            (byte)0x00, (byte)0x32, (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x6D,
371            (byte)0x00, (byte)0x65, (byte)0x00, (byte)0x73, (byte)0x00, (byte)0x73,
372            (byte)0x00, (byte)0x61, (byte)0x00, (byte)0x67, (byte)0x00, (byte)0x65,
373            (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x63, (byte)0x00, (byte)0x6F,
374            (byte)0x00, (byte)0x6E, (byte)0x00, (byte)0x74, (byte)0x00, (byte)0x61,
375            (byte)0x00, (byte)0x69, (byte)0x00, (byte)0x6E, (byte)0x00, (byte)0x69,
376            (byte)0x00, (byte)0x6E, (byte)0x00, (byte)0x67, (byte)0x00, (byte)0x20,
377            (byte)0x00, (byte)0x61, (byte)0x00, (byte)0x20, (byte)0x04, (byte)0x34,
378            (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x63, (byte)0x00, (byte)0x68,
379            (byte)0x00, (byte)0x61, (byte)0x00, (byte)0x72, (byte)0x00, (byte)0x61,
380            (byte)0x00, (byte)0x63, (byte)0x00, (byte)0x74, (byte)0x00, (byte)0x65,
381            (byte)0x00, (byte)0x72, (byte)0x00, (byte)0x0D,
382
383            (byte)0x50
384    };
385
386    private static final SmsCbLocation sEmptyLocation = new SmsCbLocation();
387
388    private static SmsCbMessage createFromPdu(byte[] pdu, int serialNumber, int category) {
389        byte[][] pdus = new byte[1][];
390        pdus[0] = pdu;
391        return createFromPdus(pdus, serialNumber, category);
392    }
393
394    private static SmsCbMessage createFromPdus(byte[][] pdus, int serialNumber, int category) {
395        try {
396            for (byte[] pdu : pdus) {
397                if (pdu.length <= 88) {
398                    // GSM format cell broadcast
399                    Log.d(TAG, "setting GSM serial number to " + serialNumber);
400                    pdu[0] = (byte) ((serialNumber >>> 8) & 0xff);
401                    pdu[1] = (byte) (serialNumber & 0xff);
402                    if (category != 0) {
403                        Log.d(TAG, "setting GSM message identifier to " + category);
404                        pdu[2] = (byte) ((category >>> 8) & 0xff);
405                        pdu[3] = (byte) (category & 0xff);
406                    }
407                } else {
408                    // UMTS format cell broadcast
409                    Log.d(TAG, "setting UMTS serial number to " + serialNumber);
410                    pdu[3] = (byte) ((serialNumber >>> 8) & 0xff);
411                    pdu[4] = (byte) (serialNumber & 0xff);
412                    if (category != 0) {
413                        Log.d(TAG, "setting UMTS message identifier to " + category);
414                        pdu[1] = (byte) ((category >>> 8) & 0xff);
415                        pdu[2] = (byte) (category & 0xff);
416                    }
417                }
418            }
419            return GsmSmsCbMessage.createSmsCbMessage(sEmptyLocation, pdus);
420        } catch (IllegalArgumentException e) {
421            return null;
422        }
423    }
424
425    public static void testSendMessage7bit(Activity activity, int serialNumber, int category) {
426        Intent intent = new Intent(Intents.SMS_CB_RECEIVED_ACTION);
427        intent.putExtra("message", createFromPdu(gsm7BitTest, serialNumber, category));
428        activity.sendOrderedBroadcast(intent, "android.permission.RECEIVE_SMS");
429    }
430
431    public static void testSendMessage7bitUmts(Activity activity, int serialNumber, int category) {
432        Intent intent = new Intent(Intents.SMS_CB_RECEIVED_ACTION);
433        intent.putExtra("message", createFromPdu(gsm7BitTestUmts, serialNumber, category));
434        activity.sendOrderedBroadcast(intent, "android.permission.RECEIVE_SMS");
435    }
436
437    public static void testSendMessage7bitNoPadding(Activity activity, int serialNumber,
438            int category) {
439        Intent intent = new Intent(Intents.SMS_CB_RECEIVED_ACTION);
440        intent.putExtra("message", createFromPdu(gsm7BitTestNoPadding, serialNumber, category));
441        activity.sendOrderedBroadcast(intent, "android.permission.RECEIVE_SMS");
442    }
443
444    public static void testSendMessage7bitNoPaddingUmts(Activity activity, int serialNumber,
445            int category) {
446        Intent intent = new Intent(Intents.SMS_CB_RECEIVED_ACTION);
447        intent.putExtra("message", createFromPdu(gsm7BitTestNoPaddingUmts, serialNumber, category));
448        activity.sendOrderedBroadcast(intent, "android.permission.RECEIVE_SMS");
449    }
450
451    public static void testSendMessage7bitMultipageGsm(Activity activity, int serialNumber,
452            int category) {
453        Intent intent = new Intent(Intents.SMS_CB_RECEIVED_ACTION);
454        byte[][] pdus = new byte[2][];
455        pdus[0] = gsm7BitTestMultipage1;
456        pdus[1] = gsm7BitTestMultipage2;
457        intent.putExtra("message", createFromPdus(pdus, serialNumber, category));
458        activity.sendOrderedBroadcast(intent, "android.permission.RECEIVE_SMS");
459    }
460
461    public static void testSendMessage7bitMultipageUmts(Activity activity, int serialNumber,
462            int category) {
463        Intent intent = new Intent(Intents.SMS_CB_RECEIVED_ACTION);
464        intent.putExtra("message", createFromPdu(gsm7BitTestMultipageUmts, serialNumber, category));
465        activity.sendOrderedBroadcast(intent, "android.permission.RECEIVE_SMS");
466    }
467
468    public static void testSendMessage7bitWithLanguage(Activity activity, int serialNumber,
469            int category) {
470        Intent intent = new Intent(Intents.SMS_CB_RECEIVED_ACTION);
471        intent.putExtra("message", createFromPdu(gsm7BitTestWithLanguage, serialNumber, category));
472        activity.sendOrderedBroadcast(intent, "android.permission.RECEIVE_SMS");
473    }
474
475    public static void testSendMessage7bitWithLanguageInBody(Activity activity, int serialNumber,
476            int category) {
477        Intent intent = new Intent(Intents.SMS_CB_RECEIVED_ACTION);
478        intent.putExtra("message", createFromPdu(gsm7BitTestWithLanguageInBody, serialNumber,
479                category));
480        activity.sendOrderedBroadcast(intent, "android.permission.RECEIVE_SMS");
481    }
482
483    public static void testSendMessage7bitWithLanguageInBodyUmts(Activity activity,
484            int serialNumber, int category) {
485        Intent intent = new Intent(Intents.SMS_CB_RECEIVED_ACTION);
486        intent.putExtra("message", createFromPdu(gsm7BitTestWithLanguageInBodyUmts, serialNumber,
487                category));
488        activity.sendOrderedBroadcast(intent, "android.permission.RECEIVE_SMS");
489    }
490
491    public static void testSendMessageUcs2(Activity activity, int serialNumber, int category) {
492        Intent intent = new Intent(Intents.SMS_CB_RECEIVED_ACTION);
493        intent.putExtra("message", createFromPdu(gsmUcs2Test, serialNumber, category));
494        activity.sendOrderedBroadcast(intent, "android.permission.RECEIVE_SMS");
495    }
496
497    public static void testSendMessageUcs2Umts(Activity activity, int serialNumber, int category) {
498        Intent intent = new Intent(Intents.SMS_CB_RECEIVED_ACTION);
499        intent.putExtra("message", createFromPdu(gsmUcs2TestUmts, serialNumber, category));
500        activity.sendOrderedBroadcast(intent, "android.permission.RECEIVE_SMS");
501    }
502
503    public static void testSendMessageUcs2MultipageUmts(Activity activity, int serialNumber,
504            int category) {
505        Intent intent = new Intent(Intents.SMS_CB_RECEIVED_ACTION);
506        intent.putExtra("message", createFromPdu(gsmUcs2TestMultipageUmts, serialNumber, category));
507        activity.sendOrderedBroadcast(intent, "android.permission.RECEIVE_SMS");
508    }
509
510    public static void testSendMessageUcs2WithLanguageInBody(Activity activity, int serialNumber,
511            int category) {
512        Intent intent = new Intent(Intents.SMS_CB_RECEIVED_ACTION);
513        intent.putExtra("message", createFromPdu(gsmUcs2TestWithLanguageInBody, serialNumber,
514                category));
515        activity.sendOrderedBroadcast(intent, "android.permission.RECEIVE_SMS");
516    }
517
518    public static void testSendMessageUcs2WithLanguageUmts(Activity activity, int serialNumber,
519            int category) {
520        Intent intent = new Intent(Intents.SMS_CB_RECEIVED_ACTION);
521        intent.putExtra("message", createFromPdu(gsmUcs2TestWithLanguageInBodyUmts, serialNumber,
522                category));
523        activity.sendOrderedBroadcast(intent, "android.permission.RECEIVE_SMS");
524    }
525
526    public static void testSendEtwsMessageNormal(Activity activity, int serialNumber) {
527        Intent intent = new Intent(Intents.SMS_EMERGENCY_CB_RECEIVED_ACTION);
528        intent.putExtra("message", createFromPdu(etwsMessageNormal, serialNumber, 0));
529        activity.sendOrderedBroadcast(intent,
530                "android.permission.RECEIVE_EMERGENCY_BROADCAST");
531    }
532
533    public static void testSendEtwsMessageCancel(Activity activity, int serialNumber) {
534        Intent intent = new Intent(Intents.SMS_EMERGENCY_CB_RECEIVED_ACTION);
535        intent.putExtra("message", createFromPdu(etwsMessageCancel, serialNumber, 0));
536        activity.sendOrderedBroadcast(intent,
537                "android.permission.RECEIVE_EMERGENCY_BROADCAST");
538    }
539
540    public static void testSendEtwsMessageTest(Activity activity, int serialNumber) {
541        Intent intent = new Intent(Intents.SMS_EMERGENCY_CB_RECEIVED_ACTION);
542        intent.putExtra("message", createFromPdu(etwsMessageTest, serialNumber, 0));
543        activity.sendOrderedBroadcast(intent,
544                "android.permission.RECEIVE_EMERGENCY_BROADCAST");
545    }
546}
547