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