Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fe0dc9cc authored by Jake Hamby's avatar Jake Hamby Committed by android-merger
Browse files

Enable support for SMS national language shift tables.

Add support for encoding and decoding SMS 7 bit user data using the
national language shift tables defined in 3GPP TS 23.038 (GSM/UMTS only),
including the new tables added in Release 9 for Indic languages.

Decoding is always supported, but encoding is only enabled for the
specific language tables added to the new integer array resources
"config_sms_enabled_single_shift_tables" and
"config_sms_enabled_locking_shift_tables" defined in
frameworks/base/core/res/res/values/config.xml. The default empty arrays
should be overridden in an OEM overlay for the specific nationalities where
SMS national language shift table encoding is allowed/mandated (e.g. Turkey).
GsmAlphabet.countGsmSeptets() will try to find the most efficient encoding
among all combinations of enabled locking shift and single shift tables.
If no 7 bit encoding is possible, 16 bit UCS-2 encoding will be used.

This change also fixes a bug in the decoder: when an escape septet
is followed by a septet with no entry in the extension (single shift)
table, TS 23.038 Table 6.2.1.1 states that the MS shall display
the character in the main GSM 7 bit default alphabet table, or the
active national language locking shift table. Previously, we were
decoding this sequence as a space character. Two consecutive escape
septets will continue to decode as a space character, according to
Note 1 of table 6.2.1.1.

