1 /* 2 * Copyright (C) 2006 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.internal.telephony.cdma.sms; 18 19 import android.telephony.TelephonyManager; 20 21 import com.android.internal.telephony.GsmAlphabet; 22 import com.android.internal.telephony.SmsHeader; 23 import com.android.internal.telephony.cdma.SmsMessage; 24 import com.android.internal.telephony.cdma.sms.BearerData; 25 import com.android.internal.telephony.cdma.sms.UserData; 26 import com.android.internal.telephony.cdma.sms.CdmaSmsAddress; 27 import com.android.internal.telephony.SmsMessageBase.TextEncodingDetails; 28 import com.android.internal.util.BitwiseInputStream; 29 import com.android.internal.util.BitwiseOutputStream; 30 import com.android.internal.util.HexDump; 31 32 import android.test.AndroidTestCase; 33 import android.test.suitebuilder.annotation.SmallTest; 34 35 import android.util.Log; 36 37 import java.util.ArrayList; 38 39 public class CdmaSmsTest extends AndroidTestCase { 40 private final static String LOG_TAG = "XXX CdmaSmsTest XXX"; 41 42 @SmallTest 43 public void testCdmaSmsAddrParsing() throws Exception { 44 CdmaSmsAddress addr = CdmaSmsAddress.parse("6502531000"); 45 assertEquals(addr.ton, CdmaSmsAddress.TON_UNKNOWN); 46 assertEquals(addr.digitMode, CdmaSmsAddress.DIGIT_MODE_4BIT_DTMF); 47 assertEquals(addr.numberMode, CdmaSmsAddress.NUMBER_MODE_NOT_DATA_NETWORK); 48 assertEquals(addr.numberOfDigits, 10); 49 assertEquals(addr.origBytes.length, 10); 50 byte[] data = {6, 5, 10, 2, 5, 3, 1, 10, 10, 10}; 51 for (int i = 0; i < data.length; i++) { 52 assertEquals(addr.origBytes[i], data[i]); 53 } 54 addr = CdmaSmsAddress.parse("(650) 253-1000"); 55 assertEquals(addr.ton, CdmaSmsAddress.TON_UNKNOWN); 56 assertEquals(addr.digitMode, CdmaSmsAddress.DIGIT_MODE_4BIT_DTMF); 57 assertEquals(addr.numberMode, CdmaSmsAddress.NUMBER_MODE_NOT_DATA_NETWORK); 58 assertEquals(addr.numberOfDigits, 10); 59 assertEquals(addr.origBytes.length, 10); 60 byte[] data2 = {6, 5, 10, 2, 5, 3, 1, 10, 10, 10}; 61 for (int i = 0; i < data2.length; i++) { 62 assertEquals(addr.origBytes[i], data2[i]); 63 } 64 addr = CdmaSmsAddress.parse("650.253.1000"); 65 assertEquals(addr.ton, CdmaSmsAddress.TON_UNKNOWN); 66 assertEquals(addr.digitMode, CdmaSmsAddress.DIGIT_MODE_4BIT_DTMF); 67 assertEquals(addr.numberMode, CdmaSmsAddress.NUMBER_MODE_NOT_DATA_NETWORK); 68 assertEquals(addr.numberOfDigits, 10); 69 assertEquals(addr.origBytes.length, 10); 70 byte[] data5 = {6, 5, 10, 2, 5, 3, 1, 10, 10, 10}; 71 for (int i = 0; i < data2.length; i++) { 72 assertEquals(addr.origBytes[i], data5[i]); 73 } 74 addr = CdmaSmsAddress.parse("(+886) 917 222 555"); 75 assertEquals(addr.ton, CdmaSmsAddress.TON_INTERNATIONAL_OR_IP); 76 assertEquals(addr.digitMode, CdmaSmsAddress.DIGIT_MODE_4BIT_DTMF); 77 assertEquals(addr.numberMode, CdmaSmsAddress.NUMBER_MODE_NOT_DATA_NETWORK); 78 assertEquals(addr.numberOfDigits, 12); 79 assertEquals(addr.origBytes.length, 12); 80 byte[] data3 = {8, 8, 6, 9, 1, 7, 2, 2, 2, 5, 5, 5}; 81 for (int i = 0; i < data3.length; i++) { 82 assertEquals(addr.origBytes[i], data3[i]); 83 } 84 addr = CdmaSmsAddress.parse("(650) *253-1000 #600"); 85 byte[] data4 = {6, 5, 10, 11, 2, 5, 3, 1, 10, 10, 10, 12, 6, 10, 10}; 86 for (int i = 0; i < data4.length; i++) { 87 assertEquals(addr.origBytes[i], data4[i]); 88 } 89 String input = "x (at) y.com,a (at) b.com"; 90 addr = CdmaSmsAddress.parse(input); 91 assertEquals(addr.ton, CdmaSmsAddress.TON_NATIONAL_OR_EMAIL); 92 assertEquals(addr.digitMode, CdmaSmsAddress.DIGIT_MODE_8BIT_CHAR); 93 assertEquals(addr.numberMode, CdmaSmsAddress.NUMBER_MODE_DATA_NETWORK); 94 assertEquals(addr.numberOfDigits, 15); 95 assertEquals(addr.origBytes.length, 15); 96 assertEquals(new String(addr.origBytes), input); 97 addr = CdmaSmsAddress.parse("foo bar"); 98 assertEquals(addr.ton, CdmaSmsAddress.TON_UNKNOWN); 99 assertEquals(addr.digitMode, CdmaSmsAddress.DIGIT_MODE_8BIT_CHAR); 100 assertEquals(addr.numberMode, CdmaSmsAddress.NUMBER_MODE_DATA_NETWORK); 101 assertEquals(addr.numberOfDigits, 6); 102 assertEquals(addr.origBytes.length, 6); 103 assertEquals(new String(addr.origBytes), "foobar"); 104 addr = CdmaSmsAddress.parse("f\noo\tb a\rr"); 105 assertEquals(new String(addr.origBytes), "foobar"); 106 assertEquals(CdmaSmsAddress.parse("f\u0000oo bar"), null); 107 assertEquals(CdmaSmsAddress.parse("f\u0007oo bar"), null); 108 assertEquals(CdmaSmsAddress.parse("f\u0080oo bar"), null); 109 assertEquals(CdmaSmsAddress.parse("f\u1ECFboo\u001fbar"), null); 110 assertEquals(CdmaSmsAddress.parse("f\u0080oo bar"), null); 111 } 112 113 @SmallTest 114 public void testUserData7bitGsm() throws Exception { 115 String pdu = "00031040900112488ea794e074d69e1b7392c270326cde9e98"; 116 BearerData bearerData = BearerData.decode(HexDump.hexStringToByteArray(pdu)); 117 assertEquals("Test standard SMS", bearerData.userData.payloadStr); 118 } 119 120 @SmallTest 121 public void testUserData7bitAscii() throws Exception { 122 String pdu = "0003100160010610262d5ab500"; 123 BearerData bearerData = BearerData.decode(HexDump.hexStringToByteArray(pdu)); 124 assertEquals("bjjj", bearerData.userData.payloadStr); 125 } 126 127 @SmallTest 128 public void testUserData7bitAsciiTwo() throws Exception { 129 String pdu = "00031001d00109104539b4d052ebb3d0"; 130 BearerData bearerData = BearerData.decode(HexDump.hexStringToByteArray(pdu)); 131 assertEquals("SMS Rulz", bearerData.userData.payloadStr); 132 } 133 134 @SmallTest 135 public void testUserDataIa5() throws Exception { 136 String pdu = "00031002100109184539b4d052ebb3d0"; 137 BearerData bearerData = BearerData.decode(HexDump.hexStringToByteArray(pdu)); 138 assertEquals("SMS Rulz", bearerData.userData.payloadStr); 139 } 140 141 @SmallTest 142 public void testUserData7bitAsciiFeedback() throws Exception { 143 BearerData bearerData = new BearerData(); 144 bearerData.messageType = BearerData.MESSAGE_TYPE_DELIVER; 145 bearerData.messageId = 0; 146 bearerData.hasUserDataHeader = false; 147 UserData userData = new UserData(); 148 userData.payloadStr = "Test standard SMS"; 149 userData.msgEncoding = UserData.ENCODING_7BIT_ASCII; 150 userData.msgEncodingSet = true; 151 bearerData.userData = userData; 152 byte []encodedSms = BearerData.encode(bearerData); 153 BearerData revBearerData = BearerData.decode(encodedSms); 154 assertEquals(BearerData.MESSAGE_TYPE_DELIVER, revBearerData.messageType); 155 assertEquals(0, revBearerData.messageId); 156 assertEquals(false, revBearerData.hasUserDataHeader); 157 assertEquals(userData.msgEncoding, revBearerData.userData.msgEncoding); 158 assertEquals(userData.payloadStr.length(), revBearerData.userData.numFields); 159 assertEquals(userData.payloadStr, revBearerData.userData.payloadStr); 160 userData.payloadStr = "Test \u007f standard \u0000 SMS"; 161 revBearerData = BearerData.decode(BearerData.encode(bearerData)); 162 assertEquals("Test standard SMS", revBearerData.userData.payloadStr); 163 userData.payloadStr = "Test \n standard \r SMS"; 164 revBearerData = BearerData.decode(BearerData.encode(bearerData)); 165 assertEquals(userData.payloadStr, revBearerData.userData.payloadStr); 166 userData.payloadStr = ""; 167 revBearerData = BearerData.decode(BearerData.encode(bearerData)); 168 assertEquals(userData.payloadStr, revBearerData.userData.payloadStr); 169 } 170 171 @SmallTest 172 public void testUserData7bitGsmFeedback() throws Exception { 173 BearerData bearerData = new BearerData(); 174 bearerData.messageType = BearerData.MESSAGE_TYPE_DELIVER; 175 bearerData.messageId = 0; 176 bearerData.hasUserDataHeader = false; 177 UserData userData = new UserData(); 178 userData.payloadStr = "Test standard SMS"; 179 userData.msgEncoding = UserData.ENCODING_GSM_7BIT_ALPHABET; 180 userData.msgEncodingSet = true; 181 bearerData.userData = userData; 182 byte []encodedSms = BearerData.encode(bearerData); 183 BearerData revBearerData = BearerData.decode(encodedSms); 184 assertEquals(BearerData.MESSAGE_TYPE_DELIVER, revBearerData.messageType); 185 assertEquals(0, revBearerData.messageId); 186 assertEquals(false, revBearerData.hasUserDataHeader); 187 assertEquals(userData.msgEncoding, revBearerData.userData.msgEncoding); 188 assertEquals(userData.payloadStr.length(), revBearerData.userData.numFields); 189 assertEquals(userData.payloadStr, revBearerData.userData.payloadStr); 190 userData.payloadStr = "1234567"; 191 revBearerData = BearerData.decode(BearerData.encode(bearerData)); 192 assertEquals(userData.payloadStr, revBearerData.userData.payloadStr); 193 userData.payloadStr = ""; 194 revBearerData = BearerData.decode(BearerData.encode(bearerData)); 195 assertEquals(userData.payloadStr, revBearerData.userData.payloadStr); 196 userData.payloadStr = "12345678901234567890123456789012345678901234567890" + 197 "12345678901234567890123456789012345678901234567890" + 198 "12345678901234567890123456789012345678901234567890" + 199 "1234567890"; 200 revBearerData = BearerData.decode(BearerData.encode(bearerData)); 201 assertEquals(userData.payloadStr, revBearerData.userData.payloadStr); 202 userData.payloadStr = "Test \u007f illegal \u0000 SMS chars"; 203 revBearerData = BearerData.decode(BearerData.encode(bearerData)); 204 assertEquals("Test illegal SMS chars", revBearerData.userData.payloadStr); 205 userData.payloadStr = "More @ testing\nis great^|^~woohoo"; 206 revBearerData = BearerData.decode(BearerData.encode(bearerData)); 207 assertEquals(userData.payloadStr, revBearerData.userData.payloadStr); 208 SmsHeader.ConcatRef concatRef = new SmsHeader.ConcatRef(); 209 concatRef.refNumber = 0xEE; 210 concatRef.msgCount = 2; 211 concatRef.seqNumber = 2; 212 concatRef.isEightBits = true; 213 SmsHeader smsHeader = new SmsHeader(); 214 smsHeader.concatRef = concatRef; 215 byte[] encodedHeader = SmsHeader.toByteArray(smsHeader); 216 userData.userDataHeader = smsHeader; 217 revBearerData = BearerData.decode(BearerData.encode(bearerData)); 218 assertEquals(userData.payloadStr, revBearerData.userData.payloadStr); 219 SmsHeader decodedHeader = revBearerData.userData.userDataHeader; 220 assertEquals(decodedHeader.concatRef.refNumber, concatRef.refNumber); 221 assertEquals(decodedHeader.concatRef.msgCount, concatRef.msgCount); 222 assertEquals(decodedHeader.concatRef.seqNumber, concatRef.seqNumber); 223 } 224 225 @SmallTest 226 public void testUserDataUtf16Feedback() throws Exception { 227 BearerData bearerData = new BearerData(); 228 bearerData.messageType = BearerData.MESSAGE_TYPE_DELIVER; 229 bearerData.messageId = 0; 230 bearerData.hasUserDataHeader = false; 231 UserData userData = new UserData(); 232 userData.payloadStr = "\u0160u\u1E5B\u0301r\u1ECFg\uD835\uDC1At\u00E9\u4E002\u3042"; 233 userData.msgEncoding = UserData.ENCODING_UNICODE_16; 234 userData.msgEncodingSet = true; 235 bearerData.userData = userData; 236 byte []encodedSms = BearerData.encode(bearerData); 237 BearerData revBearerData = BearerData.decode(encodedSms); 238 assertEquals(BearerData.MESSAGE_TYPE_DELIVER, revBearerData.messageType); 239 assertEquals(0, revBearerData.messageId); 240 assertEquals(false, revBearerData.hasUserDataHeader); 241 assertEquals(userData.msgEncoding, revBearerData.userData.msgEncoding); 242 assertEquals(userData.payloadStr.length(), revBearerData.userData.numFields); 243 assertEquals(userData.payloadStr, revBearerData.userData.payloadStr); 244 userData.msgEncoding = UserData.ENCODING_OCTET; 245 userData.msgEncodingSet = false; 246 revBearerData = BearerData.decode(BearerData.encode(bearerData)); 247 assertEquals(BearerData.MESSAGE_TYPE_DELIVER, revBearerData.messageType); 248 assertEquals(0, revBearerData.messageId); 249 assertEquals(false, revBearerData.hasUserDataHeader); 250 assertEquals(userData.msgEncoding, revBearerData.userData.msgEncoding); 251 assertEquals(userData.payloadStr.length(), revBearerData.userData.numFields); 252 assertEquals(userData.payloadStr, revBearerData.userData.payloadStr); 253 userData.payloadStr = "1234567"; 254 revBearerData = BearerData.decode(BearerData.encode(bearerData)); 255 assertEquals(userData.payloadStr, revBearerData.userData.payloadStr); 256 userData.payloadStr = ""; 257 revBearerData = BearerData.decode(BearerData.encode(bearerData)); 258 assertEquals(userData.payloadStr, revBearerData.userData.payloadStr); 259 } 260 261 @SmallTest 262 public void testMonolithicOne() throws Exception { 263 String pdu = "0003200010010410168d2002010503060812011101590501c706069706180000000701c108" + 264 "01c00901800a01e00b01030c01c00d01070e05039acc13880f018011020566"; 265 BearerData bearerData = BearerData.decode(HexDump.hexStringToByteArray(pdu)); 266 assertEquals(bearerData.messageType, BearerData.MESSAGE_TYPE_SUBMIT); 267 assertEquals(bearerData.messageId, 1); 268 assertEquals(bearerData.priority, BearerData.PRIORITY_EMERGENCY); 269 assertEquals(bearerData.privacy, BearerData.PRIVACY_CONFIDENTIAL); 270 assertEquals(bearerData.userAckReq, true); 271 assertEquals(bearerData.readAckReq, true); 272 assertEquals(bearerData.deliveryAckReq, true); 273 assertEquals(bearerData.reportReq, false); 274 assertEquals(bearerData.numberOfMessages, 3); 275 assertEquals(bearerData.alert, BearerData.ALERT_HIGH_PRIO); 276 assertEquals(bearerData.language, BearerData.LANGUAGE_HEBREW); 277 assertEquals(bearerData.callbackNumber.digitMode, CdmaSmsAddress.DIGIT_MODE_4BIT_DTMF); 278 assertEquals(bearerData.callbackNumber.numberMode, 279 CdmaSmsAddress.NUMBER_MODE_NOT_DATA_NETWORK); 280 assertEquals(bearerData.callbackNumber.ton, CdmaSmsAddress.TON_UNKNOWN); 281 assertEquals(bearerData.callbackNumber.numberPlan, CdmaSmsAddress.NUMBERING_PLAN_UNKNOWN); 282 assertEquals(bearerData.callbackNumber.numberOfDigits, 7); 283 assertEquals(bearerData.callbackNumber.address, "3598271"); 284 assertEquals(bearerData.displayMode, BearerData.DISPLAY_MODE_USER); 285 assertEquals(bearerData.depositIndex, 1382); 286 assertEquals(bearerData.userResponseCode, 5); 287 assertEquals(bearerData.msgCenterTimeStamp.year, 2008); 288 assertEquals(bearerData.msgCenterTimeStamp.month, 11); 289 assertEquals(bearerData.msgCenterTimeStamp.monthDay, 1); 290 assertEquals(bearerData.msgCenterTimeStamp.hour, 11); 291 assertEquals(bearerData.msgCenterTimeStamp.minute, 1); 292 assertEquals(bearerData.msgCenterTimeStamp.second, 59); 293 assertEquals(bearerData.validityPeriodAbsolute, null); 294 assertEquals(bearerData.validityPeriodRelative, 193); 295 assertEquals(bearerData.deferredDeliveryTimeAbsolute.year, 1997); 296 assertEquals(bearerData.deferredDeliveryTimeAbsolute.month, 5); 297 assertEquals(bearerData.deferredDeliveryTimeAbsolute.monthDay, 18); 298 assertEquals(bearerData.deferredDeliveryTimeAbsolute.hour, 0); 299 assertEquals(bearerData.deferredDeliveryTimeAbsolute.minute, 0); 300 assertEquals(bearerData.deferredDeliveryTimeAbsolute.second, 0); 301 assertEquals(bearerData.deferredDeliveryTimeRelative, 199); 302 assertEquals(bearerData.hasUserDataHeader, false); 303 assertEquals(bearerData.userData.msgEncoding, UserData.ENCODING_7BIT_ASCII); 304 assertEquals(bearerData.userData.numFields, 2); 305 assertEquals(bearerData.userData.payloadStr, "hi"); 306 } 307 308 @SmallTest 309 public void testMonolithicTwo() throws Exception { 310 String pdu = "0003200010010410168d200201050306081201110159050192060697061800000007013d0" + 311 "801c00901800a01e00b01030c01c00d01070e05039acc13880f018011020566"; 312 BearerData bearerData = BearerData.decode(HexDump.hexStringToByteArray(pdu)); 313 assertEquals(bearerData.messageType, BearerData.MESSAGE_TYPE_SUBMIT); 314 assertEquals(bearerData.messageId, 1); 315 assertEquals(bearerData.priority, BearerData.PRIORITY_EMERGENCY); 316 assertEquals(bearerData.privacy, BearerData.PRIVACY_CONFIDENTIAL); 317 assertEquals(bearerData.userAckReq, true); 318 assertEquals(bearerData.readAckReq, true); 319 assertEquals(bearerData.deliveryAckReq, true); 320 assertEquals(bearerData.reportReq, false); 321 assertEquals(bearerData.numberOfMessages, 3); 322 assertEquals(bearerData.alert, BearerData.ALERT_HIGH_PRIO); 323 assertEquals(bearerData.language, BearerData.LANGUAGE_HEBREW); 324 assertEquals(bearerData.callbackNumber.digitMode, CdmaSmsAddress.DIGIT_MODE_4BIT_DTMF); 325 assertEquals(bearerData.callbackNumber.numberMode, 326 CdmaSmsAddress.NUMBER_MODE_NOT_DATA_NETWORK); 327 assertEquals(bearerData.callbackNumber.ton, CdmaSmsAddress.TON_UNKNOWN); 328 assertEquals(bearerData.callbackNumber.numberPlan, CdmaSmsAddress.NUMBERING_PLAN_UNKNOWN); 329 assertEquals(bearerData.callbackNumber.numberOfDigits, 7); 330 assertEquals(bearerData.callbackNumber.address, "3598271"); 331 assertEquals(bearerData.displayMode, BearerData.DISPLAY_MODE_USER); 332 assertEquals(bearerData.depositIndex, 1382); 333 assertEquals(bearerData.userResponseCode, 5); 334 assertEquals(bearerData.msgCenterTimeStamp.year, 2008); 335 assertEquals(bearerData.msgCenterTimeStamp.month, 11); 336 assertEquals(bearerData.msgCenterTimeStamp.monthDay, 1); 337 assertEquals(bearerData.msgCenterTimeStamp.hour, 11); 338 assertEquals(bearerData.msgCenterTimeStamp.minute, 1); 339 assertEquals(bearerData.msgCenterTimeStamp.second, 59); 340 assertEquals(bearerData.validityPeriodAbsolute, null); 341 assertEquals(bearerData.validityPeriodRelative, 61); 342 assertEquals(bearerData.deferredDeliveryTimeAbsolute.year, 1997); 343 assertEquals(bearerData.deferredDeliveryTimeAbsolute.month, 5); 344 assertEquals(bearerData.deferredDeliveryTimeAbsolute.monthDay, 18); 345 assertEquals(bearerData.deferredDeliveryTimeAbsolute.hour, 0); 346 assertEquals(bearerData.deferredDeliveryTimeAbsolute.minute, 0); 347 assertEquals(bearerData.deferredDeliveryTimeAbsolute.second, 0); 348 assertEquals(bearerData.deferredDeliveryTimeRelative, 146); 349 assertEquals(bearerData.hasUserDataHeader, false); 350 assertEquals(bearerData.userData.msgEncoding, UserData.ENCODING_7BIT_ASCII); 351 assertEquals(bearerData.userData.numFields, 2); 352 assertEquals(bearerData.userData.payloadStr, "hi"); 353 } 354 355 @SmallTest 356 public void testUserDataHeaderConcatRefFeedback() throws Exception { 357 BearerData bearerData = new BearerData(); 358 bearerData.messageType = BearerData.MESSAGE_TYPE_DELIVER; 359 bearerData.messageId = 55; 360 SmsHeader.ConcatRef concatRef = new SmsHeader.ConcatRef(); 361 concatRef.refNumber = 0xEE; 362 concatRef.msgCount = 2; 363 concatRef.seqNumber = 2; 364 concatRef.isEightBits = true; 365 SmsHeader smsHeader = new SmsHeader(); 366 smsHeader.concatRef = concatRef; 367 byte[] encodedHeader = SmsHeader.toByteArray(smsHeader); 368 SmsHeader decodedHeader = SmsHeader.fromByteArray(encodedHeader); 369 assertEquals(decodedHeader.concatRef.refNumber, concatRef.refNumber); 370 assertEquals(decodedHeader.concatRef.msgCount, concatRef.msgCount); 371 assertEquals(decodedHeader.concatRef.seqNumber, concatRef.seqNumber); 372 assertEquals(decodedHeader.concatRef.isEightBits, concatRef.isEightBits); 373 assertEquals(decodedHeader.portAddrs, null); 374 UserData userData = new UserData(); 375 userData.payloadStr = "User Data Header (UDH) feedback test"; 376 userData.userDataHeader = smsHeader; 377 bearerData.userData = userData; 378 byte[] encodedSms = BearerData.encode(bearerData); 379 BearerData revBearerData = BearerData.decode(encodedSms); 380 decodedHeader = revBearerData.userData.userDataHeader; 381 assertEquals(decodedHeader.concatRef.refNumber, concatRef.refNumber); 382 assertEquals(decodedHeader.concatRef.msgCount, concatRef.msgCount); 383 assertEquals(decodedHeader.concatRef.seqNumber, concatRef.seqNumber); 384 assertEquals(decodedHeader.concatRef.isEightBits, concatRef.isEightBits); 385 assertEquals(decodedHeader.portAddrs, null); 386 } 387 388 @SmallTest 389 public void testUserDataHeaderIllegalConcatRef() throws Exception { 390 BearerData bearerData = new BearerData(); 391 bearerData.messageType = BearerData.MESSAGE_TYPE_DELIVER; 392 bearerData.messageId = 55; 393 SmsHeader.ConcatRef concatRef = new SmsHeader.ConcatRef(); 394 concatRef.refNumber = 0x10; 395 concatRef.msgCount = 0; 396 concatRef.seqNumber = 2; 397 concatRef.isEightBits = true; 398 SmsHeader smsHeader = new SmsHeader(); 399 smsHeader.concatRef = concatRef; 400 byte[] encodedHeader = SmsHeader.toByteArray(smsHeader); 401 SmsHeader decodedHeader = SmsHeader.fromByteArray(encodedHeader); 402 assertEquals(decodedHeader.concatRef, null); 403 concatRef.isEightBits = false; 404 encodedHeader = SmsHeader.toByteArray(smsHeader); 405 decodedHeader = SmsHeader.fromByteArray(encodedHeader); 406 assertEquals(decodedHeader.concatRef, null); 407 concatRef.msgCount = 1; 408 concatRef.seqNumber = 2; 409 encodedHeader = SmsHeader.toByteArray(smsHeader); 410 decodedHeader = SmsHeader.fromByteArray(encodedHeader); 411 assertEquals(decodedHeader.concatRef, null); 412 concatRef.msgCount = 1; 413 concatRef.seqNumber = 0; 414 encodedHeader = SmsHeader.toByteArray(smsHeader); 415 decodedHeader = SmsHeader.fromByteArray(encodedHeader); 416 assertEquals(decodedHeader.concatRef, null); 417 concatRef.msgCount = 2; 418 concatRef.seqNumber = 1; 419 encodedHeader = SmsHeader.toByteArray(smsHeader); 420 decodedHeader = SmsHeader.fromByteArray(encodedHeader); 421 assertEquals(decodedHeader.concatRef.msgCount, 2); 422 assertEquals(decodedHeader.concatRef.seqNumber, 1); 423 } 424 425 @SmallTest 426 public void testUserDataHeaderMixedFeedback() throws Exception { 427 BearerData bearerData = new BearerData(); 428 bearerData.messageType = BearerData.MESSAGE_TYPE_DELIVER; 429 bearerData.messageId = 42; 430 SmsHeader.ConcatRef concatRef = new SmsHeader.ConcatRef(); 431 concatRef.refNumber = 0x34; 432 concatRef.msgCount = 5; 433 concatRef.seqNumber = 2; 434 concatRef.isEightBits = false; 435 SmsHeader.PortAddrs portAddrs = new SmsHeader.PortAddrs(); 436 portAddrs.destPort = 88; 437 portAddrs.origPort = 66; 438 portAddrs.areEightBits = false; 439 SmsHeader smsHeader = new SmsHeader(); 440 smsHeader.concatRef = concatRef; 441 smsHeader.portAddrs = portAddrs; 442 byte[] encodedHeader = SmsHeader.toByteArray(smsHeader); 443 SmsHeader decodedHeader = SmsHeader.fromByteArray(encodedHeader); 444 assertEquals(decodedHeader.concatRef.refNumber, concatRef.refNumber); 445 assertEquals(decodedHeader.concatRef.msgCount, concatRef.msgCount); 446 assertEquals(decodedHeader.concatRef.seqNumber, concatRef.seqNumber); 447 assertEquals(decodedHeader.concatRef.isEightBits, concatRef.isEightBits); 448 assertEquals(decodedHeader.portAddrs.destPort, portAddrs.destPort); 449 assertEquals(decodedHeader.portAddrs.origPort, portAddrs.origPort); 450 assertEquals(decodedHeader.portAddrs.areEightBits, portAddrs.areEightBits); 451 UserData userData = new UserData(); 452 userData.payloadStr = "User Data Header (UDH) feedback test"; 453 userData.userDataHeader = smsHeader; 454 bearerData.userData = userData; 455 byte[] encodedSms = BearerData.encode(bearerData); 456 BearerData revBearerData = BearerData.decode(encodedSms); 457 decodedHeader = revBearerData.userData.userDataHeader; 458 assertEquals(decodedHeader.concatRef.refNumber, concatRef.refNumber); 459 assertEquals(decodedHeader.concatRef.msgCount, concatRef.msgCount); 460 assertEquals(decodedHeader.concatRef.seqNumber, concatRef.seqNumber); 461 assertEquals(decodedHeader.concatRef.isEightBits, concatRef.isEightBits); 462 assertEquals(decodedHeader.portAddrs.destPort, portAddrs.destPort); 463 assertEquals(decodedHeader.portAddrs.origPort, portAddrs.origPort); 464 assertEquals(decodedHeader.portAddrs.areEightBits, portAddrs.areEightBits); 465 } 466 467 @SmallTest 468 public void testReplyOption() throws Exception { 469 String pdu1 = "0003104090011648b6a794e0705476bf77bceae934fe5f6d94d87450080a0180"; 470 BearerData bd1 = BearerData.decode(HexDump.hexStringToByteArray(pdu1)); 471 assertEquals("Test Acknowledgement 1", bd1.userData.payloadStr); 472 assertEquals(true, bd1.userAckReq); 473 assertEquals(false, bd1.deliveryAckReq); 474 assertEquals(false, bd1.readAckReq); 475 assertEquals(false, bd1.reportReq); 476 String pdu2 = "0003104090011648b6a794e0705476bf77bceae934fe5f6d94d87490080a0140"; 477 BearerData bd2 = BearerData.decode(HexDump.hexStringToByteArray(pdu2)); 478 assertEquals("Test Acknowledgement 2", bd2.userData.payloadStr); 479 assertEquals(false, bd2.userAckReq); 480 assertEquals(true, bd2.deliveryAckReq); 481 assertEquals(false, bd2.readAckReq); 482 assertEquals(false, bd2.reportReq); 483 String pdu3 = "0003104090011648b6a794e0705476bf77bceae934fe5f6d94d874d0080a0120"; 484 BearerData bd3 = BearerData.decode(HexDump.hexStringToByteArray(pdu3)); 485 assertEquals("Test Acknowledgement 3", bd3.userData.payloadStr); 486 assertEquals(false, bd3.userAckReq); 487 assertEquals(false, bd3.deliveryAckReq); 488 assertEquals(true, bd3.readAckReq); 489 assertEquals(false, bd3.reportReq); 490 String pdu4 = "0003104090011648b6a794e0705476bf77bceae934fe5f6d94d87510080a0110"; 491 BearerData bd4 = BearerData.decode(HexDump.hexStringToByteArray(pdu4)); 492 assertEquals("Test Acknowledgement 4", bd4.userData.payloadStr); 493 assertEquals(false, bd4.userAckReq); 494 assertEquals(false, bd4.deliveryAckReq); 495 assertEquals(false, bd4.readAckReq); 496 assertEquals(true, bd4.reportReq); 497 } 498 499 @SmallTest 500 public void testReplyOptionFeedback() throws Exception { 501 BearerData bearerData = new BearerData(); 502 bearerData.messageType = BearerData.MESSAGE_TYPE_DELIVER; 503 bearerData.messageId = 0; 504 bearerData.hasUserDataHeader = false; 505 UserData userData = new UserData(); 506 userData.payloadStr = "test reply option"; 507 bearerData.userData = userData; 508 bearerData.userAckReq = true; 509 byte []encodedSms = BearerData.encode(bearerData); 510 BearerData revBearerData = BearerData.decode(encodedSms); 511 assertEquals(true, revBearerData.userAckReq); 512 assertEquals(false, revBearerData.deliveryAckReq); 513 assertEquals(false, revBearerData.readAckReq); 514 assertEquals(false, revBearerData.reportReq); 515 bearerData.userAckReq = false; 516 bearerData.deliveryAckReq = true; 517 encodedSms = BearerData.encode(bearerData); 518 revBearerData = BearerData.decode(encodedSms); 519 assertEquals(false, revBearerData.userAckReq); 520 assertEquals(true, revBearerData.deliveryAckReq); 521 assertEquals(false, revBearerData.readAckReq); 522 assertEquals(false, revBearerData.reportReq); 523 bearerData.deliveryAckReq = false; 524 bearerData.readAckReq = true; 525 encodedSms = BearerData.encode(bearerData); 526 revBearerData = BearerData.decode(encodedSms); 527 assertEquals(false, revBearerData.userAckReq); 528 assertEquals(false, revBearerData.deliveryAckReq); 529 assertEquals(true, revBearerData.readAckReq); 530 assertEquals(false, revBearerData.reportReq); 531 bearerData.readAckReq = false; 532 bearerData.reportReq = true; 533 encodedSms = BearerData.encode(bearerData); 534 revBearerData = BearerData.decode(encodedSms); 535 assertEquals(false, revBearerData.userAckReq); 536 assertEquals(false, revBearerData.deliveryAckReq); 537 assertEquals(false, revBearerData.readAckReq); 538 assertEquals(true, revBearerData.reportReq); 539 } 540 541 @SmallTest 542 public void testNumberOfMessages() throws Exception { 543 // Note that the message text below does not properly reflect 544 // the message count. The author of these messages was 545 // apparently unaware that the values are bcd encoded, and the 546 // values being tested against (not the ones in the message 547 // text) are actually correct. 548 String pdu1 = "000310409001124896a794e07595f69f199540ea759a0dc8e00b0163"; 549 BearerData bd1 = BearerData.decode(HexDump.hexStringToByteArray(pdu1)); 550 assertEquals("Test Voice mail 99", bd1.userData.payloadStr); 551 assertEquals(63, bd1.numberOfMessages); 552 String pdu2 = "00031040900113489ea794e07595f69f199540ea759a0988c0600b0164"; 553 BearerData bd2 = BearerData.decode(HexDump.hexStringToByteArray(pdu2)); 554 assertEquals("Test Voice mail 100", bd2.userData.payloadStr); 555 assertEquals(64, bd2.numberOfMessages); 556 } 557 558 @SmallTest 559 public void testCallbackNum() throws Exception { 560 String pdu1 = "00031040900112488ea794e070d436cb638bc5e035ce2f97900e06910431323334"; 561 BearerData bd1 = BearerData.decode(HexDump.hexStringToByteArray(pdu1)); 562 assertEquals("Test Callback nbr", bd1.userData.payloadStr); 563 assertEquals(CdmaSmsAddress.DIGIT_MODE_8BIT_CHAR, bd1.callbackNumber.digitMode); 564 assertEquals(CdmaSmsAddress.TON_INTERNATIONAL_OR_IP, bd1.callbackNumber.ton); 565 assertEquals(CdmaSmsAddress.NUMBER_MODE_NOT_DATA_NETWORK, bd1.callbackNumber.numberMode); 566 assertEquals(CdmaSmsAddress.NUMBERING_PLAN_ISDN_TELEPHONY, bd1.callbackNumber.numberPlan); 567 assertEquals("1234", bd1.callbackNumber.address); 568 } 569 570 @SmallTest 571 public void testCallbackNumDtmf() throws Exception { 572 String pdu1 = "00031002300109104539b4d052ebb3d00e07052d4c90a55080"; 573 BearerData bd1 = BearerData.decode(HexDump.hexStringToByteArray(pdu1)); 574 assertEquals("SMS Rulz", bd1.userData.payloadStr); 575 assertEquals(CdmaSmsAddress.DIGIT_MODE_4BIT_DTMF, bd1.callbackNumber.digitMode); 576 assertEquals(CdmaSmsAddress.TON_UNKNOWN, bd1.callbackNumber.ton); 577 assertEquals(CdmaSmsAddress.NUMBER_MODE_NOT_DATA_NETWORK, bd1.callbackNumber.numberMode); 578 assertEquals(CdmaSmsAddress.NUMBERING_PLAN_UNKNOWN, bd1.callbackNumber.numberPlan); 579 assertEquals("5099214001", bd1.callbackNumber.address); 580 } 581 582 @SmallTest 583 public void testCallbackNumFeedback() throws Exception { 584 BearerData bearerData = new BearerData(); 585 bearerData.messageType = BearerData.MESSAGE_TYPE_DELIVER; 586 bearerData.messageId = 0; 587 bearerData.hasUserDataHeader = false; 588 UserData userData = new UserData(); 589 userData.payloadStr = "test callback number"; 590 bearerData.userData = userData; 591 CdmaSmsAddress addr = new CdmaSmsAddress(); 592 addr.digitMode = CdmaSmsAddress.DIGIT_MODE_8BIT_CHAR; 593 addr.ton = CdmaSmsAddress.TON_NATIONAL_OR_EMAIL; 594 addr.numberMode = CdmaSmsAddress.NUMBER_MODE_NOT_DATA_NETWORK; 595 addr.numberPlan = CdmaSmsAddress.NUMBERING_PLAN_UNKNOWN; 596 addr.address = "8005551212"; 597 addr.numberOfDigits = (byte)addr.address.length(); 598 bearerData.callbackNumber = addr; 599 byte []encodedSms = BearerData.encode(bearerData); 600 BearerData revBearerData = BearerData.decode(encodedSms); 601 CdmaSmsAddress revAddr = revBearerData.callbackNumber; 602 assertEquals(addr.digitMode, revAddr.digitMode); 603 assertEquals(addr.ton, revAddr.ton); 604 assertEquals(addr.numberMode, revAddr.numberMode); 605 assertEquals(addr.numberPlan, revAddr.numberPlan); 606 assertEquals(addr.numberOfDigits, revAddr.numberOfDigits); 607 assertEquals(addr.address, revAddr.address); 608 addr.address = "8*55#1012"; 609 addr.numberOfDigits = (byte)addr.address.length(); 610 addr.digitMode = CdmaSmsAddress.DIGIT_MODE_4BIT_DTMF; 611 encodedSms = BearerData.encode(bearerData); 612 revBearerData = BearerData.decode(encodedSms); 613 revAddr = revBearerData.callbackNumber; 614 assertEquals(addr.digitMode, revAddr.digitMode); 615 assertEquals(addr.numberOfDigits, revAddr.numberOfDigits); 616 assertEquals(addr.address, revAddr.address); 617 } 618 619 @SmallTest 620 public void testPrivacyIndicator() throws Exception { 621 String pdu1 = "0003104090010c485f4194dfea34becf61b840090140"; 622 BearerData bd1 = BearerData.decode(HexDump.hexStringToByteArray(pdu1)); 623 assertEquals(bd1.privacy, BearerData.PRIVACY_RESTRICTED); 624 String pdu2 = "0003104090010c485f4194dfea34becf61b840090180"; 625 BearerData bd2 = BearerData.decode(HexDump.hexStringToByteArray(pdu2)); 626 assertEquals(bd2.privacy, BearerData.PRIVACY_CONFIDENTIAL); 627 String pdu3 = "0003104090010c485f4194dfea34becf61b8400901c0"; 628 BearerData bd3 = BearerData.decode(HexDump.hexStringToByteArray(pdu3)); 629 assertEquals(bd3.privacy, BearerData.PRIVACY_SECRET); 630 } 631 632 @SmallTest 633 public void testPrivacyIndicatorFeedback() throws Exception { 634 BearerData bearerData = new BearerData(); 635 bearerData.messageType = BearerData.MESSAGE_TYPE_DELIVER; 636 bearerData.messageId = 0; 637 bearerData.hasUserDataHeader = false; 638 UserData userData = new UserData(); 639 userData.payloadStr = "test privacy indicator"; 640 bearerData.userData = userData; 641 bearerData.privacy = BearerData.PRIVACY_SECRET; 642 bearerData.privacyIndicatorSet = true; 643 byte []encodedSms = BearerData.encode(bearerData); 644 BearerData revBearerData = BearerData.decode(encodedSms); 645 assertEquals(revBearerData.userData.payloadStr, userData.payloadStr); 646 assertEquals(revBearerData.privacyIndicatorSet, true); 647 assertEquals(revBearerData.privacy, BearerData.PRIVACY_SECRET); 648 bearerData.privacy = BearerData.PRIVACY_RESTRICTED; 649 encodedSms = BearerData.encode(bearerData); 650 revBearerData = BearerData.decode(encodedSms); 651 assertEquals(revBearerData.privacy, BearerData.PRIVACY_RESTRICTED); 652 } 653 654 @SmallTest 655 public void testMsgDeliveryAlert() throws Exception { 656 String pdu1 = "0003104090010d4866a794e07055965b91d040300c0100"; 657 BearerData bd1 = BearerData.decode(HexDump.hexStringToByteArray(pdu1)); 658 assertEquals(bd1.alert, 0); 659 assertEquals(bd1.userData.payloadStr, "Test Alert 0"); 660 String pdu2 = "0003104090010d4866a794e07055965b91d140300c0140"; 661 BearerData bd2 = BearerData.decode(HexDump.hexStringToByteArray(pdu2)); 662 assertEquals(bd2.alert, 1); 663 assertEquals(bd2.userData.payloadStr, "Test Alert 1"); 664 String pdu3 = "0003104090010d4866a794e07055965b91d240300c0180"; 665 BearerData bd3 = BearerData.decode(HexDump.hexStringToByteArray(pdu3)); 666 assertEquals(bd3.alert, 2); 667 assertEquals(bd3.userData.payloadStr, "Test Alert 2"); 668 String pdu4 = "0003104090010d4866a794e07055965b91d340300c01c0"; 669 BearerData bd4 = BearerData.decode(HexDump.hexStringToByteArray(pdu4)); 670 assertEquals(bd4.alert, 3); 671 assertEquals(bd4.userData.payloadStr, "Test Alert 3"); 672 String pdu5 = "00031000000126114F4CBCFA20DB979F3C39F2A0C9976" + 673 "69ED979794187665E5D1028EFA7A6840E1062D3D39A900C028000"; 674 BearerData bd5 = BearerData.decode(HexDump.hexStringToByteArray(pdu5)); 675 assertEquals(bd5.alert, BearerData.ALERT_MEDIUM_PRIO); 676 assertEquals(bd5.userData.payloadStr, "test message delivery alert (with 8 bits)"); 677 String pdu6 = "00031000000126114F4CBCFA20DB979F3C39F2A0C9976" + 678 "69ED979794187665E5D1028EFA7A6840C1062D3D39A900C00"; 679 BearerData bd6 = BearerData.decode(HexDump.hexStringToByteArray(pdu6)); 680 assertEquals(bd6.userData.payloadStr, "test message delivery alert (with 0 bits)"); 681 assertEquals(bd6.alertIndicatorSet, false); 682 } 683 684 @SmallTest 685 public void testMiscParams() throws Exception { 686 String pdu1 = "00031002400109104539b4d052ebb3d00c0180"; 687 BearerData bd1 = BearerData.decode(HexDump.hexStringToByteArray(pdu1)); 688 assertEquals(bd1.alert, BearerData.ALERT_MEDIUM_PRIO); 689 assertEquals(bd1.userData.payloadStr, "SMS Rulz"); 690 String pdu2 = "00031002500109104539b4d052ebb3d00801800901c0"; 691 BearerData bd2 = BearerData.decode(HexDump.hexStringToByteArray(pdu2)); 692 assertEquals(bd2.priority, BearerData.PRIORITY_URGENT); 693 assertEquals(bd2.privacy, BearerData.PRIVACY_SECRET); 694 assertEquals(bd2.userData.payloadStr, "SMS Rulz"); 695 String pdu3 = "00031002600109104539b4d052ebb3d00901400c01c0"; 696 BearerData bd3 = BearerData.decode(HexDump.hexStringToByteArray(pdu3)); 697 assertEquals(bd3.privacy, BearerData.PRIVACY_RESTRICTED); 698 assertEquals(bd3.alert, BearerData.ALERT_HIGH_PRIO); 699 assertEquals(bd3.userData.payloadStr, "SMS Rulz"); 700 String pdu4 = "00031002700109104539b4d052ebb3d00f0105"; 701 BearerData bd4 = BearerData.decode(HexDump.hexStringToByteArray(pdu4)); 702 assertEquals(bd4.displayMode, BearerData.DISPLAY_MODE_IMMEDIATE); 703 assertEquals(bd4.userData.payloadStr, "SMS Rulz"); 704 } 705 @SmallTest 706 public void testMsgDeliveryAlertFeedback() throws Exception { 707 BearerData bearerData = new BearerData(); 708 bearerData.messageType = BearerData.MESSAGE_TYPE_DELIVER; 709 bearerData.messageId = 0; 710 bearerData.hasUserDataHeader = false; 711 UserData userData = new UserData(); 712 userData.payloadStr = "test message delivery alert"; 713 bearerData.userData = userData; 714 bearerData.alert = BearerData.ALERT_MEDIUM_PRIO; 715 bearerData.alertIndicatorSet = true; 716 byte []encodedSms = BearerData.encode(bearerData); 717 BearerData revBearerData = BearerData.decode(encodedSms); 718 assertEquals(revBearerData.userData.payloadStr, userData.payloadStr); 719 assertEquals(revBearerData.alertIndicatorSet, true); 720 assertEquals(revBearerData.alert, bearerData.alert); 721 bearerData.alert = BearerData.ALERT_HIGH_PRIO; 722 encodedSms = BearerData.encode(bearerData); 723 revBearerData = BearerData.decode(encodedSms); 724 assertEquals(revBearerData.userData.payloadStr, userData.payloadStr); 725 assertEquals(revBearerData.alertIndicatorSet, true); 726 assertEquals(revBearerData.alert, bearerData.alert); 727 } 728 729 @SmallTest 730 public void testLanguageIndicator() throws Exception { 731 String pdu1 = "0003104090011748bea794e0731436ef3bd7c2e0352eef27a1c263fe58080d0101"; 732 BearerData bd1 = BearerData.decode(HexDump.hexStringToByteArray(pdu1)); 733 assertEquals(bd1.userData.payloadStr, "Test Language indicator"); 734 assertEquals(bd1.language, BearerData.LANGUAGE_ENGLISH); 735 String pdu2 = "0003104090011748bea794e0731436ef3bd7c2e0352eef27a1c263fe58080d0106"; 736 BearerData bd2 = BearerData.decode(HexDump.hexStringToByteArray(pdu2)); 737 assertEquals(bd2.userData.payloadStr, "Test Language indicator"); 738 assertEquals(bd2.language, BearerData.LANGUAGE_CHINESE); 739 } 740 741 @SmallTest 742 public void testLanguageIndicatorFeedback() throws Exception { 743 BearerData bearerData = new BearerData(); 744 bearerData.messageType = BearerData.MESSAGE_TYPE_DELIVER; 745 bearerData.messageId = 0; 746 bearerData.hasUserDataHeader = false; 747 UserData userData = new UserData(); 748 userData.payloadStr = "test language indicator"; 749 bearerData.userData = userData; 750 bearerData.language = BearerData.LANGUAGE_ENGLISH; 751 bearerData.languageIndicatorSet = true; 752 byte []encodedSms = BearerData.encode(bearerData); 753 BearerData revBearerData = BearerData.decode(encodedSms); 754 assertEquals(revBearerData.userData.payloadStr, userData.payloadStr); 755 assertEquals(revBearerData.languageIndicatorSet, true); 756 assertEquals(revBearerData.language, bearerData.language); 757 bearerData.language = BearerData.LANGUAGE_KOREAN; 758 encodedSms = BearerData.encode(bearerData); 759 revBearerData = BearerData.decode(encodedSms); 760 assertEquals(revBearerData.userData.payloadStr, userData.payloadStr); 761 assertEquals(revBearerData.languageIndicatorSet, true); 762 assertEquals(revBearerData.language, bearerData.language); 763 } 764 765 @SmallTest 766 public void testDisplayMode() throws Exception { 767 String pdu1 = "0003104090010c485f4194dfea34becf61b8400f0100"; 768 BearerData bd1 = BearerData.decode(HexDump.hexStringToByteArray(pdu1)); 769 assertEquals(bd1.displayMode, BearerData.DISPLAY_MODE_IMMEDIATE); 770 String pdu2 = "0003104090010c485f4194dfea34becf61b8400f0140"; 771 BearerData bd2 = BearerData.decode(HexDump.hexStringToByteArray(pdu2)); 772 assertEquals(bd2.displayMode, BearerData.DISPLAY_MODE_DEFAULT); 773 String pdu3 = "0003104090010c485f4194dfea34becf61b8400f0180"; 774 BearerData bd3 = BearerData.decode(HexDump.hexStringToByteArray(pdu3)); 775 assertEquals(bd3.displayMode, BearerData.DISPLAY_MODE_USER); 776 } 777 778 @SmallTest 779 public void testDisplayModeFeedback() throws Exception { 780 BearerData bearerData = new BearerData(); 781 bearerData.messageType = BearerData.MESSAGE_TYPE_DELIVER; 782 bearerData.messageId = 0; 783 bearerData.hasUserDataHeader = false; 784 UserData userData = new UserData(); 785 userData.payloadStr = "test display mode"; 786 bearerData.userData = userData; 787 bearerData.displayMode = BearerData.DISPLAY_MODE_IMMEDIATE; 788 bearerData.displayModeSet = true; 789 byte []encodedSms = BearerData.encode(bearerData); 790 BearerData revBearerData = BearerData.decode(encodedSms); 791 assertEquals(revBearerData.userData.payloadStr, userData.payloadStr); 792 assertEquals(revBearerData.displayModeSet, true); 793 assertEquals(revBearerData.displayMode, bearerData.displayMode); 794 bearerData.displayMode = BearerData.DISPLAY_MODE_USER; 795 encodedSms = BearerData.encode(bearerData); 796 revBearerData = BearerData.decode(encodedSms); 797 assertEquals(revBearerData.userData.payloadStr, userData.payloadStr); 798 assertEquals(revBearerData.displayModeSet, true); 799 assertEquals(revBearerData.displayMode, bearerData.displayMode); 800 } 801 802 @SmallTest 803 public void testIs91() throws Exception { 804 String pdu1 = "000320001001070c2039acc13880"; 805 BearerData bd1 = BearerData.decode(HexDump.hexStringToByteArray(pdu1)); 806 assertEquals(bd1.callbackNumber.address, "3598271"); 807 String pdu4 = "000320001001080c283c314724b34e"; 808 BearerData bd4 = BearerData.decode(HexDump.hexStringToByteArray(pdu4)); 809 assertEquals(bd4.userData.payloadStr, "ABCDEFG"); 810 } 811 812 @SmallTest 813 public void testUserDataHeaderWithEightCharMsg() throws Exception { 814 BearerData bearerData = new BearerData(); 815 bearerData.messageType = BearerData.MESSAGE_TYPE_DELIVER; 816 bearerData.messageId = 55; 817 SmsHeader.ConcatRef concatRef = new SmsHeader.ConcatRef(); 818 concatRef.refNumber = 0xEE; 819 concatRef.msgCount = 2; 820 concatRef.seqNumber = 2; 821 concatRef.isEightBits = true; 822 SmsHeader smsHeader = new SmsHeader(); 823 smsHeader.concatRef = concatRef; 824 UserData userData = new UserData(); 825 userData.payloadStr = "01234567"; 826 userData.userDataHeader = smsHeader; 827 bearerData.userData = userData; 828 byte[] encodedSms = BearerData.encode(bearerData); 829 BearerData revBearerData = BearerData.decode(encodedSms); 830 assertEquals(userData.payloadStr, revBearerData.userData.payloadStr); 831 } 832 833 @SmallTest 834 public void testFragmentText() throws Exception { 835 boolean isCdmaPhone = (TelephonyManager.getDefault().getPhoneType() == 836 TelephonyManager.PHONE_TYPE_CDMA); 837 // Valid 160 character ASCII text. 838 String text1 = "123456789012345678901234567890123456789012345678901234567890" + 839 "1234567890123456789012345678901234567890123456789012345678901234567890" + 840 "12345678901234567890123456789["; 841 TextEncodingDetails ted = SmsMessage.calculateLength(text1, false); 842 assertEquals(ted.msgCount, 1); 843 assertEquals(ted.codeUnitCount, 160); 844 assertEquals(ted.codeUnitSize, 1); 845 if (isCdmaPhone) { 846 ArrayList<String> fragments = android.telephony.SmsMessage.fragmentText(text1); 847 assertEquals(fragments.size(), 1); 848 } 849 850 /* 851 This is not a valid test: we will never encode a single-segment 852 EMS message. Leaving this here, since we may try to support 853 this in the future. 854 855 // Valid 160 character GSM text -- the last character is 856 // non-ASCII, and so this will currently generate a singleton 857 // EMS message, which is not necessarily supported by Verizon. 858 String text2 = "123456789012345678901234567890123456789012345678901234567890" + 859 "1234567890123456789012345678901234567890123456789012345678901234567890" + 860 "12345678901234567890123456789\u00a3"; // Trailing pound-currency sign. 861 ted = SmsMessage.calculateLength(text2, false); 862 assertEquals(ted.msgCount, 1); 863 assertEquals(ted.codeUnitCount, 160); 864 assertEquals(ted.codeUnitSize, 1); 865 if (isCdmaPhone) { 866 ArrayList<String> fragments = android.telephony.SmsMessage.fragmentText(text2); 867 assertEquals(fragments.size(), 1); 868 } 869 */ 870 871 // *IF* we supported single-segment EMS, this text would result in a 872 // single fragment with 7-bit encoding. But we don't, so this text 873 // results in three fragments of 16-bit encoding. 874 String text2 = "123456789012345678901234567890123456789012345678901234567890" + 875 "1234567890123456789012345678901234567890123456789012345678901234567890" + 876 "12345678901234567890123456789\u00a3"; // Trailing pound-currency sign. 877 ted = SmsMessage.calculateLength(text2, false); 878 assertEquals(3, ted.msgCount); 879 assertEquals(160, ted.codeUnitCount); 880 assertEquals(3, ted.codeUnitSize); 881 if (isCdmaPhone) { 882 ArrayList<String> fragments = android.telephony.SmsMessage.fragmentText(text2); 883 assertEquals(3, fragments.size()); 884 } 885 886 } 887 } 888