Home | History | Annotate | Download | only in telephony
      1 /*
      2  * Copyright (C) 2006 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.internal.telephony;
     18 
     19 import android.content.res.Resources;
     20 import android.text.TextUtils;
     21 import android.util.SparseIntArray;
     22 
     23 import android.util.Log;
     24 
     25 import java.nio.ByteBuffer;
     26 import java.nio.charset.Charset;
     27 import com.android.internal.R;
     28 
     29 import java.util.ArrayList;
     30 import java.util.List;
     31 
     32 import static android.telephony.SmsMessage.ENCODING_7BIT;
     33 import static android.telephony.SmsMessage.MAX_USER_DATA_SEPTETS;
     34 import static android.telephony.SmsMessage.MAX_USER_DATA_SEPTETS_WITH_HEADER;
     35 
     36 /**
     37  * This class implements the character set mapping between
     38  * the GSM SMS 7-bit alphabet specified in TS 23.038 6.2.1
     39  * and UTF-16
     40  *
     41  * {@hide}
     42  */
     43 public class GsmAlphabet {
     44     private static final String TAG = "GSM";
     45 
     46     private GsmAlphabet() { }
     47 
     48     //***** Constants
     49 
     50     /**
     51      * This escapes extended characters, and when present indicates that the
     52      * following character should be looked up in the "extended" table.
     53      *
     54      * gsmToChar(GSM_EXTENDED_ESCAPE) returns 0xffff
     55      */
     56     public static final byte GSM_EXTENDED_ESCAPE = 0x1B;
     57 
     58     /**
     59      * User data header requires one octet for length. Count as one septet, because
     60      * all combinations of header elements below will have at least one free bit
     61      * when padding to the nearest septet boundary.
     62      */
     63     public static final int UDH_SEPTET_COST_LENGTH = 1;
     64 
     65     /**
     66      * Using a non-default language locking shift table OR single shift table
     67      * requires a user data header of 3 octets, or 4 septets, plus UDH length.
     68      */
     69     public static final int UDH_SEPTET_COST_ONE_SHIFT_TABLE = 4;
     70 
     71     /**
     72      * Using a non-default language locking shift table AND single shift table
     73      * requires a user data header of 6 octets, or 7 septets, plus UDH length.
     74      */
     75     public static final int UDH_SEPTET_COST_TWO_SHIFT_TABLES = 7;
     76 
     77     /**
     78      * Multi-part messages require a user data header of 5 octets, or 6 septets,
     79      * plus UDH length.
     80      */
     81     public static final int UDH_SEPTET_COST_CONCATENATED_MESSAGE = 6;
     82 
     83     /**
     84      * Converts a char to a GSM 7 bit table index.
     85      * Returns ' ' in GSM alphabet if there's no possible match. Returns
     86      * GSM_EXTENDED_ESCAPE if this character is in the extended table.
     87      * In this case, you must call charToGsmExtended() for the value
     88      * that should follow GSM_EXTENDED_ESCAPE in the GSM alphabet string.
     89      * @param c the character to convert
     90      * @return the GSM 7 bit table index for the specified character
     91      */
     92     public static int
     93     charToGsm(char c) {
     94         try {
     95             return charToGsm(c, false);
     96         } catch (EncodeException ex) {
     97             // this should never happen
     98             return sCharsToGsmTables[0].get(' ', ' ');
     99         }
    100     }
    101 
    102     /**
    103      * Converts a char to a GSM 7 bit table index.
    104      * Returns GSM_EXTENDED_ESCAPE if this character is in the extended table.
    105      * In this case, you must call charToGsmExtended() for the value that
    106      * should follow GSM_EXTENDED_ESCAPE in the GSM alphabet string.
    107      *
    108      * @param c the character to convert
    109      * @param throwException If true, throws EncodeException on invalid char.
    110      *   If false, returns GSM alphabet ' ' char.
    111      * @throws EncodeException encode error when throwException is true
    112      * @return the GSM 7 bit table index for the specified character
    113      */
    114     public static int
    115     charToGsm(char c, boolean throwException) throws EncodeException {
    116         int ret;
    117 
    118         ret = sCharsToGsmTables[0].get(c, -1);
    119 
    120         if (ret == -1) {
    121             ret = sCharsToShiftTables[0].get(c, -1);
    122 
    123             if (ret == -1) {
    124                 if (throwException) {
    125                     throw new EncodeException(c);
    126                 } else {
    127                     return sCharsToGsmTables[0].get(' ', ' ');
    128                 }
    129             } else {
    130                 return GSM_EXTENDED_ESCAPE;
    131             }
    132         }
    133 
    134         return ret;
    135     }
    136 
    137     /**
    138      * Converts a char to an extended GSM 7 bit table index.
    139      * Extended chars should be escaped with GSM_EXTENDED_ESCAPE.
    140      * Returns ' ' in GSM alphabet if there's no possible match.
    141      * @param c the character to convert
    142      * @return the GSM 7 bit extended table index for the specified character
    143      */
    144     public static int
    145     charToGsmExtended(char c) {
    146         int ret;
    147 
    148         ret = sCharsToShiftTables[0].get(c, -1);
    149 
    150         if (ret == -1) {
    151             return sCharsToGsmTables[0].get(' ', ' ');
    152         }
    153 
    154         return ret;
    155     }
    156 
    157     /**
    158      * Converts a character in the GSM alphabet into a char.
    159      *
    160      * If GSM_EXTENDED_ESCAPE is passed, 0xffff is returned. In this case,
    161      * the following character in the stream should be decoded with
    162      * gsmExtendedToChar().
    163      *
    164      * If an unmappable value is passed (one greater than 127), ' ' is returned.
    165      *
    166      * @param gsmChar the GSM 7 bit table index to convert
    167      * @return the decoded character
    168      */
    169     public static char
    170     gsmToChar(int gsmChar) {
    171         if (gsmChar >= 0 && gsmChar < 128) {
    172             return sLanguageTables[0].charAt(gsmChar);
    173         } else {
    174             return ' ';
    175         }
    176     }
    177 
    178     /**
    179      * Converts a character in the extended GSM alphabet into a char
    180      *
    181      * if GSM_EXTENDED_ESCAPE is passed, ' ' is returned since no second
    182      * extension page has yet been defined (see Note 1 in table 6.2.1.1 of
    183      * TS 23.038 v7.00)
    184      *
    185      * If an unmappable value is passed, the character from the GSM 7 bit
    186      * default table will be used (table 6.2.1.1 of TS 23.038).
    187      *
    188      * @param gsmChar the GSM 7 bit extended table index to convert
    189      * @return the decoded character
    190      */
    191     public static char
    192     gsmExtendedToChar(int gsmChar) {
    193         if (gsmChar == GSM_EXTENDED_ESCAPE) {
    194             return ' ';
    195         } else if (gsmChar >= 0 && gsmChar < 128) {
    196             char c = sLanguageShiftTables[0].charAt(gsmChar);
    197             if (c == ' ') {
    198                 return sLanguageTables[0].charAt(gsmChar);
    199             } else {
    200                 return c;
    201             }
    202         } else {
    203             return ' ';     // out of range
    204         }
    205     }
    206 
    207     /**
    208      * Converts a String into a byte array containing the 7-bit packed
    209      * GSM Alphabet representation of the string. If a header is provided,
    210      * this is included in the returned byte array and padded to a septet
    211      * boundary. This method is used by OEM code.
    212      *
    213      * @param data The text string to encode.
    214      * @param header Optional header (including length byte) that precedes
    215      * the encoded data, padded to septet boundary.
    216      * @return Byte array containing header and encoded data.
    217      * @throws EncodeException if String is too large to encode
    218      * @see #stringToGsm7BitPackedWithHeader(String, byte[], int, int)
    219      */
    220     public static byte[] stringToGsm7BitPackedWithHeader(String data, byte[] header)
    221             throws EncodeException {
    222         return stringToGsm7BitPackedWithHeader(data, header, 0, 0);
    223     }
    224 
    225     /**
    226      * Converts a String into a byte array containing the 7-bit packed
    227      * GSM Alphabet representation of the string. If a header is provided,
    228      * this is included in the returned byte array and padded to a septet
    229      * boundary.
    230      *
    231      * Unencodable chars are encoded as spaces
    232      *
    233      * Byte 0 in the returned byte array is the count of septets used,
    234      * including the header and header padding. The returned byte array is
    235      * the minimum size required to store the packed septets. The returned
    236      * array cannot contain more than 255 septets.
    237      *
    238      * @param data The text string to encode.
    239      * @param header Optional header (including length byte) that precedes
    240      * the encoded data, padded to septet boundary.
    241      * @param languageTable the 7 bit language table, or 0 for the default GSM alphabet
    242      * @param languageShiftTable the 7 bit single shift language table, or 0 for the default
    243      *     GSM extension table
    244      * @return Byte array containing header and encoded data.
    245      * @throws EncodeException if String is too large to encode
    246      */
    247     public static byte[] stringToGsm7BitPackedWithHeader(String data, byte[] header,
    248             int languageTable, int languageShiftTable)
    249             throws EncodeException {
    250         if (header == null || header.length == 0) {
    251             return stringToGsm7BitPacked(data, languageTable, languageShiftTable);
    252         }
    253 
    254         int headerBits = (header.length + 1) * 8;
    255         int headerSeptets = (headerBits + 6) / 7;
    256 
    257         byte[] ret = stringToGsm7BitPacked(data, headerSeptets, true, languageTable,
    258                 languageShiftTable);
    259 
    260         // Paste in the header
    261         ret[1] = (byte)header.length;
    262         System.arraycopy(header, 0, ret, 2, header.length);
    263         return ret;
    264     }
    265 
    266     /**
    267      * Converts a String into a byte array containing
    268      * the 7-bit packed GSM Alphabet representation of the string.
    269      *
    270      * Unencodable chars are encoded as spaces
    271      *
    272      * Byte 0 in the returned byte array is the count of septets used
    273      * The returned byte array is the minimum size required to store
    274      * the packed septets. The returned array cannot contain more than 255
    275      * septets.
    276      *
    277      * @param data the data string to encode
    278      * @return the encoded string
    279      * @throws EncodeException if String is too large to encode
    280      */
    281     public static byte[] stringToGsm7BitPacked(String data)
    282             throws EncodeException {
    283         return stringToGsm7BitPacked(data, 0, true, 0, 0);
    284     }
    285 
    286     /**
    287      * Converts a String into a byte array containing
    288      * the 7-bit packed GSM Alphabet representation of the string.
    289      *
    290      * Unencodable chars are encoded as spaces
    291      *
    292      * Byte 0 in the returned byte array is the count of septets used
    293      * The returned byte array is the minimum size required to store
    294      * the packed septets. The returned array cannot contain more than 255
    295      * septets.
    296      *
    297      * @param data the data string to encode
    298      * @param languageTable the 7 bit language table, or 0 for the default GSM alphabet
    299      * @param languageShiftTable the 7 bit single shift language table, or 0 for the default
    300      *     GSM extension table
    301      * @return the encoded string
    302      * @throws EncodeException if String is too large to encode
    303      */
    304     public static byte[] stringToGsm7BitPacked(String data, int languageTable,
    305             int languageShiftTable)
    306             throws EncodeException {
    307         return stringToGsm7BitPacked(data, 0, true, languageTable, languageShiftTable);
    308     }
    309 
    310     /**
    311      * Converts a String into a byte array containing
    312      * the 7-bit packed GSM Alphabet representation of the string.
    313      *
    314      * Byte 0 in the returned byte array is the count of septets used
    315      * The returned byte array is the minimum size required to store
    316      * the packed septets. The returned array cannot contain more than 255
    317      * septets.
    318      *
    319      * @param data the text to convert to septets
    320      * @param startingSeptetOffset the number of padding septets to put before
    321      *  the character data at the beginning of the array
    322      * @param throwException If true, throws EncodeException on invalid char.
    323      *   If false, replaces unencodable char with GSM alphabet space char.
    324      * @param languageTable the 7 bit language table, or 0 for the default GSM alphabet
    325      * @param languageShiftTable the 7 bit single shift language table, or 0 for the default
    326      *     GSM extension table
    327      * @return the encoded message
    328      *
    329      * @throws EncodeException if String is too large to encode
    330      */
    331     public static byte[] stringToGsm7BitPacked(String data, int startingSeptetOffset,
    332             boolean throwException, int languageTable, int languageShiftTable)
    333             throws EncodeException {
    334         int dataLen = data.length();
    335         int septetCount = countGsmSeptetsUsingTables(data, !throwException,
    336                 languageTable, languageShiftTable);
    337         if (septetCount == -1) {
    338             throw new EncodeException("countGsmSeptetsUsingTables(): unencodable char");
    339         }
    340         septetCount += startingSeptetOffset;
    341         if (septetCount > 255) {
    342             throw new EncodeException("Payload cannot exceed 255 septets");
    343         }
    344         int byteCount = ((septetCount * 7) + 7) / 8;
    345         byte[] ret = new byte[byteCount + 1];  // Include space for one byte length prefix.
    346         SparseIntArray charToLanguageTable = sCharsToGsmTables[languageTable];
    347         SparseIntArray charToShiftTable = sCharsToShiftTables[languageShiftTable];
    348         for (int i = 0, septets = startingSeptetOffset, bitOffset = startingSeptetOffset * 7;
    349                  i < dataLen && septets < septetCount;
    350                  i++, bitOffset += 7) {
    351             char c = data.charAt(i);
    352             int v = charToLanguageTable.get(c, -1);
    353             if (v == -1) {
    354                 v = charToShiftTable.get(c, -1);  // Lookup the extended char.
    355                 if (v == -1) {
    356                     if (throwException) {
    357                         throw new EncodeException("stringToGsm7BitPacked(): unencodable char");
    358                     } else {
    359                         v = charToLanguageTable.get(' ', ' ');   // should return ASCII space
    360                     }
    361                 } else {
    362                     packSmsChar(ret, bitOffset, GSM_EXTENDED_ESCAPE);
    363                     bitOffset += 7;
    364                     septets++;
    365                 }
    366             }
    367             packSmsChar(ret, bitOffset, v);
    368             septets++;
    369         }
    370         ret[0] = (byte) (septetCount);  // Validated by check above.
    371         return ret;
    372     }
    373 
    374     /**
    375      * Pack a 7-bit char into its appropriate place in a byte array
    376      *
    377      * @param packedChars the destination byte array
    378      * @param bitOffset the bit offset that the septet should be packed at
    379      *                  (septet index * 7)
    380      * @param value the 7-bit character to store
    381      */
    382     private static void
    383     packSmsChar(byte[] packedChars, int bitOffset, int value) {
    384         int byteOffset = bitOffset / 8;
    385         int shift = bitOffset % 8;
    386 
    387         packedChars[++byteOffset] |= value << shift;
    388 
    389         if (shift > 1) {
    390             packedChars[++byteOffset] = (byte)(value >> (8 - shift));
    391         }
    392     }
    393 
    394     /**
    395      * Convert a GSM alphabet 7 bit packed string (SMS string) into a
    396      * {@link java.lang.String}.
    397      *
    398      * See TS 23.038 6.1.2.1 for SMS Character Packing
    399      *
    400      * @param pdu the raw data from the pdu
    401      * @param offset the byte offset of
    402      * @param lengthSeptets string length in septets, not bytes
    403      * @return String representation or null on decoding exception
    404      */
    405     public static String gsm7BitPackedToString(byte[] pdu, int offset,
    406             int lengthSeptets) {
    407         return gsm7BitPackedToString(pdu, offset, lengthSeptets, 0, 0, 0);
    408     }
    409 
    410     /**
    411      * Convert a GSM alphabet 7 bit packed string (SMS string) into a
    412      * {@link java.lang.String}.
    413      *
    414      * See TS 23.038 6.1.2.1 for SMS Character Packing
    415      *
    416      * @param pdu the raw data from the pdu
    417      * @param offset the byte offset of
    418      * @param lengthSeptets string length in septets, not bytes
    419      * @param numPaddingBits the number of padding bits before the start of the
    420      *  string in the first byte
    421      * @param languageTable the 7 bit language table, or 0 for the default GSM alphabet
    422      * @param shiftTable the 7 bit single shift language table, or 0 for the default
    423      *     GSM extension table
    424      * @return String representation or null on decoding exception
    425      */
    426     public static String gsm7BitPackedToString(byte[] pdu, int offset,
    427             int lengthSeptets, int numPaddingBits, int languageTable, int shiftTable) {
    428         StringBuilder ret = new StringBuilder(lengthSeptets);
    429 
    430         if (languageTable < 0 || languageTable > sLanguageTables.length) {
    431             Log.w(TAG, "unknown language table " + languageTable + ", using default");
    432             languageTable = 0;
    433         }
    434         if (shiftTable < 0 || shiftTable > sLanguageShiftTables.length) {
    435             Log.w(TAG, "unknown single shift table " + shiftTable + ", using default");
    436             shiftTable = 0;
    437         }
    438 
    439         try {
    440             boolean prevCharWasEscape = false;
    441             String languageTableToChar = sLanguageTables[languageTable];
    442             String shiftTableToChar = sLanguageShiftTables[shiftTable];
    443 
    444             if (languageTableToChar.isEmpty()) {
    445                 Log.w(TAG, "no language table for code " + languageTable + ", using default");
    446                 languageTableToChar = sLanguageTables[0];
    447             }
    448             if (shiftTableToChar.isEmpty()) {
    449                 Log.w(TAG, "no single shift table for code " + shiftTable + ", using default");
    450                 shiftTableToChar = sLanguageShiftTables[0];
    451             }
    452 
    453             for (int i = 0 ; i < lengthSeptets ; i++) {
    454                 int bitOffset = (7 * i) + numPaddingBits;
    455 
    456                 int byteOffset = bitOffset / 8;
    457                 int shift = bitOffset % 8;
    458                 int gsmVal;
    459 
    460                 gsmVal = (0x7f & (pdu[offset + byteOffset] >> shift));
    461 
    462                 // if it crosses a byte boundary
    463                 if (shift > 1) {
    464                     // set msb bits to 0
    465                     gsmVal &= 0x7f >> (shift - 1);
    466 
    467                     gsmVal |= 0x7f & (pdu[offset + byteOffset + 1] << (8 - shift));
    468                 }
    469 
    470                 if (prevCharWasEscape) {
    471                     if (gsmVal == GSM_EXTENDED_ESCAPE) {
    472                         ret.append(' ');    // display ' ' for reserved double escape sequence
    473                     } else {
    474                         char c = shiftTableToChar.charAt(gsmVal);
    475                         if (c == ' ') {
    476                             ret.append(languageTableToChar.charAt(gsmVal));
    477                         } else {
    478                             ret.append(c);
    479                         }
    480                     }
    481                     prevCharWasEscape = false;
    482                 } else if (gsmVal == GSM_EXTENDED_ESCAPE) {
    483                     prevCharWasEscape = true;
    484                 } else {
    485                     ret.append(languageTableToChar.charAt(gsmVal));
    486                 }
    487             }
    488         } catch (RuntimeException ex) {
    489             Log.e(TAG, "Error GSM 7 bit packed: ", ex);
    490             return null;
    491         }
    492 
    493         return ret.toString();
    494     }
    495 
    496 
    497     /**
    498      * Convert a GSM alphabet string that's stored in 8-bit unpacked
    499      * format (as it often appears in SIM records) into a String
    500      *
    501      * Field may be padded with trailing 0xff's. The decode stops
    502      * at the first 0xff encountered.
    503      *
    504      * @param data the byte array to decode
    505      * @param offset array offset for the first character to decode
    506      * @param length the number of bytes to decode
    507      * @return the decoded string
    508      */
    509     public static String
    510     gsm8BitUnpackedToString(byte[] data, int offset, int length) {
    511         return gsm8BitUnpackedToString(data, offset, length, "");
    512     }
    513 
    514     /**
    515      * Convert a GSM alphabet string that's stored in 8-bit unpacked
    516      * format (as it often appears in SIM records) into a String
    517      *
    518      * Field may be padded with trailing 0xff's. The decode stops
    519      * at the first 0xff encountered.
    520      *
    521      * Additionally, in some country(ex. Korea), there are non-ASCII or MBCS characters.
    522      * If a character set is given, characters in data are treat as MBCS.
    523      */
    524     public static String
    525     gsm8BitUnpackedToString(byte[] data, int offset, int length, String characterset) {
    526         boolean isMbcs = false;
    527         Charset charset = null;
    528         ByteBuffer mbcsBuffer = null;
    529 
    530         if (!TextUtils.isEmpty(characterset)
    531                 && !characterset.equalsIgnoreCase("us-ascii")
    532                 && Charset.isSupported(characterset)) {
    533             isMbcs = true;
    534             charset = Charset.forName(characterset);
    535             mbcsBuffer = ByteBuffer.allocate(2);
    536         }
    537 
    538         // Always use GSM 7 bit default alphabet table for this method
    539         String languageTableToChar = sLanguageTables[0];
    540         String shiftTableToChar = sLanguageShiftTables[0];
    541 
    542         StringBuilder ret = new StringBuilder(length);
    543         boolean prevWasEscape = false;
    544         for (int i = offset ; i < offset + length ; i++) {
    545             // Never underestimate the pain that can be caused
    546             // by signed bytes
    547             int c = data[i] & 0xff;
    548 
    549             if (c == 0xff) {
    550                 break;
    551             } else if (c == GSM_EXTENDED_ESCAPE) {
    552                 if (prevWasEscape) {
    553                     // Two escape chars in a row
    554                     // We treat this as a space
    555                     // See Note 1 in table 6.2.1.1 of TS 23.038 v7.00
    556                     ret.append(' ');
    557                     prevWasEscape = false;
    558                 } else {
    559                     prevWasEscape = true;
    560                 }
    561             } else {
    562                 if (prevWasEscape) {
    563                     char shiftChar = shiftTableToChar.charAt(c);
    564                     if (shiftChar == ' ') {
    565                         // display character from main table if not present in shift table
    566                         ret.append(languageTableToChar.charAt(c));
    567                     } else {
    568                         ret.append(shiftChar);
    569                     }
    570                 } else {
    571                     if (!isMbcs || c < 0x80 || i + 1 >= offset + length) {
    572                         ret.append(languageTableToChar.charAt(c));
    573                     } else {
    574                         // isMbcs must be true. So both mbcsBuffer and charset are initialized.
    575                         mbcsBuffer.clear();
    576                         mbcsBuffer.put(data, i++, 2);
    577                         mbcsBuffer.flip();
    578                         ret.append(charset.decode(mbcsBuffer).toString());
    579                     }
    580                 }
    581                 prevWasEscape = false;
    582             }
    583         }
    584 
    585         return ret.toString();
    586     }
    587 
    588     /**
    589      * Convert a string into an 8-bit unpacked GSM alphabet byte array.
    590      * Always uses GSM default 7-bit alphabet and extension table.
    591      * @param s the string to encode
    592      * @return the 8-bit GSM encoded byte array for the string
    593      */
    594     public static byte[]
    595     stringToGsm8BitPacked(String s) {
    596         byte[] ret;
    597 
    598         int septets = countGsmSeptetsUsingTables(s, true, 0, 0);
    599 
    600         // Enough for all the septets and the length byte prefix
    601         ret = new byte[septets];
    602 
    603         stringToGsm8BitUnpackedField(s, ret, 0, ret.length);
    604 
    605         return ret;
    606     }
    607 
    608 
    609     /**
    610      * Write a String into a GSM 8-bit unpacked field of
    611      * Field is padded with 0xff's, string is truncated if necessary
    612      *
    613      * @param s the string to encode
    614      * @param dest the destination byte array
    615      * @param offset the starting offset for the encoded string
    616      * @param length the maximum number of bytes to write
    617      */
    618     public static void
    619     stringToGsm8BitUnpackedField(String s, byte dest[], int offset, int length) {
    620         int outByteIndex = offset;
    621         SparseIntArray charToLanguageTable = sCharsToGsmTables[0];
    622         SparseIntArray charToShiftTable = sCharsToShiftTables[0];
    623 
    624         // Septets are stored in byte-aligned octets
    625         for (int i = 0, sz = s.length()
    626                 ; i < sz && (outByteIndex - offset) < length
    627                 ; i++
    628         ) {
    629             char c = s.charAt(i);
    630 
    631             int v = charToLanguageTable.get(c, -1);
    632 
    633             if (v == -1) {
    634                 v = charToShiftTable.get(c, -1);
    635                 if (v == -1) {
    636                     v = charToLanguageTable.get(' ', ' ');  // fall back to ASCII space
    637                 } else {
    638                     // make sure we can fit an escaped char
    639                     if (! (outByteIndex + 1 - offset < length)) {
    640                         break;
    641                     }
    642 
    643                     dest[outByteIndex++] = GSM_EXTENDED_ESCAPE;
    644                 }
    645             }
    646 
    647             dest[outByteIndex++] = (byte)v;
    648         }
    649 
    650         // pad with 0xff's
    651         while((outByteIndex - offset) < length) {
    652             dest[outByteIndex++] = (byte)0xff;
    653         }
    654     }
    655 
    656     /**
    657      * Returns the count of 7-bit GSM alphabet characters
    658      * needed to represent this character. Counts unencodable char as 1 septet.
    659      * @param c the character to examine
    660      * @return the number of septets for this character
    661      */
    662     public static int
    663     countGsmSeptets(char c) {
    664         try {
    665             return countGsmSeptets(c, false);
    666         } catch (EncodeException ex) {
    667             // This should never happen.
    668             return 0;
    669         }
    670     }
    671 
    672     /**
    673      * Returns the count of 7-bit GSM alphabet characters
    674      * needed to represent this character using the default 7 bit GSM alphabet.
    675      * @param c the character to examine
    676      * @param throwsException If true, throws EncodeException if unencodable
    677      * char. Otherwise, counts invalid char as 1 septet.
    678      * @return the number of septets for this character
    679      * @throws EncodeException the character can't be encoded and throwsException is true
    680      */
    681     public static int
    682     countGsmSeptets(char c, boolean throwsException) throws EncodeException {
    683         if (sCharsToGsmTables[0].get(c, -1) != -1) {
    684             return 1;
    685         }
    686 
    687         if (sCharsToShiftTables[0].get(c, -1) != -1) {
    688             return 2;
    689         }
    690 
    691         if (throwsException) {
    692             throw new EncodeException(c);
    693         } else {
    694             // count as a space char
    695             return 1;
    696         }
    697     }
    698 
    699     /**
    700      * Returns the count of 7-bit GSM alphabet characters needed
    701      * to represent this string, using the specified 7-bit language table
    702      * and extension table (0 for GSM default tables).
    703      * @param s the Unicode string that will be encoded
    704      * @param use7bitOnly allow using space in place of unencodable character if true,
    705      *     otherwise, return -1 if any characters are unencodable
    706      * @param languageTable the 7 bit language table, or 0 for the default GSM alphabet
    707      * @param languageShiftTable the 7 bit single shift language table, or 0 for the default
    708      *     GSM extension table
    709      * @return the septet count for s using the specified language tables, or -1 if any
    710      *     characters are unencodable and use7bitOnly is false
    711      */
    712     public static int countGsmSeptetsUsingTables(CharSequence s, boolean use7bitOnly,
    713             int languageTable, int languageShiftTable) {
    714         int count = 0;
    715         int sz = s.length();
    716         SparseIntArray charToLanguageTable = sCharsToGsmTables[languageTable];
    717         SparseIntArray charToShiftTable = sCharsToShiftTables[languageShiftTable];
    718         for (int i = 0; i < sz; i++) {
    719             char c = s.charAt(i);
    720             if (c == GSM_EXTENDED_ESCAPE) {
    721                 Log.w(TAG, "countGsmSeptets() string contains Escape character, skipping.");
    722                 continue;
    723             }
    724             if (charToLanguageTable.get(c, -1) != -1) {
    725                 count++;
    726             } else if (charToShiftTable.get(c, -1) != -1) {
    727                 count += 2; // escape + shift table index
    728             } else if (use7bitOnly) {
    729                 count++;    // encode as space
    730             } else {
    731                 return -1;  // caller must check for this case
    732             }
    733         }
    734         return count;
    735     }
    736 
    737     /**
    738      * Returns the count of 7-bit GSM alphabet characters
    739      * needed to represent this string, and the language table and
    740      * language shift table used to achieve this result.
    741      * For multi-part text messages, each message part may use its
    742      * own language table encoding as specified in the message header
    743      * for that message. However, this method will only return the
    744      * optimal encoding for the message as a whole. When the individual
    745      * pieces are encoded, a more optimal encoding may be chosen for each
    746      * piece of the message, but the message will be split into pieces
    747      * based on the encoding chosen for the message as a whole.
    748      * @param s the Unicode string that will be encoded
    749      * @param use7bitOnly allow using space in place of unencodable character if true,
    750      *     using the language table pair with the fewest unencodable characters
    751      * @return a TextEncodingDetails object containing the message and
    752      *     character counts for the most efficient 7-bit encoding,
    753      *     or null if there are no suitable language tables to encode the string.
    754      */
    755     public static SmsMessageBase.TextEncodingDetails
    756     countGsmSeptets(CharSequence s, boolean use7bitOnly) {
    757         // fast path for common case where no national language shift tables are enabled
    758         if (sEnabledSingleShiftTables.length + sEnabledLockingShiftTables.length == 0) {
    759             SmsMessageBase.TextEncodingDetails ted = new SmsMessageBase.TextEncodingDetails();
    760             int septets = GsmAlphabet.countGsmSeptetsUsingTables(s, use7bitOnly, 0, 0);
    761             if (septets == -1) {
    762                 return null;
    763             }
    764             ted.codeUnitSize = ENCODING_7BIT;
    765             ted.codeUnitCount = septets;
    766             if (septets > MAX_USER_DATA_SEPTETS) {
    767                 ted.msgCount = (septets + (MAX_USER_DATA_SEPTETS_WITH_HEADER - 1)) /
    768                         MAX_USER_DATA_SEPTETS_WITH_HEADER;
    769                 ted.codeUnitsRemaining = (ted.msgCount *
    770                         MAX_USER_DATA_SEPTETS_WITH_HEADER) - septets;
    771             } else {
    772                 ted.msgCount = 1;
    773                 ted.codeUnitsRemaining = MAX_USER_DATA_SEPTETS - septets;
    774             }
    775             ted.codeUnitSize = ENCODING_7BIT;
    776             return ted;
    777         }
    778 
    779         int maxSingleShiftCode = sHighestEnabledSingleShiftCode;
    780         List<LanguagePairCount> lpcList = new ArrayList<LanguagePairCount>(
    781                 sEnabledLockingShiftTables.length + 1);
    782 
    783         // Always add default GSM 7-bit alphabet table
    784         lpcList.add(new LanguagePairCount(0));
    785         for (int i : sEnabledLockingShiftTables) {
    786             // Avoid adding default table twice in case 0 is in the list of allowed tables
    787             if (i != 0 && !sLanguageTables[i].isEmpty()) {
    788                 lpcList.add(new LanguagePairCount(i));
    789             }
    790         }
    791 
    792         int sz = s.length();
    793         // calculate septet count for each valid table / shift table pair
    794         for (int i = 0; i < sz && !lpcList.isEmpty(); i++) {
    795             char c = s.charAt(i);
    796             if (c == GSM_EXTENDED_ESCAPE) {
    797                 Log.w(TAG, "countGsmSeptets() string contains Escape character, ignoring!");
    798                 continue;
    799             }
    800             // iterate through enabled locking shift tables
    801             for (LanguagePairCount lpc : lpcList) {
    802                 int tableIndex = sCharsToGsmTables[lpc.languageCode].get(c, -1);
    803                 if (tableIndex == -1) {
    804                     // iterate through single shift tables for this locking table
    805                     for (int table = 0; table <= maxSingleShiftCode; table++) {
    806                         if (lpc.septetCounts[table] != -1) {
    807                             int shiftTableIndex = sCharsToShiftTables[table].get(c, -1);
    808                             if (shiftTableIndex == -1) {
    809                                 if (use7bitOnly) {
    810                                     // can't encode char, use space instead
    811                                     lpc.septetCounts[table]++;
    812                                     lpc.unencodableCounts[table]++;
    813                                 } else {
    814                                     // can't encode char, remove language pair from list
    815                                     lpc.septetCounts[table] = -1;
    816                                 }
    817                             } else {
    818                                 // encode as Escape + index into shift table
    819                                 lpc.septetCounts[table] += 2;
    820                             }
    821                         }
    822                     }
    823                 } else {
    824                     // encode as index into locking shift table for all pairs
    825                     for (int table = 0; table <= maxSingleShiftCode; table++) {
    826                         if (lpc.septetCounts[table] != -1) {
    827                             lpc.septetCounts[table]++;
    828                         }
    829                     }
    830                 }
    831             }
    832         }
    833 
    834         // find the least cost encoding (lowest message count and most code units remaining)
    835         SmsMessageBase.TextEncodingDetails ted = new SmsMessageBase.TextEncodingDetails();
    836         ted.msgCount = Integer.MAX_VALUE;
    837         ted.codeUnitSize = ENCODING_7BIT;
    838         int minUnencodableCount = Integer.MAX_VALUE;
    839         for (LanguagePairCount lpc : lpcList) {
    840             for (int shiftTable = 0; shiftTable <= maxSingleShiftCode; shiftTable++) {
    841                 int septets = lpc.septetCounts[shiftTable];
    842                 if (septets == -1) {
    843                     continue;
    844                 }
    845                 int udhLength;
    846                 if (lpc.languageCode != 0 && shiftTable != 0) {
    847                     udhLength = UDH_SEPTET_COST_LENGTH + UDH_SEPTET_COST_TWO_SHIFT_TABLES;
    848                 } else if (lpc.languageCode != 0 || shiftTable != 0) {
    849                     udhLength = UDH_SEPTET_COST_LENGTH + UDH_SEPTET_COST_ONE_SHIFT_TABLE;
    850                 } else {
    851                     udhLength = 0;
    852                 }
    853                 int msgCount;
    854                 int septetsRemaining;
    855                 if (septets + udhLength > MAX_USER_DATA_SEPTETS) {
    856                     if (udhLength == 0) {
    857                         udhLength = UDH_SEPTET_COST_LENGTH;
    858                     }
    859                     udhLength += UDH_SEPTET_COST_CONCATENATED_MESSAGE;
    860                     int septetsPerMessage = MAX_USER_DATA_SEPTETS - udhLength;
    861                     msgCount = (septets + septetsPerMessage - 1) / septetsPerMessage;
    862                     septetsRemaining = (msgCount * septetsPerMessage) - septets;
    863                 } else {
    864                     msgCount = 1;
    865                     septetsRemaining = MAX_USER_DATA_SEPTETS - udhLength - septets;
    866                 }
    867                 // for 7-bit only mode, use language pair with the least unencodable chars
    868                 int unencodableCount = lpc.unencodableCounts[shiftTable];
    869                 if (use7bitOnly && unencodableCount > minUnencodableCount) {
    870                     continue;
    871                 }
    872                 if ((use7bitOnly && unencodableCount < minUnencodableCount)
    873                         || msgCount < ted.msgCount || (msgCount == ted.msgCount
    874                         && septetsRemaining > ted.codeUnitsRemaining)) {
    875                     minUnencodableCount = unencodableCount;
    876                     ted.msgCount = msgCount;
    877                     ted.codeUnitCount = septets;
    878                     ted.codeUnitsRemaining = septetsRemaining;
    879                     ted.languageTable = lpc.languageCode;
    880                     ted.languageShiftTable = shiftTable;
    881                 }
    882             }
    883         }
    884 
    885         if (ted.msgCount == Integer.MAX_VALUE) {
    886             return null;
    887         }
    888 
    889         return ted;
    890     }
    891 
    892     /**
    893      * Returns the index into <code>s</code> of the first character
    894      * after <code>limit</code> septets have been reached, starting at
    895      * index <code>start</code>.  This is used when dividing messages
    896      * into units within the SMS message size limit.
    897      *
    898      * @param s source string
    899      * @param start index of where to start counting septets
    900      * @param limit maximum septets to include,
    901      *   e.g. <code>MAX_USER_DATA_SEPTETS</code>
    902      * @param langTable the 7 bit character table to use (0 for default GSM 7-bit alphabet)
    903      * @param langShiftTable the 7 bit shift table to use (0 for default GSM extension table)
    904      * @return index of first character that won't fit, or the length
    905      *   of the entire string if everything fits
    906      */
    907     public static int
    908     findGsmSeptetLimitIndex(String s, int start, int limit, int langTable, int langShiftTable) {
    909         int accumulator = 0;
    910         int size = s.length();
    911 
    912         SparseIntArray charToLangTable = sCharsToGsmTables[langTable];
    913         SparseIntArray charToLangShiftTable = sCharsToShiftTables[langShiftTable];
    914         for (int i = start; i < size; i++) {
    915             int encodedSeptet = charToLangTable.get(s.charAt(i), -1);
    916             if (encodedSeptet == -1) {
    917                 encodedSeptet = charToLangShiftTable.get(s.charAt(i), -1);
    918                 if (encodedSeptet == -1) {
    919                     // char not found, assume we're replacing with space
    920                     accumulator++;
    921                 } else {
    922                     accumulator += 2;  // escape character + shift table index
    923                 }
    924             } else {
    925                 accumulator++;
    926             }
    927             if (accumulator > limit) {
    928                 return i;
    929             }
    930         }
    931         return size;
    932     }
    933 
    934     /**
    935      * Modify the array of enabled national language single shift tables for SMS
    936      * encoding. This is used for unit testing, but could also be used to
    937      * modify the enabled encodings based on the active MCC/MNC, for example.
    938      *
    939      * @param tables the new list of enabled single shift tables
    940      */
    941     static synchronized void setEnabledSingleShiftTables(int[] tables) {
    942         sEnabledSingleShiftTables = tables;
    943 
    944         if (tables.length > 0) {
    945             sHighestEnabledSingleShiftCode = tables[tables.length - 1];
    946         } else {
    947             sHighestEnabledSingleShiftCode = 0;
    948         }
    949     }
    950 
    951     /**
    952      * Modify the array of enabled national language locking shift tables for SMS
    953      * encoding. This is used for unit testing, but could also be used to
    954      * modify the enabled encodings based on the active MCC/MNC, for example.
    955      *
    956      * @param tables the new list of enabled locking shift tables
    957      */
    958     static synchronized void setEnabledLockingShiftTables(int[] tables) {
    959         sEnabledLockingShiftTables = tables;
    960     }
    961 
    962     /**
    963      * Return the array of enabled national language single shift tables for SMS
    964      * encoding. This is used for unit testing. The returned array is not a copy, so
    965      * the caller should be careful not to modify it.
    966      *
    967      * @return the list of enabled single shift tables
    968      */
    969     static synchronized int[] getEnabledSingleShiftTables() {
    970         return sEnabledSingleShiftTables;
    971     }
    972 
    973     /**
    974      * Return the array of enabled national language locking shift tables for SMS
    975      * encoding. This is used for unit testing. The returned array is not a copy, so
    976      * the caller should be careful not to modify it.
    977      *
    978      * @return the list of enabled locking shift tables
    979      */
    980     static synchronized int[] getEnabledLockingShiftTables() {
    981         return sEnabledLockingShiftTables;
    982     }
    983 
    984     /** Reverse mapping from Unicode characters to indexes into language tables. */
    985     private static final SparseIntArray[] sCharsToGsmTables;
    986 
    987     /** Reverse mapping from Unicode characters to indexes into language shift tables. */
    988     private static final SparseIntArray[] sCharsToShiftTables;
    989 
    990     /** OEM configured list of enabled national language single shift tables for encoding. */
    991     private static int[] sEnabledSingleShiftTables;
    992 
    993     /** OEM configured list of enabled national language locking shift tables for encoding. */
    994     private static int[] sEnabledLockingShiftTables;
    995 
    996     /** Highest language code to include in array of single shift counters. */
    997     private static int sHighestEnabledSingleShiftCode;
    998 
    999     /**
   1000      * Septet counter for a specific locking shift table and all of
   1001      * the single shift tables that it can be paired with.
   1002      */
   1003     private static class LanguagePairCount {
   1004         final int languageCode;
   1005         final int[] septetCounts;
   1006         final int[] unencodableCounts;
   1007         LanguagePairCount(int code) {
   1008             this.languageCode = code;
   1009             int maxSingleShiftCode = sHighestEnabledSingleShiftCode;
   1010             septetCounts = new int[maxSingleShiftCode + 1];
   1011             unencodableCounts = new int[maxSingleShiftCode + 1];
   1012             // set counters for disabled single shift tables to -1
   1013             // (GSM default extension table index 0 is always enabled)
   1014             for (int i = 1, tableOffset = 0; i <= maxSingleShiftCode; i++) {
   1015                 if (sEnabledSingleShiftTables[tableOffset] == i) {
   1016                     tableOffset++;
   1017                 } else {
   1018                     septetCounts[i] = -1;   // disabled
   1019                 }
   1020             }
   1021             // exclude Turkish locking + Turkish single shift table and
   1022             // Portuguese locking + Spanish single shift table (these
   1023             // combinations will never be optimal for any input).
   1024             if (code == 1 && maxSingleShiftCode >= 1) {
   1025                 septetCounts[1] = -1;   // Turkish + Turkish
   1026             } else if (code == 3 && maxSingleShiftCode >= 2) {
   1027                 septetCounts[2] = -1;   // Portuguese + Spanish
   1028             }
   1029         }
   1030     }
   1031 
   1032     /**
   1033      * GSM default 7 bit alphabet plus national language locking shift character tables.
   1034      * Comment lines above strings indicate the lower four bits of the table position.
   1035      */
   1036     private static final String[] sLanguageTables = {
   1037         /* 3GPP TS 23.038 V9.1.1 section 6.2.1 - GSM 7 bit Default Alphabet
   1038          01.....23.....4.....5.....6.....7.....8.....9.....A.B.....C.....D.E.....F.....0.....1 */
   1039         "@\u00a3$\u00a5\u00e8\u00e9\u00f9\u00ec\u00f2\u00c7\n\u00d8\u00f8\r\u00c5\u00e5\u0394_"
   1040             // 2.....3.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....E.....
   1041             + "\u03a6\u0393\u039b\u03a9\u03a0\u03a8\u03a3\u0398\u039e\uffff\u00c6\u00e6\u00df"
   1042             // F.....012.34.....56789ABCDEF0123456789ABCDEF0.....123456789ABCDEF0123456789A
   1043             + "\u00c9 !\"#\u00a4%&'()*+,-./0123456789:;<=>?\u00a1ABCDEFGHIJKLMNOPQRSTUVWXYZ"
   1044             // B.....C.....D.....E.....F.....0.....123456789ABCDEF0123456789AB.....C.....D.....
   1045             + "\u00c4\u00d6\u00d1\u00dc\u00a7\u00bfabcdefghijklmnopqrstuvwxyz\u00e4\u00f6\u00f1"
   1046             // E.....F.....
   1047             + "\u00fc\u00e0",
   1048 
   1049         /* A.3.1 Turkish National Language Locking Shift Table
   1050          01.....23.....4.....5.....6.....7.....8.....9.....A.B.....C.....D.E.....F.....0.....1 */
   1051         "@\u00a3$\u00a5\u20ac\u00e9\u00f9\u0131\u00f2\u00c7\n\u011e\u011f\r\u00c5\u00e5\u0394_"
   1052             // 2.....3.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....E.....
   1053             + "\u03a6\u0393\u039b\u03a9\u03a0\u03a8\u03a3\u0398\u039e\uffff\u015e\u015f\u00df"
   1054             // F.....012.34.....56789ABCDEF0123456789ABCDEF0.....123456789ABCDEF0123456789A
   1055             + "\u00c9 !\"#\u00a4%&'()*+,-./0123456789:;<=>?\u0130ABCDEFGHIJKLMNOPQRSTUVWXYZ"
   1056             // B.....C.....D.....E.....F.....0.....123456789ABCDEF0123456789AB.....C.....D.....
   1057             + "\u00c4\u00d6\u00d1\u00dc\u00a7\u00e7abcdefghijklmnopqrstuvwxyz\u00e4\u00f6\u00f1"
   1058             // E.....F.....
   1059             + "\u00fc\u00e0",
   1060 
   1061         /* A.3.2 Void (no locking shift table for Spanish) */
   1062         "",
   1063 
   1064         /* A.3.3 Portuguese National Language Locking Shift Table
   1065          01.....23.....4.....5.....6.....7.....8.....9.....A.B.....C.....D.E.....F.....0.....1 */
   1066         "@\u00a3$\u00a5\u00ea\u00e9\u00fa\u00ed\u00f3\u00e7\n\u00d4\u00f4\r\u00c1\u00e1\u0394_"
   1067             // 2.....3.....4.....5.....67.8.....9.....AB.....C.....D.....E.....F.....012.34.....
   1068             + "\u00aa\u00c7\u00c0\u221e^\\\u20ac\u00d3|\uffff\u00c2\u00e2\u00ca\u00c9 !\"#\u00ba"
   1069             // 56789ABCDEF0123456789ABCDEF0.....123456789ABCDEF0123456789AB.....C.....D.....E.....
   1070             + "%&'()*+,-./0123456789:;<=>?\u00cdABCDEFGHIJKLMNOPQRSTUVWXYZ\u00c3\u00d5\u00da\u00dc"
   1071             // F.....0123456789ABCDEF0123456789AB.....C.....DE.....F.....
   1072             + "\u00a7~abcdefghijklmnopqrstuvwxyz\u00e3\u00f5`\u00fc\u00e0",
   1073 
   1074         /* A.3.4 Bengali National Language Locking Shift Table
   1075          0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.B.....CD.EF.....0..... */
   1076         "\u0981\u0982\u0983\u0985\u0986\u0987\u0988\u0989\u098a\u098b\n\u098c \r \u098f\u0990"
   1077             // 123.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....E.....F.....
   1078             + "  \u0993\u0994\u0995\u0996\u0997\u0998\u0999\u099a\uffff\u099b\u099c\u099d\u099e"
   1079             // 012.....3.....4.....5.....6.....7.....89A.....B.....CD.....EF.....0123456789ABC
   1080             + " !\u099f\u09a0\u09a1\u09a2\u09a3\u09a4)(\u09a5\u09a6,\u09a7.\u09a80123456789:; "
   1081             // D.....E.....F0.....1.....2.....3.....4.....56.....789A.....B.....C.....D.....
   1082             + "\u09aa\u09ab?\u09ac\u09ad\u09ae\u09af\u09b0 \u09b2   \u09b6\u09b7\u09b8\u09b9"
   1083             // E.....F.....0.....1.....2.....3.....4.....5.....6.....789.....A.....BCD.....E.....
   1084             + "\u09bc\u09bd\u09be\u09bf\u09c0\u09c1\u09c2\u09c3\u09c4  \u09c7\u09c8  \u09cb\u09cc"
   1085             // F.....0.....123456789ABCDEF0123456789AB.....C.....D.....E.....F.....
   1086             + "\u09cd\u09ceabcdefghijklmnopqrstuvwxyz\u09d7\u09dc\u09dd\u09f0\u09f1",
   1087 
   1088         /* A.3.5 Gujarati National Language Locking Shift Table
   1089          0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.B.....C.....D.EF.....0.....*/
   1090         "\u0a81\u0a82\u0a83\u0a85\u0a86\u0a87\u0a88\u0a89\u0a8a\u0a8b\n\u0a8c\u0a8d\r \u0a8f\u0a90"
   1091             // 1.....23.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....E.....
   1092             + "\u0a91 \u0a93\u0a94\u0a95\u0a96\u0a97\u0a98\u0a99\u0a9a\uffff\u0a9b\u0a9c\u0a9d"
   1093             // F.....012.....3.....4.....5.....6.....7.....89A.....B.....CD.....EF.....0123456789AB
   1094             + "\u0a9e !\u0a9f\u0aa0\u0aa1\u0aa2\u0aa3\u0aa4)(\u0aa5\u0aa6,\u0aa7.\u0aa80123456789:;"
   1095             // CD.....E.....F0.....1.....2.....3.....4.....56.....7.....89.....A.....B.....C.....
   1096             + " \u0aaa\u0aab?\u0aac\u0aad\u0aae\u0aaf\u0ab0 \u0ab2\u0ab3 \u0ab5\u0ab6\u0ab7\u0ab8"
   1097             // D.....E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89.....A.....
   1098             + "\u0ab9\u0abc\u0abd\u0abe\u0abf\u0ac0\u0ac1\u0ac2\u0ac3\u0ac4\u0ac5 \u0ac7\u0ac8"
   1099             // B.....CD.....E.....F.....0.....123456789ABCDEF0123456789AB.....C.....D.....E.....
   1100             + "\u0ac9 \u0acb\u0acc\u0acd\u0ad0abcdefghijklmnopqrstuvwxyz\u0ae0\u0ae1\u0ae2\u0ae3"
   1101             // F.....
   1102             + "\u0af1",
   1103 
   1104         /* A.3.6 Hindi National Language Locking Shift Table
   1105          0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.B.....C.....D.E.....F.....*/
   1106         "\u0901\u0902\u0903\u0905\u0906\u0907\u0908\u0909\u090a\u090b\n\u090c\u090d\r\u090e\u090f"
   1107             // 0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....
   1108             + "\u0910\u0911\u0912\u0913\u0914\u0915\u0916\u0917\u0918\u0919\u091a\uffff\u091b\u091c"
   1109             // E.....F.....012.....3.....4.....5.....6.....7.....89A.....B.....CD.....EF.....012345
   1110             + "\u091d\u091e !\u091f\u0920\u0921\u0922\u0923\u0924)(\u0925\u0926,\u0927.\u0928012345"
   1111             // 6789ABC.....D.....E.....F0.....1.....2.....3.....4.....5.....6.....7.....8.....
   1112             + "6789:;\u0929\u092a\u092b?\u092c\u092d\u092e\u092f\u0930\u0931\u0932\u0933\u0934"
   1113             // 9.....A.....B.....C.....D.....E.....F.....0.....1.....2.....3.....4.....5.....6.....
   1114             + "\u0935\u0936\u0937\u0938\u0939\u093c\u093d\u093e\u093f\u0940\u0941\u0942\u0943\u0944"
   1115             // 7.....8.....9.....A.....B.....C.....D.....E.....F.....0.....123456789ABCDEF012345678
   1116             + "\u0945\u0946\u0947\u0948\u0949\u094a\u094b\u094c\u094d\u0950abcdefghijklmnopqrstuvwx"
   1117             // 9AB.....C.....D.....E.....F.....
   1118             + "yz\u0972\u097b\u097c\u097e\u097f",
   1119 
   1120         /* A.3.7 Kannada National Language Locking Shift Table
   1121            NOTE: TS 23.038 V9.1.1 shows code 0x24 as \u0caa, corrected to \u0ca1 (typo)
   1122          01.....2.....3.....4.....5.....6.....7.....8.....9.....A.B.....CD.E.....F.....0.....1 */
   1123         " \u0c82\u0c83\u0c85\u0c86\u0c87\u0c88\u0c89\u0c8a\u0c8b\n\u0c8c \r\u0c8e\u0c8f\u0c90 "
   1124             // 2.....3.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....E.....F.....
   1125             + "\u0c92\u0c93\u0c94\u0c95\u0c96\u0c97\u0c98\u0c99\u0c9a\uffff\u0c9b\u0c9c\u0c9d\u0c9e"
   1126             // 012.....3.....4.....5.....6.....7.....89A.....B.....CD.....EF.....0123456789ABC
   1127             + " !\u0c9f\u0ca0\u0ca1\u0ca2\u0ca3\u0ca4)(\u0ca5\u0ca6,\u0ca7.\u0ca80123456789:; "
   1128             // D.....E.....F0.....1.....2.....3.....4.....5.....6.....7.....89.....A.....B.....
   1129             + "\u0caa\u0cab?\u0cac\u0cad\u0cae\u0caf\u0cb0\u0cb1\u0cb2\u0cb3 \u0cb5\u0cb6\u0cb7"
   1130             // C.....D.....E.....F.....0.....1.....2.....3.....4.....5.....6.....78.....9.....
   1131             + "\u0cb8\u0cb9\u0cbc\u0cbd\u0cbe\u0cbf\u0cc0\u0cc1\u0cc2\u0cc3\u0cc4 \u0cc6\u0cc7"
   1132             // A.....BC.....D.....E.....F.....0.....123456789ABCDEF0123456789AB.....C.....D.....
   1133             + "\u0cc8 \u0cca\u0ccb\u0ccc\u0ccd\u0cd5abcdefghijklmnopqrstuvwxyz\u0cd6\u0ce0\u0ce1"
   1134             // E.....F.....
   1135             + "\u0ce2\u0ce3",
   1136 
   1137         /* A.3.8 Malayalam National Language Locking Shift Table
   1138          01.....2.....3.....4.....5.....6.....7.....8.....9.....A.B.....CD.E.....F.....0.....1 */
   1139         " \u0d02\u0d03\u0d05\u0d06\u0d07\u0d08\u0d09\u0d0a\u0d0b\n\u0d0c \r\u0d0e\u0d0f\u0d10 "
   1140             // 2.....3.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....E.....F.....
   1141             + "\u0d12\u0d13\u0d14\u0d15\u0d16\u0d17\u0d18\u0d19\u0d1a\uffff\u0d1b\u0d1c\u0d1d\u0d1e"
   1142             // 012.....3.....4.....5.....6.....7.....89A.....B.....CD.....EF.....0123456789ABC
   1143             + " !\u0d1f\u0d20\u0d21\u0d22\u0d23\u0d24)(\u0d25\u0d26,\u0d27.\u0d280123456789:; "
   1144             // D.....E.....F0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.....
   1145             + "\u0d2a\u0d2b?\u0d2c\u0d2d\u0d2e\u0d2f\u0d30\u0d31\u0d32\u0d33\u0d34\u0d35\u0d36"
   1146             // B.....C.....D.....EF.....0.....1.....2.....3.....4.....5.....6.....78.....9.....
   1147             + "\u0d37\u0d38\u0d39 \u0d3d\u0d3e\u0d3f\u0d40\u0d41\u0d42\u0d43\u0d44 \u0d46\u0d47"
   1148             // A.....BC.....D.....E.....F.....0.....123456789ABCDEF0123456789AB.....C.....D.....
   1149             + "\u0d48 \u0d4a\u0d4b\u0d4c\u0d4d\u0d57abcdefghijklmnopqrstuvwxyz\u0d60\u0d61\u0d62"
   1150             // E.....F.....
   1151             + "\u0d63\u0d79",
   1152 
   1153         /* A.3.9 Oriya National Language Locking Shift Table
   1154          0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.B.....CD.EF.....0.....12 */
   1155         "\u0b01\u0b02\u0b03\u0b05\u0b06\u0b07\u0b08\u0b09\u0b0a\u0b0b\n\u0b0c \r \u0b0f\u0b10  "
   1156             // 3.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....E.....F.....01
   1157             + "\u0b13\u0b14\u0b15\u0b16\u0b17\u0b18\u0b19\u0b1a\uffff\u0b1b\u0b1c\u0b1d\u0b1e !"
   1158             // 2.....3.....4.....5.....6.....7.....89A.....B.....CD.....EF.....0123456789ABCD.....
   1159             + "\u0b1f\u0b20\u0b21\u0b22\u0b23\u0b24)(\u0b25\u0b26,\u0b27.\u0b280123456789:; \u0b2a"
   1160             // E.....F0.....1.....2.....3.....4.....56.....7.....89.....A.....B.....C.....D.....
   1161             + "\u0b2b?\u0b2c\u0b2d\u0b2e\u0b2f\u0b30 \u0b32\u0b33 \u0b35\u0b36\u0b37\u0b38\u0b39"
   1162             // E.....F.....0.....1.....2.....3.....4.....5.....6.....789.....A.....BCD.....E.....
   1163             + "\u0b3c\u0b3d\u0b3e\u0b3f\u0b40\u0b41\u0b42\u0b43\u0b44  \u0b47\u0b48  \u0b4b\u0b4c"
   1164             // F.....0.....123456789ABCDEF0123456789AB.....C.....D.....E.....F.....
   1165             + "\u0b4d\u0b56abcdefghijklmnopqrstuvwxyz\u0b57\u0b60\u0b61\u0b62\u0b63",
   1166 
   1167         /* A.3.10 Punjabi National Language Locking Shift Table
   1168          0.....1.....2.....3.....4.....5.....6.....7.....8.....9A.BCD.EF.....0.....123.....4.....*/
   1169         "\u0a01\u0a02\u0a03\u0a05\u0a06\u0a07\u0a08\u0a09\u0a0a \n  \r \u0a0f\u0a10  \u0a13\u0a14"
   1170             // 5.....6.....7.....8.....9.....A.....B.....C.....D.....E.....F.....012.....3.....
   1171             + "\u0a15\u0a16\u0a17\u0a18\u0a19\u0a1a\uffff\u0a1b\u0a1c\u0a1d\u0a1e !\u0a1f\u0a20"
   1172             // 4.....5.....6.....7.....89A.....B.....CD.....EF.....0123456789ABCD.....E.....F0.....
   1173             + "\u0a21\u0a22\u0a23\u0a24)(\u0a25\u0a26,\u0a27.\u0a280123456789:; \u0a2a\u0a2b?\u0a2c"
   1174             // 1.....2.....3.....4.....56.....7.....89.....A.....BC.....D.....E.....F0.....1.....
   1175             + "\u0a2d\u0a2e\u0a2f\u0a30 \u0a32\u0a33 \u0a35\u0a36 \u0a38\u0a39\u0a3c \u0a3e\u0a3f"
   1176             // 2.....3.....4.....56789.....A.....BCD.....E.....F.....0.....123456789ABCDEF012345678
   1177             + "\u0a40\u0a41\u0a42    \u0a47\u0a48  \u0a4b\u0a4c\u0a4d\u0a51abcdefghijklmnopqrstuvwx"
   1178             // 9AB.....C.....D.....E.....F.....
   1179             + "yz\u0a70\u0a71\u0a72\u0a73\u0a74",
   1180 
   1181         /* A.3.11 Tamil National Language Locking Shift Table
   1182          01.....2.....3.....4.....5.....6.....7.....8.....9A.BCD.E.....F.....0.....12.....3..... */
   1183         " \u0b82\u0b83\u0b85\u0b86\u0b87\u0b88\u0b89\u0b8a \n  \r\u0b8e\u0b8f\u0b90 \u0b92\u0b93"
   1184             // 4.....5.....6789.....A.....B.....CD.....EF.....012.....3456.....7.....89ABCDEF.....
   1185             + "\u0b94\u0b95   \u0b99\u0b9a\uffff \u0b9c \u0b9e !\u0b9f   \u0ba3\u0ba4)(  , .\u0ba8"
   1186             // 0123456789ABC.....D.....EF012.....3.....4.....5.....6.....7.....8.....9.....A.....
   1187             + "0123456789:;\u0ba9\u0baa ?  \u0bae\u0baf\u0bb0\u0bb1\u0bb2\u0bb3\u0bb4\u0bb5\u0bb6"
   1188             // B.....C.....D.....EF0.....1.....2.....3.....4.....5678.....9.....A.....BC.....D.....
   1189             + "\u0bb7\u0bb8\u0bb9  \u0bbe\u0bbf\u0bc0\u0bc1\u0bc2   \u0bc6\u0bc7\u0bc8 \u0bca\u0bcb"
   1190             // E.....F.....0.....123456789ABCDEF0123456789AB.....C.....D.....E.....F.....
   1191             + "\u0bcc\u0bcd\u0bd0abcdefghijklmnopqrstuvwxyz\u0bd7\u0bf0\u0bf1\u0bf2\u0bf9",
   1192 
   1193         /* A.3.12 Telugu National Language Locking Shift Table
   1194          0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.B.....CD.E.....F.....0.....*/
   1195         "\u0c01\u0c02\u0c03\u0c05\u0c06\u0c07\u0c08\u0c09\u0c0a\u0c0b\n\u0c0c \r\u0c0e\u0c0f\u0c10"
   1196             // 12.....3.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....E.....
   1197             + " \u0c12\u0c13\u0c14\u0c15\u0c16\u0c17\u0c18\u0c19\u0c1a\uffff\u0c1b\u0c1c\u0c1d"
   1198             // F.....012.....3.....4.....5.....6.....7.....89A.....B.....CD.....EF.....0123456789AB
   1199             + "\u0c1e !\u0c1f\u0c20\u0c21\u0c22\u0c23\u0c24)(\u0c25\u0c26,\u0c27.\u0c280123456789:;"
   1200             // CD.....E.....F0.....1.....2.....3.....4.....5.....6.....7.....89.....A.....B.....
   1201             + " \u0c2a\u0c2b?\u0c2c\u0c2d\u0c2e\u0c2f\u0c30\u0c31\u0c32\u0c33 \u0c35\u0c36\u0c37"
   1202             // C.....D.....EF.....0.....1.....2.....3.....4.....5.....6.....78.....9.....A.....B
   1203             + "\u0c38\u0c39 \u0c3d\u0c3e\u0c3f\u0c40\u0c41\u0c42\u0c43\u0c44 \u0c46\u0c47\u0c48 "
   1204             // C.....D.....E.....F.....0.....123456789ABCDEF0123456789AB.....C.....D.....E.....
   1205             + "\u0c4a\u0c4b\u0c4c\u0c4d\u0c55abcdefghijklmnopqrstuvwxyz\u0c56\u0c60\u0c61\u0c62"
   1206             // F.....
   1207             + "\u0c63",
   1208 
   1209         /* A.3.13 Urdu National Language Locking Shift Table
   1210          0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.B.....C.....D.E.....F.....*/
   1211         "\u0627\u0622\u0628\u067b\u0680\u067e\u06a6\u062a\u06c2\u067f\n\u0679\u067d\r\u067a\u067c"
   1212             // 0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....
   1213             + "\u062b\u062c\u0681\u0684\u0683\u0685\u0686\u0687\u062d\u062e\u062f\uffff\u068c\u0688"
   1214             // E.....F.....012.....3.....4.....5.....6.....7.....89A.....B.....CD.....EF.....012345
   1215             + "\u0689\u068a !\u068f\u068d\u0630\u0631\u0691\u0693)(\u0699\u0632,\u0696.\u0698012345"
   1216             // 6789ABC.....D.....E.....F0.....1.....2.....3.....4.....5.....6.....7.....8.....
   1217             + "6789:;\u069a\u0633\u0634?\u0635\u0636\u0637\u0638\u0639\u0641\u0642\u06a9\u06aa"
   1218             // 9.....A.....B.....C.....D.....E.....F.....0.....1.....2.....3.....4.....5.....6.....
   1219             + "\u06ab\u06af\u06b3\u06b1\u0644\u0645\u0646\u06ba\u06bb\u06bc\u0648\u06c4\u06d5\u06c1"
   1220             // 7.....8.....9.....A.....B.....C.....D.....E.....F.....0.....123456789ABCDEF012345678
   1221             + "\u06be\u0621\u06cc\u06d0\u06d2\u064d\u0650\u064f\u0657\u0654abcdefghijklmnopqrstuvwx"
   1222             // 9AB.....C.....D.....E.....F.....
   1223             + "yz\u0655\u0651\u0653\u0656\u0670"
   1224     };
   1225 
   1226     /**
   1227      * GSM default extension table plus national language single shift character tables.
   1228      */
   1229     private static final String[] sLanguageShiftTables = new String[]{
   1230         /* 6.2.1.1 GSM 7 bit Default Alphabet Extension Table
   1231          0123456789A.....BCDEF0123456789ABCDEF0123456789ABCDEF.0123456789ABCDEF0123456789ABCDEF */
   1232         "          \u000c         ^                   {}     \\            [~] |               "
   1233             // 0123456789ABCDEF012345.....6789ABCDEF0123456789ABCDEF
   1234             + "                     \u20ac                          ",
   1235 
   1236         /* A.2.1 Turkish National Language Single Shift Table
   1237          0123456789A.....BCDEF0123456789ABCDEF0123456789ABCDEF.0123456789ABCDEF01234567.....8 */
   1238         "          \u000c         ^                   {}     \\            [~] |      \u011e "
   1239             // 9.....ABCDEF0123.....456789ABCDEF0123.....45.....67.....89.....ABCDEF0123.....
   1240             + "\u0130         \u015e               \u00e7 \u20ac \u011f \u0131         \u015f"
   1241             // 456789ABCDEF
   1242             + "            ",
   1243 
   1244         /* A.2.2 Spanish National Language Single Shift Table
   1245          0123456789.....A.....BCDEF0123456789ABCDEF0123456789ABCDEF.0123456789ABCDEF01.....23 */
   1246         "         \u00e7\u000c         ^                   {}     \\            [~] |\u00c1  "
   1247             // 456789.....ABCDEF.....012345.....6789ABCDEF01.....2345.....6789.....ABCDEF.....012
   1248             + "     \u00cd     \u00d3     \u00da           \u00e1   \u20ac   \u00ed     \u00f3   "
   1249             // 345.....6789ABCDEF
   1250             + "  \u00fa          ",
   1251 
   1252         /* A.2.3 Portuguese National Language Single Shift Table
   1253          012345.....6789.....A.....B.....C.....DE.....F.....012.....3.....45.....6.....7.....8....*/
   1254         "     \u00ea   \u00e7\u000c\u00d4\u00f4 \u00c1\u00e1  \u03a6\u0393^\u03a9\u03a0\u03a8\u03a3"
   1255             // 9.....ABCDEF.....0123456789ABCDEF.0123456789ABCDEF01.....23456789.....ABCDE
   1256             + "\u0398     \u00ca        {}     \\            [~] |\u00c0       \u00cd     "
   1257             // F.....012345.....6789AB.....C.....DEF01.....2345.....6789.....ABCDEF.....01234
   1258             + "\u00d3     \u00da     \u00c3\u00d5    \u00c2   \u20ac   \u00ed     \u00f3     "
   1259             // 5.....6789AB.....C.....DEF.....
   1260             + "\u00fa     \u00e3\u00f5  \u00e2",
   1261 
   1262         /* A.2.4 Bengali National Language Single Shift Table
   1263          01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */
   1264         "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u09e6\u09e7 \u09e8\u09e9"
   1265             // E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89A.....B.....C.....
   1266             + "\u09ea\u09eb\u09ec\u09ed\u09ee\u09ef\u09df\u09e0\u09e1\u09e2{}\u09e3\u09f2\u09f3"
   1267             // D.....E.....F.0.....1.....2.....3.....4.....56789ABCDEF0123456789ABCDEF
   1268             + "\u09f4\u09f5\\\u09f6\u09f7\u09f8\u09f9\u09fa       [~] |ABCDEFGHIJKLMNO"
   1269             // 0123456789ABCDEF012345.....6789ABCDEF0123456789ABCDEF
   1270             + "PQRSTUVWXYZ          \u20ac                          ",
   1271 
   1272         /* A.2.5 Gujarati National Language Single Shift Table
   1273          01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */
   1274         "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u0964\u0965 \u0ae6\u0ae7"
   1275             // E.....F.....0.....1.....2.....3.....4.....5.....6789ABCDEF.0123456789ABCDEF
   1276             + "\u0ae8\u0ae9\u0aea\u0aeb\u0aec\u0aed\u0aee\u0aef  {}     \\            [~] "
   1277             // 0123456789ABCDEF0123456789ABCDEF012345.....6789ABCDEF0123456789ABCDEF
   1278             + "|ABCDEFGHIJKLMNOPQRSTUVWXYZ          \u20ac                          ",
   1279 
   1280         /* A.2.6 Hindi National Language Single Shift Table
   1281          01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */
   1282         "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u0964\u0965 \u0966\u0967"
   1283             // E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89A.....B.....C.....
   1284             + "\u0968\u0969\u096a\u096b\u096c\u096d\u096e\u096f\u0951\u0952{}\u0953\u0954\u0958"
   1285             // D.....E.....F.0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.....
   1286             + "\u0959\u095a\\\u095b\u095c\u095d\u095e\u095f\u0960\u0961\u0962\u0963\u0970\u0971"
   1287             // BCDEF0123456789ABCDEF0123456789ABCDEF012345.....6789ABCDEF0123456789ABCDEF
   1288             + " [~] |ABCDEFGHIJKLMNOPQRSTUVWXYZ          \u20ac                          ",
   1289 
   1290         /* A.2.7 Kannada National Language Single Shift Table
   1291          01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */
   1292         "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u0964\u0965 \u0ce6\u0ce7"
   1293             // E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89A.....BCDEF.01234567
   1294             + "\u0ce8\u0ce9\u0cea\u0ceb\u0cec\u0ced\u0cee\u0cef\u0cde\u0cf1{}\u0cf2    \\        "
   1295             // 89ABCDEF0123456789ABCDEF0123456789ABCDEF012345.....6789ABCDEF0123456789ABCDEF
   1296             + "    [~] |ABCDEFGHIJKLMNOPQRSTUVWXYZ          \u20ac                          ",
   1297 
   1298         /* A.2.8 Malayalam National Language Single Shift Table
   1299          01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */
   1300         "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u0964\u0965 \u0d66\u0d67"
   1301             // E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89A.....B.....C.....
   1302             + "\u0d68\u0d69\u0d6a\u0d6b\u0d6c\u0d6d\u0d6e\u0d6f\u0d70\u0d71{}\u0d72\u0d73\u0d74"
   1303             // D.....E.....F.0.....1.....2.....3.....4.....56789ABCDEF0123456789ABCDEF0123456789A
   1304             + "\u0d75\u0d7a\\\u0d7b\u0d7c\u0d7d\u0d7e\u0d7f       [~] |ABCDEFGHIJKLMNOPQRSTUVWXYZ"
   1305             // BCDEF012345.....6789ABCDEF0123456789ABCDEF
   1306             + "          \u20ac                          ",
   1307 
   1308         /* A.2.9 Oriya National Language Single Shift Table
   1309          01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */
   1310         "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u0964\u0965 \u0b66\u0b67"
   1311             // E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89A.....B.....C.....DE
   1312             + "\u0b68\u0b69\u0b6a\u0b6b\u0b6c\u0b6d\u0b6e\u0b6f\u0b5c\u0b5d{}\u0b5f\u0b70\u0b71  "
   1313             // F.0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF012345.....6789ABCDEF0123456789A
   1314             + "\\            [~] |ABCDEFGHIJKLMNOPQRSTUVWXYZ          \u20ac                     "
   1315             // BCDEF
   1316             + "     ",
   1317 
   1318         /* A.2.10 Punjabi National Language Single Shift Table
   1319          01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */
   1320         "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u0964\u0965 \u0a66\u0a67"
   1321             // E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89A.....B.....C.....
   1322             + "\u0a68\u0a69\u0a6a\u0a6b\u0a6c\u0a6d\u0a6e\u0a6f\u0a59\u0a5a{}\u0a5b\u0a5c\u0a5e"
   1323             // D.....EF.0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF012345.....6789ABCDEF01
   1324             + "\u0a75 \\            [~] |ABCDEFGHIJKLMNOPQRSTUVWXYZ          \u20ac            "
   1325             // 23456789ABCDEF
   1326             + "              ",
   1327 
   1328         /* A.2.11 Tamil National Language Single Shift Table
   1329            NOTE: TS 23.038 V9.1.1 shows code 0x24 as \u0bef, corrected to \u0bee (typo)
   1330          01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */
   1331         "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u0964\u0965 \u0be6\u0be7"
   1332             // E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89A.....B.....C.....
   1333             + "\u0be8\u0be9\u0bea\u0beb\u0bec\u0bed\u0bee\u0bef\u0bf3\u0bf4{}\u0bf5\u0bf6\u0bf7"
   1334             // D.....E.....F.0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF012345.....6789ABC
   1335             + "\u0bf8\u0bfa\\            [~] |ABCDEFGHIJKLMNOPQRSTUVWXYZ          \u20ac       "
   1336             // DEF0123456789ABCDEF
   1337             + "                   ",
   1338 
   1339         /* A.2.12 Telugu National Language Single Shift Table
   1340            NOTE: TS 23.038 V9.1.1 shows code 0x22-0x23 as \u06cc\u06cd, corrected to \u0c6c\u0c6d
   1341          01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789ABC.....D.....E.....F..... */
   1342         "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*   \u0c66\u0c67\u0c68\u0c69"
   1343             // 0.....1.....2.....3.....4.....5.....6.....7.....89A.....B.....C.....D.....E.....F.
   1344             + "\u0c6a\u0c6b\u0c6c\u0c6d\u0c6e\u0c6f\u0c58\u0c59{}\u0c78\u0c79\u0c7a\u0c7b\u0c7c\\"
   1345             // 0.....1.....2.....3456789ABCDEF0123456789ABCDEF0123456789ABCDEF012345.....6789ABCD
   1346             + "\u0c7d\u0c7e\u0c7f         [~] |ABCDEFGHIJKLMNOPQRSTUVWXYZ          \u20ac        "
   1347             // EF0123456789ABCDEF
   1348             + "                  ",
   1349 
   1350         /* A.2.13 Urdu National Language Single Shift Table
   1351          01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */
   1352         "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u0600\u0601 \u06f0\u06f1"
   1353             // E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89A.....B.....C.....
   1354             + "\u06f2\u06f3\u06f4\u06f5\u06f6\u06f7\u06f8\u06f9\u060c\u060d{}\u060e\u060f\u0610"
   1355             // D.....E.....F.0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.....
   1356             + "\u0611\u0612\\\u0613\u0614\u061b\u061f\u0640\u0652\u0658\u066b\u066c\u0672\u0673"
   1357             // B.....CDEF.....0123456789ABCDEF0123456789ABCDEF012345.....6789ABCDEF0123456789ABCDEF
   1358             + "\u06cd[~]\u06d4|ABCDEFGHIJKLMNOPQRSTUVWXYZ          \u20ac                          "
   1359     };
   1360 
   1361     static {
   1362         Resources r = Resources.getSystem();
   1363         // See comments in frameworks/base/core/res/res/values/config.xml for allowed values
   1364         sEnabledSingleShiftTables = r.getIntArray(R.array.config_sms_enabled_single_shift_tables);
   1365         sEnabledLockingShiftTables = r.getIntArray(R.array.config_sms_enabled_locking_shift_tables);
   1366         int numTables = sLanguageTables.length;
   1367         int numShiftTables = sLanguageShiftTables.length;
   1368         if (numTables != numShiftTables) {
   1369             Log.e(TAG, "Error: language tables array length " + numTables +
   1370                     " != shift tables array length " + numShiftTables);
   1371         }
   1372 
   1373         if (sEnabledSingleShiftTables.length > 0) {
   1374             sHighestEnabledSingleShiftCode =
   1375                     sEnabledSingleShiftTables[sEnabledSingleShiftTables.length-1];
   1376         } else {
   1377             sHighestEnabledSingleShiftCode = 0;
   1378         }
   1379 
   1380         sCharsToGsmTables = new SparseIntArray[numTables];
   1381         for (int i = 0; i < numTables; i++) {
   1382             String table = sLanguageTables[i];
   1383 
   1384             int tableLen = table.length();
   1385             if (tableLen != 0 && tableLen != 128) {
   1386                 Log.e(TAG, "Error: language tables index " + i +
   1387                         " length " + tableLen + " (expected 128 or 0)");
   1388             }
   1389 
   1390             SparseIntArray charToGsmTable = new SparseIntArray(tableLen);
   1391             sCharsToGsmTables[i] = charToGsmTable;
   1392             for (int j = 0; j < tableLen; j++) {
   1393                 char c = table.charAt(j);
   1394                 charToGsmTable.put(c, j);
   1395             }
   1396         }
   1397 
   1398         sCharsToShiftTables = new SparseIntArray[numTables];
   1399         for (int i = 0; i < numShiftTables; i++) {
   1400             String shiftTable = sLanguageShiftTables[i];
   1401 
   1402             int shiftTableLen = shiftTable.length();
   1403             if (shiftTableLen != 0 && shiftTableLen != 128) {
   1404                 Log.e(TAG, "Error: language shift tables index " + i +
   1405                         " length " + shiftTableLen + " (expected 128 or 0)");
   1406             }
   1407 
   1408             SparseIntArray charToShiftTable = new SparseIntArray(shiftTableLen);
   1409             sCharsToShiftTables[i] = charToShiftTable;
   1410             for (int j = 0; j < shiftTableLen; j++) {
   1411                 char c = shiftTable.charAt(j);
   1412                 if (c != ' ') {
   1413                     charToShiftTable.put(c, j);
   1414                 }
   1415             }
   1416         }
   1417     }
   1418 }
   1419