10825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville/* 20825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Copyright (C) 2008 The Android Open Source Project 30825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * 40825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Licensed under the Apache License, Version 2.0 (the "License"); 50825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * you may not use this file except in compliance with the License. 60825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * You may obtain a copy of the License at 70825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * 80825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * http://www.apache.org/licenses/LICENSE-2.0 90825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * 100825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Unless required by applicable law or agreed to in writing, software 110825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * distributed under the License is distributed on an "AS IS" BASIS, 120825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 130825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * See the License for the specific language governing permissions and 140825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * limitations under the License. 150825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 160825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 170825495a331bb44df395a0cdb79fab85e68db5d5Wink Savillepackage android.telephony; 180825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 19f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajanimport android.os.Binder; 200825495a331bb44df395a0cdb79fab85e68db5d5Wink Savilleimport android.os.Parcel; 21f3166841bf9df142e2fbd63b7647bae7da712044Xia Yingimport android.content.res.Resources; 222463a1471273614bda6d3db8f207b31ca27443ccXia Yingimport android.text.TextUtils; 230825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 240825495a331bb44df395a0cdb79fab85e68db5d5Wink Savilleimport com.android.internal.telephony.GsmAlphabet; 250825495a331bb44df395a0cdb79fab85e68db5d5Wink Savilleimport com.android.internal.telephony.GsmAlphabet.TextEncodingDetails; 260825495a331bb44df395a0cdb79fab85e68db5d5Wink Savilleimport com.android.internal.telephony.SmsConstants; 270825495a331bb44df395a0cdb79fab85e68db5d5Wink Savilleimport com.android.internal.telephony.SmsMessageBase; 280825495a331bb44df395a0cdb79fab85e68db5d5Wink Savilleimport com.android.internal.telephony.SmsMessageBase.SubmitPduBase; 298b53bb26569395511e3dbd5f94bda74ea6b9e37cXia Yingimport com.android.internal.telephony.Sms7BitEncodingTranslator; 300825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 310825495a331bb44df395a0cdb79fab85e68db5d5Wink Savilleimport java.lang.Math; 320825495a331bb44df395a0cdb79fab85e68db5d5Wink Savilleimport java.util.ArrayList; 330825495a331bb44df395a0cdb79fab85e68db5d5Wink Savilleimport java.util.Arrays; 340825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 350825495a331bb44df395a0cdb79fab85e68db5d5Wink Savilleimport static android.telephony.TelephonyManager.PHONE_TYPE_CDMA; 360825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 370825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 380825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville/** 390825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * A Short Message Service message. 4029305a0d8e45e8b6731ab91e59fcba7a4d6ff766Scott Main * @see android.provider.Telephony.Sms.Intents#getMessagesFromIntent 410825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 420825495a331bb44df395a0cdb79fab85e68db5d5Wink Savillepublic class SmsMessage { 43cbaa45bbf2cab852b6c9c3a887e9f803d4e857eaWink Saville private static final String LOG_TAG = "SmsMessage"; 440825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 450825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 460825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * SMS Class enumeration. 470825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * See TS 23.038. 480825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * 490825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 500825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public enum MessageClass{ 510825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville UNKNOWN, CLASS_0, CLASS_1, CLASS_2, CLASS_3; 520825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 530825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 540825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** User data text encoding code unit size */ 550825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public static final int ENCODING_UNKNOWN = 0; 560825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public static final int ENCODING_7BIT = 1; 570825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public static final int ENCODING_8BIT = 2; 580825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public static final int ENCODING_16BIT = 3; 590825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 600825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @hide This value is not defined in global standard. Only in Korea, this is used. 610825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 620825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public static final int ENCODING_KSC5601 = 4; 630825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 640825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** The maximum number of payload bytes per message */ 650825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public static final int MAX_USER_DATA_BYTES = 140; 660825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 670825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 680825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * The maximum number of payload bytes per message if a user data header 690825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * is present. This assumes the header only contains the 700825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * CONCATENATED_8_BIT_REFERENCE element. 710825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 720825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public static final int MAX_USER_DATA_BYTES_WITH_HEADER = 134; 730825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 740825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** The maximum number of payload septets per message */ 750825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public static final int MAX_USER_DATA_SEPTETS = 160; 760825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 770825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 780825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * The maximum number of payload septets per message if a user data header 790825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * is present. This assumes the header only contains the 800825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * CONCATENATED_8_BIT_REFERENCE element. 810825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 820825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public static final int MAX_USER_DATA_SEPTETS_WITH_HEADER = 153; 830825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 840825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 850825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Indicates a 3GPP format SMS message. 860825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @hide pending API council approval 870825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 880825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public static final String FORMAT_3GPP = "3gpp"; 890825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 900825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 910825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Indicates a 3GPP2 format SMS message. 920825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @hide pending API council approval 930825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 940825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public static final String FORMAT_3GPP2 = "3gpp2"; 950825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 960825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** Contains actual SmsMessage. Only public for debugging and for framework layer. 970825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * 980825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @hide 990825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 1000825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public SmsMessageBase mWrappedSmsMessage; 1010825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 102a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville /** Indicates the subId 103a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville * 104a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville * @hide 105a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville */ 106b237a11044ed842d2865ff8c8716befb06b6ca25Wink Saville private int mSubId = 0; 107a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville 108a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville /** set Subscription information 109a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville * 110a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville * @hide 111a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville */ 112b237a11044ed842d2865ff8c8716befb06b6ca25Wink Saville public void setSubId(int subId) { 113a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville mSubId = subId; 114a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville } 115a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville 116a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville /** get Subscription information 117a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville * 118a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville * @hide 119a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville */ 120b237a11044ed842d2865ff8c8716befb06b6ca25Wink Saville public int getSubId() { 121a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville return mSubId; 122a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville } 123a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville 1240825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public static class SubmitPdu { 1250825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 1260825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public byte[] encodedScAddress; // Null if not applicable. 1270825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public byte[] encodedMessage; 1280825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 129cbaa45bbf2cab852b6c9c3a887e9f803d4e857eaWink Saville @Override 1300825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public String toString() { 1310825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return "SubmitPdu: encodedScAddress = " 1320825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville + Arrays.toString(encodedScAddress) 1330825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville + ", encodedMessage = " 1340825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville + Arrays.toString(encodedMessage); 1350825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 1360825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 1370825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 1380825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @hide 1390825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 1400825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville protected SubmitPdu(SubmitPduBase spb) { 1410825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville this.encodedMessage = spb.encodedMessage; 1420825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville this.encodedScAddress = spb.encodedScAddress; 1430825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 1440825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 1450825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 1460825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 1470825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville private SmsMessage(SmsMessageBase smb) { 1480825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville mWrappedSmsMessage = smb; 1490825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 1500825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 1510825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 152b12b6f7260d84c853bd585b23623509a18686f1eCheuksan Wang * Create an SmsMessage from a raw PDU. Guess format based on Voice 153b12b6f7260d84c853bd585b23623509a18686f1eCheuksan Wang * technology first, if it fails use other format. 154b12b6f7260d84c853bd585b23623509a18686f1eCheuksan Wang * All applications which handle 1550825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * incoming SMS messages by processing the {@code SMS_RECEIVED_ACTION} broadcast 1560825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * intent <b>must</b> now pass the new {@code format} String extra from the intent 1570825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * into the new method {@code createFromPdu(byte[], String)} which takes an 1580825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * extra format parameter. This is required in order to correctly decode the PDU on 1590825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * devices that require support for both 3GPP and 3GPP2 formats at the same time, 160b12b6f7260d84c853bd585b23623509a18686f1eCheuksan Wang * such as dual-mode GSM/CDMA and CDMA/LTE phones. 161b12b6f7260d84c853bd585b23623509a18686f1eCheuksan Wang * @deprecated Use {@link #createFromPdu(byte[], String)} instead. 1620825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 163b12b6f7260d84c853bd585b23623509a18686f1eCheuksan Wang @Deprecated 1640825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public static SmsMessage createFromPdu(byte[] pdu) { 1651260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa SmsMessage message = null; 1661260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa 1671260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa // cdma(3gpp2) vs gsm(3gpp) format info was not given, 1681260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa // guess from active voice phone type 1690825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville int activePhone = TelephonyManager.getDefault().getCurrentPhoneType(); 1700825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville String format = (PHONE_TYPE_CDMA == activePhone) ? 1710825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville SmsConstants.FORMAT_3GPP2 : SmsConstants.FORMAT_3GPP; 1721260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa message = createFromPdu(pdu, format); 1731260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa 1741260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa if (null == message || null == message.mWrappedSmsMessage) { 1751260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa // decoding pdu failed based on activePhone type, must be other format 1761260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa format = (PHONE_TYPE_CDMA == activePhone) ? 1771260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa SmsConstants.FORMAT_3GPP : SmsConstants.FORMAT_3GPP2; 1781260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa message = createFromPdu(pdu, format); 1791260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa } 1801260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa return message; 1810825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 1820825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 1830825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 1840825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Create an SmsMessage from a raw PDU with the specified message format. The 185b12b6f7260d84c853bd585b23623509a18686f1eCheuksan Wang * message format is passed in the 186b12b6f7260d84c853bd585b23623509a18686f1eCheuksan Wang * {@link android.provider.Telephony.Sms.Intents#SMS_RECEIVED_ACTION} as the {@code format} 1870825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * String extra, and will be either "3gpp" for GSM/UMTS/LTE messages in 3GPP format 1880825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * or "3gpp2" for CDMA/LTE messages in 3GPP2 format. 1890825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * 190b12b6f7260d84c853bd585b23623509a18686f1eCheuksan Wang * @param pdu the message PDU from the 191b12b6f7260d84c853bd585b23623509a18686f1eCheuksan Wang * {@link android.provider.Telephony.Sms.Intents#SMS_RECEIVED_ACTION} intent 192b12b6f7260d84c853bd585b23623509a18686f1eCheuksan Wang * @param format the format extra from the 193b12b6f7260d84c853bd585b23623509a18686f1eCheuksan Wang * {@link android.provider.Telephony.Sms.Intents#SMS_RECEIVED_ACTION} intent 1940825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 1950825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public static SmsMessage createFromPdu(byte[] pdu, String format) { 1960825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville SmsMessageBase wrappedMessage; 1970825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 1980825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville if (SmsConstants.FORMAT_3GPP2.equals(format)) { 1990825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville wrappedMessage = com.android.internal.telephony.cdma.SmsMessage.createFromPdu(pdu); 2000825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } else if (SmsConstants.FORMAT_3GPP.equals(format)) { 2010825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville wrappedMessage = com.android.internal.telephony.gsm.SmsMessage.createFromPdu(pdu); 2020825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } else { 20399c2e1d6749cfad2a8ca94a47857d8c3bfc09454Wink Saville Rlog.e(LOG_TAG, "createFromPdu(): unsupported message format " + format); 2040825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return null; 2050825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 2060825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 207676e73ec8586d1a8f2b471780d198e556ea95ecfAmit Mahajan if (wrappedMessage != null) { 208676e73ec8586d1a8f2b471780d198e556ea95ecfAmit Mahajan return new SmsMessage(wrappedMessage); 209676e73ec8586d1a8f2b471780d198e556ea95ecfAmit Mahajan } else { 210676e73ec8586d1a8f2b471780d198e556ea95ecfAmit Mahajan Rlog.e(LOG_TAG, "createFromPdu(): wrappedMessage is null"); 211676e73ec8586d1a8f2b471780d198e556ea95ecfAmit Mahajan return null; 212676e73ec8586d1a8f2b471780d198e556ea95ecfAmit Mahajan } 2130825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 2140825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 2150825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 2160825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * TS 27.005 3.4.1 lines[0] and lines[1] are the two lines read from the 2170825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * +CMT unsolicited response (PDU mode, of course) 2180825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * +CMT: [<alpha>],<length><CR><LF><pdu> 2190825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * 2200825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Only public for debugging and for RIL 2210825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * 2220825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * {@hide} 2230825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 2240825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public static SmsMessage newFromCMT(String[] lines) { 2250825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville // received SMS in 3GPP format 2260825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville SmsMessageBase wrappedMessage = 2270825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville com.android.internal.telephony.gsm.SmsMessage.newFromCMT(lines); 2280825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 229676e73ec8586d1a8f2b471780d198e556ea95ecfAmit Mahajan if (wrappedMessage != null) { 230676e73ec8586d1a8f2b471780d198e556ea95ecfAmit Mahajan return new SmsMessage(wrappedMessage); 231676e73ec8586d1a8f2b471780d198e556ea95ecfAmit Mahajan } else { 232676e73ec8586d1a8f2b471780d198e556ea95ecfAmit Mahajan Rlog.e(LOG_TAG, "newFromCMT(): wrappedMessage is null"); 233676e73ec8586d1a8f2b471780d198e556ea95ecfAmit Mahajan return null; 234676e73ec8586d1a8f2b471780d198e556ea95ecfAmit Mahajan } 2350825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 2360825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 2370825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** @hide */ 2380825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public static SmsMessage newFromParcel(Parcel p) { 2390825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville // received SMS in 3GPP2 format 2400825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville SmsMessageBase wrappedMessage = 2410825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville com.android.internal.telephony.cdma.SmsMessage.newFromParcel(p); 2420825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 2430825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return new SmsMessage(wrappedMessage); 2440825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 2450825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 2460825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 2470825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Create an SmsMessage from an SMS EF record. 2480825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * 2490825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @param index Index of SMS record. This should be index in ArrayList 2500825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * returned by SmsManager.getAllMessagesFromSim + 1. 2510825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @param data Record data. 2520825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @return An SmsMessage representing the record. 2530825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * 2540825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @hide 2550825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 2560825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public static SmsMessage createFromEfRecord(int index, byte[] data) { 2570825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville SmsMessageBase wrappedMessage; 2580825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 2591260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa if (isCdmaVoice()) { 2600825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville wrappedMessage = com.android.internal.telephony.cdma.SmsMessage.createFromEfRecord( 2610825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville index, data); 2620825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } else { 2630825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville wrappedMessage = com.android.internal.telephony.gsm.SmsMessage.createFromEfRecord( 2640825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville index, data); 2650825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 2660825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 267676e73ec8586d1a8f2b471780d198e556ea95ecfAmit Mahajan if (wrappedMessage != null) { 268676e73ec8586d1a8f2b471780d198e556ea95ecfAmit Mahajan return new SmsMessage(wrappedMessage); 269676e73ec8586d1a8f2b471780d198e556ea95ecfAmit Mahajan } else { 270676e73ec8586d1a8f2b471780d198e556ea95ecfAmit Mahajan Rlog.e(LOG_TAG, "createFromEfRecord(): wrappedMessage is null"); 271676e73ec8586d1a8f2b471780d198e556ea95ecfAmit Mahajan return null; 272676e73ec8586d1a8f2b471780d198e556ea95ecfAmit Mahajan } 2730825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 2740825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 2750825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 2760825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Get the TP-Layer-Length for the given SMS-SUBMIT PDU Basically, the 2770825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * length in bytes (not hex chars) less the SMSC header 2780825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * 2790825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * FIXME: This method is only used by a CTS test case that isn't run on CDMA devices. 2800825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * We should probably deprecate it and remove the obsolete test case. 2810825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 2820825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public static int getTPLayerLengthForPDU(String pdu) { 2831260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa if (isCdmaVoice()) { 2840825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return com.android.internal.telephony.cdma.SmsMessage.getTPLayerLengthForPDU(pdu); 2850825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } else { 2860825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return com.android.internal.telephony.gsm.SmsMessage.getTPLayerLengthForPDU(pdu); 2870825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 2880825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 2890825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 2900825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /* 2910825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * TODO(cleanup): It would make some sense if the result of 2920825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * preprocessing a message to determine the proper encoding (i.e. 2930825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * the resulting data structure from calculateLength) could be 2940825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * passed as an argument to the actual final encoding function. 2950825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * This would better ensure that the logic behind size calculation 2960825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * actually matched the encoding. 2970825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 2980825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 2990825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 3000825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Calculates the number of SMS's required to encode the message body and 3010825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * the number of characters remaining until the next message. 3020825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * 3030825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @param msgBody the message to encode 3040825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @param use7bitOnly if true, characters that are not part of the 3050825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * radio-specific 7-bit encoding are counted as single 3060825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * space chars. If false, and if the messageBody contains 3070825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * non-7-bit encodable characters, length is calculated 3080825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * using a 16-bit encoding. 3090825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @return an int[4] with int[0] being the number of SMS's 3100825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * required, int[1] the number of code units used, and 3110825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * int[2] is the number of code units remaining until the 3120825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * next message. int[3] is an indicator of the encoding 3130825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * code unit size (see the ENCODING_* definitions in SmsConstants) 3140825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 3150825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public static int[] calculateLength(CharSequence msgBody, boolean use7bitOnly) { 3161260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa // this function is for MO SMS 3171260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa TextEncodingDetails ted = (useCdmaFormatForMoSms()) ? 3183ce96a061c2c6e24f4ff3bd237e18c29fc0c0108Amit Mahajan com.android.internal.telephony.cdma.SmsMessage.calculateLength(msgBody, use7bitOnly, 3193ce96a061c2c6e24f4ff3bd237e18c29fc0c0108Amit Mahajan true) : 3200825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville com.android.internal.telephony.gsm.SmsMessage.calculateLength(msgBody, use7bitOnly); 3210825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville int ret[] = new int[4]; 3220825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville ret[0] = ted.msgCount; 3230825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville ret[1] = ted.codeUnitCount; 3240825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville ret[2] = ted.codeUnitsRemaining; 3250825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville ret[3] = ted.codeUnitSize; 3260825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return ret; 3270825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 3280825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 3290825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 3300825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Divide a message text into several fragments, none bigger than 3310825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * the maximum SMS message text size. 3320825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * 3330825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @param text text, must not be null. 3340825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @return an <code>ArrayList</code> of strings that, in order, 3350825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * comprise the original msg text 3360825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * 3370825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @hide 3380825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 3390825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public static ArrayList<String> fragmentText(String text) { 3401260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa // This function is for MO SMS 3411260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa TextEncodingDetails ted = (useCdmaFormatForMoSms()) ? 3423ce96a061c2c6e24f4ff3bd237e18c29fc0c0108Amit Mahajan com.android.internal.telephony.cdma.SmsMessage.calculateLength(text, false, true) : 3430825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville com.android.internal.telephony.gsm.SmsMessage.calculateLength(text, false); 3440825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 3450825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville // TODO(cleanup): The code here could be rolled into the logic 3460825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville // below cleanly if these MAX_* constants were defined more 3470825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville // flexibly... 3480825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 3490825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville int limit; 3500825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville if (ted.codeUnitSize == SmsConstants.ENCODING_7BIT) { 3510825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville int udhLength; 3520825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville if (ted.languageTable != 0 && ted.languageShiftTable != 0) { 3530825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville udhLength = GsmAlphabet.UDH_SEPTET_COST_TWO_SHIFT_TABLES; 3540825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } else if (ted.languageTable != 0 || ted.languageShiftTable != 0) { 3550825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville udhLength = GsmAlphabet.UDH_SEPTET_COST_ONE_SHIFT_TABLE; 3560825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } else { 3570825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville udhLength = 0; 3580825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 3590825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 3600825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville if (ted.msgCount > 1) { 3610825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville udhLength += GsmAlphabet.UDH_SEPTET_COST_CONCATENATED_MESSAGE; 3620825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 3630825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 3640825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville if (udhLength != 0) { 3650825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville udhLength += GsmAlphabet.UDH_SEPTET_COST_LENGTH; 3660825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 3670825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 3680825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville limit = SmsConstants.MAX_USER_DATA_SEPTETS - udhLength; 3690825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } else { 3700825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville if (ted.msgCount > 1) { 3710825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville limit = SmsConstants.MAX_USER_DATA_BYTES_WITH_HEADER; 372f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying // If EMS is not supported, break down EMS into single segment SMS 373f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying // and add page info " x/y". 374f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying // In the case of UCS2 encoding, we need 8 bytes for this, 375f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying // but we only have 6 bytes from UDH, so truncate the limit for 376f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying // each segment by 2 bytes (1 char). 377f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying // Make sure total number of segments is less than 10. 378f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying if (!hasEmsSupport() && ted.msgCount < 10) { 379f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying limit -= 2; 380f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying } 3810825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } else { 3820825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville limit = SmsConstants.MAX_USER_DATA_BYTES; 3830825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 3840825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 3850825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 3868b53bb26569395511e3dbd5f94bda74ea6b9e37cXia Ying String newMsgBody = null; 3878b53bb26569395511e3dbd5f94bda74ea6b9e37cXia Ying Resources r = Resources.getSystem(); 3888b53bb26569395511e3dbd5f94bda74ea6b9e37cXia Ying if (r.getBoolean(com.android.internal.R.bool.config_sms_force_7bit_encoding)) { 3898b53bb26569395511e3dbd5f94bda74ea6b9e37cXia Ying newMsgBody = Sms7BitEncodingTranslator.translate(text); 3908b53bb26569395511e3dbd5f94bda74ea6b9e37cXia Ying } 3918b53bb26569395511e3dbd5f94bda74ea6b9e37cXia Ying if (TextUtils.isEmpty(newMsgBody)) { 3928b53bb26569395511e3dbd5f94bda74ea6b9e37cXia Ying newMsgBody = text; 3938b53bb26569395511e3dbd5f94bda74ea6b9e37cXia Ying } 3940825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville int pos = 0; // Index in code units. 3958b53bb26569395511e3dbd5f94bda74ea6b9e37cXia Ying int textLen = newMsgBody.length(); 3960825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville ArrayList<String> result = new ArrayList<String>(ted.msgCount); 3970825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville while (pos < textLen) { 3980825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville int nextPos = 0; // Counts code units. 3990825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville if (ted.codeUnitSize == SmsConstants.ENCODING_7BIT) { 4001260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa if (useCdmaFormatForMoSms() && ted.msgCount == 1) { 4010825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville // For a singleton CDMA message, the encoding must be ASCII... 4020825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville nextPos = pos + Math.min(limit, textLen - pos); 4030825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } else { 4040825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville // For multi-segment messages, CDMA 7bit equals GSM 7bit encoding (EMS mode). 4058b53bb26569395511e3dbd5f94bda74ea6b9e37cXia Ying nextPos = GsmAlphabet.findGsmSeptetLimitIndex(newMsgBody, pos, limit, 4060825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville ted.languageTable, ted.languageShiftTable); 4070825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 4080825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } else { // Assume unicode. 409e472090bda6d8c16975807e37b52e6bb558426bfCheuksan Wang nextPos = SmsMessageBase.findNextUnicodePosition(pos, limit, newMsgBody); 4100825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 4110825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville if ((nextPos <= pos) || (nextPos > textLen)) { 41299c2e1d6749cfad2a8ca94a47857d8c3bfc09454Wink Saville Rlog.e(LOG_TAG, "fragmentText failed (" + pos + " >= " + nextPos + " or " + 4130825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville nextPos + " >= " + textLen + ")"); 4140825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville break; 4150825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 4168b53bb26569395511e3dbd5f94bda74ea6b9e37cXia Ying result.add(newMsgBody.substring(pos, nextPos)); 4170825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville pos = nextPos; 4180825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 4190825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return result; 4200825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 4210825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 4220825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 4230825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Calculates the number of SMS's required to encode the message body and 4240825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * the number of characters remaining until the next message, given the 4250825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * current encoding. 4260825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * 4270825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @param messageBody the message to encode 4280825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @param use7bitOnly if true, characters that are not part of the radio 4290825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * specific (GSM / CDMA) alphabet encoding are converted to as a 4300825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * single space characters. If false, a messageBody containing 4310825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * non-GSM or non-CDMA alphabet characters are encoded using 4320825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * 16-bit encoding. 4330825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @return an int[4] with int[0] being the number of SMS's required, int[1] 4340825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * the number of code units used, and int[2] is the number of code 4350825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * units remaining until the next message. int[3] is the encoding 4360825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * type that should be used for the message. 4370825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 4380825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public static int[] calculateLength(String messageBody, boolean use7bitOnly) { 4390825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return calculateLength((CharSequence)messageBody, use7bitOnly); 4400825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 4410825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 4420825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /* 4430825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * TODO(cleanup): It looks like there is now no useful reason why 4440825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * apps should generate pdus themselves using these routines, 4450825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * instead of handing the raw data to SMSDispatcher (and thereby 4460825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * have the phone process do the encoding). Moreover, CDMA now 4470825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * has shared state (in the form of the msgId system property) 4480825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * which can only be modified by the phone process, and hence 4490825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * makes the output of these routines incorrect. Since they now 4500825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * serve no purpose, they should probably just return null 4510825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * directly, and be deprecated. Going further in that direction, 4520825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * the above parsers of serialized pdu data should probably also 4530825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * be gotten rid of, hiding all but the necessarily visible 4540825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * structured data from client apps. A possible concern with 4550825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * doing this is that apps may be using these routines to generate 4560825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * pdus that are then sent elsewhere, some network server, for 4570825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * example, and that always returning null would thereby break 4580825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * otherwise useful apps. 4590825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 4600825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 4610825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 4620825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Get an SMS-SUBMIT PDU for a destination address and a message. 4630825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * This method will not attempt to use any GSM national language 7 bit encodings. 4640825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * 4650825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @param scAddress Service Centre address. Null means use default. 4660825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @return a <code>SubmitPdu</code> containing the encoded SC 4670825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * address, if applicable, and the encoded message. 4680825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Returns null on encode error. 4690825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 4700825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public static SubmitPdu getSubmitPdu(String scAddress, 4710825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville String destinationAddress, String message, boolean statusReportRequested) { 4720825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville SubmitPduBase spb; 4730825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 4741260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa if (useCdmaFormatForMoSms()) { 4750825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville spb = com.android.internal.telephony.cdma.SmsMessage.getSubmitPdu(scAddress, 4760825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville destinationAddress, message, statusReportRequested, null); 4770825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } else { 4780825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville spb = com.android.internal.telephony.gsm.SmsMessage.getSubmitPdu(scAddress, 4790825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville destinationAddress, message, statusReportRequested); 4800825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 4810825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 4820825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return new SubmitPdu(spb); 4830825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 4840825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 4850825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 4860825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Get an SMS-SUBMIT PDU for a data message to a destination address & port. 4870825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * This method will not attempt to use any GSM national language 7 bit encodings. 4880825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * 4890825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @param scAddress Service Centre address. null == use default 4900825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @param destinationAddress the address of the destination for the message 4910825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @param destinationPort the port to deliver the message to at the 4920825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * destination 4930825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @param data the data for the message 4940825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @return a <code>SubmitPdu</code> containing the encoded SC 4950825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * address, if applicable, and the encoded message. 4960825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Returns null on encode error. 4970825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 4980825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public static SubmitPdu getSubmitPdu(String scAddress, 4990825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville String destinationAddress, short destinationPort, byte[] data, 5000825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville boolean statusReportRequested) { 5010825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville SubmitPduBase spb; 5020825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 5031260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa if (useCdmaFormatForMoSms()) { 5040825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville spb = com.android.internal.telephony.cdma.SmsMessage.getSubmitPdu(scAddress, 5050825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville destinationAddress, destinationPort, data, statusReportRequested); 5060825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } else { 5070825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville spb = com.android.internal.telephony.gsm.SmsMessage.getSubmitPdu(scAddress, 5080825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville destinationAddress, destinationPort, data, statusReportRequested); 5090825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 5100825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 5110825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return new SubmitPdu(spb); 5120825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 5130825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 5140825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 5150825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Returns the address of the SMS service center that relayed this message 5160825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * or null if there is none. 5170825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 5180825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public String getServiceCenterAddress() { 5190825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return mWrappedSmsMessage.getServiceCenterAddress(); 5200825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 5210825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 5220825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 5230825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Returns the originating address (sender) of this SMS message in String 5240825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * form or null if unavailable 5250825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 5260825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public String getOriginatingAddress() { 5270825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return mWrappedSmsMessage.getOriginatingAddress(); 5280825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 5290825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 5300825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 5310825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Returns the originating address, or email from address if this message 5320825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * was from an email gateway. Returns null if originating address 5330825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * unavailable. 5340825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 5350825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public String getDisplayOriginatingAddress() { 5360825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return mWrappedSmsMessage.getDisplayOriginatingAddress(); 5370825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 5380825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 5390825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 5400825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Returns the message body as a String, if it exists and is text based. 5410825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @return message body is there is one, otherwise null 5420825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 5430825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public String getMessageBody() { 5440825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return mWrappedSmsMessage.getMessageBody(); 5450825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 5460825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 5470825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 5480825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Returns the class of this message. 5490825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 5500825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public MessageClass getMessageClass() { 5510825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville switch(mWrappedSmsMessage.getMessageClass()) { 5520825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville case CLASS_0: return MessageClass.CLASS_0; 5530825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville case CLASS_1: return MessageClass.CLASS_1; 5540825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville case CLASS_2: return MessageClass.CLASS_2; 5550825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville case CLASS_3: return MessageClass.CLASS_3; 5560825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville default: return MessageClass.UNKNOWN; 5570825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 5580825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 5590825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 5600825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 5610825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 5620825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Returns the message body, or email message body if this message was from 5630825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * an email gateway. Returns null if message body unavailable. 5640825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 5650825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public String getDisplayMessageBody() { 5660825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return mWrappedSmsMessage.getDisplayMessageBody(); 5670825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 5680825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 5690825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 5700825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Unofficial convention of a subject line enclosed in parens empty string 5710825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * if not present 5720825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 5730825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public String getPseudoSubject() { 5740825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return mWrappedSmsMessage.getPseudoSubject(); 5750825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 5760825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 5770825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 5780825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Returns the service centre timestamp in currentTimeMillis() format 5790825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 5800825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public long getTimestampMillis() { 5810825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return mWrappedSmsMessage.getTimestampMillis(); 5820825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 5830825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 5840825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 5850825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Returns true if message is an email. 5860825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * 5870825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @return true if this message came through an email gateway and email 5880825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * sender / subject / parsed body are available 5890825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 5900825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public boolean isEmail() { 5910825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return mWrappedSmsMessage.isEmail(); 5920825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 5930825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 5940825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 5950825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @return if isEmail() is true, body of the email sent through the gateway. 5960825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * null otherwise 5970825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 5980825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public String getEmailBody() { 5990825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return mWrappedSmsMessage.getEmailBody(); 6000825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 6010825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 6020825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 6030825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @return if isEmail() is true, email from address of email sent through 6040825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * the gateway. null otherwise 6050825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 6060825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public String getEmailFrom() { 6070825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return mWrappedSmsMessage.getEmailFrom(); 6080825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 6090825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 6100825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 6110825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Get protocol identifier. 6120825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 6130825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public int getProtocolIdentifier() { 6140825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return mWrappedSmsMessage.getProtocolIdentifier(); 6150825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 6160825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 6170825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 6180825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * See TS 23.040 9.2.3.9 returns true if this is a "replace short message" 6190825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * SMS 6200825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 6210825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public boolean isReplace() { 6220825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return mWrappedSmsMessage.isReplace(); 6230825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 6240825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 6250825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 6260825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Returns true for CPHS MWI toggle message. 6270825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * 6280825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @return true if this is a CPHS MWI toggle message See CPHS 4.2 section 6290825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * B.4.2 6300825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 6310825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public boolean isCphsMwiMessage() { 6320825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return mWrappedSmsMessage.isCphsMwiMessage(); 6330825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 6340825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 6350825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 6360825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * returns true if this message is a CPHS voicemail / message waiting 6370825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * indicator (MWI) clear message 6380825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 6390825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public boolean isMWIClearMessage() { 6400825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return mWrappedSmsMessage.isMWIClearMessage(); 6410825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 6420825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 6430825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 6440825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * returns true if this message is a CPHS voicemail / message waiting 6450825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * indicator (MWI) set message 6460825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 6470825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public boolean isMWISetMessage() { 6480825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return mWrappedSmsMessage.isMWISetMessage(); 6490825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 6500825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 6510825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 6520825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * returns true if this message is a "Message Waiting Indication Group: 6530825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Discard Message" notification and should not be stored. 6540825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 6550825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public boolean isMwiDontStore() { 6560825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return mWrappedSmsMessage.isMwiDontStore(); 6570825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 6580825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 6590825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 6600825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * returns the user data section minus the user data header if one was 6610825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * present. 6620825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 6630825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public byte[] getUserData() { 6640825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return mWrappedSmsMessage.getUserData(); 6650825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 6660825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 6670825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 6680825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Returns the raw PDU for the message. 6690825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * 6700825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @return the raw PDU for the message. 6710825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 6720825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public byte[] getPdu() { 6730825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return mWrappedSmsMessage.getPdu(); 6740825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 6750825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 6760825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 6770825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Returns the status of the message on the SIM (read, unread, sent, unsent). 6780825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * 6790825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @return the status of the message on the SIM. These are: 6800825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * SmsManager.STATUS_ON_SIM_FREE 6810825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * SmsManager.STATUS_ON_SIM_READ 6820825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * SmsManager.STATUS_ON_SIM_UNREAD 6830825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * SmsManager.STATUS_ON_SIM_SEND 6840825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * SmsManager.STATUS_ON_SIM_UNSENT 6850825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @deprecated Use getStatusOnIcc instead. 6860825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 6870825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville @Deprecated public int getStatusOnSim() { 6880825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return mWrappedSmsMessage.getStatusOnIcc(); 6890825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 6900825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 6910825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 6920825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Returns the status of the message on the ICC (read, unread, sent, unsent). 6930825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * 6940825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @return the status of the message on the ICC. These are: 6950825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * SmsManager.STATUS_ON_ICC_FREE 6960825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * SmsManager.STATUS_ON_ICC_READ 6970825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * SmsManager.STATUS_ON_ICC_UNREAD 6980825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * SmsManager.STATUS_ON_ICC_SEND 6990825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * SmsManager.STATUS_ON_ICC_UNSENT 7000825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 7010825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public int getStatusOnIcc() { 7020825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return mWrappedSmsMessage.getStatusOnIcc(); 7030825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 7040825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 7050825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 7060825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Returns the record index of the message on the SIM (1-based index). 7070825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @return the record index of the message on the SIM, or -1 if this 7080825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * SmsMessage was not created from a SIM SMS EF record. 7090825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @deprecated Use getIndexOnIcc instead. 7100825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 7110825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville @Deprecated public int getIndexOnSim() { 7120825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return mWrappedSmsMessage.getIndexOnIcc(); 7130825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 7140825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 7150825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 7160825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Returns the record index of the message on the ICC (1-based index). 7170825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @return the record index of the message on the ICC, or -1 if this 7180825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * SmsMessage was not created from a ICC SMS EF record. 7190825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 7200825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public int getIndexOnIcc() { 7210825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return mWrappedSmsMessage.getIndexOnIcc(); 7220825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 7230825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 7240825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 7250825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * GSM: 7260825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * For an SMS-STATUS-REPORT message, this returns the status field from 7270825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * the status report. This field indicates the status of a previously 7280825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * submitted SMS, if requested. See TS 23.040, 9.2.3.15 TP-Status for a 7290825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * description of values. 7300825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * CDMA: 7310825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * For not interfering with status codes from GSM, the value is 7320825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * shifted to the bits 31-16. 7330825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * The value is composed of an error class (bits 25-24) and a status code (bits 23-16). 7340825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Possible codes are described in C.S0015-B, v2.0, 4.5.21. 7350825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * 7360825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * @return 0 indicates the previously sent message was received. 7370825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * See TS 23.040, 9.9.2.3.15 and C.S0015-B, v2.0, 4.5.21 7380825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * for a description of other possible values. 7390825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 7400825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public int getStatus() { 7410825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return mWrappedSmsMessage.getStatus(); 7420825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 7430825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 7440825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 7450825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Return true iff the message is a SMS-STATUS-REPORT message. 7460825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 7470825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public boolean isStatusReportMessage() { 7480825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return mWrappedSmsMessage.isStatusReportMessage(); 7490825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 7500825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville 7510825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville /** 7520825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Returns true iff the <code>TP-Reply-Path</code> bit is set in 7530825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * this message. 7540825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */ 7550825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville public boolean isReplyPathPresent() { 7560825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville return mWrappedSmsMessage.isReplyPathPresent(); 7570825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville } 7581260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa 7591260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa /** 7601260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa * Determines whether or not to use CDMA format for MO SMS. 7611260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa * If SMS over IMS is supported, then format is based on IMS SMS format, 7621260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa * otherwise format is based on current phone type. 7631260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa * 7641260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa * @return true if Cdma format should be used for MO SMS, false otherwise. 7651260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa */ 7661260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa private static boolean useCdmaFormatForMoSms() { 7671260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa if (!SmsManager.getDefault().isImsSmsSupported()) { 7681260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa // use Voice technology to determine SMS format. 7691260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa return isCdmaVoice(); 7701260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa } 7711260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa // IMS is registered with SMS support, check the SMS format supported 7721260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa return (SmsConstants.FORMAT_3GPP2.equals(SmsManager.getDefault().getImsSmsFormat())); 7731260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa } 7741260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa 7751260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa /** 7761260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa * Determines whether or not to current phone type is cdma. 7771260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa * 7781260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa * @return true if current phone type is cdma, false otherwise. 7791260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa */ 7801260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa private static boolean isCdmaVoice() { 7811260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa int activePhone = TelephonyManager.getDefault().getCurrentPhoneType(); 7821260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa return (PHONE_TYPE_CDMA == activePhone); 7831260f1c6c909f2940989b72afe1b91fd83845eaaSukanya Rajkhowa } 784f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying 785f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying /** 786f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying * Decide if the carrier supports long SMS. 787f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying * {@hide} 788f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying */ 789f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying public static boolean hasEmsSupport() { 790f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying if (!isNoEmsSupportConfigListExisted()) { 791f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying return true; 792f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying } 793f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying 794f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan String simOperator; 795f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan String gid; 796f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan final long identity = Binder.clearCallingIdentity(); 797f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan try { 798e70617d81dcd42350a737b11c25532e1d43df4ffLegler Wu simOperator = TelephonyManager.getDefault().getSimOperatorNumeric(); 799f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan gid = TelephonyManager.getDefault().getGroupIdLevel1(); 800f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan } finally { 801f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan Binder.restoreCallingIdentity(identity); 802f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan } 8032463a1471273614bda6d3db8f207b31ca27443ccXia Ying 804306ab2c93d1a1102c3029fd95e2c586a0f82091eAmit Mahajan if (!TextUtils.isEmpty(simOperator)) { 805306ab2c93d1a1102c3029fd95e2c586a0f82091eAmit Mahajan for (NoEmsSupportConfig currentConfig : mNoEmsSupportConfigList) { 806306ab2c93d1a1102c3029fd95e2c586a0f82091eAmit Mahajan if (simOperator.startsWith(currentConfig.mOperatorNumber) && 807306ab2c93d1a1102c3029fd95e2c586a0f82091eAmit Mahajan (TextUtils.isEmpty(currentConfig.mGid1) || 808306ab2c93d1a1102c3029fd95e2c586a0f82091eAmit Mahajan (!TextUtils.isEmpty(currentConfig.mGid1) && 809306ab2c93d1a1102c3029fd95e2c586a0f82091eAmit Mahajan currentConfig.mGid1.equalsIgnoreCase(gid)))) { 810306ab2c93d1a1102c3029fd95e2c586a0f82091eAmit Mahajan return false; 811306ab2c93d1a1102c3029fd95e2c586a0f82091eAmit Mahajan } 812f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying } 813306ab2c93d1a1102c3029fd95e2c586a0f82091eAmit Mahajan } 814f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying return true; 815f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying } 816f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying 817f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying /** 818f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying * Check where to add " x/y" in each SMS segment, begin or end. 819f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying * {@hide} 820f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying */ 821f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying public static boolean shouldAppendPageNumberAsPrefix() { 822f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying if (!isNoEmsSupportConfigListExisted()) { 823f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying return false; 824f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying } 825f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying 826f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan String simOperator; 827f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan String gid; 828f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan final long identity = Binder.clearCallingIdentity(); 829f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan try { 830e70617d81dcd42350a737b11c25532e1d43df4ffLegler Wu simOperator = TelephonyManager.getDefault().getSimOperatorNumeric(); 831f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan gid = TelephonyManager.getDefault().getGroupIdLevel1(); 832f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan } finally { 833f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan Binder.restoreCallingIdentity(identity); 834f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan } 835e70617d81dcd42350a737b11c25532e1d43df4ffLegler Wu 836f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying for (NoEmsSupportConfig currentConfig : mNoEmsSupportConfigList) { 8372463a1471273614bda6d3db8f207b31ca27443ccXia Ying if (simOperator.startsWith(currentConfig.mOperatorNumber) && 8382463a1471273614bda6d3db8f207b31ca27443ccXia Ying (TextUtils.isEmpty(currentConfig.mGid1) || 8392463a1471273614bda6d3db8f207b31ca27443ccXia Ying (!TextUtils.isEmpty(currentConfig.mGid1) 8402463a1471273614bda6d3db8f207b31ca27443ccXia Ying && currentConfig.mGid1.equalsIgnoreCase(gid)))) { 841f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying return currentConfig.mIsPrefix; 842f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying } 843f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying } 844f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying return false; 845f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying } 846f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying 847f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying private static class NoEmsSupportConfig { 848f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying String mOperatorNumber; 8492463a1471273614bda6d3db8f207b31ca27443ccXia Ying String mGid1; 850f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying boolean mIsPrefix; 851f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying 852f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying public NoEmsSupportConfig(String[] config) { 853f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying mOperatorNumber = config[0]; 854f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying mIsPrefix = "prefix".equals(config[1]); 8552463a1471273614bda6d3db8f207b31ca27443ccXia Ying mGid1 = config.length > 2 ? config[2] : null; 856f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying } 857f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying 858f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying @Override 859f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying public String toString() { 860f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying return "NoEmsSupportConfig { mOperatorNumber = " + mOperatorNumber 8612463a1471273614bda6d3db8f207b31ca27443ccXia Ying + ", mIsPrefix = " + mIsPrefix + ", mGid1 = " + mGid1 + " }"; 862f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying } 863f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying } 864f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying 865f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying private static NoEmsSupportConfig[] mNoEmsSupportConfigList = null; 866f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying private static boolean mIsNoEmsSupportConfigListLoaded = false; 867f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying 868f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying private static boolean isNoEmsSupportConfigListExisted() { 869f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying if (!mIsNoEmsSupportConfigListLoaded) { 870f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying Resources r = Resources.getSystem(); 871f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying if (r != null) { 872f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying String[] listArray = r.getStringArray( 873f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying com.android.internal.R.array.no_ems_support_sim_operators); 874f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying if ((listArray != null) && (listArray.length > 0)) { 875f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying mNoEmsSupportConfigList = new NoEmsSupportConfig[listArray.length]; 876f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying for (int i=0; i<listArray.length; i++) { 877f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying mNoEmsSupportConfigList[i] = new NoEmsSupportConfig(listArray[i].split(";")); 878f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying } 879f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying } 880f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying mIsNoEmsSupportConfigListLoaded = true; 881f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying } 882f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying } 883f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying 884f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying if (mNoEmsSupportConfigList != null && mNoEmsSupportConfigList.length != 0) { 885f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying return true; 886f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying } 887f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying 888f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying return false; 889f3166841bf9df142e2fbd63b7647bae7da712044Xia Ying } 8900825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville} 891