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