diff options
author | Jake Hamby <jhamby@google.com> | 2011-03-15 20:09:46 -0700 |
---|---|---|
committer | Jake Hamby <jhamby@google.com> | 2011-04-06 14:20:04 -0700 |
commit | b49a73dfc4c9817bba1f227e9330555acdf9b56f (patch) | |
tree | 6a896e163c52be242c20b72be02fc5d2bc17a500 /telephony/java | |
parent | 43707a83ec12957fb84a406276a38fbaf4e23fd3 (diff) | |
download | frameworks_base-b49a73dfc4c9817bba1f227e9330555acdf9b56f.zip frameworks_base-b49a73dfc4c9817bba1f227e9330555acdf9b56f.tar.gz frameworks_base-b49a73dfc4c9817bba1f227e9330555acdf9b56f.tar.bz2 |
Enable support for SMS national language shift tables.
Add support for encoding and decoding SMS 7 bit user data using the
national language shift tables defined in 3GPP TS 23.038 (GSM/UMTS only),
including the new tables added in Release 9 for Indic languages.
Decoding is always supported, but encoding is only enabled for the
specific language tables added to the new integer array resources
"config_sms_enabled_single_shift_tables" and
"config_sms_enabled_locking_shift_tables" defined in
frameworks/base/core/res/res/values/config.xml. The default empty arrays
should be overridden in an OEM overlay for the specific nationalities where
SMS national language shift table encoding is allowed/mandated (e.g. Turkey).
GsmAlphabet.countGsmSeptets() will try to find the most efficient encoding
among all combinations of enabled locking shift and single shift tables.
If no 7 bit encoding is possible, 16 bit UCS-2 encoding will be used.
This change also fixes a bug in the decoder: when an escape septet
is followed by a septet with no entry in the extension (single shift)
table, TS 23.038 Table 6.2.1.1 states that the MS shall display
the character in the main GSM 7 bit default alphabet table, or the
active national language locking shift table. Previously, we were
decoding this sequence as a space character. Two consecutive escape
septets will continue to decode as a space character, according to
Note 1 of table 6.2.1.1.
Change-Id: I4dab3f0ffe39f3df2064ed93c9c05f26e274d18b
Diffstat (limited to 'telephony/java')
9 files changed, 970 insertions, 410 deletions
diff --git a/telephony/java/android/telephony/SmsMessage.java b/telephony/java/android/telephony/SmsMessage.java index a284ea5..34ca902 100644 --- a/telephony/java/android/telephony/SmsMessage.java +++ b/telephony/java/android/telephony/SmsMessage.java @@ -314,7 +314,8 @@ public class SmsMessage { nextPos = pos + Math.min(limit, textLen - pos); } else { // For multi-segment messages, CDMA 7bit equals GSM 7bit encoding (EMS mode). - nextPos = GsmAlphabet.findGsmSeptetLimitIndex(text, pos, limit); + nextPos = GsmAlphabet.findGsmSeptetLimitIndex(text, pos, limit, + ted.languageTable, ted.languageShiftTable); } } else { // Assume unicode. nextPos = pos + Math.min(limit / 2, textLen - pos); @@ -370,7 +371,8 @@ public class SmsMessage { */ /** - * Get an SMS-SUBMIT PDU for a destination address and a message + * Get an SMS-SUBMIT PDU for a destination address and a message. + * This method will not attempt to use any GSM national language 7 bit encodings. * * @param scAddress Service Centre address. Null means use default. * @return a <code>SubmitPdu</code> containing the encoded SC @@ -397,7 +399,8 @@ public class SmsMessage { } /** - * Get an SMS-SUBMIT PDU for a destination address and a message + * Get an SMS-SUBMIT PDU for a destination address and a message. + * This method will not attempt to use any GSM national language 7 bit encodings. * * @param scAddress Service Centre address. Null means use default. * @return a <code>SubmitPdu</code> containing the encoded SC @@ -421,7 +424,8 @@ public class SmsMessage { } /** - * Get an SMS-SUBMIT PDU for a data message to a destination address & port + * Get an SMS-SUBMIT PDU for a data message to a destination address & port. + * This method will not attempt to use any GSM national language 7 bit encodings. * * @param scAddress Service Centre address. null == use default * @param destinationAddress the address of the destination for the message diff --git a/telephony/java/android/telephony/gsm/SmsMessage.java b/telephony/java/android/telephony/gsm/SmsMessage.java index 0c63c37..1b95cd4 100644 --- a/telephony/java/android/telephony/gsm/SmsMessage.java +++ b/telephony/java/android/telephony/gsm/SmsMessage.java @@ -297,37 +297,14 @@ public class SmsMessage { */ @Deprecated public static int[] calculateLength(CharSequence messageBody, boolean use7bitOnly) { + SmsMessageBase.TextEncodingDetails ted = + com.android.internal.telephony.gsm.SmsMessage + .calculateLength(messageBody, use7bitOnly); int ret[] = new int[4]; - - try { - // Try GSM alphabet - int septets = GsmAlphabet.countGsmSeptets(messageBody, !use7bitOnly); - ret[1] = septets; - if (septets > MAX_USER_DATA_SEPTETS) { - ret[0] = (septets + (MAX_USER_DATA_SEPTETS_WITH_HEADER - 1)) / - MAX_USER_DATA_SEPTETS_WITH_HEADER; - ret[2] = (ret[0] * MAX_USER_DATA_SEPTETS_WITH_HEADER) - septets; - } else { - ret[0] = 1; - ret[2] = MAX_USER_DATA_SEPTETS - septets; - } - ret[3] = ENCODING_7BIT; - } catch (EncodeException ex) { - // fall back to UCS-2 - int octets = messageBody.length() * 2; - ret[1] = messageBody.length(); - if (octets > MAX_USER_DATA_BYTES) { - // 6 is the size of the user data header - ret[0] = (octets + (MAX_USER_DATA_BYTES_WITH_HEADER - 1)) / - MAX_USER_DATA_BYTES_WITH_HEADER; - ret[2] = ((ret[0] * MAX_USER_DATA_BYTES_WITH_HEADER) - octets) / 2; - } else { - ret[0] = 1; - ret[2] = (MAX_USER_DATA_BYTES - octets)/2; - } - ret[3] = ENCODING_16BIT; - } - + ret[0] = ted.msgCount; + ret[1] = ted.codeUnitCount; + ret[2] = ted.codeUnitsRemaining; + ret[3] = ted.codeUnitSize; return ret; } diff --git a/telephony/java/com/android/internal/telephony/GsmAlphabet.java b/telephony/java/com/android/internal/telephony/GsmAlphabet.java index 30ee77c..57d73e3 100644 --- a/telephony/java/com/android/internal/telephony/GsmAlphabet.java +++ b/telephony/java/com/android/internal/telephony/GsmAlphabet.java @@ -16,11 +16,20 @@ package com.android.internal.telephony; -import android.telephony.SmsMessage; +import android.content.res.Resources; import android.util.SparseIntArray; import android.util.Log; +import com.android.internal.R; + +import java.util.ArrayList; +import java.util.List; + +import static android.telephony.SmsMessage.ENCODING_7BIT; +import static android.telephony.SmsMessage.MAX_USER_DATA_SEPTETS; +import static android.telephony.SmsMessage.MAX_USER_DATA_SEPTETS_WITH_HEADER; + /** * This class implements the character set mapping between * the GSM SMS 7-bit alphabet specified in TS 23.038 6.2.1 @@ -29,29 +38,51 @@ import android.util.Log; * {@hide} */ public class GsmAlphabet { - static final String LOG_TAG = "GSM"; - + private static final String TAG = "GSM"; + private GsmAlphabet() { } //***** Constants /** * This escapes extended characters, and when present indicates that the - * following character should - * be looked up in the "extended" table + * following character should be looked up in the "extended" table. * * gsmToChar(GSM_EXTENDED_ESCAPE) returns 0xffff */ - public static final byte GSM_EXTENDED_ESCAPE = 0x1B; + /** + * User data header requires one octet for length. Count as one septet, because + * all combinations of header elements below will have at least one free bit + * when padding to the nearest septet boundary. + */ + private static final int UDH_SEPTET_COST_LENGTH = 1; /** - * char to GSM alphabet char - * Returns ' ' in GSM alphabet if there's no possible match - * Returns GSM_EXTENDED_ESCAPE if this character is in the extended table - * In this case, you must call charToGsmExtended() for the value that - * should follow GSM_EXTENDED_ESCAPE in the GSM alphabet string + * Using a non-default language locking shift table OR single shift table + * requires a user data header of 3 octets, or 4 septets, plus UDH length. + */ + private static final int UDH_SEPTET_COST_ONE_SHIFT_TABLE = 4; + + /** + * Using a non-default language locking shift table AND single shift table + * requires a user data header of 6 octets, or 7 septets, plus UDH length. + */ + private static final int UDH_SEPTET_COST_TWO_SHIFT_TABLES = 7; + + /** + * Multi-part messages require a user data header of 5 octets, or 6 septets, + * plus UDH length. + */ + private static final int UDH_SEPTET_COST_CONCATENATED_MESSAGE = 6; + + /** + * Converts a char to a GSM 7 bit table index. + * Returns ' ' in GSM alphabet if there's no possible match. Returns + * GSM_EXTENDED_ESCAPE if this character is in the extended table. + * In this case, you must call charToGsmExtended() for the value + * that should follow GSM_EXTENDED_ESCAPE in the GSM alphabet string. */ public static int charToGsm(char c) { @@ -59,12 +90,12 @@ public class GsmAlphabet { return charToGsm(c, false); } catch (EncodeException ex) { // this should never happen - return sGsmSpaceChar; + return sCharsToGsmTables[0].get(' ', ' '); } } /** - * char to GSM alphabet char + * Converts a char to a GSM 7 bit table index. * @param throwException If true, throws EncodeException on invalid char. * If false, returns GSM alphabet ' ' char. * @@ -72,21 +103,20 @@ public class GsmAlphabet { * In this case, you must call charToGsmExtended() for the value that * should follow GSM_EXTENDED_ESCAPE in the GSM alphabet string */ - public static int charToGsm(char c, boolean throwException) throws EncodeException { int ret; - ret = charToGsm.get(c, -1); + ret = sCharsToGsmTables[0].get(c, -1); if (ret == -1) { - ret = charToGsmExtended.get(c, -1); + ret = sCharsToShiftTables[0].get(c, -1); if (ret == -1) { if (throwException) { throw new EncodeException(c); } else { - return sGsmSpaceChar; + return sCharsToGsmTables[0].get(' ', ' '); } } else { return GSM_EXTENDED_ESCAPE; @@ -94,44 +124,42 @@ public class GsmAlphabet { } return ret; - } - /** - * char to extended GSM alphabet char - * - * Extended chars should be escaped with GSM_EXTENDED_ESCAPE - * - * Returns ' ' in GSM alphabet if there's no possible match - * + * Converts a char to an extended GSM 7 bit table index. + * Extended chars should be escaped with GSM_EXTENDED_ESCAPE. + * Returns ' ' in GSM alphabet if there's no possible match. */ public static int charToGsmExtended(char c) { int ret; - ret = charToGsmExtended.get(c, -1); + ret = sCharsToShiftTables[0].get(c, -1); if (ret == -1) { - return sGsmSpaceChar; + return sCharsToGsmTables[0].get(' ', ' '); } return ret; } /** - * Converts a character in the GSM alphabet into a char + * Converts a character in the GSM alphabet into a char. * - * if GSM_EXTENDED_ESCAPE is passed, 0xffff is returned. In this case, + * If GSM_EXTENDED_ESCAPE is passed, 0xffff is returned. In this case, * the following character in the stream should be decoded with - * gsmExtendedToChar() + * gsmExtendedToChar(). * - * If an unmappable value is passed (one greater than 127), ' ' is returned + * If an unmappable value is passed (one greater than 127), ' ' is returned. */ - public static char gsmToChar(int gsmChar) { - return (char)gsmToChar.get(gsmChar, ' '); + if (gsmChar >= 0 && gsmChar < 128) { + return sLanguageTables[0].charAt(gsmChar); + } else { + return ' '; + } } /** @@ -141,20 +169,23 @@ public class GsmAlphabet { * extension page has yet been defined (see Note 1 in table 6.2.1.1 of * TS 23.038 v7.00) * - * If an unmappable value is passed , ' ' is returned + * If an unmappable value is passed, the character from the GSM 7 bit + * default table will be used (table 6.2.1.1 of TS 23.038). */ - public static char gsmExtendedToChar(int gsmChar) { - int ret; - - ret = gsmExtendedToChar.get(gsmChar, -1); - - if (ret == -1) { + if (gsmChar == GSM_EXTENDED_ESCAPE) { return ' '; + } else if (gsmChar >= 0 && gsmChar < 128) { + char c = sLanguageShiftTables[0].charAt(gsmChar); + if (c == ' ') { + return sLanguageTables[0].charAt(gsmChar); + } else { + return c; + } + } else { + return ' '; // out of range } - - return (char)ret; } /** @@ -173,19 +204,24 @@ public class GsmAlphabet { * @param data The text string to encode. * @param header Optional header (including length byte) that precedes * the encoded data, padded to septet boundary. + * @param languageTable the 7 bit language table, or 0 for the default GSM alphabet + * @param languageShiftTable the 7 bit single shift language table, or 0 for the default + * GSM extension table * @return Byte array containing header and encoded data. + * @throws EncodeException if String is too large to encode */ - public static byte[] stringToGsm7BitPackedWithHeader(String data, byte[] header) + public static byte[] stringToGsm7BitPackedWithHeader(String data, byte[] header, + int languageTable, int languageShiftTable) throws EncodeException { - if (header == null || header.length == 0) { - return stringToGsm7BitPacked(data); + return stringToGsm7BitPacked(data, languageTable, languageShiftTable); } int headerBits = (header.length + 1) * 8; int headerSeptets = (headerBits + 6) / 7; - byte[] ret = stringToGsm7BitPacked(data, headerSeptets, true); + byte[] ret = stringToGsm7BitPacked(data, headerSeptets, true, languageTable, + languageShiftTable); // Paste in the header ret[1] = (byte)header.length; @@ -205,11 +241,16 @@ public class GsmAlphabet { * septets. * * @param data the data string to encode + * @param languageTable the 7 bit language table, or 0 for the default GSM alphabet + * @param languageShiftTable the 7 bit single shift language table, or 0 for the default + * GSM extension table + * @return the encoded string * @throws EncodeException if String is too large to encode */ - public static byte[] stringToGsm7BitPacked(String data) + public static byte[] stringToGsm7BitPacked(String data, int languageTable, + int languageShiftTable) throws EncodeException { - return stringToGsm7BitPacked(data, 0, true); + return stringToGsm7BitPacked(data, 0, true, languageTable, languageShiftTable); } /** @@ -226,28 +267,48 @@ public class GsmAlphabet { * the character data at the beginning of the array * @param throwException If true, throws EncodeException on invalid char. * If false, replaces unencodable char with GSM alphabet space char. + * @param languageTable the 7 bit language table, or 0 for the default GSM alphabet + * @param languageShiftTable the 7 bit single shift language table, or 0 for the default + * GSM extension table + * @return the encoded message * * @throws EncodeException if String is too large to encode */ public static byte[] stringToGsm7BitPacked(String data, int startingSeptetOffset, - boolean throwException) throws EncodeException { + boolean throwException, int languageTable, int languageShiftTable) + throws EncodeException { int dataLen = data.length(); - int septetCount = countGsmSeptets(data, throwException) + startingSeptetOffset; + int septetCount = countGsmSeptetsUsingTables(data, !throwException, + languageTable, languageShiftTable); + if (septetCount == -1) { + throw new EncodeException("countGsmSeptetsUsingTables(): unencodable char"); + } + septetCount += startingSeptetOffset; if (septetCount > 255) { throw new EncodeException("Payload cannot exceed 255 septets"); } int byteCount = ((septetCount * 7) + 7) / 8; byte[] ret = new byte[byteCount + 1]; // Include space for one byte length prefix. + SparseIntArray charToLanguageTable = sCharsToGsmTables[languageTable]; + SparseIntArray charToShiftTable = sCharsToShiftTables[languageShiftTable]; for (int i = 0, septets = startingSeptetOffset, bitOffset = startingSeptetOffset * 7; i < dataLen && septets < septetCount; i++, bitOffset += 7) { char c = data.charAt(i); - int v = GsmAlphabet.charToGsm(c, throwException); - if (v == GSM_EXTENDED_ESCAPE) { - v = GsmAlphabet.charToGsmExtended(c); // Lookup the extended char. - packSmsChar(ret, bitOffset, GSM_EXTENDED_ESCAPE); - bitOffset += 7; - septets++; + int v = charToLanguageTable.get(c, -1); + if (v == -1) { + v = charToShiftTable.get(c, -1); // Lookup the extended char. + if (v == -1) { + if (throwException) { + throw new EncodeException("stringToGsm7BitPacked(): unencodable char"); + } else { + v = charToLanguageTable.get(' ', ' '); // should return ASCII space + } + } else { + packSmsChar(ret, bitOffset, GSM_EXTENDED_ESCAPE); + bitOffset += 7; + septets++; + } } packSmsChar(ret, bitOffset, v); septets++; @@ -259,8 +320,10 @@ public class GsmAlphabet { /** * Pack a 7-bit char into its appropriate place in a byte array * + * @param packedChars the destination byte array * @param bitOffset the bit offset that the septet should be packed at * (septet index * 7) + * @param value the 7-bit character to store */ private static void packSmsChar(byte[] packedChars, int bitOffset, int value) { @@ -287,7 +350,7 @@ public class GsmAlphabet { */ public static String gsm7BitPackedToString(byte[] pdu, int offset, int lengthSeptets) { - return gsm7BitPackedToString(pdu, offset, lengthSeptets, 0); + return gsm7BitPackedToString(pdu, offset, lengthSeptets, 0, 0, 0); } /** @@ -301,15 +364,37 @@ public class GsmAlphabet { * @param lengthSeptets string length in septets, not bytes * @param numPaddingBits the number of padding bits before the start of the * string in the first byte + * @param languageTable the 7 bit language table, or 0 for the default GSM alphabet + * @param shiftTable the 7 bit single shift language table, or 0 for the default + * GSM extension table * @return String representation or null on decoding exception */ public static String gsm7BitPackedToString(byte[] pdu, int offset, - int lengthSeptets, int numPaddingBits) { + int lengthSeptets, int numPaddingBits, int languageTable, int shiftTable) { StringBuilder ret = new StringBuilder(lengthSeptets); - boolean prevCharWasEscape; + + if (languageTable < 0 || languageTable > sLanguageTables.length) { + Log.w(TAG, "unknown language table " + languageTable + ", using default"); + languageTable = 0; + } + if (shiftTable < 0 || shiftTable > sLanguageShiftTables.length) { + Log.w(TAG, "unknown single shift table " + shiftTable + ", using default"); + shiftTable = 0; + } try { - prevCharWasEscape = false; + boolean prevCharWasEscape = false; + String languageTableToChar = sLanguageTables[languageTable]; + String shiftTableToChar = sLanguageShiftTables[shiftTable]; + + if (languageTableToChar.isEmpty()) { + Log.w(TAG, "no language table for code " + languageTable + ", using default"); + languageTableToChar = sLanguageTables[0]; + } + if (shiftTableToChar.isEmpty()) { + Log.w(TAG, "no single shift table for code " + shiftTable + ", using default"); + shiftTableToChar = sLanguageShiftTables[0]; + } for (int i = 0 ; i < lengthSeptets ; i++) { int bitOffset = (7 * i) + numPaddingBits; @@ -320,7 +405,7 @@ public class GsmAlphabet { gsmVal = (0x7f & (pdu[offset + byteOffset] >> shift)); - // if it crosses a byte boundry + // if it crosses a byte boundary if (shift > 1) { // set msb bits to 0 gsmVal &= 0x7f >> (shift - 1); @@ -329,16 +414,25 @@ public class GsmAlphabet { } if (prevCharWasEscape) { - ret.append(GsmAlphabet.gsmExtendedToChar(gsmVal)); + if (gsmVal == GSM_EXTENDED_ESCAPE) { + ret.append(' '); // display ' ' for reserved double escape sequence + } else { + char c = shiftTableToChar.charAt(gsmVal); + if (c == ' ') { + ret.append(languageTableToChar.charAt(gsmVal)); + } else { + ret.append(c); + } + } prevCharWasEscape = false; } else if (gsmVal == GSM_EXTENDED_ESCAPE) { prevCharWasEscape = true; } else { - ret.append(GsmAlphabet.gsmToChar(gsmVal)); + ret.append(languageTableToChar.charAt(gsmVal)); } } } catch (RuntimeException ex) { - Log.e(LOG_TAG, "Error GSM 7 bit packed: ", ex); + Log.e(TAG, "Error GSM 7 bit packed: ", ex); return null; } @@ -355,10 +449,12 @@ public class GsmAlphabet { */ public static String gsm8BitUnpackedToString(byte[] data, int offset, int length) { - boolean prevWasEscape; - StringBuilder ret = new StringBuilder(length); + // Always use GSM 7 bit default alphabet table for this method + String languageTableToChar = sLanguageTables[0]; + String shiftTableToChar = sLanguageShiftTables[0]; - prevWasEscape = false; + StringBuilder ret = new StringBuilder(length); + boolean prevWasEscape = false; for (int i = offset ; i < offset + length ; i++) { // Never underestimate the pain that can be caused // by signed bytes @@ -378,9 +474,15 @@ public class GsmAlphabet { } } else { if (prevWasEscape) { - ret.append((char)gsmExtendedToChar.get(c, ' ')); + char shiftChar = shiftTableToChar.charAt(c); + if (shiftChar == ' ') { + // display character from main table if not present in shift table + ret.append(languageTableToChar.charAt(c)); + } else { + ret.append(shiftChar); + } } else { - ret.append((char)gsmToChar.get(c, ' ')); + ret.append(languageTableToChar.charAt(c)); } prevWasEscape = false; } @@ -390,16 +492,14 @@ public class GsmAlphabet { } /** - * Convert a string into an 8-bit unpacked GSM alphabet byte - * array + * Convert a string into an 8-bit unpacked GSM alphabet byte array. + * Always uses GSM default 7-bit alphabet and extension table. */ public static byte[] stringToGsm8BitPacked(String s) { byte[] ret; - int septets = 0; - - septets = countGsmSeptets(s); + int septets = countGsmSeptetsUsingTables(s, true, 0, 0); // Enough for all the septets and the length byte prefix ret = new byte[septets]; @@ -420,6 +520,8 @@ public class GsmAlphabet { public static void stringToGsm8BitUnpackedField(String s, byte dest[], int offset, int length) { int outByteIndex = offset; + SparseIntArray charToLanguageTable = sCharsToGsmTables[0]; + SparseIntArray charToShiftTable = sCharsToShiftTables[0]; // Septets are stored in byte-aligned octets for (int i = 0, sz = s.length() @@ -428,17 +530,20 @@ public class GsmAlphabet { ) { char c = s.charAt(i); - int v = GsmAlphabet.charToGsm(c); - - if (v == GSM_EXTENDED_ESCAPE) { - // make sure we can fit an escaped char - if (! (outByteIndex + 1 - offset < length)) { - break; - } + int v = charToLanguageTable.get(c, -1); - dest[outByteIndex++] = GSM_EXTENDED_ESCAPE; + if (v == -1) { + v = charToShiftTable.get(c, -1); + if (v == -1) { + v = charToLanguageTable.get(' ', ' '); // fall back to ASCII space + } else { + // make sure we can fit an escaped char + if (! (outByteIndex + 1 - offset < length)) { + break; + } - v = GsmAlphabet.charToGsmExtended(c); + dest[outByteIndex++] = GSM_EXTENDED_ESCAPE; + } } dest[outByteIndex++] = (byte)v; @@ -466,17 +571,17 @@ public class GsmAlphabet { /** * Returns the count of 7-bit GSM alphabet characters - * needed to represent this character + * needed to represent this character using the default 7 bit GSM alphabet. * @param throwsException If true, throws EncodeException if unencodable * char. Otherwise, counts invalid char as 1 septet */ public static int countGsmSeptets(char c, boolean throwsException) throws EncodeException { - if (charToGsm.get(c, -1) != -1) { + if (sCharsToGsmTables[0].get(c, -1) != -1) { return 1; } - if (charToGsmExtended.get(c, -1) != -1) { + if (sCharsToShiftTables[0].get(c, -1) != -1) { return 2; } @@ -489,37 +594,196 @@ public class GsmAlphabet { } /** - * Returns the count of 7-bit GSM alphabet characters - * needed to represent this string. Counts unencodable char as 1 septet. + * Returns the count of 7-bit GSM alphabet characters needed + * to represent this string, using the specified 7-bit language table + * and extension table (0 for GSM default tables). + * @param s the Unicode string that will be encoded + * @param use7bitOnly allow using space in place of unencodable character if true, + * otherwise, return -1 if any characters are unencodable + * @param languageTable the 7 bit language table, or 0 for the default GSM alphabet + * @param languageShiftTable the 7 bit single shift language table, or 0 for the default + * GSM extension table + * @return the septet count for s using the specified language tables, or -1 if any + * characters are unencodable and use7bitOnly is false */ - public static int - countGsmSeptets(CharSequence s) { - try { - return countGsmSeptets(s, false); - } catch (EncodeException ex) { - // this should never happen - return 0; + public static int countGsmSeptetsUsingTables(CharSequence s, boolean use7bitOnly, + int languageTable, int languageShiftTable) { + int count = 0; + int sz = s.length(); + SparseIntArray charToLanguageTable = sCharsToGsmTables[languageTable]; + SparseIntArray charToShiftTable = sCharsToShiftTables[languageShiftTable]; + for (int i = 0; i < sz; i++) { + char c = s.charAt(i); + if (c == GSM_EXTENDED_ESCAPE) { + Log.w(TAG, "countGsmSeptets() string contains Escape character, skipping."); + continue; + } + if (charToLanguageTable.get(c, -1) != -1) { + count++; + } else if (charToShiftTable.get(c, -1) != -1) { + count += 2; // escape + shift table index + } else if (use7bitOnly) { + count++; // encode as space + } else { + return -1; // caller must check for this case + } } + return count; } /** * Returns the count of 7-bit GSM alphabet characters - * needed to represent this string. - * @param throwsException If true, throws EncodeException if unencodable - * char. Otherwise, counts invalid char as 1 septet + * needed to represent this string, and the language table and + * language shift table used to achieve this result. + * For multi-part text messages, each message part may use its + * own language table encoding as specified in the message header + * for that message. However, this method will only return the + * optimal encoding for the message as a whole. When the individual + * pieces are encoded, a more optimal encoding may be chosen for each + * piece of the message, but the message will be split into pieces + * based on the encoding chosen for the message as a whole. + * @param s the Unicode string that will be encoded + * @param use7bitOnly allow using space in place of unencodable character if true, + * using the language table pair with the fewest unencodable characters + * @return a TextEncodingDetails object containing the message and + * character counts for the most efficient 7-bit encoding, + * or null if there are no suitable language tables to encode the string. */ - public static int - countGsmSeptets(CharSequence s, boolean throwsException) throws EncodeException { - int charIndex = 0; + public static SmsMessageBase.TextEncodingDetails + countGsmSeptets(CharSequence s, boolean use7bitOnly) { + // fast path for common case where no national language shift tables are enabled + if (sEnabledSingleShiftTables.length + sEnabledLockingShiftTables.length == 0) { + SmsMessageBase.TextEncodingDetails ted = new SmsMessageBase.TextEncodingDetails(); + int septets = GsmAlphabet.countGsmSeptetsUsingTables(s, use7bitOnly, 0, 0); + if (septets == -1) { + return null; + } + ted.codeUnitSize = ENCODING_7BIT; + ted.codeUnitCount = septets; + if (septets > MAX_USER_DATA_SEPTETS) { + ted.msgCount = (septets + (MAX_USER_DATA_SEPTETS_WITH_HEADER - 1)) / + MAX_USER_DATA_SEPTETS_WITH_HEADER; + ted.codeUnitsRemaining = (ted.msgCount * + MAX_USER_DATA_SEPTETS_WITH_HEADER) - septets; + } else { + ted.msgCount = 1; + ted.codeUnitsRemaining = MAX_USER_DATA_SEPTETS - septets; + } + ted.codeUnitSize = ENCODING_7BIT; + return ted; + } + + int maxSingleShiftCode = sHighestEnabledSingleShiftCode; + List<LanguagePairCount> lpcList = new ArrayList<LanguagePairCount>( + sEnabledLockingShiftTables.length + 1); + + // Always add default GSM 7-bit alphabet table + lpcList.add(new LanguagePairCount(0)); + for (int i : sEnabledLockingShiftTables) { + // Avoid adding default table twice in case 0 is in the list of allowed tables + if (i != 0 && !sLanguageTables[i].isEmpty()) { + lpcList.add(new LanguagePairCount(i)); + } + } + int sz = s.length(); - int count = 0; + // calculate septet count for each valid table / shift table pair + for (int i = 0; i < sz && !lpcList.isEmpty(); i++) { + char c = s.charAt(i); + if (c == GSM_EXTENDED_ESCAPE) { + Log.w(TAG, "countGsmSeptets() string contains Escape character, ignoring!"); + continue; + } + // iterate through enabled locking shift tables + for (LanguagePairCount lpc : lpcList) { + int tableIndex = sCharsToGsmTables[lpc.languageCode].get(c, -1); + if (tableIndex == -1) { + // iterate through single shift tables for this locking table + for (int table = 0; table <= maxSingleShiftCode; table++) { + if (lpc.septetCounts[table] != -1) { + int shiftTableIndex = sCharsToShiftTables[table].get(c, -1); + if (shiftTableIndex == -1) { + if (use7bitOnly) { + // can't encode char, use space instead + lpc.septetCounts[table]++; + lpc.unencodableCounts[table]++; + } else { + // can't encode char, remove language pair from list + lpc.septetCounts[table] = -1; + } + } else { + // encode as Escape + index into shift table + lpc.septetCounts[table] += 2; + } + } + } + } else { + // encode as index into locking shift table for all pairs + for (int table = 0; table <= maxSingleShiftCode; table++) { + if (lpc.septetCounts[table] != -1) { + lpc.septetCounts[table]++; + } + } + } + } + } - while (charIndex < sz) { - count += countGsmSeptets(s.charAt(charIndex), throwsException); - charIndex++; + // find the least cost encoding (lowest message count and most code units remaining) + SmsMessageBase.TextEncodingDetails ted = new SmsMessageBase.TextEncodingDetails(); + ted.msgCount = Integer.MAX_VALUE; + ted.codeUnitSize = ENCODING_7BIT; + int minUnencodableCount = Integer.MAX_VALUE; + for (LanguagePairCount lpc : lpcList) { + for (int shiftTable = 0; shiftTable <= maxSingleShiftCode; shiftTable++) { + int septets = lpc.septetCounts[shiftTable]; + if (septets == -1) { + continue; + } + int udhLength; + if (lpc.languageCode != 0 && shiftTable != 0) { + udhLength = UDH_SEPTET_COST_LENGTH + UDH_SEPTET_COST_TWO_SHIFT_TABLES; + } else if (lpc.languageCode != 0 || shiftTable != 0) { + udhLength = UDH_SEPTET_COST_LENGTH + UDH_SEPTET_COST_ONE_SHIFT_TABLE; + } else { + udhLength = 0; + } + int msgCount; + int septetsRemaining; + if (septets + udhLength > MAX_USER_DATA_SEPTETS) { + if (udhLength == 0) { + udhLength = UDH_SEPTET_COST_LENGTH; + } + udhLength += UDH_SEPTET_COST_CONCATENATED_MESSAGE; + int septetsPerMessage = MAX_USER_DATA_SEPTETS - udhLength; + msgCount = (septets + septetsPerMessage - 1) / septetsPerMessage; + septetsRemaining = (msgCount * septetsPerMessage) - septets; + } else { + msgCount = 1; + septetsRemaining = MAX_USER_DATA_SEPTETS - udhLength - septets; + } + // for 7-bit only mode, use language pair with the least unencodable chars + int unencodableCount = lpc.unencodableCounts[shiftTable]; + if (use7bitOnly && unencodableCount > minUnencodableCount) { + continue; + } + if ((use7bitOnly && unencodableCount < minUnencodableCount) + || msgCount < ted.msgCount || (msgCount == ted.msgCount + && septetsRemaining > ted.codeUnitsRemaining)) { + minUnencodableCount = unencodableCount; + ted.msgCount = msgCount; + ted.codeUnitCount = septets; + ted.codeUnitsRemaining = septetsRemaining; + ted.languageTable = lpc.languageCode; + ted.languageShiftTable = shiftTable; + } + } } - return count; + if (ted.msgCount == Integer.MAX_VALUE) { + return null; + } + + return ted; } /** @@ -532,16 +796,31 @@ public class GsmAlphabet { * @param start index of where to start counting septets * @param limit maximum septets to include, * e.g. <code>MAX_USER_DATA_SEPTETS</code> + * @param langTable the 7 bit character table to use (0 for default GSM 7-bit alphabet) + * @param langShiftTable the 7 bit shift table to use (0 for default GSM extension table) * @return index of first character that won't fit, or the length * of the entire string if everything fits */ public static int - findGsmSeptetLimitIndex(String s, int start, int limit) { + findGsmSeptetLimitIndex(String s, int start, int limit, int langTable, int langShiftTable) { int accumulator = 0; int size = s.length(); + SparseIntArray charToLangTable = sCharsToGsmTables[langTable]; + SparseIntArray charToLangShiftTable = sCharsToShiftTables[langShiftTable]; for (int i = start; i < size; i++) { - accumulator += countGsmSeptets(s.charAt(i)); + int encodedSeptet = charToLangTable.get(s.charAt(i), -1); + if (encodedSeptet == -1) { + encodedSeptet = charToLangShiftTable.get(s.charAt(i), -1); + if (encodedSeptet == -1) { + // char not found, assume we're replacing with space + accumulator++; + } else { + accumulator += 2; // escape character + shift table index + } + } else { + accumulator++; + } if (accumulator > limit) { return i; } @@ -549,178 +828,488 @@ public class GsmAlphabet { return size; } - // Set in the static initializer - private static int sGsmSpaceChar; + /** + * Modify the array of enabled national language single shift tables for SMS + * encoding. This is used for unit testing, but could also be used to + * modify the enabled encodings based on the active MCC/MNC, for example. + * + * @param tables the new list of enabled single shift tables + */ + static synchronized void setEnabledSingleShiftTables(int[] tables) { + sEnabledSingleShiftTables = tables; - private static final SparseIntArray charToGsm = new SparseIntArray(); - private static final SparseIntArray gsmToChar = new SparseIntArray(); - private static final SparseIntArray charToGsmExtended = new SparseIntArray(); - private static final SparseIntArray gsmExtendedToChar = new SparseIntArray(); + if (tables.length > 0) { + sHighestEnabledSingleShiftCode = tables[tables.length - 1]; + } else { + sHighestEnabledSingleShiftCode = 0; + } + } - static { - int i = 0; - - charToGsm.put('@', i++); - charToGsm.put('\u00a3', i++); - charToGsm.put('$', i++); - charToGsm.put('\u00a5', i++); - charToGsm.put('\u00e8', i++); - charToGsm.put('\u00e9', i++); - charToGsm.put('\u00f9', i++); - charToGsm.put('\u00ec', i++); - charToGsm.put('\u00f2', i++); - charToGsm.put('\u00c7', i++); - charToGsm.put('\n', i++); - charToGsm.put('\u00d8', i++); - charToGsm.put('\u00f8', i++); - charToGsm.put('\r', i++); - charToGsm.put('\u00c5', i++); - charToGsm.put('\u00e5', i++); - - charToGsm.put('\u0394', i++); - charToGsm.put('_', i++); - charToGsm.put('\u03a6', i++); - charToGsm.put('\u0393', i++); - charToGsm.put('\u039b', i++); - charToGsm.put('\u03a9', i++); - charToGsm.put('\u03a0', i++); - charToGsm.put('\u03a8', i++); - charToGsm.put('\u03a3', i++); - charToGsm.put('\u0398', i++); - charToGsm.put('\u039e', i++); - charToGsm.put('\uffff', i++); - charToGsm.put('\u00c6', i++); - charToGsm.put('\u00e6', i++); - charToGsm.put('\u00df', i++); - charToGsm.put('\u00c9', i++); - - charToGsm.put(' ', i++); - charToGsm.put('!', i++); - charToGsm.put('"', i++); - charToGsm.put('#', i++); - charToGsm.put('\u00a4', i++); - charToGsm.put('%', i++); - charToGsm.put('&', i++); - charToGsm.put('\'', i++); - charToGsm.put('(', i++); - charToGsm.put(')', i++); - charToGsm.put('*', i++); - charToGsm.put('+', i++); - charToGsm.put(',', i++); - charToGsm.put('-', i++); - charToGsm.put('.', i++); - charToGsm.put('/', i++); - - charToGsm.put('0', i++); - charToGsm.put('1', i++); - charToGsm.put('2', i++); - charToGsm.put('3', i++); - charToGsm.put('4', i++); - charToGsm.put('5', i++); - charToGsm.put('6', i++); - charToGsm.put('7', i++); - charToGsm.put('8', i++); - charToGsm.put('9', i++); - charToGsm.put(':', i++); - charToGsm.put(';', i++); - charToGsm.put('<', i++); - charToGsm.put('=', i++); - charToGsm.put('>', i++); - charToGsm.put('?', i++); - - charToGsm.put('\u00a1', i++); - charToGsm.put('A', i++); - charToGsm.put('B', i++); - charToGsm.put('C', i++); - charToGsm.put('D', i++); - charToGsm.put('E', i++); - charToGsm.put('F', i++); - charToGsm.put('G', i++); - charToGsm.put('H', i++); - charToGsm.put('I', i++); - charToGsm.put('J', i++); - charToGsm.put('K', i++); - charToGsm.put('L', i++); - charToGsm.put('M', i++); - charToGsm.put('N', i++); - charToGsm.put('O', i++); - - charToGsm.put('P', i++); - charToGsm.put('Q', i++); - charToGsm.put('R', i++); - charToGsm.put('S', i++); - charToGsm.put('T', i++); - charToGsm.put('U', i++); - charToGsm.put('V', i++); - charToGsm.put('W', i++); - charToGsm.put('X', i++); - charToGsm.put('Y', i++); - charToGsm.put('Z', i++); - charToGsm.put('\u00c4', i++); - charToGsm.put('\u00d6', i++); - charToGsm.put('\u00d1', i++); - charToGsm.put('\u00dc', i++); - charToGsm.put('\u00a7', i++); - - charToGsm.put('\u00bf', i++); - charToGsm.put('a', i++); - charToGsm.put('b', i++); - charToGsm.put('c', i++); - charToGsm.put('d', i++); - charToGsm.put('e', i++); - charToGsm.put('f', i++); - charToGsm.put('g', i++); - charToGsm.put('h', i++); - charToGsm.put('i', i++); - charToGsm.put('j', i++); - charToGsm.put('k', i++); - charToGsm.put('l', i++); - charToGsm.put('m', i++); - charToGsm.put('n', i++); - charToGsm.put('o', i++); - - charToGsm.put('p', i++); - charToGsm.put('q', i++); - charToGsm.put('r', i++); - charToGsm.put('s', i++); - charToGsm.put('t', i++); - charToGsm.put('u', i++); - charToGsm.put('v', i++); - charToGsm.put('w', i++); - charToGsm.put('x', i++); - charToGsm.put('y', i++); - charToGsm.put('z', i++); - charToGsm.put('\u00e4', i++); - charToGsm.put('\u00f6', i++); - charToGsm.put('\u00f1', i++); - charToGsm.put('\u00fc', i++); - charToGsm.put('\u00e0', i++); - - - charToGsmExtended.put('\f', 10); - charToGsmExtended.put('^', 20); - charToGsmExtended.put('{', 40); - charToGsmExtended.put('}', 41); - charToGsmExtended.put('\\', 47); - charToGsmExtended.put('[', 60); - charToGsmExtended.put('~', 61); - charToGsmExtended.put(']', 62); - charToGsmExtended.put('|', 64); - charToGsmExtended.put('\u20ac', 101); - - int size = charToGsm.size(); - for (int j=0; j<size; j++) { - gsmToChar.put(charToGsm.valueAt(j), charToGsm.keyAt(j)); - } - - size = charToGsmExtended.size(); - for (int j=0; j<size; j++) { - gsmExtendedToChar.put(charToGsmExtended.valueAt(j), charToGsmExtended.keyAt(j)); - } - - - sGsmSpaceChar = charToGsm.get(' '); + /** + * Modify the array of enabled national language locking shift tables for SMS + * encoding. This is used for unit testing, but could also be used to + * modify the enabled encodings based on the active MCC/MNC, for example. + * + * @param tables the new list of enabled locking shift tables + */ + static synchronized void setEnabledLockingShiftTables(int[] tables) { + sEnabledLockingShiftTables = tables; } + /** + * Return the array of enabled national language single shift tables for SMS + * encoding. This is used for unit testing. The returned array is not a copy, so + * the caller should be careful not to modify it. + * + * @return the list of enabled single shift tables + */ + static synchronized int[] getEnabledSingleShiftTables() { + return sEnabledSingleShiftTables; + } + /** + * Return the array of enabled national language locking shift tables for SMS + * encoding. This is used for unit testing. The returned array is not a copy, so + * the caller should be careful not to modify it. + * + * @return the list of enabled locking shift tables + */ + static synchronized int[] getEnabledLockingShiftTables() { + return sEnabledLockingShiftTables; + } + + /** Reverse mapping from Unicode characters to indexes into language tables. */ + private static final SparseIntArray[] sCharsToGsmTables; + + /** Reverse mapping from Unicode characters to indexes into language shift tables. */ + private static final SparseIntArray[] sCharsToShiftTables; + + /** OEM configured list of enabled national language single shift tables for encoding. */ + private static int[] sEnabledSingleShiftTables; + + /** OEM configured list of enabled national language locking shift tables for encoding. */ + private static int[] sEnabledLockingShiftTables; + + /** Highest language code to include in array of single shift counters. */ + private static int sHighestEnabledSingleShiftCode; + + /** + * Septet counter for a specific locking shift table and all of + * the single shift tables that it can be paired with. + */ + private static class LanguagePairCount { + final int languageCode; + final int[] septetCounts; + final int[] unencodableCounts; + LanguagePairCount(int code) { + this.languageCode = code; + int maxSingleShiftCode = sHighestEnabledSingleShiftCode; + septetCounts = new int[maxSingleShiftCode + 1]; + unencodableCounts = new int[maxSingleShiftCode + 1]; + // set counters for disabled single shift tables to -1 + // (GSM default extension table index 0 is always enabled) + for (int i = 1, tableOffset = 0; i <= maxSingleShiftCode; i++) { + if (sEnabledSingleShiftTables[tableOffset] == i) { + tableOffset++; + } else { + septetCounts[i] = -1; // disabled + } + } + // exclude Turkish locking + Turkish single shift table and + // Portuguese locking + Spanish single shift table (these + // combinations will never be optimal for any input). + if (code == 1 && maxSingleShiftCode >= 1) { + septetCounts[1] = -1; // Turkish + Turkish + } else if (code == 3 && maxSingleShiftCode >= 2) { + septetCounts[2] = -1; // Portuguese + Spanish + } + } + } + + /** + * GSM default 7 bit alphabet plus national language locking shift character tables. + * Comment lines above strings indicate the lower four bits of the table position. + */ + private static final String[] sLanguageTables = { + /* 3GPP TS 23.038 V9.1.1 section 6.2.1 - GSM 7 bit Default Alphabet + 01.....23.....4.....5.....6.....7.....8.....9.....A.B.....C.....D.E.....F.....0.....1 */ + "@\u00a3$\u00a5\u00e8\u00e9\u00f9\u00ec\u00f2\u00c7\n\u00d8\u00f8\r\u00c5\u00e5\u0394_" + // 2.....3.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....E..... + + "\u03a6\u0393\u039b\u03a9\u03a0\u03a8\u03a3\u0398\u039e\uffff\u00c6\u00e6\u00df" + // F.....012.34.....56789ABCDEF0123456789ABCDEF0.....123456789ABCDEF0123456789A + + "\u00c9 !\"#\u00a4%&'()*+,-./0123456789:;<=>?\u00a1ABCDEFGHIJKLMNOPQRSTUVWXYZ" + // B.....C.....D.....E.....F.....0.....123456789ABCDEF0123456789AB.....C.....D..... + + "\u00c4\u00d6\u00d1\u00dc\u00a7\u00bfabcdefghijklmnopqrstuvwxyz\u00e4\u00f6\u00f1" + // E.....F..... + + "\u00fc\u00e0", + + /* A.3.1 Turkish National Language Locking Shift Table + 01.....23.....4.....5.....6.....7.....8.....9.....A.B.....C.....D.E.....F.....0.....1 */ + "@\u00a3$\u00a5\u20ac\u00e9\u00f9\u0131\u00f2\u00c7\n\u011e\u011f\r\u00c5\u00e5\u0394_" + // 2.....3.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....E..... + + "\u03a6\u0393\u039b\u03a9\u03a0\u03a8\u03a3\u0398\u039e\uffff\u015e\u015f\u00df" + // F.....012.34.....56789ABCDEF0123456789ABCDEF0.....123456789ABCDEF0123456789A + + "\u00c9 !\"#\u00a4%&'()*+,-./0123456789:;<=>?\u0130ABCDEFGHIJKLMNOPQRSTUVWXYZ" + // B.....C.....D.....E.....F.....0.....123456789ABCDEF0123456789AB.....C.....D..... + + "\u00c4\u00d6\u00d1\u00dc\u00a7\u00e7abcdefghijklmnopqrstuvwxyz\u00e4\u00f6\u00f1" + // E.....F..... + + "\u00fc\u00e0", + + /* A.3.2 Void (no locking shift table for Spanish) */ + "", + + /* A.3.3 Portuguese National Language Locking Shift Table + 01.....23.....4.....5.....6.....7.....8.....9.....A.B.....C.....D.E.....F.....0.....1 */ + "@\u00a3$\u00a5\u00ea\u00e9\u00fa\u00ed\u00f3\u00e7\n\u00d4\u00f4\r\u00c1\u00e1\u0394_" + // 2.....3.....4.....5.....67.8.....9.....AB.....C.....D.....E.....F.....012.34..... + + "\u00aa\u00c7\u00c0\u221e^\\\u20ac\u00d3|\uffff\u00c2\u00e2\u00ca\u00c9 !\"#\u00ba" + // 56789ABCDEF0123456789ABCDEF0.....123456789ABCDEF0123456789AB.....C.....D.....E..... + + "%&'()*+,-./0123456789:;<=>?\u00cdABCDEFGHIJKLMNOPQRSTUVWXYZ\u00c3\u00d5\u00da\u00dc" + // F.....0123456789ABCDEF0123456789AB.....C.....DE.....F..... + + "\u00a7~abcdefghijklmnopqrstuvwxyz\u00e3\u00f5`\u00fc\u00e0", + + /* A.3.4 Bengali National Language Locking Shift Table + 0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.B.....CD.EF.....0..... */ + "\u0981\u0982\u0983\u0985\u0986\u0987\u0988\u0989\u098a\u098b\n\u098c \r \u098f\u0990" + // 123.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....E.....F..... + + " \u0993\u0994\u0995\u0996\u0997\u0998\u0999\u099a\uffff\u099b\u099c\u099d\u099e" + // 012.....3.....4.....5.....6.....7.....89A.....B.....CD.....EF.....0123456789ABC + + " !\u099f\u09a0\u09a1\u09a2\u09a3\u09a4)(\u09a5\u09a6,\u09a7.\u09a80123456789:; " + // D.....E.....F0.....1.....2.....3.....4.....56.....789A.....B.....C.....D..... + + "\u09aa\u09ab?\u09ac\u09ad\u09ae\u09af\u09b0 \u09b2 \u09b6\u09b7\u09b8\u09b9" + // E.....F.....0.....1.....2.....3.....4.....5.....6.....789.....A.....BCD.....E..... + + "\u09bc\u09bd\u09be\u09bf\u09c0\u09c1\u09c2\u09c3\u09c4 \u09c7\u09c8 \u09cb\u09cc" + // F.....0.....123456789ABCDEF0123456789AB.....C.....D.....E.....F..... + + "\u09cd\u09ceabcdefghijklmnopqrstuvwxyz\u09d7\u09dc\u09dd\u09f0\u09f1", + + /* A.3.5 Gujarati National Language Locking Shift Table + 0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.B.....C.....D.EF.....0.....*/ + "\u0a81\u0a82\u0a83\u0a85\u0a86\u0a87\u0a88\u0a89\u0a8a\u0a8b\n\u0a8c\u0a8d\r \u0a8f\u0a90" + // 1.....23.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....E..... + + "\u0a91 \u0a93\u0a94\u0a95\u0a96\u0a97\u0a98\u0a99\u0a9a\uffff\u0a9b\u0a9c\u0a9d" + // F.....012.....3.....4.....5.....6.....7.....89A.....B.....CD.....EF.....0123456789AB + + "\u0a9e !\u0a9f\u0aa0\u0aa1\u0aa2\u0aa3\u0aa4)(\u0aa5\u0aa6,\u0aa7.\u0aa80123456789:;" + // CD.....E.....F0.....1.....2.....3.....4.....56.....7.....89.....A.....B.....C..... + + " \u0aaa\u0aab?\u0aac\u0aad\u0aae\u0aaf\u0ab0 \u0ab2\u0ab3 \u0ab5\u0ab6\u0ab7\u0ab8" + // D.....E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89.....A..... + + "\u0ab9\u0abc\u0abd\u0abe\u0abf\u0ac0\u0ac1\u0ac2\u0ac3\u0ac4\u0ac5 \u0ac7\u0ac8" + // B.....CD.....E.....F.....0.....123456789ABCDEF0123456789AB.....C.....D.....E..... + + "\u0ac9 \u0acb\u0acc\u0acd\u0ad0abcdefghijklmnopqrstuvwxyz\u0ae0\u0ae1\u0ae2\u0ae3" + // F..... + + "\u0af1", + + /* A.3.6 Hindi National Language Locking Shift Table + 0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.B.....C.....D.E.....F.....*/ + "\u0901\u0902\u0903\u0905\u0906\u0907\u0908\u0909\u090a\u090b\n\u090c\u090d\r\u090e\u090f" + // 0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D..... + + "\u0910\u0911\u0912\u0913\u0914\u0915\u0916\u0917\u0918\u0919\u091a\uffff\u091b\u091c" + // E.....F.....012.....3.....4.....5.....6.....7.....89A.....B.....CD.....EF.....012345 + + "\u091d\u091e !\u091f\u0920\u0921\u0922\u0923\u0924)(\u0925\u0926,\u0927.\u0928012345" + // 6789ABC.....D.....E.....F0.....1.....2.....3.....4.....5.....6.....7.....8..... + + "6789:;\u0929\u092a\u092b?\u092c\u092d\u092e\u092f\u0930\u0931\u0932\u0933\u0934" + // 9.....A.....B.....C.....D.....E.....F.....0.....1.....2.....3.....4.....5.....6..... + + "\u0935\u0936\u0937\u0938\u0939\u093c\u093d\u093e\u093f\u0940\u0941\u0942\u0943\u0944" + // 7.....8.....9.....A.....B.....C.....D.....E.....F.....0.....123456789ABCDEF012345678 + + "\u0945\u0946\u0947\u0948\u0949\u094a\u094b\u094c\u094d\u0950abcdefghijklmnopqrstuvwx" + // 9AB.....C.....D.....E.....F..... + + "yz\u0972\u097b\u097c\u097e\u097f", + + /* A.3.7 Kannada National Language Locking Shift Table + NOTE: TS 23.038 V9.1.1 shows code 0x24 as \u0caa, corrected to \u0ca1 (typo) + 01.....2.....3.....4.....5.....6.....7.....8.....9.....A.B.....CD.E.....F.....0.....1 */ + " \u0c82\u0c83\u0c85\u0c86\u0c87\u0c88\u0c89\u0c8a\u0c8b\n\u0c8c \r\u0c8e\u0c8f\u0c90 " + // 2.....3.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....E.....F..... + + "\u0c92\u0c93\u0c94\u0c95\u0c96\u0c97\u0c98\u0c99\u0c9a\uffff\u0c9b\u0c9c\u0c9d\u0c9e" + // 012.....3.....4.....5.....6.....7.....89A.....B.....CD.....EF.....0123456789ABC + + " !\u0c9f\u0ca0\u0ca1\u0ca2\u0ca3\u0ca4)(\u0ca5\u0ca6,\u0ca7.\u0ca80123456789:; " + // D.....E.....F0.....1.....2.....3.....4.....5.....6.....7.....89.....A.....B..... + + "\u0caa\u0cab?\u0cac\u0cad\u0cae\u0caf\u0cb0\u0cb1\u0cb2\u0cb3 \u0cb5\u0cb6\u0cb7" + // C.....D.....E.....F.....0.....1.....2.....3.....4.....5.....6.....78.....9..... + + "\u0cb8\u0cb9\u0cbc\u0cbd\u0cbe\u0cbf\u0cc0\u0cc1\u0cc2\u0cc3\u0cc4 \u0cc6\u0cc7" + // A.....BC.....D.....E.....F.....0.....123456789ABCDEF0123456789AB.....C.....D..... + + "\u0cc8 \u0cca\u0ccb\u0ccc\u0ccd\u0cd5abcdefghijklmnopqrstuvwxyz\u0cd6\u0ce0\u0ce1" + // E.....F..... + + "\u0ce2\u0ce3", + + /* A.3.8 Malayalam National Language Locking Shift Table + 01.....2.....3.....4.....5.....6.....7.....8.....9.....A.B.....CD.E.....F.....0.....1 */ + " \u0d02\u0d03\u0d05\u0d06\u0d07\u0d08\u0d09\u0d0a\u0d0b\n\u0d0c \r\u0d0e\u0d0f\u0d10 " + // 2.....3.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....E.....F..... + + "\u0d12\u0d13\u0d14\u0d15\u0d16\u0d17\u0d18\u0d19\u0d1a\uffff\u0d1b\u0d1c\u0d1d\u0d1e" + // 012.....3.....4.....5.....6.....7.....89A.....B.....CD.....EF.....0123456789ABC + + " !\u0d1f\u0d20\u0d21\u0d22\u0d23\u0d24)(\u0d25\u0d26,\u0d27.\u0d280123456789:; " + // D.....E.....F0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A..... + + "\u0d2a\u0d2b?\u0d2c\u0d2d\u0d2e\u0d2f\u0d30\u0d31\u0d32\u0d33\u0d34\u0d35\u0d36" + // B.....C.....D.....EF.....0.....1.....2.....3.....4.....5.....6.....78.....9..... + + "\u0d37\u0d38\u0d39 \u0d3d\u0d3e\u0d3f\u0d40\u0d41\u0d42\u0d43\u0d44 \u0d46\u0d47" + // A.....BC.....D.....E.....F.....0.....123456789ABCDEF0123456789AB.....C.....D..... + + "\u0d48 \u0d4a\u0d4b\u0d4c\u0d4d\u0d57abcdefghijklmnopqrstuvwxyz\u0d60\u0d61\u0d62" + // E.....F..... + + "\u0d63\u0d79", + + /* A.3.9 Oriya National Language Locking Shift Table + 0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.B.....CD.EF.....0.....12 */ + "\u0b01\u0b02\u0b03\u0b05\u0b06\u0b07\u0b08\u0b09\u0b0a\u0b0b\n\u0b0c \r \u0b0f\u0b10 " + // 3.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....E.....F.....01 + + "\u0b13\u0b14\u0b15\u0b16\u0b17\u0b18\u0b19\u0b1a\uffff\u0b1b\u0b1c\u0b1d\u0b1e !" + // 2.....3.....4.....5.....6.....7.....89A.....B.....CD.....EF.....0123456789ABCD..... + + "\u0b1f\u0b20\u0b21\u0b22\u0b23\u0b24)(\u0b25\u0b26,\u0b27.\u0b280123456789:; \u0b2a" + // E.....F0.....1.....2.....3.....4.....56.....7.....89.....A.....B.....C.....D..... + + "\u0b2b?\u0b2c\u0b2d\u0b2e\u0b2f\u0b30 \u0b32\u0b33 \u0b35\u0b36\u0b37\u0b38\u0b39" + // E.....F.....0.....1.....2.....3.....4.....5.....6.....789.....A.....BCD.....E..... + + "\u0b3c\u0b3d\u0b3e\u0b3f\u0b40\u0b41\u0b42\u0b43\u0b44 \u0b47\u0b48 \u0b4b\u0b4c" + // F.....0.....123456789ABCDEF0123456789AB.....C.....D.....E.....F..... + + "\u0b4d\u0b56abcdefghijklmnopqrstuvwxyz\u0b57\u0b60\u0b61\u0b62\u0b63", + + /* A.3.10 Punjabi National Language Locking Shift Table + 0.....1.....2.....3.....4.....5.....6.....7.....8.....9A.BCD.EF.....0.....123.....4.....*/ + "\u0a01\u0a02\u0a03\u0a05\u0a06\u0a07\u0a08\u0a09\u0a0a \n \r \u0a0f\u0a10 \u0a13\u0a14" + // 5.....6.....7.....8.....9.....A.....B.....C.....D.....E.....F.....012.....3..... + + "\u0a15\u0a16\u0a17\u0a18\u0a19\u0a1a\uffff\u0a1b\u0a1c\u0a1d\u0a1e !\u0a1f\u0a20" + // 4.....5.....6.....7.....89A.....B.....CD.....EF.....0123456789ABCD.....E.....F0..... + + "\u0a21\u0a22\u0a23\u0a24)(\u0a25\u0a26,\u0a27.\u0a280123456789:; \u0a2a\u0a2b?\u0a2c" + // 1.....2.....3.....4.....56.....7.....89.....A.....BC.....D.....E.....F0.....1..... + + "\u0a2d\u0a2e\u0a2f\u0a30 \u0a32\u0a33 \u0a35\u0a36 \u0a38\u0a39\u0a3c \u0a3e\u0a3f" + // 2.....3.....4.....56789.....A.....BCD.....E.....F.....0.....123456789ABCDEF012345678 + + "\u0a40\u0a41\u0a42 \u0a47\u0a48 \u0a4b\u0a4c\u0a4d\u0a51abcdefghijklmnopqrstuvwx" + // 9AB.....C.....D.....E.....F..... + + "yz\u0a70\u0a71\u0a72\u0a73\u0a74", + + /* A.3.11 Tamil National Language Locking Shift Table + 01.....2.....3.....4.....5.....6.....7.....8.....9A.BCD.E.....F.....0.....12.....3..... */ + " \u0b82\u0b83\u0b85\u0b86\u0b87\u0b88\u0b89\u0b8a \n \r\u0b8e\u0b8f\u0b90 \u0b92\u0b93" + // 4.....5.....6789.....A.....B.....CD.....EF.....012.....3456.....7.....89ABCDEF..... + + "\u0b94\u0b95 \u0b99\u0b9a\uffff \u0b9c \u0b9e !\u0b9f \u0ba3\u0ba4)( , .\u0ba8" + // 0123456789ABC.....D.....EF012.....3.....4.....5.....6.....7.....8.....9.....A..... + + "0123456789:;\u0ba9\u0baa ? \u0bae\u0baf\u0bb0\u0bb1\u0bb2\u0bb3\u0bb4\u0bb5\u0bb6" + // B.....C.....D.....EF0.....1.....2.....3.....4.....5678.....9.....A.....BC.....D..... + + "\u0bb7\u0bb8\u0bb9 \u0bbe\u0bbf\u0bc0\u0bc1\u0bc2 \u0bc6\u0bc7\u0bc8 \u0bca\u0bcb" + // E.....F.....0.....123456789ABCDEF0123456789AB.....C.....D.....E.....F..... + + "\u0bcc\u0bcd\u0bd0abcdefghijklmnopqrstuvwxyz\u0bd7\u0bf0\u0bf1\u0bf2\u0bf9", + + /* A.3.12 Telugu National Language Locking Shift Table + 0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.B.....CD.E.....F.....0.....*/ + "\u0c01\u0c02\u0c03\u0c05\u0c06\u0c07\u0c08\u0c09\u0c0a\u0c0b\n\u0c0c \r\u0c0e\u0c0f\u0c10" + // 12.....3.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....E..... + + " \u0c12\u0c13\u0c14\u0c15\u0c16\u0c17\u0c18\u0c19\u0c1a\uffff\u0c1b\u0c1c\u0c1d" + // F.....012.....3.....4.....5.....6.....7.....89A.....B.....CD.....EF.....0123456789AB + + "\u0c1e !\u0c1f\u0c20\u0c21\u0c22\u0c23\u0c24)(\u0c25\u0c26,\u0c27.\u0c280123456789:;" + // CD.....E.....F0.....1.....2.....3.....4.....5.....6.....7.....89.....A.....B..... + + " \u0c2a\u0c2b?\u0c2c\u0c2d\u0c2e\u0c2f\u0c30\u0c31\u0c32\u0c33 \u0c35\u0c36\u0c37" + // C.....D.....EF.....0.....1.....2.....3.....4.....5.....6.....78.....9.....A.....B + + "\u0c38\u0c39 \u0c3d\u0c3e\u0c3f\u0c40\u0c41\u0c42\u0c43\u0c44 \u0c46\u0c47\u0c48 " + // C.....D.....E.....F.....0.....123456789ABCDEF0123456789AB.....C.....D.....E..... + + "\u0c4a\u0c4b\u0c4c\u0c4d\u0c55abcdefghijklmnopqrstuvwxyz\u0c56\u0c60\u0c61\u0c62" + // F..... + + "\u0c63", + + /* A.3.13 Urdu National Language Locking Shift Table + 0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.B.....C.....D.E.....F.....*/ + "\u0627\u0622\u0628\u067b\u0680\u067e\u06a6\u062a\u06c2\u067f\n\u0679\u067d\r\u067a\u067c" + // 0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D..... + + "\u062b\u062c\u0681\u0684\u0683\u0685\u0686\u0687\u062d\u062e\u062f\uffff\u068c\u0688" + // E.....F.....012.....3.....4.....5.....6.....7.....89A.....B.....CD.....EF.....012345 + + "\u0689\u068a !\u068f\u068d\u0630\u0631\u0691\u0693)(\u0699\u0632,\u0696.\u0698012345" + // 6789ABC.....D.....E.....F0.....1.....2.....3.....4.....5.....6.....7.....8..... + + "6789:;\u069a\u0633\u0634?\u0635\u0636\u0637\u0638\u0639\u0641\u0642\u06a9\u06aa" + // 9.....A.....B.....C.....D.....E.....F.....0.....1.....2.....3.....4.....5.....6..... + + "\u06ab\u06af\u06b3\u06b1\u0644\u0645\u0646\u06ba\u06bb\u06bc\u0648\u06c4\u06d5\u06c1" + // 7.....8.....9.....A.....B.....C.....D.....E.....F.....0.....123456789ABCDEF012345678 + + "\u06be\u0621\u06cc\u06d0\u06d2\u064d\u0650\u064f\u0657\u0654abcdefghijklmnopqrstuvwx" + // 9AB.....C.....D.....E.....F..... + + "yz\u0655\u0651\u0653\u0656\u0670" + }; + + /** + * GSM default extension table plus national language single shift character tables. + */ + private static final String[] sLanguageShiftTables = new String[]{ + /* 6.2.1.1 GSM 7 bit Default Alphabet Extension Table + 0123456789A.....BCDEF0123456789ABCDEF0123456789ABCDEF.0123456789ABCDEF0123456789ABCDEF */ + " \u000c ^ {} \\ [~] | " + // 0123456789ABCDEF012345.....6789ABCDEF0123456789ABCDEF + + " \u20ac ", + + /* A.2.1 Turkish National Language Single Shift Table + 0123456789A.....BCDEF0123456789ABCDEF0123456789ABCDEF.0123456789ABCDEF01234567.....8 */ + " \u000c ^ {} \\ [~] | \u011e " + // 9.....ABCDEF0123.....456789ABCDEF0123.....45.....67.....89.....ABCDEF0123..... + + "\u0130 \u015e \u00e7 \u20ac \u011f \u0131 \u015f" + // 456789ABCDEF + + " ", + + /* A.2.2 Spanish National Language Single Shift Table + 0123456789.....A.....BCDEF0123456789ABCDEF0123456789ABCDEF.0123456789ABCDEF01.....23 */ + " \u00e7\u000c ^ {} \\ [~] |\u00c1 " + // 456789.....ABCDEF.....012345.....6789ABCDEF01.....2345.....6789.....ABCDEF.....012 + + " \u00cd \u00d3 \u00da \u00e1 \u20ac \u00ed \u00f3 " + // 345.....6789ABCDEF + + " \u00fa ", + + /* A.2.3 Portuguese National Language Single Shift Table + 012345.....6789.....A.....B.....C.....DE.....F.....012.....3.....45.....6.....7.....8....*/ + " \u00ea \u00e7\u000c\u00d4\u00f4 \u00c1\u00e1 \u03a6\u0393^\u03a9\u03a0\u03a8\u03a3" + // 9.....ABCDEF.....0123456789ABCDEF.0123456789ABCDEF01.....23456789.....ABCDE + + "\u0398 \u00ca {} \\ [~] |\u00c0 \u00cd " + // F.....012345.....6789AB.....C.....DEF01.....2345.....6789.....ABCDEF.....01234 + + "\u00d3 \u00da \u00c3\u00d5 \u00c2 \u20ac \u00ed \u00f3 " + // 5.....6789AB.....C.....DEF..... + + "\u00fa \u00e3\u00f5 \u00e2", + + /* A.2.4 Bengali National Language Single Shift Table + 01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */ + "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u09e6\u09e7 \u09e8\u09e9" + // E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89A.....B.....C..... + + "\u09ea\u09eb\u09ec\u09ed\u09ee\u09ef\u09df\u09e0\u09e1\u09e2{}\u09e3\u09f2\u09f3" + // D.....E.....F.0.....1.....2.....3.....4.....56789ABCDEF0123456789ABCDEF + + "\u09f4\u09f5\\\u09f6\u09f7\u09f8\u09f9\u09fa [~] |ABCDEFGHIJKLMNO" + // 0123456789ABCDEF012345.....6789ABCDEF0123456789ABCDEF + + "PQRSTUVWXYZ \u20ac ", + + /* A.2.5 Gujarati National Language Single Shift Table + 01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */ + "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u0964\u0965 \u0ae6\u0ae7" + // E.....F.....0.....1.....2.....3.....4.....5.....6789ABCDEF.0123456789ABCDEF + + "\u0ae8\u0ae9\u0aea\u0aeb\u0aec\u0aed\u0aee\u0aef {} \\ [~] " + // 0123456789ABCDEF0123456789ABCDEF012345.....6789ABCDEF0123456789ABCDEF + + "|ABCDEFGHIJKLMNOPQRSTUVWXYZ \u20ac ", + + /* A.2.6 Hindi National Language Single Shift Table + 01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */ + "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u0964\u0965 \u0966\u0967" + // E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89A.....B.....C..... + + "\u0968\u0969\u096a\u096b\u096c\u096d\u096e\u096f\u0951\u0952{}\u0953\u0954\u0958" + // D.....E.....F.0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A..... + + "\u0959\u095a\\\u095b\u095c\u095d\u095e\u095f\u0960\u0961\u0962\u0963\u0970\u0971" + // BCDEF0123456789ABCDEF0123456789ABCDEF012345.....6789ABCDEF0123456789ABCDEF + + " [~] |ABCDEFGHIJKLMNOPQRSTUVWXYZ \u20ac ", + + /* A.2.7 Kannada National Language Single Shift Table + 01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */ + "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u0964\u0965 \u0ce6\u0ce7" + // E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89A.....BCDEF.01234567 + + "\u0ce8\u0ce9\u0cea\u0ceb\u0cec\u0ced\u0cee\u0cef\u0cde\u0cf1{}\u0cf2 \\ " + // 89ABCDEF0123456789ABCDEF0123456789ABCDEF012345.....6789ABCDEF0123456789ABCDEF + + " [~] |ABCDEFGHIJKLMNOPQRSTUVWXYZ \u20ac ", + + /* A.2.8 Malayalam National Language Single Shift Table + 01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */ + "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u0964\u0965 \u0d66\u0d67" + // E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89A.....B.....C..... + + "\u0d68\u0d69\u0d6a\u0d6b\u0d6c\u0d6d\u0d6e\u0d6f\u0d70\u0d71{}\u0d72\u0d73\u0d74" + // D.....E.....F.0.....1.....2.....3.....4.....56789ABCDEF0123456789ABCDEF0123456789A + + "\u0d75\u0d7a\\\u0d7b\u0d7c\u0d7d\u0d7e\u0d7f [~] |ABCDEFGHIJKLMNOPQRSTUVWXYZ" + // BCDEF012345.....6789ABCDEF0123456789ABCDEF + + " \u20ac ", + + /* A.2.9 Oriya National Language Single Shift Table + 01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */ + "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u0964\u0965 \u0b66\u0b67" + // E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89A.....B.....C.....DE + + "\u0b68\u0b69\u0b6a\u0b6b\u0b6c\u0b6d\u0b6e\u0b6f\u0b5c\u0b5d{}\u0b5f\u0b70\u0b71 " + // F.0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF012345.....6789ABCDEF0123456789A + + "\\ [~] |ABCDEFGHIJKLMNOPQRSTUVWXYZ \u20ac " + // BCDEF + + " ", + + /* A.2.10 Punjabi National Language Single Shift Table + 01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */ + "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u0964\u0965 \u0a66\u0a67" + // E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89A.....B.....C..... + + "\u0a68\u0a69\u0a6a\u0a6b\u0a6c\u0a6d\u0a6e\u0a6f\u0a59\u0a5a{}\u0a5b\u0a5c\u0a5e" + // D.....EF.0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF012345.....6789ABCDEF01 + + "\u0a75 \\ [~] |ABCDEFGHIJKLMNOPQRSTUVWXYZ \u20ac " + // 23456789ABCDEF + + " ", + + /* A.2.11 Tamil National Language Single Shift Table + NOTE: TS 23.038 V9.1.1 shows code 0x24 as \u0bef, corrected to \u0bee (typo) + 01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */ + "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u0964\u0965 \u0be6\u0be7" + // E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89A.....B.....C..... + + "\u0be8\u0be9\u0bea\u0beb\u0bec\u0bed\u0bee\u0bef\u0bf3\u0bf4{}\u0bf5\u0bf6\u0bf7" + // D.....E.....F.0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF012345.....6789ABC + + "\u0bf8\u0bfa\\ [~] |ABCDEFGHIJKLMNOPQRSTUVWXYZ \u20ac " + // DEF0123456789ABCDEF + + " ", + + /* A.2.12 Telugu National Language Single Shift Table + NOTE: TS 23.038 V9.1.1 shows code 0x22-0x23 as \u06cc\u06cd, corrected to \u0c6c\u0c6d + 01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789ABC.....D.....E.....F..... */ + "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#* \u0c66\u0c67\u0c68\u0c69" + // 0.....1.....2.....3.....4.....5.....6.....7.....89A.....B.....C.....D.....E.....F. + + "\u0c6a\u0c6b\u0c6c\u0c6d\u0c6e\u0c6f\u0c58\u0c59{}\u0c78\u0c79\u0c7a\u0c7b\u0c7c\\" + // 0.....1.....2.....3456789ABCDEF0123456789ABCDEF0123456789ABCDEF012345.....6789ABCD + + "\u0c7d\u0c7e\u0c7f [~] |ABCDEFGHIJKLMNOPQRSTUVWXYZ \u20ac " + // EF0123456789ABCDEF + + " ", + + /* A.2.13 Urdu National Language Single Shift Table + 01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */ + "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u0600\u0601 \u06f0\u06f1" + // E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89A.....B.....C..... + + "\u06f2\u06f3\u06f4\u06f5\u06f6\u06f7\u06f8\u06f9\u060c\u060d{}\u060e\u060f\u0610" + // D.....E.....F.0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A..... + + "\u0611\u0612\\\u0613\u0614\u061b\u061f\u0640\u0652\u0658\u066b\u066c\u0672\u0673" + // B.....CDEF.....0123456789ABCDEF0123456789ABCDEF012345.....6789ABCDEF0123456789ABCDEF + + "\u06cd[~]\u06d4|ABCDEFGHIJKLMNOPQRSTUVWXYZ \u20ac " + }; + + static { + Resources r = Resources.getSystem(); + // See comments in frameworks/base/core/res/res/values/config.xml for allowed values + sEnabledSingleShiftTables = r.getIntArray(R.array.config_sms_enabled_single_shift_tables); + sEnabledLockingShiftTables = r.getIntArray(R.array.config_sms_enabled_locking_shift_tables); + int numTables = sLanguageTables.length; + int numShiftTables = sLanguageShiftTables.length; + if (numTables != numShiftTables) { + Log.e(TAG, "Error: language tables array length " + numTables + + " != shift tables array length " + numShiftTables); + } + + if (sEnabledSingleShiftTables.length > 0) { + sHighestEnabledSingleShiftCode = + sEnabledSingleShiftTables[sEnabledSingleShiftTables.length-1]; + } else { + sHighestEnabledSingleShiftCode = 0; + } + + sCharsToGsmTables = new SparseIntArray[numTables]; + for (int i = 0; i < numTables; i++) { + String table = sLanguageTables[i]; + + int tableLen = table.length(); + if (tableLen != 0 && tableLen != 128) { + Log.e(TAG, "Error: language tables index " + i + + " length " + tableLen + " (expected 128 or 0)"); + } + + SparseIntArray charToGsmTable = new SparseIntArray(tableLen); + sCharsToGsmTables[i] = charToGsmTable; + for (int j = 0; j < tableLen; j++) { + char c = table.charAt(j); + charToGsmTable.put(c, j); + } + } + + sCharsToShiftTables = new SparseIntArray[numTables]; + for (int i = 0; i < numShiftTables; i++) { + String shiftTable = sLanguageShiftTables[i]; + + int shiftTableLen = shiftTable.length(); + if (shiftTableLen != 0 && shiftTableLen != 128) { + Log.e(TAG, "Error: language shift tables index " + i + + " length " + shiftTableLen + " (expected 128 or 0)"); + } + + SparseIntArray charToShiftTable = new SparseIntArray(shiftTableLen); + sCharsToShiftTables[i] = charToShiftTable; + for (int j = 0; j < shiftTableLen; j++) { + char c = shiftTable.charAt(j); + if (c != ' ') { + charToShiftTable.put(c, j); + } + } + } + } } diff --git a/telephony/java/com/android/internal/telephony/SmsHeader.java b/telephony/java/com/android/internal/telephony/SmsHeader.java index 7872eec..9492e0e 100644 --- a/telephony/java/com/android/internal/telephony/SmsHeader.java +++ b/telephony/java/com/android/internal/telephony/SmsHeader.java @@ -30,7 +30,7 @@ import java.util.ArrayList; */ public class SmsHeader { - // TODO(cleanup): this datastructure is generally referred to as + // TODO(cleanup): this data structure is generally referred to as // the 'user data header' or UDH, and so the class name should // change to reflect this... @@ -66,6 +66,8 @@ public class SmsHeader { public static final int ELT_ID_HYPERLINK_FORMAT_ELEMENT = 0x21; public static final int ELT_ID_REPLY_ADDRESS_ELEMENT = 0x22; public static final int ELT_ID_ENHANCED_VOICE_MAIL_INFORMATION = 0x23; + public static final int ELT_ID_NATIONAL_LANGUAGE_SINGLE_SHIFT = 0x24; + public static final int ELT_ID_NATIONAL_LANGUAGE_LOCKING_SHIFT = 0x25; public static final int PORT_WAP_PUSH = 2948; public static final int PORT_WAP_WSP = 9200; @@ -96,6 +98,12 @@ public class SmsHeader { public ConcatRef concatRef; public ArrayList<MiscElt> miscEltList = new ArrayList<MiscElt>(); + /** 7 bit national language locking shift table, or 0 for GSM default 7 bit alphabet. */ + public int languageTable; + + /** 7 bit national language single shift table, or 0 for GSM default 7 bit extension table. */ + public int languageShiftTable; + public SmsHeader() {} /** @@ -157,6 +165,12 @@ public class SmsHeader { portAddrs.areEightBits = false; smsHeader.portAddrs = portAddrs; break; + case ELT_ID_NATIONAL_LANGUAGE_SINGLE_SHIFT: + smsHeader.languageShiftTable = inStream.read(); + break; + case ELT_ID_NATIONAL_LANGUAGE_LOCKING_SHIFT: + smsHeader.languageTable = inStream.read(); + break; default: MiscElt miscElt = new MiscElt(); miscElt.id = id; @@ -212,6 +226,16 @@ public class SmsHeader { outStream.write(portAddrs.origPort & 0x00FF); } } + if (smsHeader.languageShiftTable != 0) { + outStream.write(ELT_ID_NATIONAL_LANGUAGE_SINGLE_SHIFT); + outStream.write(1); + outStream.write(smsHeader.languageShiftTable); + } + if (smsHeader.languageTable != 0) { + outStream.write(ELT_ID_NATIONAL_LANGUAGE_LOCKING_SHIFT); + outStream.write(1); + outStream.write(smsHeader.languageTable); + } for (MiscElt miscElt : smsHeader.miscEltList) { outStream.write(miscElt.id); outStream.write(miscElt.data.length); @@ -243,6 +267,12 @@ public class SmsHeader { builder.append(", areEightBits=" + portAddrs.areEightBits); builder.append(" }"); } + if (languageShiftTable != 0) { + builder.append(", languageShiftTable=" + languageShiftTable); + } + if (languageTable != 0) { + builder.append(", languageTable=" + languageTable); + } for (MiscElt miscElt : miscEltList) { builder.append(", MiscElt "); builder.append("{ id=" + miscElt.id); diff --git a/telephony/java/com/android/internal/telephony/SmsMessageBase.java b/telephony/java/com/android/internal/telephony/SmsMessageBase.java index af6c5f8..9f9d203 100644 --- a/telephony/java/com/android/internal/telephony/SmsMessageBase.java +++ b/telephony/java/com/android/internal/telephony/SmsMessageBase.java @@ -118,6 +118,16 @@ public abstract class SmsMessageBase { */ public int codeUnitSize; + /** + * The GSM national language table to use, or 0 for the default 7-bit alphabet. + */ + public int languageTable; + + /** + * The GSM national language shift table to use, or 0 for the default 7-bit extension table. + */ + public int languageShiftTable; + @Override public String toString() { return "TextEncodingDetails " + @@ -125,6 +135,8 @@ public abstract class SmsMessageBase { ", codeUnitCount=" + codeUnitCount + ", codeUnitsRemaining=" + codeUnitsRemaining + ", codeUnitSize=" + codeUnitSize + + ", languageTable=" + languageTable + + ", languageShiftTable=" + languageShiftTable + " }"; } } diff --git a/telephony/java/com/android/internal/telephony/cdma/sms/BearerData.java b/telephony/java/com/android/internal/telephony/cdma/sms/BearerData.java index 7bc48ca..5b21ec1 100755 --- a/telephony/java/com/android/internal/telephony/cdma/sms/BearerData.java +++ b/telephony/java/com/android/internal/telephony/cdma/sms/BearerData.java @@ -21,7 +21,6 @@ import static android.telephony.SmsMessage.MAX_USER_DATA_BYTES; import static android.telephony.SmsMessage.MAX_USER_DATA_BYTES_WITH_HEADER; import android.util.Log; -import android.util.SparseIntArray; import android.telephony.SmsMessage; @@ -30,10 +29,8 @@ import android.text.format.Time; import com.android.internal.telephony.IccUtils; import com.android.internal.telephony.GsmAlphabet; import com.android.internal.telephony.SmsHeader; -import com.android.internal.telephony.cdma.sms.UserData; import com.android.internal.telephony.SmsMessageBase.TextEncodingDetails; -import com.android.internal.util.HexDump; import com.android.internal.util.BitwiseInputStream; import com.android.internal.util.BitwiseOutputStream; @@ -504,7 +501,7 @@ public final class BearerData { * stringToGsm7BitPacked, and potentially directly support * access to the main bitwise stream from encode/decode. */ - byte[] fullData = GsmAlphabet.stringToGsm7BitPacked(msg, septetOffset, !force); + byte[] fullData = GsmAlphabet.stringToGsm7BitPacked(msg, septetOffset, !force, 0, 0); Gsm7bitCodingResult result = new Gsm7bitCodingResult(); result.data = new byte[fullData.length - 1]; System.arraycopy(fullData, 1, result.data, 0, fullData.length - 1); @@ -928,7 +925,7 @@ public final class BearerData { private static String decodeUtf16(byte[] data, int offset, int numFields) throws CodingException { - // Start reading from the next 16-bit aligned boundry after offset. + // Start reading from the next 16-bit aligned boundary after offset. int padding = offset % 2; numFields -= (offset + padding) / 2; try { @@ -974,12 +971,13 @@ public final class BearerData { private static String decode7bitGsm(byte[] data, int offset, int numFields) throws CodingException { - // Start reading from the next 7-bit aligned boundry after offset. + // Start reading from the next 7-bit aligned boundary after offset. int offsetBits = offset * 8; int offsetSeptets = (offsetBits + 6) / 7; numFields -= offsetSeptets; int paddingBits = (offsetSeptets * 7) - offsetBits; - String result = GsmAlphabet.gsm7BitPackedToString(data, offset, numFields, paddingBits); + String result = GsmAlphabet.gsm7BitPackedToString(data, offset, numFields, paddingBits, + 0, 0); if (result == null) { throw new CodingException("7bit GSM decoding failed"); } diff --git a/telephony/java/com/android/internal/telephony/gsm/GsmSMSDispatcher.java b/telephony/java/com/android/internal/telephony/gsm/GsmSMSDispatcher.java index e7b6c37..be22bf4 100755 --- a/telephony/java/com/android/internal/telephony/gsm/GsmSMSDispatcher.java +++ b/telephony/java/com/android/internal/telephony/gsm/GsmSMSDispatcher.java @@ -61,9 +61,8 @@ final class GsmSMSDispatcher extends SMSDispatcher { String pduString = (String) ar.result; SmsMessage sms = SmsMessage.newFromCDS(pduString); - int tpStatus = sms.getStatus(); - if (sms != null) { + int tpStatus = sms.getStatus(); int messageRef = sms.messageRef; for (int i = 0, count = deliveryPendingList.size(); i < count; i++) { SmsTracker tracker = deliveryPendingList.get(i); @@ -182,6 +181,7 @@ final class GsmSMSDispatcher extends SMSDispatcher { mRemainingMessages = msgCount; + TextEncodingDetails[] encodingForParts = new TextEncodingDetails[msgCount]; for (int i = 0; i < msgCount; i++) { TextEncodingDetails details = SmsMessage.calculateLength(parts.get(i), false); if (encoding != details.codeUnitSize @@ -189,6 +189,7 @@ final class GsmSMSDispatcher extends SMSDispatcher { || encoding == android.telephony.SmsMessage.ENCODING_7BIT)) { encoding = details.codeUnitSize; } + encodingForParts[i] = details; } for (int i = 0; i < msgCount; i++) { @@ -205,6 +206,10 @@ final class GsmSMSDispatcher extends SMSDispatcher { concatRef.isEightBits = true; SmsHeader smsHeader = new SmsHeader(); smsHeader.concatRef = concatRef; + if (encoding == android.telephony.SmsMessage.ENCODING_7BIT) { + smsHeader.languageTable = encodingForParts[i].languageTable; + smsHeader.languageShiftTable = encodingForParts[i].languageShiftTable; + } PendingIntent sentIntent = null; if (sentIntents != null && sentIntents.size() > i) { @@ -218,7 +223,7 @@ final class GsmSMSDispatcher extends SMSDispatcher { SmsMessage.SubmitPdu pdus = SmsMessage.getSubmitPdu(scAddress, destinationAddress, parts.get(i), deliveryIntent != null, SmsHeader.toByteArray(smsHeader), - encoding); + encoding, smsHeader.languageTable, smsHeader.languageShiftTable); sendRawPdu(pdus.encodedScAddress, pdus.encodedMessage, sentIntent, deliveryIntent); } @@ -273,6 +278,7 @@ final class GsmSMSDispatcher extends SMSDispatcher { mRemainingMessages = msgCount; + TextEncodingDetails[] encodingForParts = new TextEncodingDetails[msgCount]; for (int i = 0; i < msgCount; i++) { TextEncodingDetails details = SmsMessage.calculateLength(parts.get(i), false); if (encoding != details.codeUnitSize @@ -280,6 +286,7 @@ final class GsmSMSDispatcher extends SMSDispatcher { || encoding == android.telephony.SmsMessage.ENCODING_7BIT)) { encoding = details.codeUnitSize; } + encodingForParts[i] = details; } for (int i = 0; i < msgCount; i++) { @@ -290,6 +297,10 @@ final class GsmSMSDispatcher extends SMSDispatcher { concatRef.isEightBits = false; SmsHeader smsHeader = new SmsHeader(); smsHeader.concatRef = concatRef; + if (encoding == android.telephony.SmsMessage.ENCODING_7BIT) { + smsHeader.languageTable = encodingForParts[i].languageTable; + smsHeader.languageShiftTable = encodingForParts[i].languageShiftTable; + } PendingIntent sentIntent = null; if (sentIntents != null && sentIntents.size() > i) { @@ -303,7 +314,7 @@ final class GsmSMSDispatcher extends SMSDispatcher { SmsMessage.SubmitPdu pdus = SmsMessage.getSubmitPdu(scAddress, destinationAddress, parts.get(i), deliveryIntent != null, SmsHeader.toByteArray(smsHeader), - encoding); + encoding, smsHeader.languageTable, smsHeader.languageShiftTable); HashMap<String, Object> map = new HashMap<String, Object>(); map.put("smsc", pdus.encodedScAddress); diff --git a/telephony/java/com/android/internal/telephony/gsm/SmsMessage.java b/telephony/java/com/android/internal/telephony/gsm/SmsMessage.java index 50dd402..d16d426 100644 --- a/telephony/java/com/android/internal/telephony/gsm/SmsMessage.java +++ b/telephony/java/com/android/internal/telephony/gsm/SmsMessage.java @@ -26,7 +26,6 @@ import com.android.internal.telephony.EncodeException; import com.android.internal.telephony.GsmAlphabet; import com.android.internal.telephony.SmsHeader; import com.android.internal.telephony.SmsMessageBase; -import com.android.internal.telephony.SmsMessageBase.TextEncodingDetails; import java.io.ByteArrayOutputStream; import java.io.UnsupportedEncodingException; @@ -38,7 +37,6 @@ import static android.telephony.SmsMessage.ENCODING_UNKNOWN; import static android.telephony.SmsMessage.MAX_USER_DATA_BYTES; import static android.telephony.SmsMessage.MAX_USER_DATA_BYTES_WITH_HEADER; import static android.telephony.SmsMessage.MAX_USER_DATA_SEPTETS; -import static android.telephony.SmsMessage.MAX_USER_DATA_SEPTETS_WITH_HEADER; import static android.telephony.SmsMessage.MessageClass; /** @@ -214,9 +212,7 @@ public class SmsMessage extends SmsMessageBase{ */ public static int getTPLayerLengthForPDU(String pdu) { int len = pdu.length() / 2; - int smscLen = 0; - - smscLen = Integer.parseInt(pdu.substring(0, 2), 16); + int smscLen = Integer.parseInt(pdu.substring(0, 2), 16); return len - smscLen - 1; } @@ -234,7 +230,7 @@ public class SmsMessage extends SmsMessageBase{ String destinationAddress, String message, boolean statusReportRequested, byte[] header) { return getSubmitPdu(scAddress, destinationAddress, message, statusReportRequested, header, - ENCODING_UNKNOWN); + ENCODING_UNKNOWN, 0, 0); } @@ -244,6 +240,8 @@ public class SmsMessage extends SmsMessageBase{ * * @param scAddress Service Centre address. Null means use default. * @param encoding Encoding defined by constants in android.telephony.SmsMessage.ENCODING_* + * @param languageTable + * @param languageShiftTable * @return a <code>SubmitPdu</code> containing the encoded SC * address, if applicable, and the encoded message. * Returns null on encode error. @@ -251,7 +249,8 @@ public class SmsMessage extends SmsMessageBase{ */ public static SubmitPdu getSubmitPdu(String scAddress, String destinationAddress, String message, - boolean statusReportRequested, byte[] header, int encoding) { + boolean statusReportRequested, byte[] header, int encoding, + int languageTable, int languageShiftTable) { // Perform null parameter checks. if (message == null || destinationAddress == null) { @@ -272,7 +271,8 @@ public class SmsMessage extends SmsMessageBase{ } try { if (encoding == ENCODING_7BIT) { - userData = GsmAlphabet.stringToGsm7BitPackedWithHeader(message, header); + userData = GsmAlphabet.stringToGsm7BitPackedWithHeader(message, header, + languageTable, languageShiftTable); } else { //assume UCS-2 try { userData = encodeUCS2(message, header); @@ -377,7 +377,7 @@ public class SmsMessage extends SmsMessageBase{ * @param destinationAddress the address of the destination for the message * @param destinationPort the port to deliver the message to at the * destination - * @param data the dat for the message + * @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. @@ -573,7 +573,7 @@ public class SmsMessage extends SmsMessageBase{ int second = IccUtils.gsmBcdByteToInt(pdu[cur++]); // For the timezone, the most significant bit of the - // least signficant nibble is the sign byte + // least significant nibble is the sign byte // (meaning the max range of this field is 79 quarter-hours, // which is more than enough) @@ -632,7 +632,7 @@ public class SmsMessage extends SmsMessageBase{ /* * Here we just create the user data length to be the remainder of * the pdu minus the user data header, since userDataLength means - * the number of uncompressed sepets. + * the number of uncompressed septets. */ bufferLen = pdu.length - offset; } else { @@ -690,70 +690,19 @@ public class SmsMessage extends SmsMessageBase{ return userDataHeader; } -/* - XXX Not sure what this one is supposed to be doing, and no one is using - it. - String getUserDataGSM8bit() { - // System.out.println("remainder of pud:" + - // HexDump.dumpHexString(pdu, cur, pdu.length - cur)); - int count = pdu[cur++] & 0xff; - int size = pdu[cur++]; - - // skip over header for now - cur += size; - - if (pdu[cur - 1] == 0x01) { - int tid = pdu[cur++] & 0xff; - int type = pdu[cur++] & 0xff; - - size = pdu[cur++] & 0xff; - - int i = cur; - - while (pdu[i++] != '\0') { - } - - int length = i - cur; - String mimeType = new String(pdu, cur, length); - - cur += length; - - if (false) { - System.out.println("tid = 0x" + HexDump.toHexString(tid)); - System.out.println("type = 0x" + HexDump.toHexString(type)); - System.out.println("header size = " + size); - System.out.println("mimeType = " + mimeType); - System.out.println("remainder of header:" + - HexDump.dumpHexString(pdu, cur, (size - mimeType.length()))); - } - - cur += size - mimeType.length(); - - // System.out.println("data count = " + count + " cur = " + cur - // + " :" + HexDump.dumpHexString(pdu, cur, pdu.length - cur)); - - MMSMessage msg = MMSMessage.parseEncoding(mContext, pdu, cur, - pdu.length - cur); - } else { - System.out.println(new String(pdu, cur, pdu.length - cur - 1)); - } - - return IccUtils.bytesToHexString(pdu); - } -*/ - /** - * Interprets the user data payload as pack GSM 7bit characters, and + * Interprets the user data payload as packed GSM 7bit characters, and * decodes them into a String. * * @param septetCount the number of septets in the user data payload * @return a String with the decoded characters */ - String getUserDataGSM7Bit(int septetCount) { + String getUserDataGSM7Bit(int septetCount, int languageTable, + int languageShiftTable) { String ret; ret = GsmAlphabet.gsm7BitPackedToString(pdu, cur, septetCount, - mUserDataSeptetPadding); + mUserDataSeptetPadding, languageTable, languageShiftTable); cur += (septetCount * 7) / 8; @@ -795,21 +744,9 @@ public class SmsMessage extends SmsMessageBase{ */ public static TextEncodingDetails calculateLength(CharSequence msgBody, boolean use7bitOnly) { - TextEncodingDetails ted = new TextEncodingDetails(); - try { - int septets = GsmAlphabet.countGsmSeptets(msgBody, !use7bitOnly); - ted.codeUnitCount = septets; - if (septets > MAX_USER_DATA_SEPTETS) { - ted.msgCount = (septets + (MAX_USER_DATA_SEPTETS_WITH_HEADER - 1)) / - MAX_USER_DATA_SEPTETS_WITH_HEADER; - ted.codeUnitsRemaining = (ted.msgCount * - MAX_USER_DATA_SEPTETS_WITH_HEADER) - septets; - } else { - ted.msgCount = 1; - ted.codeUnitsRemaining = MAX_USER_DATA_SEPTETS - septets; - } - ted.codeUnitSize = ENCODING_7BIT; - } catch (EncodeException ex) { + TextEncodingDetails ted = GsmAlphabet.countGsmSeptets(msgBody, use7bitOnly); + if (ted == null) { + ted = new TextEncodingDetails(); int octets = msgBody.length() * 2; ted.codeUnitCount = msgBody.length(); if (octets > MAX_USER_DATA_BYTES) { @@ -846,7 +783,7 @@ public class SmsMessage extends SmsMessageBase{ /** {@inheritDoc} */ public boolean isMWIClearMessage() { - if (isMwi && (mwiSense == false)) { + if (isMwi && !mwiSense) { return true; } @@ -856,7 +793,7 @@ public class SmsMessage extends SmsMessageBase{ /** {@inheritDoc} */ public boolean isMWISetMessage() { - if (isMwi && (mwiSense == true)) { + if (isMwi && mwiSense) { return true; } @@ -902,13 +839,13 @@ public class SmsMessage extends SmsMessageBase{ * TS 27.005 3.1, <pdu> definition "In the case of SMS: 3GPP TS 24.011 [6] * SC address followed by 3GPP TS 23.040 [3] TPDU in hexadecimal format: * ME/TA converts each octet of TP data unit into two IRA character long - * hexad number (e.g. octet with integer value 42 is presented to TE as two + * hex number (e.g. octet with integer value 42 is presented to TE as two * characters 2A (IRA 50 and 65))" ...in the case of cell broadcast, * something else... */ private void parsePdu(byte[] pdu) { mPdu = pdu; - // Log.d(LOG_TAG, "raw sms mesage:"); + // Log.d(LOG_TAG, "raw sms message:"); // Log.d(LOG_TAG, s); PduParser p = new PduParser(pdu); @@ -1123,7 +1060,9 @@ public class SmsMessage extends SmsMessageBase{ break; case ENCODING_7BIT: - messageBody = p.getUserDataGSM7Bit(count); + messageBody = p.getUserDataGSM7Bit(count, + hasUserDataHeader ? userDataHeader.languageTable : 0, + hasUserDataHeader ? userDataHeader.languageShiftTable : 0); break; case ENCODING_16BIT: diff --git a/telephony/java/com/android/internal/telephony/gsm/stk/ResponseData.java b/telephony/java/com/android/internal/telephony/gsm/stk/ResponseData.java index afd1bba..fab916e 100644 --- a/telephony/java/com/android/internal/telephony/gsm/stk/ResponseData.java +++ b/telephony/java/com/android/internal/telephony/gsm/stk/ResponseData.java @@ -101,7 +101,7 @@ class GetInkeyInputResponseData extends ResponseData { int size = mInData.length(); byte[] tempData = GsmAlphabet - .stringToGsm7BitPacked(mInData); + .stringToGsm7BitPacked(mInData, 0, 0); data = new byte[size]; // Since stringToGsm7BitPacked() set byte 0 in the // returned byte array to the count of septets used... |