Change-Id: I4dab3f0ffe39f3df2064ed93c9c05f26e274d18b
parent 54d3e905
Loading
Loading
Loading
Loading
+40 −0
Original line number Diff line number Diff line
@@ -404,6 +404,46 @@
         option to enable/disable read reports is removed in the Messaging app. -->
    <bool name="config_mms_read_reports_support">true</bool>

    <!-- National Language Identifier codes for the following two config items.
         (from 3GPP TS 23.038 V9.1.1 Table 6.2.1.2.4.1):
          0  - reserved
          1  - Turkish
          2  - Spanish (single shift table only)
          3  - Portuguese
          4  - Bengali
          5  - Gujarati
          6  - Hindi
          7  - Kannada
          8  - Malayalam
          9  - Oriya
         10  - Punjabi
         11  - Tamil
         12  - Telugu
         13  - Urdu
         14+ - reserved -->

    <!-- National language single shift tables to enable for SMS encoding.
         Decoding is always enabled. 3GPP TS 23.038 states that this feature
         should not be enabled until a formal request is issued by the relevant
         national regulatory body. Array elements are codes from the table above.
         Example 1: devices sold in Turkey must include table 1 to conform with
           By-Law Number 27230. (http://www.btk.gov.tr/eng/pdf/2009/BY-LAW_SMS.pdf)
         Example 2: devices sold in India should include tables 4 through 13
           to enable use of the new Release 9 tables for Indic languages. -->
    <integer-array name="config_sms_enabled_single_shift_tables"></integer-array>

    <!-- National language locking shift tables to enable for SMS encoding.
         Decoding is always enabled. 3GPP TS 23.038 states that this feature
         should not be enabled until a formal request is issued by the relevant
         national regulatory body. Array elements are codes from the table above.
         Example 1: devices sold in Turkey must include table 1 after the
           Turkish Telecommunication Authority requires locking shift encoding
           to be enabled (est. July 2012). (http://www.btk.gov.tr/eng/pdf/2009/BY-LAW_SMS.pdf)
           See also: http://www.mobitech.com.tr/tr/ersanozturkblog_en/index.php?entry=entry090223-160014
         Example 2: devices sold in India should include tables 4 through 13
         to enable use of the new Release 9 tables for Indic languages. -->
    <integer-array name="config_sms_enabled_locking_shift_tables"></integer-array>

    <!-- Set and Unsets WiMAX -->
    <bool name="config_wimaxEnabled">false</bool>
    <!-- Location of the wimax framwork jar location -->
+3 −8
Original line number Diff line number Diff line
@@ -47,30 +47,25 @@ import android.os.SystemClock;
import android.os.WorkSource;
import android.provider.Settings;
import android.provider.Telephony.Sms.Intents;
import android.telephony.SmsMessage;
import android.telephony.TelephonyManager;
import android.telephony.gsm.GsmCellLocation;
import android.telephony.SmsMessage;
import android.util.Log;
import android.util.SparseIntArray;

import com.android.internal.app.IBatteryStats;
import com.android.internal.telephony.Phone;
import com.android.internal.location.GpsNetInitiatedHandler;
import com.android.internal.location.GpsNetInitiatedHandler.GpsNiNotification;
import com.android.internal.telephony.GsmAlphabet;
import com.android.internal.telephony.SmsHeader;
import com.android.internal.util.HexDump;
import com.android.internal.telephony.Phone;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.StringBufferInputStream;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Date;
import java.util.Properties;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.concurrent.CountDownLatch;

/**
+8 −4
Original line number Diff line number Diff line
@@ -314,7 +314,8 @@ public class SmsMessage {
                    nextPos = pos + Math.min(limit, textLen - pos);
                } else {
                    // For multi-segment messages, CDMA 7bit equals GSM 7bit encoding (EMS mode).
                    nextPos = GsmAlphabet.findGsmSeptetLimitIndex(text, pos, limit);
                    nextPos = GsmAlphabet.findGsmSeptetLimitIndex(text, pos, limit,
                            ted.languageTable, ted.languageShiftTable);
                }
            } else {  // Assume unicode.
                nextPos = pos + Math.min(limit / 2, textLen - pos);
@@ -370,7 +371,8 @@ public class SmsMessage {
     */

    /**
     * Get an SMS-SUBMIT PDU for a destination address and a message
     * Get an SMS-SUBMIT PDU for a destination address and a message.
     * This method will not attempt to use any GSM national language 7 bit encodings.
     *
     * @param scAddress Service Centre address.  Null means use default.
     * @return a <code>SubmitPdu</code> containing the encoded SC
@@ -397,7 +399,8 @@ public class SmsMessage {
    }

    /**
     * Get an SMS-SUBMIT PDU for a destination address and a message
     * Get an SMS-SUBMIT PDU for a destination address and a message.
     * This method will not attempt to use any GSM national language 7 bit encodings.
     *
     * @param scAddress Service Centre address.  Null means use default.
     * @return a <code>SubmitPdu</code> containing the encoded SC
@@ -421,7 +424,8 @@ public class SmsMessage {
    }

    /**
     * Get an SMS-SUBMIT PDU for a data message to a destination address &amp; port
     * Get an SMS-SUBMIT PDU for a data message to a destination address &amp; port.
     * This method will not attempt to use any GSM national language 7 bit encodings.
     *
     * @param scAddress Service Centre address. null == use default
     * @param destinationAddress the address of the destination for the message
+7 −30
Original line number Diff line number Diff line
@@ -297,37 +297,14 @@ public class SmsMessage {
     */
    @Deprecated
    public static int[] calculateLength(CharSequence messageBody, boolean use7bitOnly) {
        SmsMessageBase.TextEncodingDetails ted =
                com.android.internal.telephony.gsm.SmsMessage
                        .calculateLength(messageBody, use7bitOnly);
        int ret[] = new int[4];

        try {
            // Try GSM alphabet
            int septets = GsmAlphabet.countGsmSeptets(messageBody, !use7bitOnly);
            ret[1] = septets;
            if (septets > MAX_USER_DATA_SEPTETS) {
                ret[0] = (septets + (MAX_USER_DATA_SEPTETS_WITH_HEADER - 1)) /
                            MAX_USER_DATA_SEPTETS_WITH_HEADER;
                ret[2] = (ret[0] * MAX_USER_DATA_SEPTETS_WITH_HEADER) - septets;
            } else {
                ret[0] = 1;
                ret[2] = MAX_USER_DATA_SEPTETS - septets;
            }
            ret[3] = ENCODING_7BIT;
        } catch (EncodeException ex) {
            // fall back to UCS-2
            int octets = messageBody.length() * 2;
            ret[1] = messageBody.length();
            if (octets > MAX_USER_DATA_BYTES) {
                // 6 is the size of the user data header
                ret[0] = (octets + (MAX_USER_DATA_BYTES_WITH_HEADER - 1)) /
                            MAX_USER_DATA_BYTES_WITH_HEADER;
                ret[2] = ((ret[0] * MAX_USER_DATA_BYTES_WITH_HEADER) - octets) / 2;
            } else {
                ret[0] = 1;
                ret[2] = (MAX_USER_DATA_BYTES - octets)/2;
            }
            ret[3] = ENCODING_16BIT;
        }

        ret[0] = ted.msgCount;
        ret[1] = ted.codeUnitCount;
        ret[2] = ted.codeUnitsRemaining;
        ret[3] = ted.codeUnitSize;
        return ret;
    }

+866 −277

File changed.

Preview size limit exceeded, changes collapsed.

Loading