use of com.android.internal.telephony.SmsHeader in project android_frameworks_opt_telephony by LineageOS.
the class CdmaSmsTest method testFragmentText.
@SmallTest
public void testFragmentText() throws Exception {
boolean isCdmaPhone = (TelephonyManager.getDefault().getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA);
// Valid 160 character ASCII text.
String text1 = "123456789012345678901234567890123456789012345678901234567890" + "1234567890123456789012345678901234567890123456789012345678901234567890" + "12345678901234567890123456789[";
TextEncodingDetails ted = SmsMessage.calculateLength(text1, false, true);
assertEquals(ted.msgCount, 1);
assertEquals(ted.codeUnitCount, 160);
assertEquals(ted.codeUnitSize, 1);
if (isCdmaPhone) {
ArrayList<String> fragments = android.telephony.SmsMessage.fragmentText(text1);
assertEquals(fragments.size(), 1);
}
/*
This is not a valid test: we will never encode a single-segment
EMS message. Leaving this here, since we may try to support
this in the future.
// Valid 160 character GSM text -- the last character is
// non-ASCII, and so this will currently generate a singleton
// EMS message, which is not necessarily supported by Verizon.
String text2 = "123456789012345678901234567890123456789012345678901234567890" +
"1234567890123456789012345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789\u00a3"; // Trailing pound-currency sign.
ted = SmsMessage.calculateLength(text2, false);
assertEquals(ted.msgCount, 1);
assertEquals(ted.codeUnitCount, 160);
assertEquals(ted.codeUnitSize, 1);
if (isCdmaPhone) {
ArrayList<String> fragments = android.telephony.SmsMessage.fragmentText(text2);
assertEquals(fragments.size(), 1);
}
*/
// *IF* we supported single-segment EMS, this text would result in a
// single fragment with 7-bit encoding. But we don't, so this text
// results in three fragments of 16-bit encoding.
String text2 = "123456789012345678901234567890123456789012345678901234567890" + "1234567890123456789012345678901234567890123456789012345678901234567890" + // Trailing pound-currency sign.
"12345678901234567890123456789\u00a3";
ted = SmsMessage.calculateLength(text2, false, true);
assertEquals(3, ted.msgCount);
assertEquals(160, ted.codeUnitCount);
assertEquals(3, ted.codeUnitSize);
if (isCdmaPhone) {
ArrayList<String> fragments = android.telephony.SmsMessage.fragmentText(text2);
assertEquals(3, fragments.size());
for (int i = 0; i < 3; i++) {
SmsHeader header = getConcatUserDataHeader(i + 1, 3);
SmsHeader header2 = getOddLengthUserDataHeader();
encodeDecodeAssertEquals(fragments.get(i), header, -1);
encodeDecodeAssertEquals(fragments.get(i), header2, -1);
}
}
// Test case for multi-part UTF-16 message.
String text3 = sUnicodeChars + sUnicodeChars + sUnicodeChars;
ted = SmsMessage.calculateLength(text3, false, true);
assertEquals(3, ted.msgCount);
assertEquals(189, ted.codeUnitCount);
assertEquals(3, ted.codeUnitSize);
if (isCdmaPhone) {
ArrayList<String> fragments = android.telephony.SmsMessage.fragmentText(text3);
assertEquals(3, fragments.size());
for (int i = 0; i < 3; i++) {
SmsHeader header = getConcatUserDataHeader(i + 1, 3);
SmsHeader header2 = getOddLengthUserDataHeader();
encodeDecodeAssertEquals(fragments.get(i), header, -1);
encodeDecodeAssertEquals(fragments.get(i), header2, -1);
}
}
}
use of com.android.internal.telephony.SmsHeader in project android_frameworks_opt_telephony by LineageOS.
the class CdmaSmsTest method testUserData7bitGsmFeedback.
@SmallTest
public void testUserData7bitGsmFeedback() throws Exception {
BearerData bearerData = new BearerData();
bearerData.messageType = BearerData.MESSAGE_TYPE_DELIVER;
bearerData.messageId = 0;
bearerData.hasUserDataHeader = false;
UserData userData = new UserData();
userData.payloadStr = "Test standard SMS";
userData.msgEncoding = UserData.ENCODING_GSM_7BIT_ALPHABET;
userData.msgEncodingSet = true;
bearerData.userData = userData;
byte[] encodedSms = BearerData.encode(bearerData);
BearerData revBearerData = BearerData.decode(encodedSms);
assertEquals(BearerData.MESSAGE_TYPE_DELIVER, revBearerData.messageType);
assertEquals(0, revBearerData.messageId);
assertEquals(false, revBearerData.hasUserDataHeader);
assertEquals(userData.msgEncoding, revBearerData.userData.msgEncoding);
assertEquals(userData.payloadStr.length(), revBearerData.userData.numFields);
assertEquals(userData.payloadStr, revBearerData.userData.payloadStr);
userData.payloadStr = "1234567";
revBearerData = BearerData.decode(BearerData.encode(bearerData));
assertEquals(userData.payloadStr, revBearerData.userData.payloadStr);
userData.payloadStr = "";
revBearerData = BearerData.decode(BearerData.encode(bearerData));
assertEquals(userData.payloadStr, revBearerData.userData.payloadStr);
userData.payloadStr = "12345678901234567890123456789012345678901234567890" + "12345678901234567890123456789012345678901234567890" + "12345678901234567890123456789012345678901234567890" + "1234567890";
revBearerData = BearerData.decode(BearerData.encode(bearerData));
assertEquals(userData.payloadStr, revBearerData.userData.payloadStr);
userData.payloadStr = "Test \u007f illegal \u0000 SMS chars";
revBearerData = BearerData.decode(BearerData.encode(bearerData));
assertEquals("Test illegal SMS chars", revBearerData.userData.payloadStr);
userData.payloadStr = "More @ testing\nis great^|^~woohoo";
revBearerData = BearerData.decode(BearerData.encode(bearerData));
assertEquals(userData.payloadStr, revBearerData.userData.payloadStr);
SmsHeader.ConcatRef concatRef = new SmsHeader.ConcatRef();
concatRef.refNumber = 0xEE;
concatRef.msgCount = 2;
concatRef.seqNumber = 2;
concatRef.isEightBits = true;
SmsHeader smsHeader = new SmsHeader();
smsHeader.concatRef = concatRef;
byte[] encodedHeader = SmsHeader.toByteArray(smsHeader);
userData.userDataHeader = smsHeader;
revBearerData = BearerData.decode(BearerData.encode(bearerData));
assertEquals(userData.payloadStr, revBearerData.userData.payloadStr);
SmsHeader decodedHeader = revBearerData.userData.userDataHeader;
assertEquals(decodedHeader.concatRef.refNumber, concatRef.refNumber);
assertEquals(decodedHeader.concatRef.msgCount, concatRef.msgCount);
assertEquals(decodedHeader.concatRef.seqNumber, concatRef.seqNumber);
}
use of com.android.internal.telephony.SmsHeader in project android_frameworks_opt_telephony by LineageOS.
the class CdmaSmsTest method testUserDataHeaderIllegalConcatRef.
@SmallTest
public void testUserDataHeaderIllegalConcatRef() throws Exception {
BearerData bearerData = new BearerData();
bearerData.messageType = BearerData.MESSAGE_TYPE_DELIVER;
bearerData.messageId = 55;
SmsHeader.ConcatRef concatRef = new SmsHeader.ConcatRef();
concatRef.refNumber = 0x10;
concatRef.msgCount = 0;
concatRef.seqNumber = 2;
concatRef.isEightBits = true;
SmsHeader smsHeader = new SmsHeader();
smsHeader.concatRef = concatRef;
byte[] encodedHeader = SmsHeader.toByteArray(smsHeader);
SmsHeader decodedHeader = SmsHeader.fromByteArray(encodedHeader);
assertEquals(decodedHeader.concatRef, null);
concatRef.isEightBits = false;
encodedHeader = SmsHeader.toByteArray(smsHeader);
decodedHeader = SmsHeader.fromByteArray(encodedHeader);
assertEquals(decodedHeader.concatRef, null);
concatRef.msgCount = 1;
concatRef.seqNumber = 2;
encodedHeader = SmsHeader.toByteArray(smsHeader);
decodedHeader = SmsHeader.fromByteArray(encodedHeader);
assertEquals(decodedHeader.concatRef, null);
concatRef.msgCount = 1;
concatRef.seqNumber = 0;
encodedHeader = SmsHeader.toByteArray(smsHeader);
decodedHeader = SmsHeader.fromByteArray(encodedHeader);
assertEquals(decodedHeader.concatRef, null);
concatRef.msgCount = 2;
concatRef.seqNumber = 1;
encodedHeader = SmsHeader.toByteArray(smsHeader);
decodedHeader = SmsHeader.fromByteArray(encodedHeader);
assertEquals(decodedHeader.concatRef.msgCount, 2);
assertEquals(decodedHeader.concatRef.seqNumber, 1);
}
use of com.android.internal.telephony.SmsHeader in project android_frameworks_opt_telephony by LineageOS.
the class CdmaSmsTest method getConcatUserDataHeader.
// Return a user data header for a concatenated message
private static SmsHeader getConcatUserDataHeader(int index, int total) {
SmsHeader smsHeader = new SmsHeader();
SmsHeader.ConcatRef concatRef = new SmsHeader.ConcatRef();
concatRef.refNumber = 0xEE;
concatRef.msgCount = total;
concatRef.seqNumber = index;
concatRef.isEightBits = true;
smsHeader.concatRef = concatRef;
return smsHeader;
}
use of com.android.internal.telephony.SmsHeader in project XobotOS by xamarin.
the class SmsMessage method getSubmitPdu.
/**
* Get an SMS-SUBMIT PDU for a data message to a destination address and port.
*
* @param scAddr Service Centre address. null == use default
* @param destAddr the address of the destination for the message
* @param destPort the port to deliver the message to at the
* destination
* @param data the data for the message
* @return a <code>SubmitPdu</code> containing the encoded SC
* address, if applicable, and the encoded message.
* Returns null on encode error.
*/
public static SubmitPdu getSubmitPdu(String scAddr, String destAddr, int destPort, byte[] data, boolean statusReportRequested) {
/**
* TODO(cleanup): this is not a general-purpose SMS creation
* method, but rather something specialized to messages
* containing OCTET encoded (meaning non-human-readable) user
* data. The name should reflect that, and not just overload.
*/
SmsHeader.PortAddrs portAddrs = new SmsHeader.PortAddrs();
portAddrs.destPort = destPort;
portAddrs.origPort = 0;
portAddrs.areEightBits = false;
SmsHeader smsHeader = new SmsHeader();
smsHeader.portAddrs = portAddrs;
UserData uData = new UserData();
uData.userDataHeader = smsHeader;
uData.msgEncoding = UserData.ENCODING_OCTET;
uData.msgEncodingSet = true;
uData.payload = data;
return privateGetSubmitPdu(destAddr, statusReportRequested, uData);
}
Aggregations