summaryrefslogtreecommitdiffstats
path: root/telephony
diff options
context:
space:
mode:
Diffstat (limited to 'telephony')
-rw-r--r--telephony/java/android/telephony/JapanesePhoneNumberFormatter.java8
-rw-r--r--telephony/java/android/telephony/SmsCbConstants.java117
-rw-r--r--telephony/java/android/telephony/SmsCbMessage.java226
-rw-r--r--telephony/java/android/telephony/SmsManager.java64
-rw-r--r--telephony/java/android/telephony/SmsMessage.java12
-rw-r--r--telephony/java/android/telephony/TelephonyManager.java49
-rw-r--r--telephony/java/android/telephony/gsm/SmsMessage.java37
-rw-r--r--telephony/java/com/android/internal/telephony/CallManager.java20
-rw-r--r--telephony/java/com/android/internal/telephony/CallerInfo.java85
-rw-r--r--telephony/java/com/android/internal/telephony/CallerInfoAsyncQuery.java40
-rw-r--r--telephony/java/com/android/internal/telephony/DataConnectionTracker.java66
-rw-r--r--telephony/java/com/android/internal/telephony/GsmAlphabet.java1201
-rw-r--r--telephony/java/com/android/internal/telephony/ISms.aidl28
-rw-r--r--telephony/java/com/android/internal/telephony/IccPhoneBookInterfaceManager.java55
-rw-r--r--telephony/java/com/android/internal/telephony/IccSmsInterfaceManager.java2
-rw-r--r--telephony/java/com/android/internal/telephony/IccSmsInterfaceManagerProxy.java9
-rw-r--r--telephony/java/com/android/internal/telephony/IccUtils.java1
-rw-r--r--telephony/java/com/android/internal/telephony/IntRangeManager.java568
-rw-r--r--telephony/java/com/android/internal/telephony/PhoneBase.java4
-rw-r--r--telephony/java/com/android/internal/telephony/RIL.java9
-rw-r--r--[-rwxr-xr-x]telephony/java/com/android/internal/telephony/SMSDispatcher.java61
-rw-r--r--telephony/java/com/android/internal/telephony/SmsHeader.java30
-rw-r--r--telephony/java/com/android/internal/telephony/SmsMessageBase.java12
-rwxr-xr-x[-rw-r--r--]telephony/java/com/android/internal/telephony/WapPushOverSms.java27
-rwxr-xr-x[-rw-r--r--]telephony/java/com/android/internal/telephony/WspTypeDecoder.java1
-rw-r--r--telephony/java/com/android/internal/telephony/cat/CatService.java3
-rw-r--r--telephony/java/com/android/internal/telephony/cat/ResponseData.java2
-rwxr-xr-xtelephony/java/com/android/internal/telephony/cdma/CDMAPhone.java9
-rwxr-xr-xtelephony/java/com/android/internal/telephony/cdma/CdmaConnection.java5
-rw-r--r--telephony/java/com/android/internal/telephony/cdma/CdmaLteServiceStateTracker.java2
-rwxr-xr-x[-rw-r--r--]telephony/java/com/android/internal/telephony/cdma/CdmaSMSDispatcher.java76
-rwxr-xr-xtelephony/java/com/android/internal/telephony/cdma/CdmaServiceStateTracker.java2
-rw-r--r--telephony/java/com/android/internal/telephony/cdma/RuimPhoneBookInterfaceManager.java11
-rwxr-xr-x[-rw-r--r--]telephony/java/com/android/internal/telephony/cdma/RuimRecords.java47
-rw-r--r--telephony/java/com/android/internal/telephony/cdma/RuimSmsInterfaceManager.java12
-rw-r--r--telephony/java/com/android/internal/telephony/cdma/SmsMessage.java19
-rwxr-xr-xtelephony/java/com/android/internal/telephony/cdma/sms/BearerData.java5
-rw-r--r--telephony/java/com/android/internal/telephony/gsm/GSMPhone.java27
-rw-r--r--telephony/java/com/android/internal/telephony/gsm/GsmConnection.java3
-rw-r--r--telephony/java/com/android/internal/telephony/gsm/GsmDataConnection.java34
-rw-r--r--[-rwxr-xr-x]telephony/java/com/android/internal/telephony/gsm/GsmSMSDispatcher.java60
-rw-r--r--telephony/java/com/android/internal/telephony/gsm/GsmServiceStateTracker.java5
-rw-r--r--telephony/java/com/android/internal/telephony/gsm/SimPhoneBookInterfaceManager.java11
-rw-r--r--telephony/java/com/android/internal/telephony/gsm/SimSmsInterfaceManager.java107
-rw-r--r--telephony/java/com/android/internal/telephony/gsm/SmsBroadcastConfigInfo.java24
-rw-r--r--telephony/java/com/android/internal/telephony/gsm/SmsCbHeader.java179
-rw-r--r--telephony/java/com/android/internal/telephony/gsm/SmsMessage.java113
-rw-r--r--[-rwxr-xr-x]telephony/java/com/android/internal/telephony/sip/SipPhone.java5
-rw-r--r--telephony/tests/telephonytests/src/com/android/internal/telephony/GsmAlphabetTest.java59
-rw-r--r--telephony/tests/telephonytests/src/com/android/internal/telephony/GsmSmsCbTest.java410
-rw-r--r--telephony/tests/telephonytests/src/com/android/internal/telephony/GsmSmsTest.java193
-rw-r--r--telephony/tests/telephonytests/src/com/android/internal/telephony/IntRangeManagerTest.java374
-rw-r--r--telephony/tests/telephonytests/src/com/android/internal/telephony/PhoneNumberUtilsTest.java13
-rw-r--r--telephony/tests/telephonytests/src/com/android/internal/telephony/SmsMessageBodyTest.java450
54 files changed, 4193 insertions, 799 deletions
diff --git a/telephony/java/android/telephony/JapanesePhoneNumberFormatter.java b/telephony/java/android/telephony/JapanesePhoneNumberFormatter.java
index 6390d8e..f5e53ef 100644
--- a/telephony/java/android/telephony/JapanesePhoneNumberFormatter.java
+++ b/telephony/java/android/telephony/JapanesePhoneNumberFormatter.java
@@ -24,6 +24,7 @@ import android.text.Editable;
*
* 022-229-1234 0223-23-1234 022-301-9876 015-482-7849 0154-91-3478
* 01547-5-4534 090-1234-1234 080-0123-6789
+ * 050-0000-0000 060-0000-0000
* 0800-000-9999 0570-000-000 0276-00-0000
*
* As you can see, there is no straight-forward rule here.
@@ -31,7 +32,7 @@ import android.text.Editable;
*/
/* package */ class JapanesePhoneNumberFormatter {
private static short FORMAT_MAP[] = {
- -100, 10, 220, -15, 410, 530, -15, 670, 780, 1060,
+ -100, 10, 220, -15, 410, 530, 1200, 670, 780, 1060,
-100, -25, 20, 40, 70, 100, 150, 190, 200, 210,
-36, -100, -100, -35, -35, -35, 30, -100, -100, -100,
-35, -35, -35, -35, -35, -35, -35, -45, -35, -35,
@@ -84,7 +85,7 @@ import android.text.Editable;
-35, -25, -25, -25, -25, -25, -25, -25, -25, -25,
-25, -25, -25, -35, -35, -35, -25, -25, -25, 520,
-100, -100, -45, -100, -45, -100, -45, -100, -45, -100,
- -25, -100, -25, 540, 580, 590, 600, 610, 630, 640,
+ -26, -100, -25, 540, 580, 590, 600, 610, 630, 640,
-25, -35, -35, -35, -25, -25, -35, -35, -35, 550,
-35, -35, -25, -25, -25, -25, 560, 570, -25, -35,
-35, -35, -35, -35, -25, -25, -25, -25, -25, -25,
@@ -150,7 +151,8 @@ import android.text.Editable;
-35, 1170, -25, -35, 1180, -35, 1190, -35, -25, -25,
-100, -100, -45, -45, -100, -100, -100, -100, -100, -100,
-25, -35, -35, -35, -35, -35, -35, -25, -25, -35,
- -35, -35, -35, -35, -35, -35, -35, -35, -35, -45};
+ -35, -35, -35, -35, -35, -35, -35, -35, -35, -45,
+ -26, -15, -15, -15, -15, -15, -15, -15, -15, -15};
public static void format(Editable text) {
// Here, "root" means the position of "'":
diff --git a/telephony/java/android/telephony/SmsCbConstants.java b/telephony/java/android/telephony/SmsCbConstants.java
new file mode 100644
index 0000000..a1b4adf
--- /dev/null
+++ b/telephony/java/android/telephony/SmsCbConstants.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.telephony;
+
+/**
+ * Constants used in SMS Cell Broadcast messages.
+ *
+ * {@hide}
+ */
+public interface SmsCbConstants {
+ /** Start of PWS Message Identifier range (includes ETWS and CMAS). */
+ public static final int MESSAGE_ID_PWS_FIRST_IDENTIFIER = 0x1100;
+
+ /** Bitmask for messages of ETWS type (including future extensions). */
+ public static final int MESSAGE_ID_ETWS_TYPE_MASK = 0xFFF8;
+
+ /** Value for messages of ETWS type after applying {@link #MESSAGE_ID_ETWS_TYPE_MASK}. */
+ public static final int MESSAGE_ID_ETWS_TYPE = 0x1100;
+
+ /** ETWS Message Identifier for earthquake warning message. */
+ public static final int MESSAGE_ID_ETWS_EARTHQUAKE_WARNING = 0x1100;
+
+ /** ETWS Message Identifier for tsunami warning message. */
+ public static final int MESSAGE_ID_ETWS_TSUNAMI_WARNING = 0x1101;
+
+ /** ETWS Message Identifier for earthquake and tsunami combined warning message. */
+ public static final int MESSAGE_ID_ETWS_EARTHQUAKE_AND_TSUNAMI_WARNING = 0x1102;
+
+ /** ETWS Message Identifier for test message. */
+ public static final int MESSAGE_ID_ETWS_TEST_MESSAGE = 0x1103;
+
+ /** ETWS Message Identifier for messages related to other emergency types. */
+ public static final int MESSAGE_ID_ETWS_OTHER_EMERGENCY_TYPE = 0x1104;
+
+ /** Start of CMAS Message Identifier range. */
+ public static final int MESSAGE_ID_CMAS_FIRST_IDENTIFIER = 0x1112;
+
+ /** CMAS Message Identifier for Presidential Level alerts. */
+ public static final int MESSAGE_ID_CMAS_ALERT_PRESIDENTIAL_LEVEL = 0x1112;
+
+ /** CMAS Message Identifier for Extreme alerts, Urgency=Immediate, Certainty=Observed. */
+ public static final int MESSAGE_ID_CMAS_ALERT_EXTREME_IMMEDIATE_OBSERVED = 0x1113;
+
+ /** CMAS Message Identifier for Extreme alerts, Urgency=Immediate, Certainty=Likely. */
+ public static final int MESSAGE_ID_CMAS_ALERT_EXTREME_IMMEDIATE_LIKELY = 0x1114;
+
+ /** CMAS Message Identifier for Extreme alerts, Urgency=Expected, Certainty=Observed. */
+ public static final int MESSAGE_ID_CMAS_ALERT_EXTREME_EXPECTED_OBSERVED = 0x1115;
+
+ /** CMAS Message Identifier for Extreme alerts, Urgency=Expected, Certainty=Likely. */
+ public static final int MESSAGE_ID_CMAS_ALERT_EXTREME_EXPECTED_LIKELY = 0x1116;
+
+ /** CMAS Message Identifier for Severe alerts, Urgency=Immediate, Certainty=Observed. */
+ public static final int MESSAGE_ID_CMAS_ALERT_SEVERE_IMMEDIATE_OBSERVED = 0x1117;
+
+ /** CMAS Message Identifier for Severe alerts, Urgency=Immediate, Certainty=Likely. */
+ public static final int MESSAGE_ID_CMAS_ALERT_SEVERE_IMMEDIATE_LIKELY = 0x1118;
+
+ /** CMAS Message Identifier for Severe alerts, Urgency=Expected, Certainty=Observed. */
+ public static final int MESSAGE_ID_CMAS_ALERT_SEVERE_EXPECTED_OBSERVED = 0x1119;
+
+ /** CMAS Message Identifier for Severe alerts, Urgency=Expected, Certainty=Likely. */
+ public static final int MESSAGE_ID_CMAS_ALERT_SEVERE_EXPECTED_LIKELY = 0x111A;
+
+ /** CMAS Message Identifier for Child Abduction Emergency (Amber Alert). */
+ public static final int MESSAGE_ID_CMAS_ALERT_CHILD_ABDUCTION_EMERGENCY = 0x111B;
+
+ /** CMAS Message Identifier for the Required Monthly Test. */
+ public static final int MESSAGE_ID_CMAS_ALERT_REQUIRED_MONTHLY_TEST = 0x111C;
+
+ /** CMAS Message Identifier for CMAS Exercise. */
+ public static final int MESSAGE_ID_CMAS_ALERT_EXERCISE = 0x111D;
+
+ /** CMAS Message Identifier for operator defined use. */
+ public static final int MESSAGE_ID_CMAS_ALERT_OPERATOR_DEFINED_USE = 0x111E;
+
+ /** End of CMAS Message Identifier range (including future extensions). */
+ public static final int MESSAGE_ID_CMAS_LAST_IDENTIFIER = 0x112F;
+
+ /** End of PWS Message Identifier range (includes ETWS, CMAS, and future extensions). */
+ public static final int MESSAGE_ID_PWS_LAST_IDENTIFIER = 0x18FF;
+
+ /** ETWS message code flag to activate the popup display. */
+ public static final int MESSAGE_CODE_ETWS_ACTIVATE_POPUP = 0x100;
+
+ /** ETWS message code flag to activate the emergency user alert. */
+ public static final int MESSAGE_CODE_ETWS_EMERGENCY_USER_ALERT = 0x200;
+
+ /** ETWS warning type value for earthquake. */
+ public static final int ETWS_WARNING_TYPE_EARTHQUAKE = 0x00;
+
+ /** ETWS warning type value for tsunami. */
+ public static final int ETWS_WARNING_TYPE_TSUNAMI = 0x01;
+
+ /** ETWS warning type value for earthquake and tsunami. */
+ public static final int ETWS_WARNING_TYPE_EARTHQUAKE_AND_TSUNAMI = 0x02;
+
+ /** ETWS warning type value for test broadcast. */
+ public static final int ETWS_WARNING_TYPE_TEST = 0x03;
+
+ /** ETWS warning type value for other notifications. */
+ public static final int ETWS_WARNING_TYPE_OTHER = 0x04;
+}
diff --git a/telephony/java/android/telephony/SmsCbMessage.java b/telephony/java/android/telephony/SmsCbMessage.java
index 3543275..383e0f9 100644
--- a/telephony/java/android/telephony/SmsCbMessage.java
+++ b/telephony/java/android/telephony/SmsCbMessage.java
@@ -16,7 +16,11 @@
package android.telephony;
+import android.text.format.Time;
+import android.util.Log;
+
import com.android.internal.telephony.GsmAlphabet;
+import com.android.internal.telephony.IccUtils;
import com.android.internal.telephony.gsm.SmsCbHeader;
import java.io.UnsupportedEncodingException;
@@ -58,10 +62,13 @@ public class SmsCbMessage {
try {
return new SmsCbMessage(pdu);
} catch (IllegalArgumentException e) {
+ Log.w(LOG_TAG, "Failed parsing SMS-CB pdu", e);
return null;
}
}
+ private static final String LOG_TAG = "SMSCB";
+
/**
* Languages in the 0000xxxx DCS group as defined in 3GPP TS 23.038, section 5.
*/
@@ -80,15 +87,34 @@ public class SmsCbMessage {
private static final char CARRIAGE_RETURN = 0x0d;
+ private static final int PDU_BODY_PAGE_LENGTH = 82;
+
private SmsCbHeader mHeader;
private String mLanguage;
private String mBody;
+ /** Timestamp of ETWS primary notification with security. */
+ private long mPrimaryNotificationTimestamp;
+
+ /** 43 byte digital signature of ETWS primary notification with security. */
+ private byte[] mPrimaryNotificationDigitalSignature;
+
private SmsCbMessage(byte[] pdu) throws IllegalArgumentException {
mHeader = new SmsCbHeader(pdu);
- parseBody(pdu);
+ if (mHeader.format == SmsCbHeader.FORMAT_ETWS_PRIMARY) {
+ mBody = "ETWS";
+ // ETWS primary notification with security is 56 octets in length
+ if (pdu.length >= SmsCbHeader.PDU_LENGTH_ETWS) {
+ mPrimaryNotificationTimestamp = getTimestampMillis(pdu);
+ mPrimaryNotificationDigitalSignature = new byte[43];
+ // digital signature starts after 6 byte header and 7 byte timestamp
+ System.arraycopy(pdu, 13, mPrimaryNotificationDigitalSignature, 0, 43);
+ }
+ } else {
+ parseBody(pdu);
+ }
}
/**
@@ -149,6 +175,62 @@ public class SmsCbMessage {
return mHeader.updateNumber;
}
+ /**
+ * Get the format of this message.
+ * @return {@link SmsCbHeader#FORMAT_GSM}, {@link SmsCbHeader#FORMAT_UMTS}, or
+ * {@link SmsCbHeader#FORMAT_ETWS_PRIMARY}
+ */
+ public int getMessageFormat() {
+ return mHeader.format;
+ }
+
+ /**
+ * For ETWS primary notifications, return the emergency user alert flag.
+ * @return true to notify terminal to activate emergency user alert; false otherwise
+ */
+ public boolean getEtwsEmergencyUserAlert() {
+ return mHeader.etwsEmergencyUserAlert;
+ }
+
+ /**
+ * For ETWS primary notifications, return the popup flag.
+ * @return true to notify terminal to activate display popup; false otherwise
+ */
+ public boolean getEtwsPopup() {
+ return mHeader.etwsPopup;
+ }
+
+ /**
+ * For ETWS primary notifications, return the warning type.
+ * @return a value such as {@link SmsCbConstants#ETWS_WARNING_TYPE_EARTHQUAKE}
+ */
+ public int getEtwsWarningType() {
+ return mHeader.etwsWarningType;
+ }
+
+ /**
+ * For ETWS primary notifications, return the Warning-Security-Information timestamp.
+ * @return a timestamp in System.currentTimeMillis() format.
+ */
+ public long getEtwsSecurityTimestamp() {
+ return mPrimaryNotificationTimestamp;
+ }
+
+ /**
+ * For ETWS primary notifications, return the 43 byte digital signature.
+ * @return a byte array containing a copy of the digital signature
+ */
+ public byte[] getEtwsSecuritySignature() {
+ return mPrimaryNotificationDigitalSignature.clone();
+ }
+
+ /**
+ * Parse and unpack the body text according to the encoding in the DCS.
+ * After completing successfully this method will have assigned the body
+ * text into mBody, and optionally the language code into mLanguage
+ *
+ * @param pdu The pdu
+ */
private void parseBody(byte[] pdu) {
int encoding;
boolean hasLanguageIndicator = false;
@@ -221,28 +303,81 @@ public class SmsCbMessage {
break;
}
+ if (mHeader.format == SmsCbHeader.FORMAT_UMTS) {
+ // Payload may contain multiple pages
+ int nrPages = pdu[SmsCbHeader.PDU_HEADER_LENGTH];
+
+ if (pdu.length < SmsCbHeader.PDU_HEADER_LENGTH + 1 + (PDU_BODY_PAGE_LENGTH + 1)
+ * nrPages) {
+ throw new IllegalArgumentException("Pdu length " + pdu.length + " does not match "
+ + nrPages + " pages");
+ }
+
+ StringBuilder sb = new StringBuilder();
+
+ for (int i = 0; i < nrPages; i++) {
+ // Each page is 82 bytes followed by a length octet indicating
+ // the number of useful octets within those 82
+ int offset = SmsCbHeader.PDU_HEADER_LENGTH + 1 + (PDU_BODY_PAGE_LENGTH + 1) * i;
+ int length = pdu[offset + PDU_BODY_PAGE_LENGTH];
+
+ if (length > PDU_BODY_PAGE_LENGTH) {
+ throw new IllegalArgumentException("Page length " + length
+ + " exceeds maximum value " + PDU_BODY_PAGE_LENGTH);
+ }
+
+ sb.append(unpackBody(pdu, encoding, offset, length, hasLanguageIndicator));
+ }
+ mBody = sb.toString();
+ } else {
+ // Payload is one single page
+ int offset = SmsCbHeader.PDU_HEADER_LENGTH;
+ int length = pdu.length - offset;
+
+ mBody = unpackBody(pdu, encoding, offset, length, hasLanguageIndicator);
+ }
+ }
+
+ /**
+ * Unpack body text from the pdu using the given encoding, position and
+ * length within the pdu
+ *
+ * @param pdu The pdu
+ * @param encoding The encoding, as derived from the DCS
+ * @param offset Position of the first byte to unpack
+ * @param length Number of bytes to unpack
+ * @param hasLanguageIndicator true if the body text is preceded by a
+ * language indicator. If so, this method will as a side-effect
+ * assign the extracted language code into mLanguage
+ * @return Body text
+ */
+ private String unpackBody(byte[] pdu, int encoding, int offset, int length,
+ boolean hasLanguageIndicator) {
+ String body = null;
+
switch (encoding) {
case SmsMessage.ENCODING_7BIT:
- mBody = GsmAlphabet.gsm7BitPackedToString(pdu, SmsCbHeader.PDU_HEADER_LENGTH,
- (pdu.length - SmsCbHeader.PDU_HEADER_LENGTH) * 8 / 7);
+ body = GsmAlphabet.gsm7BitPackedToString(pdu, offset, length * 8 / 7);
- if (hasLanguageIndicator && mBody != null && mBody.length() > 2) {
- mLanguage = mBody.substring(0, 2);
- mBody = mBody.substring(3);
+ if (hasLanguageIndicator && body != null && body.length() > 2) {
+ // Language is two GSM characters followed by a CR.
+ // The actual body text is offset by 3 characters.
+ mLanguage = body.substring(0, 2);
+ body = body.substring(3);
}
break;
case SmsMessage.ENCODING_16BIT:
- int offset = SmsCbHeader.PDU_HEADER_LENGTH;
-
- if (hasLanguageIndicator && pdu.length >= SmsCbHeader.PDU_HEADER_LENGTH + 2) {
- mLanguage = GsmAlphabet.gsm7BitPackedToString(pdu,
- SmsCbHeader.PDU_HEADER_LENGTH, 2);
+ if (hasLanguageIndicator && pdu.length >= offset + 2) {
+ // Language is two GSM characters.
+ // The actual body text is offset by 2 bytes.
+ mLanguage = GsmAlphabet.gsm7BitPackedToString(pdu, offset, 2);
offset += 2;
+ length -= 2;
}
try {
- mBody = new String(pdu, offset, (pdu.length & 0xfffe) - offset, "utf-16");
+ body = new String(pdu, offset, (length & 0xfffe), "utf-16");
} catch (UnsupportedEncodingException e) {
// Eeeek
}
@@ -252,16 +387,73 @@ public class SmsCbMessage {
break;
}
- if (mBody != null) {
+ if (body != null) {
// Remove trailing carriage return
- for (int i = mBody.length() - 1; i >= 0; i--) {
- if (mBody.charAt(i) != CARRIAGE_RETURN) {
- mBody = mBody.substring(0, i + 1);
+ for (int i = body.length() - 1; i >= 0; i--) {
+ if (body.charAt(i) != CARRIAGE_RETURN) {
+ body = body.substring(0, i + 1);
break;
}
}
} else {
- mBody = "";
+ body = "";
}
+
+ return body;
+ }
+
+ /**
+ * Parses an ETWS primary notification timestamp and returns a currentTimeMillis()-style
+ * timestamp. Copied from com.android.internal.telephony.gsm.SmsMessage.
+ * @param pdu the ETWS primary notification PDU to decode
+ * @return the UTC timestamp from the Warning-Security-Information parameter
+ */
+ private long getTimestampMillis(byte[] pdu) {
+ // Timestamp starts after CB header, in pdu[6]
+ int year = IccUtils.gsmBcdByteToInt(pdu[6]);
+ int month = IccUtils.gsmBcdByteToInt(pdu[7]);
+ int day = IccUtils.gsmBcdByteToInt(pdu[8]);
+ int hour = IccUtils.gsmBcdByteToInt(pdu[9]);
+ int minute = IccUtils.gsmBcdByteToInt(pdu[10]);
+ int second = IccUtils.gsmBcdByteToInt(pdu[11]);
+
+ // For the timezone, the most significant bit of the
+ // least significant nibble is the sign byte
+ // (meaning the max range of this field is 79 quarter-hours,
+ // which is more than enough)
+
+ byte tzByte = pdu[12];
+
+ // Mask out sign bit.
+ int timezoneOffset = IccUtils.gsmBcdByteToInt((byte) (tzByte & (~0x08)));
+
+ timezoneOffset = ((tzByte & 0x08) == 0) ? timezoneOffset : -timezoneOffset;
+
+ Time time = new Time(Time.TIMEZONE_UTC);
+
+ // It's 2006. Should I really support years < 2000?
+ time.year = year >= 90 ? year + 1900 : year + 2000;
+ time.month = month - 1;
+ time.monthDay = day;
+ time.hour = hour;
+ time.minute = minute;
+ time.second = second;
+
+ // Timezone offset is in quarter hours.
+ return time.toMillis(true) - (timezoneOffset * 15 * 60 * 1000);
+ }
+
+ /**
+ * Append text to the message body. This is used to concatenate multi-page GSM broadcasts.
+ * @param body the text to append to this message
+ */
+ public void appendToBody(String body) {
+ mBody = mBody + body;
+ }
+
+ @Override
+ public String toString() {
+ return "SmsCbMessage{" + mHeader.toString() + ", language=" + mLanguage +
+ ", body=\"" + mBody + "\"}";
}
}
diff --git a/telephony/java/android/telephony/SmsManager.java b/telephony/java/android/telephony/SmsManager.java
index 6a346af..5bdc146 100644
--- a/telephony/java/android/telephony/SmsManager.java
+++ b/telephony/java/android/telephony/SmsManager.java
@@ -345,7 +345,7 @@ public final class SmsManager {
* message identifier. Note that if two different clients enable the same
* message identifier, they must both disable it for the device to stop
* receiving those messages. All received messages will be broadcast in an
- * intent with the action "android.provider.telephony.SMS_CB_RECEIVED".
+ * intent with the action "android.provider.Telephony.SMS_CB_RECEIVED".
* Note: This call is blocking, callers may want to avoid calling it from
* the main thread of an application.
*
@@ -401,6 +401,68 @@ public final class SmsManager {
}
/**
+ * Enable reception of cell broadcast (SMS-CB) messages with the given
+ * message identifier range. Note that if two different clients enable the same
+ * message identifier, they must both disable it for the device to stop
+ * receiving those messages. All received messages will be broadcast in an
+ * intent with the action "android.provider.Telephony.SMS_CB_RECEIVED".
+ * Note: This call is blocking, callers may want to avoid calling it from
+ * the main thread of an application.
+ *
+ * @param startMessageId first message identifier as specified in TS 23.041
+ * @param endMessageId last message identifier as specified in TS 23.041
+ * @return true if successful, false otherwise
+ * @see #disableCellBroadcastRange(int, int)
+ *
+ * {@hide}
+ */
+ public boolean enableCellBroadcastRange(int startMessageId, int endMessageId) {
+ boolean success = false;
+
+ try {
+ ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
+ if (iccISms != null) {
+ success = iccISms.enableCellBroadcastRange(startMessageId, endMessageId);
+ }
+ } catch (RemoteException ex) {
+ // ignore it
+ }
+
+ return success;
+ }
+
+ /**
+ * Disable reception of cell broadcast (SMS-CB) messages with the given
+ * message identifier range. Note that if two different clients enable the same
+ * message identifier, they must both disable it for the device to stop
+ * receiving those messages.
+ * Note: This call is blocking, callers may want to avoid calling it from
+ * the main thread of an application.
+ *
+ * @param startMessageId first message identifier as specified in TS 23.041
+ * @param endMessageId last message identifier as specified in TS 23.041
+ * @return true if successful, false otherwise
+ *
+ * @see #enableCellBroadcastRange(int, int)
+ *
+ * {@hide}
+ */
+ public boolean disableCellBroadcastRange(int startMessageId, int endMessageId) {
+ boolean success = false;
+
+ try {
+ ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
+ if (iccISms != null) {
+ success = iccISms.disableCellBroadcastRange(startMessageId, endMessageId);
+ }
+ } catch (RemoteException ex) {
+ // ignore it
+ }
+
+ return success;
+ }
+
+ /**
* Create a list of <code>SmsMessage</code>s from a list of RawSmsData
* records returned by <code>getAllMessagesFromIcc()</code>
*
diff --git a/telephony/java/android/telephony/SmsMessage.java b/telephony/java/android/telephony/SmsMessage.java
index 93d89a7..e75d96d 100644
--- a/telephony/java/android/telephony/SmsMessage.java
+++ b/telephony/java/android/telephony/SmsMessage.java
@@ -317,7 +317,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);
@@ -373,7 +374,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
@@ -400,7 +402,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
@@ -424,7 +427,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
diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java
index acbf08b..f7e0c66 100644
--- a/telephony/java/android/telephony/TelephonyManager.java
+++ b/telephony/java/android/telephony/TelephonyManager.java
@@ -61,7 +61,7 @@ public class TelephonyManager {
/** @hide */
public TelephonyManager(Context context) {
if (sContext == null) {
- sContext = context;
+ sContext = context.getApplicationContext();
sRegistry = ITelephonyRegistry.Stub.asInterface(ServiceManager.getService(
"telephony.registry"));
@@ -469,6 +469,46 @@ public class TelephonyManager {
}
}
+ /** Unknown network class. {@hide} */
+ public static final int NETWORK_CLASS_UNKNOWN = 0;
+ /** Class of broadly defined "2G" networks. {@hide} */
+ public static final int NETWORK_CLASS_2_G = 1;
+ /** Class of broadly defined "3G" networks. {@hide} */
+ public static final int NETWORK_CLASS_3_G = 2;
+ /** Class of broadly defined "4G" networks. {@hide} */
+ public static final int NETWORK_CLASS_4_G = 3;
+
+ /**
+ * Return general class of network type, such as "3G" or "4G". In cases
+ * where classification is contentious, this method is conservative.
+ *
+ * @hide
+ */
+ public static int getNetworkClass(int networkType) {
+ switch (networkType) {
+ case NETWORK_TYPE_GPRS:
+ case NETWORK_TYPE_EDGE:
+ case NETWORK_TYPE_CDMA:
+ case NETWORK_TYPE_1xRTT:
+ case NETWORK_TYPE_IDEN:
+ return NETWORK_CLASS_2_G;
+ case NETWORK_TYPE_UMTS:
+ case NETWORK_TYPE_EVDO_0:
+ case NETWORK_TYPE_EVDO_A:
+ case NETWORK_TYPE_HSDPA:
+ case NETWORK_TYPE_HSUPA:
+ case NETWORK_TYPE_HSPA:
+ case NETWORK_TYPE_EVDO_B:
+ case NETWORK_TYPE_EHRPD:
+ case NETWORK_TYPE_HSPAP:
+ return NETWORK_CLASS_3_G;
+ case NETWORK_TYPE_LTE:
+ return NETWORK_CLASS_4_G;
+ default:
+ return NETWORK_CLASS_UNKNOWN;
+ }
+ }
+
/**
* Returns a string representation of the radio technology (network type)
* currently in use on the device.
@@ -477,7 +517,12 @@ public class TelephonyManager {
* @hide pending API council review
*/
public String getNetworkTypeName() {
- switch (getNetworkType()) {
+ return getNetworkTypeName(getNetworkType());
+ }
+
+ /** {@hide} */
+ public static String getNetworkTypeName(int type) {
+ switch (type) {
case NETWORK_TYPE_GPRS:
return "GPRS";
case NETWORK_TYPE_EDGE:
diff --git a/telephony/java/android/telephony/gsm/SmsMessage.java b/telephony/java/android/telephony/gsm/SmsMessage.java
index 6880175..4af99a6 100644
--- a/telephony/java/android/telephony/gsm/SmsMessage.java
+++ b/telephony/java/android/telephony/gsm/SmsMessage.java
@@ -297,37 +297,14 @@ public class SmsMessage {
*/
@Deprecated
public static int[] calculateLength(CharSequence messageBody, boolean use7bitOnly) {
+ SmsMessageBase.TextEncodingDetails ted =
+ com.android.internal.telephony.gsm.SmsMessage
+ .calculateLength(messageBody, use7bitOnly);
int ret[] = new int[4];
-
- try {
- // Try GSM alphabet
- int septets = GsmAlphabet.countGsmSeptets(messageBody, !use7bitOnly);
- ret[1] = septets;
- if (septets > MAX_USER_DATA_SEPTETS) {
- ret[0] = (septets + (MAX_USER_DATA_SEPTETS_WITH_HEADER - 1)) /
- MAX_USER_DATA_SEPTETS_WITH_HEADER;
- ret[2] = (ret[0] * MAX_USER_DATA_SEPTETS_WITH_HEADER) - septets;
- } else {
- ret[0] = 1;
- ret[2] = MAX_USER_DATA_SEPTETS - septets;
- }
- ret[3] = ENCODING_7BIT;
- } catch (EncodeException ex) {
- // fall back to UCS-2
- int octets = messageBody.length() * 2;
- ret[1] = messageBody.length();
- if (octets > MAX_USER_DATA_BYTES) {
- // 6 is the size of the user data header
- ret[0] = (octets + (MAX_USER_DATA_BYTES_WITH_HEADER - 1)) /
- MAX_USER_DATA_BYTES_WITH_HEADER;
- ret[2] = ((ret[0] * MAX_USER_DATA_BYTES_WITH_HEADER) - octets) / 2;
- } else {
- ret[0] = 1;
- ret[2] = (MAX_USER_DATA_BYTES - octets)/2;
- }
- ret[3] = ENCODING_16BIT;
- }
-
+ ret[0] = ted.msgCount;
+ ret[1] = ted.codeUnitCount;
+ ret[2] = ted.codeUnitsRemaining;
+ ret[3] = ted.codeUnitSize;
return ret;
}
diff --git a/telephony/java/com/android/internal/telephony/CallManager.java b/telephony/java/com/android/internal/telephony/CallManager.java
index 7abae09..171b371 100644
--- a/telephony/java/com/android/internal/telephony/CallManager.java
+++ b/telephony/java/com/android/internal/telephony/CallManager.java
@@ -1803,33 +1803,33 @@ public final class CallManager {
Call call;
StringBuilder b = new StringBuilder();
- b.append("########### Dump CallManager ############");
- b.append("\nCallManager state = " + getState());
+ b.append("CallManager {");
+ b.append("\nstate = " + getState());
call = getActiveFgCall();
- b.append("\n - Foreground: " + getActiveFgCallState());
+ b.append("\n- Foreground: " + getActiveFgCallState());
b.append(" from " + call.getPhone());
- b.append("\n Conn: ").append(getFgCallConnections());
+ b.append("\n Conn: ").append(getFgCallConnections());
call = getFirstActiveBgCall();
- b.append("\n - Background: " + call.getState());
+ b.append("\n- Background: " + call.getState());
b.append(" from " + call.getPhone());
- b.append("\n Conn: ").append(getBgCallConnections());
+ b.append("\n Conn: ").append(getBgCallConnections());
call = getFirstActiveRingingCall();
- b.append("\n - Ringing: " +call.getState());
+ b.append("\n- Ringing: " +call.getState());
b.append(" from " + call.getPhone());
for (Phone phone : getAllPhones()) {
if (phone != null) {
- b.append("\n Phone: " + phone + ", name = " + phone.getPhoneName()
+ b.append("\nPhone: " + phone + ", name = " + phone.getPhoneName()
+ ", state = " + phone.getState());
call = phone.getForegroundCall();
- b.append("\n - Foreground: ").append(call);
+ b.append("\n- Foreground: ").append(call);
call = phone.getBackgroundCall();
b.append(" Background: ").append(call);
call = phone.getRingingCall();
b.append(" Ringing: ").append(call);
}
}
- b.append("\n########## End Dump CallManager ##########");
+ b.append("\n}");
return b.toString();
}
}
diff --git a/telephony/java/com/android/internal/telephony/CallerInfo.java b/telephony/java/com/android/internal/telephony/CallerInfo.java
index 014901d..68e0045 100644
--- a/telephony/java/com/android/internal/telephony/CallerInfo.java
+++ b/telephony/java/com/android/internal/telephony/CallerInfo.java
@@ -19,6 +19,7 @@ package com.android.internal.telephony;
import android.content.Context;
import android.database.Cursor;
import android.graphics.drawable.Drawable;
+import android.location.CountryDetector;
import android.net.Uri;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.Data;
@@ -29,6 +30,13 @@ import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
+import com.google.i18n.phonenumbers.geocoding.PhoneNumberOfflineGeocoder;
+import com.google.i18n.phonenumbers.NumberParseException;
+import com.google.i18n.phonenumbers.PhoneNumberUtil;
+import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
+
+import java.util.Locale;
+
/**
* Looks up caller information for the given phone number.
@@ -72,7 +80,8 @@ public class CallerInfo {
*/
public String name;
public String phoneNumber;
- public String nomalizedNumber;
+ public String normalizedNumber;
+ public String geoDescription;
public String cnapName;
public int numberPresentation;
@@ -131,7 +140,7 @@ public class CallerInfo {
info.isCachedPhotoCurrent = false;
info.contactExists = false;
- if (VDBG) Log.v(TAG, "construct callerInfo from cursor");
+ if (VDBG) Log.v(TAG, "getCallerInfo() based on cursor...");
if (cursor != null) {
if (cursor.moveToFirst()) {
@@ -156,7 +165,7 @@ public class CallerInfo {
// Look for the normalized number
columnIndex = cursor.getColumnIndex(PhoneLookup.NORMALIZED_NUMBER);
if (columnIndex != -1) {
- info.nomalizedNumber = cursor.getString(columnIndex);
+ info.normalizedNumber = cursor.getString(columnIndex);
}
// Look for the label/type combo
@@ -236,6 +245,8 @@ public class CallerInfo {
* with all relevant fields empty or null.
*/
public static CallerInfo getCallerInfo(Context context, String number) {
+ if (VDBG) Log.v(TAG, "getCallerInfo() based on number...");
+
if (TextUtils.isEmpty(number)) {
return null;
}
@@ -473,6 +484,68 @@ public class CallerInfo {
}
/**
+ * Updates this CallerInfo's geoDescription field, based on the raw
+ * phone number in the phoneNumber field.
+ *
+ * (Note that the various getCallerInfo() methods do *not* set the
+ * geoDescription automatically; you need to call this method
+ * explicitly to get it.)
+ *
+ * @param context the context used to look up the current locale / country
+ * @param fallbackNumber if this CallerInfo's phoneNumber field is empty,
+ * this specifies a fallback number to use instead.
+ */
+ public void updateGeoDescription(Context context, String fallbackNumber) {
+ String number = TextUtils.isEmpty(phoneNumber) ? fallbackNumber : phoneNumber;
+ geoDescription = getGeoDescription(context, number);
+ }
+
+ /**
+ * @return a geographical description string for the specified number.
+ * @see com.google.i18n.phonenumbers.PhoneNumberOfflineGeocoder
+ */
+ private static String getGeoDescription(Context context, String number) {
+ if (VDBG) Log.v(TAG, "getGeoDescription('" + number + "')...");
+
+ if (TextUtils.isEmpty(number)) {
+ return null;
+ }
+
+ PhoneNumberUtil util = PhoneNumberUtil.getInstance();
+ PhoneNumberOfflineGeocoder geocoder = PhoneNumberOfflineGeocoder.getInstance();
+
+ String countryIso;
+ Locale locale = context.getResources().getConfiguration().locale;
+ CountryDetector detector = (CountryDetector) context.getSystemService(
+ Context.COUNTRY_DETECTOR);
+ if (detector != null) {
+ countryIso = detector.detectCountry().getCountryIso();
+ } else {
+ countryIso = locale.getCountry();
+ Log.w(TAG, "No CountryDetector; falling back to countryIso based on locale: "
+ + countryIso);
+ }
+
+ PhoneNumber pn = null;
+ try {
+ if (VDBG) Log.v(TAG, "parsing '" + number
+ + "' for countryIso '" + countryIso + "'...");
+ pn = util.parse(number, countryIso);
+ if (VDBG) Log.v(TAG, "- parsed number: " + pn);
+ } catch (NumberParseException e) {
+ Log.w(TAG, "getGeoDescription: NumberParseException for incoming number '" + number + "'");
+ }
+
+ if (pn != null) {
+ String description = geocoder.getDescriptionForNumber(pn, locale);
+ if (VDBG) Log.v(TAG, "- got description: '" + description + "'");
+ return description;
+ } else {
+ return null;
+ }
+ }
+
+ /**
* @return a string debug representation of this instance.
*/
public String toString() {
@@ -482,8 +555,11 @@ public class CallerInfo {
if (VERBOSE_DEBUG) {
return new StringBuilder(384)
+ .append(super.toString() + " { ")
.append("\nname: " + name)
.append("\nphoneNumber: " + phoneNumber)
+ .append("\nnormalizedNumber: " + normalizedNumber)
+ .append("\ngeoDescription: " + geoDescription)
.append("\ncnapName: " + cnapName)
.append("\nnumberPresentation: " + numberPresentation)
.append("\nnamePresentation: " + namePresentation)
@@ -502,10 +578,11 @@ public class CallerInfo {
.append("\nemergency: " + mIsEmergency)
.append("\nvoicemail " + mIsVoiceMail)
.append("\ncontactExists " + contactExists)
+ .append(" }")
.toString();
} else {
return new StringBuilder(128)
- .append("CallerInfo { ")
+ .append(super.toString() + " { ")
.append("name " + ((name == null) ? "null" : "non-null"))
.append(", phoneNumber " + ((phoneNumber == null) ? "null" : "non-null"))
.append(" }")
diff --git a/telephony/java/com/android/internal/telephony/CallerInfoAsyncQuery.java b/telephony/java/com/android/internal/telephony/CallerInfoAsyncQuery.java
index c47e076..2e8a742 100644
--- a/telephony/java/com/android/internal/telephony/CallerInfoAsyncQuery.java
+++ b/telephony/java/com/android/internal/telephony/CallerInfoAsyncQuery.java
@@ -34,9 +34,11 @@ import android.text.TextUtils;
import android.util.Log;
/**
- * ASYNCHRONOUS QUERY API
+ * Helper class to make it easier to run asynchronous caller-id lookup queries.
+ * @see CallerInfo
+ *
+ * {@hide}
*/
-
public class CallerInfoAsyncQuery {
private static final boolean DBG = false;
private static final String LOG_TAG = "CallerInfoAsyncQuery";
@@ -49,6 +51,12 @@ public class CallerInfoAsyncQuery {
private CallerInfoAsyncQueryHandler mHandler;
+ // If the CallerInfo query finds no contacts, should we use the
+ // PhoneNumberOfflineGeocoder to look up a "geo description"?
+ // (TODO: This could become a flag in config.xml if it ever needs to be
+ // configured on a per-product basis.)
+ private static final boolean ENABLE_UNKNOWN_NUMBER_GEO_DESCRIPTION = true;
+
/**
* Interface for a CallerInfoAsyncQueryHandler result return.
*/
@@ -239,12 +247,34 @@ public class CallerInfoAsyncQuery {
+ mCallerInfo);
}
+ // Final step: look up the geocoded description.
+ if (ENABLE_UNKNOWN_NUMBER_GEO_DESCRIPTION) {
+ // Note we do this only if we *don't* have a valid name (i.e. if
+ // no contacts matched the phone number of the incoming call),
+ // since that's the only case where the incoming-call UI cares
+ // about this field.
+ //
+ // (TODO: But if we ever want the UI to show the geoDescription
+ // even when we *do* match a contact, we'll need to either call
+ // updateGeoDescription() unconditionally here, or possibly add a
+ // new parameter to CallerInfoAsyncQuery.startQuery() to force
+ // the geoDescription field to be populated.)
+
+ if (TextUtils.isEmpty(mCallerInfo.name)) {
+ // Actually when no contacts match the incoming phone number,
+ // the CallerInfo object is totally blank here (i.e. no name
+ // *or* phoneNumber). So we need to pass in cw.number as
+ // a fallback number.
+ mCallerInfo.updateGeoDescription(mQueryContext, cw.number);
+ }
+ }
+
// Use the number entered by the user for display.
if (!TextUtils.isEmpty(cw.number)) {
CountryDetector detector = (CountryDetector) mQueryContext.getSystemService(
Context.COUNTRY_DETECTOR);
mCallerInfo.phoneNumber = PhoneNumberUtils.formatNumber(cw.number,
- mCallerInfo.nomalizedNumber,
+ mCallerInfo.normalizedNumber,
detector.detectCountry().getCountryIso());
}
}
@@ -412,7 +442,7 @@ public class CallerInfoAsyncQuery {
* Method to create a new CallerInfoAsyncQueryHandler object, ensuring correct
* state of context and uri.
*/
- private void allocate (Context context, Uri contactRef) {
+ private void allocate(Context context, Uri contactRef) {
if ((context == null) || (contactRef == null)){
throw new QueryPoolException("Bad context or query uri.");
}
@@ -424,7 +454,7 @@ public class CallerInfoAsyncQuery {
/**
* Releases the relevant data.
*/
- private void release () {
+ private void release() {
mHandler.mQueryContext = null;
mHandler.mQueryUri = null;
mHandler.mCallerInfo = null;
diff --git a/telephony/java/com/android/internal/telephony/DataConnectionTracker.java b/telephony/java/com/android/internal/telephony/DataConnectionTracker.java
index 923cc21..3bd78e0 100644
--- a/telephony/java/com/android/internal/telephony/DataConnectionTracker.java
+++ b/telephony/java/com/android/internal/telephony/DataConnectionTracker.java
@@ -18,10 +18,12 @@ package com.android.internal.telephony;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
+import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
+import android.database.ContentObserver;
import android.net.LinkCapabilities;
import android.net.LinkProperties;
import android.net.NetworkInfo;
@@ -335,6 +337,31 @@ public abstract class DataConnectionTracker extends Handler {
}
};
+ private final DataRoamingSettingObserver mDataRoamingSettingObserver;
+
+ private class DataRoamingSettingObserver extends ContentObserver {
+ public DataRoamingSettingObserver(Handler handler) {
+ super(handler);
+ }
+
+ public void register(Context context) {
+ final ContentResolver resolver = context.getContentResolver();
+ resolver.registerContentObserver(
+ Settings.Secure.getUriFor(Settings.Secure.DATA_ROAMING), false, this);
+ }
+
+ public void unregister(Context context) {
+ final ContentResolver resolver = context.getContentResolver();
+ resolver.unregisterContentObserver(this);
+ }
+
+ @Override
+ public void onChange(boolean selfChange) {
+ // already running on mPhone handler thread
+ handleDataOnRoamingChange();
+ }
+ }
+
protected boolean isDataSetupCompleteOk(AsyncResult ar) {
if (ar.exception != null) {
if (DBG) log("isDataSetupCompleteOk return false, ar.result=" + ar.result);
@@ -399,6 +426,10 @@ public abstract class DataConnectionTracker extends Handler {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
mAutoAttachOnCreation = sp.getBoolean(PhoneBase.DATA_DISABLED_ON_BOOT_KEY, false);
+
+ // watch for changes to Settings.Secure.DATA_ROAMING
+ mDataRoamingSettingObserver = new DataRoamingSettingObserver(mPhone);
+ mDataRoamingSettingObserver.register(mPhone.getContext());
}
public void dispose() {
@@ -408,6 +439,7 @@ public abstract class DataConnectionTracker extends Handler {
mDataConnectionAsyncChannels.clear();
mIsDisposed = true;
mPhone.getContext().unregisterReceiver(this.mIntentReceiver);
+ mDataRoamingSettingObserver.unregister(mPhone.getContext());
}
protected void broadcastMessenger() {
@@ -462,32 +494,38 @@ public abstract class DataConnectionTracker extends Handler {
return result;
}
- //The data roaming setting is now located in the shared preferences.
- // See if the requested preference value is the same as that stored in
- // the shared values. If it is not, then update it.
+ /**
+ * Modify {@link Settings.Secure#DATA_ROAMING} value.
+ */
public void setDataOnRoamingEnabled(boolean enabled) {
if (getDataOnRoamingEnabled() != enabled) {
- Settings.Secure.putInt(mPhone.getContext().getContentResolver(),
- Settings.Secure.DATA_ROAMING, enabled ? 1 : 0);
- if (mPhone.getServiceState().getRoaming()) {
- if (enabled) {
- resetAllRetryCounts();
- }
- sendMessage(obtainMessage(EVENT_ROAMING_ON));
- }
+ final ContentResolver resolver = mPhone.getContext().getContentResolver();
+ Settings.Secure.putInt(resolver, Settings.Secure.DATA_ROAMING, enabled ? 1 : 0);
+ // will trigger handleDataOnRoamingChange() through observer
}
}
- // Retrieve the data roaming setting from the shared preferences.
+ /**
+ * Return current {@link Settings.Secure#DATA_ROAMING} value.
+ */
public boolean getDataOnRoamingEnabled() {
try {
- return Settings.Secure.getInt(
- mPhone.getContext().getContentResolver(), Settings.Secure.DATA_ROAMING) > 0;
+ final ContentResolver resolver = mPhone.getContext().getContentResolver();
+ return Settings.Secure.getInt(resolver, Settings.Secure.DATA_ROAMING) != 0;
} catch (SettingNotFoundException snfe) {
return false;
}
}
+ private void handleDataOnRoamingChange() {
+ if (mPhone.getServiceState().getRoaming()) {
+ if (getDataOnRoamingEnabled()) {
+ resetAllRetryCounts();
+ }
+ sendMessage(obtainMessage(EVENT_ROAMING_ON));
+ }
+ }
+
// abstract methods
protected abstract String getActionIntentReconnectAlarm();
protected abstract void startNetStatPoll();
diff --git a/telephony/java/com/android/internal/telephony/GsmAlphabet.java b/telephony/java/com/android/internal/telephony/GsmAlphabet.java
index e42827f..a3f4f1f 100644
--- a/telephony/java/com/android/internal/telephony/GsmAlphabet.java
+++ b/telephony/java/com/android/internal/telephony/GsmAlphabet.java
@@ -16,6 +16,7 @@
package com.android.internal.telephony;
+import android.content.res.Resources;
import android.text.TextUtils;
import android.util.SparseIntArray;
@@ -23,6 +24,14 @@ import android.util.Log;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
+import com.android.internal.R;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static android.telephony.SmsMessage.ENCODING_7BIT;
+import static android.telephony.SmsMessage.MAX_USER_DATA_SEPTETS;
+import static android.telephony.SmsMessage.MAX_USER_DATA_SEPTETS_WITH_HEADER;
/**
* This class implements the character set mapping between
@@ -32,29 +41,53 @@ import java.nio.charset.Charset;
* {@hide}
*/
public class GsmAlphabet {
- static final String LOG_TAG = "GSM";
-
+ private static final String TAG = "GSM";
+ private GsmAlphabet() { }
//***** Constants
/**
* This escapes extended characters, and when present indicates that the
- * following character should
- * be looked up in the "extended" table
+ * following character should be looked up in the "extended" table.
*
* gsmToChar(GSM_EXTENDED_ESCAPE) returns 0xffff
*/
-
public static final byte GSM_EXTENDED_ESCAPE = 0x1B;
+ /**
+ * User data header requires one octet for length. Count as one septet, because
+ * all combinations of header elements below will have at least one free bit
+ * when padding to the nearest septet boundary.
+ */
+ private static final int UDH_SEPTET_COST_LENGTH = 1;
/**
- * char to GSM alphabet char
- * Returns ' ' in GSM alphabet if there's no possible match
- * Returns GSM_EXTENDED_ESCAPE if this character is in the extended table
- * In this case, you must call charToGsmExtended() for the value that
- * should follow GSM_EXTENDED_ESCAPE in the GSM alphabet string
+ * Using a non-default language locking shift table OR single shift table
+ * requires a user data header of 3 octets, or 4 septets, plus UDH length.
+ */
+ private static final int UDH_SEPTET_COST_ONE_SHIFT_TABLE = 4;
+
+ /**
+ * Using a non-default language locking shift table AND single shift table
+ * requires a user data header of 6 octets, or 7 septets, plus UDH length.
+ */
+ private static final int UDH_SEPTET_COST_TWO_SHIFT_TABLES = 7;
+
+ /**
+ * Multi-part messages require a user data header of 5 octets, or 6 septets,
+ * plus UDH length.
+ */
+ private static final int UDH_SEPTET_COST_CONCATENATED_MESSAGE = 6;
+
+ /**
+ * Converts a char to a GSM 7 bit table index.
+ * Returns ' ' in GSM alphabet if there's no possible match. Returns
+ * GSM_EXTENDED_ESCAPE if this character is in the extended table.
+ * In this case, you must call charToGsmExtended() for the value
+ * that should follow GSM_EXTENDED_ESCAPE in the GSM alphabet string.
+ * @param c the character to convert
+ * @return the GSM 7 bit table index for the specified character
*/
public static int
charToGsm(char c) {
@@ -62,34 +95,36 @@ public class GsmAlphabet {
return charToGsm(c, false);
} catch (EncodeException ex) {
// this should never happen
- return sGsmSpaceChar;
+ return sCharsToGsmTables[0].get(' ', ' ');
}
}
/**
- * char to GSM alphabet char
+ * Converts a char to a GSM 7 bit table index.
+ * Returns GSM_EXTENDED_ESCAPE if this character is in the extended table.
+ * In this case, you must call charToGsmExtended() for the value that
+ * should follow GSM_EXTENDED_ESCAPE in the GSM alphabet string.
+ *
+ * @param c the character to convert
* @param throwException If true, throws EncodeException on invalid char.
* If false, returns GSM alphabet ' ' char.
- *
- * Returns GSM_EXTENDED_ESCAPE if this character is in the extended table
- * In this case, you must call charToGsmExtended() for the value that
- * should follow GSM_EXTENDED_ESCAPE in the GSM alphabet string
+ * @throws EncodeException encode error when throwException is true
+ * @return the GSM 7 bit table index for the specified character
*/
-
public static int
charToGsm(char c, boolean throwException) throws EncodeException {
int ret;
- ret = charToGsm.get(c, -1);
+ ret = sCharsToGsmTables[0].get(c, -1);
if (ret == -1) {
- ret = charToGsmExtended.get(c, -1);
+ ret = sCharsToShiftTables[0].get(c, -1);
if (ret == -1) {
if (throwException) {
throw new EncodeException(c);
} else {
- return sGsmSpaceChar;
+ return sCharsToGsmTables[0].get(' ', ' ');
}
} else {
return GSM_EXTENDED_ESCAPE;
@@ -97,44 +132,47 @@ public class GsmAlphabet {
}
return ret;
-
}
-
/**
- * char to extended GSM alphabet char
- *
- * Extended chars should be escaped with GSM_EXTENDED_ESCAPE
- *
- * Returns ' ' in GSM alphabet if there's no possible match
- *
+ * Converts a char to an extended GSM 7 bit table index.
+ * Extended chars should be escaped with GSM_EXTENDED_ESCAPE.
+ * Returns ' ' in GSM alphabet if there's no possible match.
+ * @param c the character to convert
+ * @return the GSM 7 bit extended table index for the specified character
*/
public static int
charToGsmExtended(char c) {
int ret;
- ret = charToGsmExtended.get(c, -1);
+ ret = sCharsToShiftTables[0].get(c, -1);
if (ret == -1) {
- return sGsmSpaceChar;
+ return sCharsToGsmTables[0].get(' ', ' ');
}
return ret;
}
/**
- * Converts a character in the GSM alphabet into a char
+ * Converts a character in the GSM alphabet into a char.
*
- * if GSM_EXTENDED_ESCAPE is passed, 0xffff is returned. In this case,
+ * If GSM_EXTENDED_ESCAPE is passed, 0xffff is returned. In this case,
* the following character in the stream should be decoded with
- * gsmExtendedToChar()
+ * gsmExtendedToChar().
+ *
+ * If an unmappable value is passed (one greater than 127), ' ' is returned.
*
- * If an unmappable value is passed (one greater than 127), ' ' is returned
+ * @param gsmChar the GSM 7 bit table index to convert
+ * @return the decoded character
*/
-
public static char
gsmToChar(int gsmChar) {
- return (char)gsmToChar.get(gsmChar, ' ');
+ if (gsmChar >= 0 && gsmChar < 128) {
+ return sLanguageTables[0].charAt(gsmChar);
+ } else {
+ return ' ';
+ }
}
/**
@@ -144,20 +182,26 @@ public class GsmAlphabet {
* extension page has yet been defined (see Note 1 in table 6.2.1.1 of
* TS 23.038 v7.00)
*
- * If an unmappable value is passed , ' ' is returned
+ * If an unmappable value is passed, the character from the GSM 7 bit
+ * default table will be used (table 6.2.1.1 of TS 23.038).
+ *
+ * @param gsmChar the GSM 7 bit extended table index to convert
+ * @return the decoded character
*/
-
public static char
gsmExtendedToChar(int gsmChar) {
- int ret;
-
- ret = gsmExtendedToChar.get(gsmChar, -1);
-
- if (ret == -1) {
+ if (gsmChar == GSM_EXTENDED_ESCAPE) {
return ' ';
+ } else if (gsmChar >= 0 && gsmChar < 128) {
+ char c = sLanguageShiftTables[0].charAt(gsmChar);
+ if (c == ' ') {
+ return sLanguageTables[0].charAt(gsmChar);
+ } else {
+ return c;
+ }
+ } else {
+ return ' '; // out of range
}
-
- return (char)ret;
}
/**
@@ -176,19 +220,24 @@ public class GsmAlphabet {
* @param data The text string to encode.
* @param header Optional header (including length byte) that precedes
* the encoded data, padded to septet boundary.
+ * @param languageTable the 7 bit language table, or 0 for the default GSM alphabet
+ * @param languageShiftTable the 7 bit single shift language table, or 0 for the default
+ * GSM extension table
* @return Byte array containing header and encoded data.
+ * @throws EncodeException if String is too large to encode
*/
- public static byte[] stringToGsm7BitPackedWithHeader(String data, byte[] header)
+ public static byte[] stringToGsm7BitPackedWithHeader(String data, byte[] header,
+ int languageTable, int languageShiftTable)
throws EncodeException {
-
if (header == null || header.length == 0) {
- return stringToGsm7BitPacked(data);
+ return stringToGsm7BitPacked(data, languageTable, languageShiftTable);
}
int headerBits = (header.length + 1) * 8;
int headerSeptets = (headerBits + 6) / 7;
- byte[] ret = stringToGsm7BitPacked(data, headerSeptets, true);
+ byte[] ret = stringToGsm7BitPacked(data, headerSeptets, true, languageTable,
+ languageShiftTable);
// Paste in the header
ret[1] = (byte)header.length;
@@ -208,11 +257,36 @@ public class GsmAlphabet {
* septets.
*
* @param data the data string to encode
+ * @return the encoded string
* @throws EncodeException if String is too large to encode
*/
public static byte[] stringToGsm7BitPacked(String data)
throws EncodeException {
- return stringToGsm7BitPacked(data, 0, true);
+ return stringToGsm7BitPacked(data, 0, true, 0, 0);
+ }
+
+ /**
+ * Converts a String into a byte array containing
+ * the 7-bit packed GSM Alphabet representation of the string.
+ *
+ * Unencodable chars are encoded as spaces
+ *
+ * Byte 0 in the returned byte array is the count of septets used
+ * The returned byte array is the minimum size required to store
+ * the packed septets. The returned array cannot contain more than 255
+ * septets.
+ *
+ * @param data the data string to encode
+ * @param languageTable the 7 bit language table, or 0 for the default GSM alphabet
+ * @param languageShiftTable the 7 bit single shift language table, or 0 for the default
+ * GSM extension table
+ * @return the encoded string
+ * @throws EncodeException if String is too large to encode
+ */
+ public static byte[] stringToGsm7BitPacked(String data, int languageTable,
+ int languageShiftTable)
+ throws EncodeException {
+ return stringToGsm7BitPacked(data, 0, true, languageTable, languageShiftTable);
}
/**
@@ -229,28 +303,48 @@ public class GsmAlphabet {
* the character data at the beginning of the array
* @param throwException If true, throws EncodeException on invalid char.
* If false, replaces unencodable char with GSM alphabet space char.
+ * @param languageTable the 7 bit language table, or 0 for the default GSM alphabet
+ * @param languageShiftTable the 7 bit single shift language table, or 0 for the default
+ * GSM extension table
+ * @return the encoded message
*
* @throws EncodeException if String is too large to encode
*/
public static byte[] stringToGsm7BitPacked(String data, int startingSeptetOffset,
- boolean throwException) throws EncodeException {
+ boolean throwException, int languageTable, int languageShiftTable)
+ throws EncodeException {
int dataLen = data.length();
- int septetCount = countGsmSeptets(data, throwException) + startingSeptetOffset;
+ int septetCount = countGsmSeptetsUsingTables(data, !throwException,
+ languageTable, languageShiftTable);
+ if (septetCount == -1) {
+ throw new EncodeException("countGsmSeptetsUsingTables(): unencodable char");
+ }
+ septetCount += startingSeptetOffset;
if (septetCount > 255) {
throw new EncodeException("Payload cannot exceed 255 septets");
}
int byteCount = ((septetCount * 7) + 7) / 8;
byte[] ret = new byte[byteCount + 1]; // Include space for one byte length prefix.
+ SparseIntArray charToLanguageTable = sCharsToGsmTables[languageTable];
+ SparseIntArray charToShiftTable = sCharsToShiftTables[languageShiftTable];
for (int i = 0, septets = startingSeptetOffset, bitOffset = startingSeptetOffset * 7;
i < dataLen && septets < septetCount;
i++, bitOffset += 7) {
char c = data.charAt(i);
- int v = GsmAlphabet.charToGsm(c, throwException);
- if (v == GSM_EXTENDED_ESCAPE) {
- v = GsmAlphabet.charToGsmExtended(c); // Lookup the extended char.
- packSmsChar(ret, bitOffset, GSM_EXTENDED_ESCAPE);
- bitOffset += 7;
- septets++;
+ int v = charToLanguageTable.get(c, -1);
+ if (v == -1) {
+ v = charToShiftTable.get(c, -1); // Lookup the extended char.
+ if (v == -1) {
+ if (throwException) {
+ throw new EncodeException("stringToGsm7BitPacked(): unencodable char");
+ } else {
+ v = charToLanguageTable.get(' ', ' '); // should return ASCII space
+ }
+ } else {
+ packSmsChar(ret, bitOffset, GSM_EXTENDED_ESCAPE);
+ bitOffset += 7;
+ septets++;
+ }
}
packSmsChar(ret, bitOffset, v);
septets++;
@@ -262,8 +356,10 @@ public class GsmAlphabet {
/**
* Pack a 7-bit char into its appropriate place in a byte array
*
+ * @param packedChars the destination byte array
* @param bitOffset the bit offset that the septet should be packed at
* (septet index * 7)
+ * @param value the 7-bit character to store
*/
private static void
packSmsChar(byte[] packedChars, int bitOffset, int value) {
@@ -290,7 +386,7 @@ public class GsmAlphabet {
*/
public static String gsm7BitPackedToString(byte[] pdu, int offset,
int lengthSeptets) {
- return gsm7BitPackedToString(pdu, offset, lengthSeptets, 0);
+ return gsm7BitPackedToString(pdu, offset, lengthSeptets, 0, 0, 0);
}
/**
@@ -304,15 +400,37 @@ public class GsmAlphabet {
* @param lengthSeptets string length in septets, not bytes
* @param numPaddingBits the number of padding bits before the start of the
* string in the first byte
+ * @param languageTable the 7 bit language table, or 0 for the default GSM alphabet
+ * @param shiftTable the 7 bit single shift language table, or 0 for the default
+ * GSM extension table
* @return String representation or null on decoding exception
*/
public static String gsm7BitPackedToString(byte[] pdu, int offset,
- int lengthSeptets, int numPaddingBits) {
+ int lengthSeptets, int numPaddingBits, int languageTable, int shiftTable) {
StringBuilder ret = new StringBuilder(lengthSeptets);
- boolean prevCharWasEscape;
+
+ if (languageTable < 0 || languageTable > sLanguageTables.length) {
+ Log.w(TAG, "unknown language table " + languageTable + ", using default");
+ languageTable = 0;
+ }
+ if (shiftTable < 0 || shiftTable > sLanguageShiftTables.length) {
+ Log.w(TAG, "unknown single shift table " + shiftTable + ", using default");
+ shiftTable = 0;
+ }
try {
- prevCharWasEscape = false;
+ boolean prevCharWasEscape = false;
+ String languageTableToChar = sLanguageTables[languageTable];
+ String shiftTableToChar = sLanguageShiftTables[shiftTable];
+
+ if (languageTableToChar.isEmpty()) {
+ Log.w(TAG, "no language table for code " + languageTable + ", using default");
+ languageTableToChar = sLanguageTables[0];
+ }
+ if (shiftTableToChar.isEmpty()) {
+ Log.w(TAG, "no single shift table for code " + shiftTable + ", using default");
+ shiftTableToChar = sLanguageShiftTables[0];
+ }
for (int i = 0 ; i < lengthSeptets ; i++) {
int bitOffset = (7 * i) + numPaddingBits;
@@ -332,16 +450,25 @@ public class GsmAlphabet {
}
if (prevCharWasEscape) {
- ret.append(GsmAlphabet.gsmExtendedToChar(gsmVal));
+ if (gsmVal == GSM_EXTENDED_ESCAPE) {
+ ret.append(' '); // display ' ' for reserved double escape sequence
+ } else {
+ char c = shiftTableToChar.charAt(gsmVal);
+ if (c == ' ') {
+ ret.append(languageTableToChar.charAt(gsmVal));
+ } else {
+ ret.append(c);
+ }
+ }
prevCharWasEscape = false;
} else if (gsmVal == GSM_EXTENDED_ESCAPE) {
prevCharWasEscape = true;
} else {
- ret.append(GsmAlphabet.gsmToChar(gsmVal));
+ ret.append(languageTableToChar.charAt(gsmVal));
}
}
} catch (RuntimeException ex) {
- Log.e(LOG_TAG, "Error GSM 7 bit packed: ", ex);
+ Log.e(TAG, "Error GSM 7 bit packed: ", ex);
return null;
}
@@ -355,6 +482,11 @@ public class GsmAlphabet {
*
* Field may be padded with trailing 0xff's. The decode stops
* at the first 0xff encountered.
+ *
+ * @param data the byte array to decode
+ * @param offset array offset for the first character to decode
+ * @param length the number of bytes to decode
+ * @return the decoded string
*/
public static String
gsm8BitUnpackedToString(byte[] data, int offset, int length) {
@@ -384,10 +516,13 @@ public class GsmAlphabet {
charset = Charset.forName(characterset);
mbcsBuffer = ByteBuffer.allocate(2);
}
- boolean prevWasEscape;
- StringBuilder ret = new StringBuilder(length);
- prevWasEscape = false;
+ // Always use GSM 7 bit default alphabet table for this method
+ String languageTableToChar = sLanguageTables[0];
+ String shiftTableToChar = sLanguageShiftTables[0];
+
+ StringBuilder ret = new StringBuilder(length);
+ boolean prevWasEscape = false;
for (int i = offset ; i < offset + length ; i++) {
// Never underestimate the pain that can be caused
// by signed bytes
@@ -407,10 +542,16 @@ public class GsmAlphabet {
}
} else {
if (prevWasEscape) {
- ret.append((char)gsmExtendedToChar.get(c, ' '));
+ char shiftChar = shiftTableToChar.charAt(c);
+ if (shiftChar == ' ') {
+ // display character from main table if not present in shift table
+ ret.append(languageTableToChar.charAt(c));
+ } else {
+ ret.append(shiftChar);
+ }
} else {
if (!isMbcs || c < 0x80 || i + 1 >= offset + length) {
- ret.append((char)gsmToChar.get(c, ' '));
+ ret.append(languageTableToChar.charAt(c));
} else {
// isMbcs must be true. So both mbcsBuffer and charset are initialized.
mbcsBuffer.clear();
@@ -427,16 +568,16 @@ public class GsmAlphabet {
}
/**
- * Convert a string into an 8-bit unpacked GSM alphabet byte
- * array
+ * Convert a string into an 8-bit unpacked GSM alphabet byte array.
+ * Always uses GSM default 7-bit alphabet and extension table.
+ * @param s the string to encode
+ * @return the 8-bit GSM encoded byte array for the string
*/
public static byte[]
stringToGsm8BitPacked(String s) {
byte[] ret;
- int septets = 0;
-
- septets = countGsmSeptets(s);
+ int septets = countGsmSeptetsUsingTables(s, true, 0, 0);
// Enough for all the septets and the length byte prefix
ret = new byte[septets];
@@ -449,14 +590,18 @@ public class GsmAlphabet {
/**
* Write a String into a GSM 8-bit unpacked field of
- * @param length size at @param offset in @param dest
- *
* Field is padded with 0xff's, string is truncated if necessary
+ *
+ * @param s the string to encode
+ * @param dest the destination byte array
+ * @param offset the starting offset for the encoded string
+ * @param length the maximum number of bytes to write
*/
-
public static void
stringToGsm8BitUnpackedField(String s, byte dest[], int offset, int length) {
int outByteIndex = offset;
+ SparseIntArray charToLanguageTable = sCharsToGsmTables[0];
+ SparseIntArray charToShiftTable = sCharsToShiftTables[0];
// Septets are stored in byte-aligned octets
for (int i = 0, sz = s.length()
@@ -465,17 +610,20 @@ public class GsmAlphabet {
) {
char c = s.charAt(i);
- int v = GsmAlphabet.charToGsm(c);
+ int v = charToLanguageTable.get(c, -1);
- if (v == GSM_EXTENDED_ESCAPE) {
- // make sure we can fit an escaped char
- if (! (outByteIndex + 1 - offset < length)) {
- break;
- }
-
- dest[outByteIndex++] = GSM_EXTENDED_ESCAPE;
+ if (v == -1) {
+ v = charToShiftTable.get(c, -1);
+ if (v == -1) {
+ v = charToLanguageTable.get(' ', ' '); // fall back to ASCII space
+ } else {
+ // make sure we can fit an escaped char
+ if (! (outByteIndex + 1 - offset < length)) {
+ break;
+ }
- v = GsmAlphabet.charToGsmExtended(c);
+ dest[outByteIndex++] = GSM_EXTENDED_ESCAPE;
+ }
}
dest[outByteIndex++] = (byte)v;
@@ -490,6 +638,8 @@ public class GsmAlphabet {
/**
* Returns the count of 7-bit GSM alphabet characters
* needed to represent this character. Counts unencodable char as 1 septet.
+ * @param c the character to examine
+ * @return the number of septets for this character
*/
public static int
countGsmSeptets(char c) {
@@ -503,17 +653,20 @@ public class GsmAlphabet {
/**
* Returns the count of 7-bit GSM alphabet characters
- * needed to represent this character
+ * needed to represent this character using the default 7 bit GSM alphabet.
+ * @param c the character to examine
* @param throwsException If true, throws EncodeException if unencodable
- * char. Otherwise, counts invalid char as 1 septet
+ * char. Otherwise, counts invalid char as 1 septet.
+ * @return the number of septets for this character
+ * @throws EncodeException the character can't be encoded and throwsException is true
*/
public static int
countGsmSeptets(char c, boolean throwsException) throws EncodeException {
- if (charToGsm.get(c, -1) != -1) {
+ if (sCharsToGsmTables[0].get(c, -1) != -1) {
return 1;
}
- if (charToGsmExtended.get(c, -1) != -1) {
+ if (sCharsToShiftTables[0].get(c, -1) != -1) {
return 2;
}
@@ -526,37 +679,196 @@ public class GsmAlphabet {
}
/**
- * Returns the count of 7-bit GSM alphabet characters
- * needed to represent this string. Counts unencodable char as 1 septet.
+ * Returns the count of 7-bit GSM alphabet characters needed
+ * to represent this string, using the specified 7-bit language table
+ * and extension table (0 for GSM default tables).
+ * @param s the Unicode string that will be encoded
+ * @param use7bitOnly allow using space in place of unencodable character if true,
+ * otherwise, return -1 if any characters are unencodable
+ * @param languageTable the 7 bit language table, or 0 for the default GSM alphabet
+ * @param languageShiftTable the 7 bit single shift language table, or 0 for the default
+ * GSM extension table
+ * @return the septet count for s using the specified language tables, or -1 if any
+ * characters are unencodable and use7bitOnly is false
*/
- public static int
- countGsmSeptets(CharSequence s) {
- try {
- return countGsmSeptets(s, false);
- } catch (EncodeException ex) {
- // this should never happen
- return 0;
+ public static int countGsmSeptetsUsingTables(CharSequence s, boolean use7bitOnly,
+ int languageTable, int languageShiftTable) {
+ int count = 0;
+ int sz = s.length();
+ SparseIntArray charToLanguageTable = sCharsToGsmTables[languageTable];
+ SparseIntArray charToShiftTable = sCharsToShiftTables[languageShiftTable];
+ for (int i = 0; i < sz; i++) {
+ char c = s.charAt(i);
+ if (c == GSM_EXTENDED_ESCAPE) {
+ Log.w(TAG, "countGsmSeptets() string contains Escape character, skipping.");
+ continue;
+ }
+ if (charToLanguageTable.get(c, -1) != -1) {
+ count++;
+ } else if (charToShiftTable.get(c, -1) != -1) {
+ count += 2; // escape + shift table index
+ } else if (use7bitOnly) {
+ count++; // encode as space
+ } else {
+ return -1; // caller must check for this case
+ }
}
+ return count;
}
/**
* Returns the count of 7-bit GSM alphabet characters
- * needed to represent this string.
- * @param throwsException If true, throws EncodeException if unencodable
- * char. Otherwise, counts invalid char as 1 septet
+ * needed to represent this string, and the language table and
+ * language shift table used to achieve this result.
+ * For multi-part text messages, each message part may use its
+ * own language table encoding as specified in the message header
+ * for that message. However, this method will only return the
+ * optimal encoding for the message as a whole. When the individual
+ * pieces are encoded, a more optimal encoding may be chosen for each
+ * piece of the message, but the message will be split into pieces
+ * based on the encoding chosen for the message as a whole.
+ * @param s the Unicode string that will be encoded
+ * @param use7bitOnly allow using space in place of unencodable character if true,
+ * using the language table pair with the fewest unencodable characters
+ * @return a TextEncodingDetails object containing the message and
+ * character counts for the most efficient 7-bit encoding,
+ * or null if there are no suitable language tables to encode the string.
*/
- public static int
- countGsmSeptets(CharSequence s, boolean throwsException) throws EncodeException {
- int charIndex = 0;
+ public static SmsMessageBase.TextEncodingDetails
+ countGsmSeptets(CharSequence s, boolean use7bitOnly) {
+ // fast path for common case where no national language shift tables are enabled
+ if (sEnabledSingleShiftTables.length + sEnabledLockingShiftTables.length == 0) {
+ SmsMessageBase.TextEncodingDetails ted = new SmsMessageBase.TextEncodingDetails();
+ int septets = GsmAlphabet.countGsmSeptetsUsingTables(s, use7bitOnly, 0, 0);
+ if (septets == -1) {
+ return null;
+ }
+ ted.codeUnitSize = ENCODING_7BIT;
+ ted.codeUnitCount = septets;
+ if (septets > MAX_USER_DATA_SEPTETS) {
+ ted.msgCount = (septets + (MAX_USER_DATA_SEPTETS_WITH_HEADER - 1)) /
+ MAX_USER_DATA_SEPTETS_WITH_HEADER;
+ ted.codeUnitsRemaining = (ted.msgCount *
+ MAX_USER_DATA_SEPTETS_WITH_HEADER) - septets;
+ } else {
+ ted.msgCount = 1;
+ ted.codeUnitsRemaining = MAX_USER_DATA_SEPTETS - septets;
+ }
+ ted.codeUnitSize = ENCODING_7BIT;
+ return ted;
+ }
+
+ int maxSingleShiftCode = sHighestEnabledSingleShiftCode;
+ List<LanguagePairCount> lpcList = new ArrayList<LanguagePairCount>(
+ sEnabledLockingShiftTables.length + 1);
+
+ // Always add default GSM 7-bit alphabet table
+ lpcList.add(new LanguagePairCount(0));
+ for (int i : sEnabledLockingShiftTables) {
+ // Avoid adding default table twice in case 0 is in the list of allowed tables
+ if (i != 0 && !sLanguageTables[i].isEmpty()) {
+ lpcList.add(new LanguagePairCount(i));
+ }
+ }
+
int sz = s.length();
- int count = 0;
+ // calculate septet count for each valid table / shift table pair
+ for (int i = 0; i < sz && !lpcList.isEmpty(); i++) {
+ char c = s.charAt(i);
+ if (c == GSM_EXTENDED_ESCAPE) {
+ Log.w(TAG, "countGsmSeptets() string contains Escape character, ignoring!");
+ continue;
+ }
+ // iterate through enabled locking shift tables
+ for (LanguagePairCount lpc : lpcList) {
+ int tableIndex = sCharsToGsmTables[lpc.languageCode].get(c, -1);
+ if (tableIndex == -1) {
+ // iterate through single shift tables for this locking table
+ for (int table = 0; table <= maxSingleShiftCode; table++) {
+ if (lpc.septetCounts[table] != -1) {
+ int shiftTableIndex = sCharsToShiftTables[table].get(c, -1);
+ if (shiftTableIndex == -1) {
+ if (use7bitOnly) {
+ // can't encode char, use space instead
+ lpc.septetCounts[table]++;
+ lpc.unencodableCounts[table]++;
+ } else {
+ // can't encode char, remove language pair from list
+ lpc.septetCounts[table] = -1;
+ }
+ } else {
+ // encode as Escape + index into shift table
+ lpc.septetCounts[table] += 2;
+ }
+ }
+ }
+ } else {
+ // encode as index into locking shift table for all pairs
+ for (int table = 0; table <= maxSingleShiftCode; table++) {
+ if (lpc.septetCounts[table] != -1) {
+ lpc.septetCounts[table]++;
+ }
+ }
+ }
+ }
+ }
- while (charIndex < sz) {
- count += countGsmSeptets(s.charAt(charIndex), throwsException);
- charIndex++;
+ // find the least cost encoding (lowest message count and most code units remaining)
+ SmsMessageBase.TextEncodingDetails ted = new SmsMessageBase.TextEncodingDetails();
+ ted.msgCount = Integer.MAX_VALUE;
+ ted.codeUnitSize = ENCODING_7BIT;
+ int minUnencodableCount = Integer.MAX_VALUE;
+ for (LanguagePairCount lpc : lpcList) {
+ for (int shiftTable = 0; shiftTable <= maxSingleShiftCode; shiftTable++) {
+ int septets = lpc.septetCounts[shiftTable];
+ if (septets == -1) {
+ continue;
+ }
+ int udhLength;
+ if (lpc.languageCode != 0 && shiftTable != 0) {
+ udhLength = UDH_SEPTET_COST_LENGTH + UDH_SEPTET_COST_TWO_SHIFT_TABLES;
+ } else if (lpc.languageCode != 0 || shiftTable != 0) {
+ udhLength = UDH_SEPTET_COST_LENGTH + UDH_SEPTET_COST_ONE_SHIFT_TABLE;
+ } else {
+ udhLength = 0;
+ }
+ int msgCount;
+ int septetsRemaining;
+ if (septets + udhLength > MAX_USER_DATA_SEPTETS) {
+ if (udhLength == 0) {
+ udhLength = UDH_SEPTET_COST_LENGTH;
+ }
+ udhLength += UDH_SEPTET_COST_CONCATENATED_MESSAGE;
+ int septetsPerMessage = MAX_USER_DATA_SEPTETS - udhLength;
+ msgCount = (septets + septetsPerMessage - 1) / septetsPerMessage;
+ septetsRemaining = (msgCount * septetsPerMessage) - septets;
+ } else {
+ msgCount = 1;
+ septetsRemaining = MAX_USER_DATA_SEPTETS - udhLength - septets;
+ }
+ // for 7-bit only mode, use language pair with the least unencodable chars
+ int unencodableCount = lpc.unencodableCounts[shiftTable];
+ if (use7bitOnly && unencodableCount > minUnencodableCount) {
+ continue;
+ }
+ if ((use7bitOnly && unencodableCount < minUnencodableCount)
+ || msgCount < ted.msgCount || (msgCount == ted.msgCount
+ && septetsRemaining > ted.codeUnitsRemaining)) {
+ minUnencodableCount = unencodableCount;
+ ted.msgCount = msgCount;
+ ted.codeUnitCount = septets;
+ ted.codeUnitsRemaining = septetsRemaining;
+ ted.languageTable = lpc.languageCode;
+ ted.languageShiftTable = shiftTable;
+ }
+ }
}
- return count;
+ if (ted.msgCount == Integer.MAX_VALUE) {
+ return null;
+ }
+
+ return ted;
}
/**
@@ -569,16 +881,31 @@ public class GsmAlphabet {
* @param start index of where to start counting septets
* @param limit maximum septets to include,
* e.g. <code>MAX_USER_DATA_SEPTETS</code>
+ * @param langTable the 7 bit character table to use (0 for default GSM 7-bit alphabet)
+ * @param langShiftTable the 7 bit shift table to use (0 for default GSM extension table)
* @return index of first character that won't fit, or the length
* of the entire string if everything fits
*/
public static int
- findGsmSeptetLimitIndex(String s, int start, int limit) {
+ findGsmSeptetLimitIndex(String s, int start, int limit, int langTable, int langShiftTable) {
int accumulator = 0;
int size = s.length();
+ SparseIntArray charToLangTable = sCharsToGsmTables[langTable];
+ SparseIntArray charToLangShiftTable = sCharsToShiftTables[langShiftTable];
for (int i = start; i < size; i++) {
- accumulator += countGsmSeptets(s.charAt(i));
+ int encodedSeptet = charToLangTable.get(s.charAt(i), -1);
+ if (encodedSeptet == -1) {
+ encodedSeptet = charToLangShiftTable.get(s.charAt(i), -1);
+ if (encodedSeptet == -1) {
+ // char not found, assume we're replacing with space
+ accumulator++;
+ } else {
+ accumulator += 2; // escape character + shift table index
+ }
+ } else {
+ accumulator++;
+ }
if (accumulator > limit) {
return i;
}
@@ -586,178 +913,488 @@ public class GsmAlphabet {
return size;
}
- // Set in the static initializer
- private static int sGsmSpaceChar;
+ /**
+ * Modify the array of enabled national language single shift tables for SMS
+ * encoding. This is used for unit testing, but could also be used to
+ * modify the enabled encodings based on the active MCC/MNC, for example.
+ *
+ * @param tables the new list of enabled single shift tables
+ */
+ static synchronized void setEnabledSingleShiftTables(int[] tables) {
+ sEnabledSingleShiftTables = tables;
- private static final SparseIntArray charToGsm = new SparseIntArray();
- private static final SparseIntArray gsmToChar = new SparseIntArray();
- private static final SparseIntArray charToGsmExtended = new SparseIntArray();
- private static final SparseIntArray gsmExtendedToChar = new SparseIntArray();
+ if (tables.length > 0) {
+ sHighestEnabledSingleShiftCode = tables[tables.length - 1];
+ } else {
+ sHighestEnabledSingleShiftCode = 0;
+ }
+ }
- static {
- int i = 0;
-
- charToGsm.put('@', i++);
- charToGsm.put('\u00a3', i++);
- charToGsm.put('$', i++);
- charToGsm.put('\u00a5', i++);
- charToGsm.put('\u00e8', i++);
- charToGsm.put('\u00e9', i++);
- charToGsm.put('\u00f9', i++);
- charToGsm.put('\u00ec', i++);
- charToGsm.put('\u00f2', i++);
- charToGsm.put('\u00c7', i++);
- charToGsm.put('\n', i++);
- charToGsm.put('\u00d8', i++);
- charToGsm.put('\u00f8', i++);
- charToGsm.put('\r', i++);
- charToGsm.put('\u00c5', i++);
- charToGsm.put('\u00e5', i++);
-
- charToGsm.put('\u0394', i++);
- charToGsm.put('_', i++);
- charToGsm.put('\u03a6', i++);
- charToGsm.put('\u0393', i++);
- charToGsm.put('\u039b', i++);
- charToGsm.put('\u03a9', i++);
- charToGsm.put('\u03a0', i++);
- charToGsm.put('\u03a8', i++);
- charToGsm.put('\u03a3', i++);
- charToGsm.put('\u0398', i++);
- charToGsm.put('\u039e', i++);
- charToGsm.put('\uffff', i++);
- charToGsm.put('\u00c6', i++);
- charToGsm.put('\u00e6', i++);
- charToGsm.put('\u00df', i++);
- charToGsm.put('\u00c9', i++);
-
- charToGsm.put(' ', i++);
- charToGsm.put('!', i++);
- charToGsm.put('"', i++);
- charToGsm.put('#', i++);
- charToGsm.put('\u00a4', i++);
- charToGsm.put('%', i++);
- charToGsm.put('&', i++);
- charToGsm.put('\'', i++);
- charToGsm.put('(', i++);
- charToGsm.put(')', i++);
- charToGsm.put('*', i++);
- charToGsm.put('+', i++);
- charToGsm.put(',', i++);
- charToGsm.put('-', i++);
- charToGsm.put('.', i++);
- charToGsm.put('/', i++);
-
- charToGsm.put('0', i++);
- charToGsm.put('1', i++);
- charToGsm.put('2', i++);
- charToGsm.put('3', i++);
- charToGsm.put('4', i++);
- charToGsm.put('5', i++);
- charToGsm.put('6', i++);
- charToGsm.put('7', i++);
- charToGsm.put('8', i++);
- charToGsm.put('9', i++);
- charToGsm.put(':', i++);
- charToGsm.put(';', i++);
- charToGsm.put('<', i++);
- charToGsm.put('=', i++);
- charToGsm.put('>', i++);
- charToGsm.put('?', i++);
-
- charToGsm.put('\u00a1', i++);
- charToGsm.put('A', i++);
- charToGsm.put('B', i++);
- charToGsm.put('C', i++);
- charToGsm.put('D', i++);
- charToGsm.put('E', i++);
- charToGsm.put('F', i++);
- charToGsm.put('G', i++);
- charToGsm.put('H', i++);
- charToGsm.put('I', i++);
- charToGsm.put('J', i++);
- charToGsm.put('K', i++);
- charToGsm.put('L', i++);
- charToGsm.put('M', i++);
- charToGsm.put('N', i++);
- charToGsm.put('O', i++);
-
- charToGsm.put('P', i++);
- charToGsm.put('Q', i++);
- charToGsm.put('R', i++);
- charToGsm.put('S', i++);
- charToGsm.put('T', i++);
- charToGsm.put('U', i++);
- charToGsm.put('V', i++);
- charToGsm.put('W', i++);
- charToGsm.put('X', i++);
- charToGsm.put('Y', i++);
- charToGsm.put('Z', i++);
- charToGsm.put('\u00c4', i++);
- charToGsm.put('\u00d6', i++);
- charToGsm.put('\u00d1', i++);
- charToGsm.put('\u00dc', i++);
- charToGsm.put('\u00a7', i++);
-
- charToGsm.put('\u00bf', i++);
- charToGsm.put('a', i++);
- charToGsm.put('b', i++);
- charToGsm.put('c', i++);
- charToGsm.put('d', i++);
- charToGsm.put('e', i++);
- charToGsm.put('f', i++);
- charToGsm.put('g', i++);
- charToGsm.put('h', i++);
- charToGsm.put('i', i++);
- charToGsm.put('j', i++);
- charToGsm.put('k', i++);
- charToGsm.put('l', i++);
- charToGsm.put('m', i++);
- charToGsm.put('n', i++);
- charToGsm.put('o', i++);
-
- charToGsm.put('p', i++);
- charToGsm.put('q', i++);
- charToGsm.put('r', i++);
- charToGsm.put('s', i++);
- charToGsm.put('t', i++);
- charToGsm.put('u', i++);
- charToGsm.put('v', i++);
- charToGsm.put('w', i++);
- charToGsm.put('x', i++);
- charToGsm.put('y', i++);
- charToGsm.put('z', i++);
- charToGsm.put('\u00e4', i++);
- charToGsm.put('\u00f6', i++);
- charToGsm.put('\u00f1', i++);
- charToGsm.put('\u00fc', i++);
- charToGsm.put('\u00e0', i++);
-
-
- charToGsmExtended.put('\f', 10);
- charToGsmExtended.put('^', 20);
- charToGsmExtended.put('{', 40);
- charToGsmExtended.put('}', 41);
- charToGsmExtended.put('\\', 47);
- charToGsmExtended.put('[', 60);
- charToGsmExtended.put('~', 61);
- charToGsmExtended.put(']', 62);
- charToGsmExtended.put('|', 64);
- charToGsmExtended.put('\u20ac', 101);
-
- int size = charToGsm.size();
- for (int j=0; j<size; j++) {
- gsmToChar.put(charToGsm.valueAt(j), charToGsm.keyAt(j));
- }
-
- size = charToGsmExtended.size();
- for (int j=0; j<size; j++) {
- gsmExtendedToChar.put(charToGsmExtended.valueAt(j), charToGsmExtended.keyAt(j));
- }
-
-
- sGsmSpaceChar = charToGsm.get(' ');
+ /**
+ * Modify the array of enabled national language locking shift tables for SMS
+ * encoding. This is used for unit testing, but could also be used to
+ * modify the enabled encodings based on the active MCC/MNC, for example.
+ *
+ * @param tables the new list of enabled locking shift tables
+ */
+ static synchronized void setEnabledLockingShiftTables(int[] tables) {
+ sEnabledLockingShiftTables = tables;
}
+ /**
+ * Return the array of enabled national language single shift tables for SMS
+ * encoding. This is used for unit testing. The returned array is not a copy, so
+ * the caller should be careful not to modify it.
+ *
+ * @return the list of enabled single shift tables
+ */
+ static synchronized int[] getEnabledSingleShiftTables() {
+ return sEnabledSingleShiftTables;
+ }
+
+ /**
+ * Return the array of enabled national language locking shift tables for SMS
+ * encoding. This is used for unit testing. The returned array is not a copy, so
+ * the caller should be careful not to modify it.
+ *
+ * @return the list of enabled locking shift tables
+ */
+ static synchronized int[] getEnabledLockingShiftTables() {
+ return sEnabledLockingShiftTables;
+ }
+
+ /** Reverse mapping from Unicode characters to indexes into language tables. */
+ private static final SparseIntArray[] sCharsToGsmTables;
+
+ /** Reverse mapping from Unicode characters to indexes into language shift tables. */
+ private static final SparseIntArray[] sCharsToShiftTables;
+
+ /** OEM configured list of enabled national language single shift tables for encoding. */
+ private static int[] sEnabledSingleShiftTables;
+ /** OEM configured list of enabled national language locking shift tables for encoding. */
+ private static int[] sEnabledLockingShiftTables;
+
+ /** Highest language code to include in array of single shift counters. */
+ private static int sHighestEnabledSingleShiftCode;
+
+ /**
+ * Septet counter for a specific locking shift table and all of
+ * the single shift tables that it can be paired with.
+ */
+ private static class LanguagePairCount {
+ final int languageCode;
+ final int[] septetCounts;
+ final int[] unencodableCounts;
+ LanguagePairCount(int code) {
+ this.languageCode = code;
+ int maxSingleShiftCode = sHighestEnabledSingleShiftCode;
+ septetCounts = new int[maxSingleShiftCode + 1];
+ unencodableCounts = new int[maxSingleShiftCode + 1];
+ // set counters for disabled single shift tables to -1
+ // (GSM default extension table index 0 is always enabled)
+ for (int i = 1, tableOffset = 0; i <= maxSingleShiftCode; i++) {
+ if (sEnabledSingleShiftTables[tableOffset] == i) {
+ tableOffset++;
+ } else {
+ septetCounts[i] = -1; // disabled
+ }
+ }
+ // exclude Turkish locking + Turkish single shift table and
+ // Portuguese locking + Spanish single shift table (these
+ // combinations will never be optimal for any input).
+ if (code == 1 && maxSingleShiftCode >= 1) {
+ septetCounts[1] = -1; // Turkish + Turkish
+ } else if (code == 3 && maxSingleShiftCode >= 2) {
+ septetCounts[2] = -1; // Portuguese + Spanish
+ }
+ }
+ }
+
+ /**
+ * GSM default 7 bit alphabet plus national language locking shift character tables.
+ * Comment lines above strings indicate the lower four bits of the table position.
+ */
+ private static final String[] sLanguageTables = {
+ /* 3GPP TS 23.038 V9.1.1 section 6.2.1 - GSM 7 bit Default Alphabet
+ 01.....23.....4.....5.....6.....7.....8.....9.....A.B.....C.....D.E.....F.....0.....1 */
+ "@\u00a3$\u00a5\u00e8\u00e9\u00f9\u00ec\u00f2\u00c7\n\u00d8\u00f8\r\u00c5\u00e5\u0394_"
+ // 2.....3.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....E.....
+ + "\u03a6\u0393\u039b\u03a9\u03a0\u03a8\u03a3\u0398\u039e\uffff\u00c6\u00e6\u00df"
+ // F.....012.34.....56789ABCDEF0123456789ABCDEF0.....123456789ABCDEF0123456789A
+ + "\u00c9 !\"#\u00a4%&'()*+,-./0123456789:;<=>?\u00a1ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ // B.....C.....D.....E.....F.....0.....123456789ABCDEF0123456789AB.....C.....D.....
+ + "\u00c4\u00d6\u00d1\u00dc\u00a7\u00bfabcdefghijklmnopqrstuvwxyz\u00e4\u00f6\u00f1"
+ // E.....F.....
+ + "\u00fc\u00e0",
+
+ /* A.3.1 Turkish National Language Locking Shift Table
+ 01.....23.....4.....5.....6.....7.....8.....9.....A.B.....C.....D.E.....F.....0.....1 */
+ "@\u00a3$\u00a5\u20ac\u00e9\u00f9\u0131\u00f2\u00c7\n\u011e\u011f\r\u00c5\u00e5\u0394_"
+ // 2.....3.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....E.....
+ + "\u03a6\u0393\u039b\u03a9\u03a0\u03a8\u03a3\u0398\u039e\uffff\u015e\u015f\u00df"
+ // F.....012.34.....56789ABCDEF0123456789ABCDEF0.....123456789ABCDEF0123456789A
+ + "\u00c9 !\"#\u00a4%&'()*+,-./0123456789:;<=>?\u0130ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ // B.....C.....D.....E.....F.....0.....123456789ABCDEF0123456789AB.....C.....D.....
+ + "\u00c4\u00d6\u00d1\u00dc\u00a7\u00e7abcdefghijklmnopqrstuvwxyz\u00e4\u00f6\u00f1"
+ // E.....F.....
+ + "\u00fc\u00e0",
+
+ /* A.3.2 Void (no locking shift table for Spanish) */
+ "",
+
+ /* A.3.3 Portuguese National Language Locking Shift Table
+ 01.....23.....4.....5.....6.....7.....8.....9.....A.B.....C.....D.E.....F.....0.....1 */
+ "@\u00a3$\u00a5\u00ea\u00e9\u00fa\u00ed\u00f3\u00e7\n\u00d4\u00f4\r\u00c1\u00e1\u0394_"
+ // 2.....3.....4.....5.....67.8.....9.....AB.....C.....D.....E.....F.....012.34.....
+ + "\u00aa\u00c7\u00c0\u221e^\\\u20ac\u00d3|\uffff\u00c2\u00e2\u00ca\u00c9 !\"#\u00ba"
+ // 56789ABCDEF0123456789ABCDEF0.....123456789ABCDEF0123456789AB.....C.....D.....E.....
+ + "%&'()*+,-./0123456789:;<=>?\u00cdABCDEFGHIJKLMNOPQRSTUVWXYZ\u00c3\u00d5\u00da\u00dc"
+ // F.....0123456789ABCDEF0123456789AB.....C.....DE.....F.....
+ + "\u00a7~abcdefghijklmnopqrstuvwxyz\u00e3\u00f5`\u00fc\u00e0",
+
+ /* A.3.4 Bengali National Language Locking Shift Table
+ 0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.B.....CD.EF.....0..... */
+ "\u0981\u0982\u0983\u0985\u0986\u0987\u0988\u0989\u098a\u098b\n\u098c \r \u098f\u0990"
+ // 123.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....E.....F.....
+ + " \u0993\u0994\u0995\u0996\u0997\u0998\u0999\u099a\uffff\u099b\u099c\u099d\u099e"
+ // 012.....3.....4.....5.....6.....7.....89A.....B.....CD.....EF.....0123456789ABC
+ + " !\u099f\u09a0\u09a1\u09a2\u09a3\u09a4)(\u09a5\u09a6,\u09a7.\u09a80123456789:; "
+ // D.....E.....F0.....1.....2.....3.....4.....56.....789A.....B.....C.....D.....
+ + "\u09aa\u09ab?\u09ac\u09ad\u09ae\u09af\u09b0 \u09b2 \u09b6\u09b7\u09b8\u09b9"
+ // E.....F.....0.....1.....2.....3.....4.....5.....6.....789.....A.....BCD.....E.....
+ + "\u09bc\u09bd\u09be\u09bf\u09c0\u09c1\u09c2\u09c3\u09c4 \u09c7\u09c8 \u09cb\u09cc"
+ // F.....0.....123456789ABCDEF0123456789AB.....C.....D.....E.....F.....
+ + "\u09cd\u09ceabcdefghijklmnopqrstuvwxyz\u09d7\u09dc\u09dd\u09f0\u09f1",
+
+ /* A.3.5 Gujarati National Language Locking Shift Table
+ 0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.B.....C.....D.EF.....0.....*/
+ "\u0a81\u0a82\u0a83\u0a85\u0a86\u0a87\u0a88\u0a89\u0a8a\u0a8b\n\u0a8c\u0a8d\r \u0a8f\u0a90"
+ // 1.....23.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....E.....
+ + "\u0a91 \u0a93\u0a94\u0a95\u0a96\u0a97\u0a98\u0a99\u0a9a\uffff\u0a9b\u0a9c\u0a9d"
+ // F.....012.....3.....4.....5.....6.....7.....89A.....B.....CD.....EF.....0123456789AB
+ + "\u0a9e !\u0a9f\u0aa0\u0aa1\u0aa2\u0aa3\u0aa4)(\u0aa5\u0aa6,\u0aa7.\u0aa80123456789:;"
+ // CD.....E.....F0.....1.....2.....3.....4.....56.....7.....89.....A.....B.....C.....
+ + " \u0aaa\u0aab?\u0aac\u0aad\u0aae\u0aaf\u0ab0 \u0ab2\u0ab3 \u0ab5\u0ab6\u0ab7\u0ab8"
+ // D.....E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89.....A.....
+ + "\u0ab9\u0abc\u0abd\u0abe\u0abf\u0ac0\u0ac1\u0ac2\u0ac3\u0ac4\u0ac5 \u0ac7\u0ac8"
+ // B.....CD.....E.....F.....0.....123456789ABCDEF0123456789AB.....C.....D.....E.....
+ + "\u0ac9 \u0acb\u0acc\u0acd\u0ad0abcdefghijklmnopqrstuvwxyz\u0ae0\u0ae1\u0ae2\u0ae3"
+ // F.....
+ + "\u0af1",
+
+ /* A.3.6 Hindi National Language Locking Shift Table
+ 0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.B.....C.....D.E.....F.....*/
+ "\u0901\u0902\u0903\u0905\u0906\u0907\u0908\u0909\u090a\u090b\n\u090c\u090d\r\u090e\u090f"
+ // 0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....
+ + "\u0910\u0911\u0912\u0913\u0914\u0915\u0916\u0917\u0918\u0919\u091a\uffff\u091b\u091c"
+ // E.....F.....012.....3.....4.....5.....6.....7.....89A.....B.....CD.....EF.....012345
+ + "\u091d\u091e !\u091f\u0920\u0921\u0922\u0923\u0924)(\u0925\u0926,\u0927.\u0928012345"
+ // 6789ABC.....D.....E.....F0.....1.....2.....3.....4.....5.....6.....7.....8.....
+ + "6789:;\u0929\u092a\u092b?\u092c\u092d\u092e\u092f\u0930\u0931\u0932\u0933\u0934"
+ // 9.....A.....B.....C.....D.....E.....F.....0.....1.....2.....3.....4.....5.....6.....
+ + "\u0935\u0936\u0937\u0938\u0939\u093c\u093d\u093e\u093f\u0940\u0941\u0942\u0943\u0944"
+ // 7.....8.....9.....A.....B.....C.....D.....E.....F.....0.....123456789ABCDEF012345678
+ + "\u0945\u0946\u0947\u0948\u0949\u094a\u094b\u094c\u094d\u0950abcdefghijklmnopqrstuvwx"
+ // 9AB.....C.....D.....E.....F.....
+ + "yz\u0972\u097b\u097c\u097e\u097f",
+
+ /* A.3.7 Kannada National Language Locking Shift Table
+ NOTE: TS 23.038 V9.1.1 shows code 0x24 as \u0caa, corrected to \u0ca1 (typo)
+ 01.....2.....3.....4.....5.....6.....7.....8.....9.....A.B.....CD.E.....F.....0.....1 */
+ " \u0c82\u0c83\u0c85\u0c86\u0c87\u0c88\u0c89\u0c8a\u0c8b\n\u0c8c \r\u0c8e\u0c8f\u0c90 "
+ // 2.....3.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....E.....F.....
+ + "\u0c92\u0c93\u0c94\u0c95\u0c96\u0c97\u0c98\u0c99\u0c9a\uffff\u0c9b\u0c9c\u0c9d\u0c9e"
+ // 012.....3.....4.....5.....6.....7.....89A.....B.....CD.....EF.....0123456789ABC
+ + " !\u0c9f\u0ca0\u0ca1\u0ca2\u0ca3\u0ca4)(\u0ca5\u0ca6,\u0ca7.\u0ca80123456789:; "
+ // D.....E.....F0.....1.....2.....3.....4.....5.....6.....7.....89.....A.....B.....
+ + "\u0caa\u0cab?\u0cac\u0cad\u0cae\u0caf\u0cb0\u0cb1\u0cb2\u0cb3 \u0cb5\u0cb6\u0cb7"
+ // C.....D.....E.....F.....0.....1.....2.....3.....4.....5.....6.....78.....9.....
+ + "\u0cb8\u0cb9\u0cbc\u0cbd\u0cbe\u0cbf\u0cc0\u0cc1\u0cc2\u0cc3\u0cc4 \u0cc6\u0cc7"
+ // A.....BC.....D.....E.....F.....0.....123456789ABCDEF0123456789AB.....C.....D.....
+ + "\u0cc8 \u0cca\u0ccb\u0ccc\u0ccd\u0cd5abcdefghijklmnopqrstuvwxyz\u0cd6\u0ce0\u0ce1"
+ // E.....F.....
+ + "\u0ce2\u0ce3",
+
+ /* A.3.8 Malayalam National Language Locking Shift Table
+ 01.....2.....3.....4.....5.....6.....7.....8.....9.....A.B.....CD.E.....F.....0.....1 */
+ " \u0d02\u0d03\u0d05\u0d06\u0d07\u0d08\u0d09\u0d0a\u0d0b\n\u0d0c \r\u0d0e\u0d0f\u0d10 "
+ // 2.....3.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....E.....F.....
+ + "\u0d12\u0d13\u0d14\u0d15\u0d16\u0d17\u0d18\u0d19\u0d1a\uffff\u0d1b\u0d1c\u0d1d\u0d1e"
+ // 012.....3.....4.....5.....6.....7.....89A.....B.....CD.....EF.....0123456789ABC
+ + " !\u0d1f\u0d20\u0d21\u0d22\u0d23\u0d24)(\u0d25\u0d26,\u0d27.\u0d280123456789:; "
+ // D.....E.....F0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.....
+ + "\u0d2a\u0d2b?\u0d2c\u0d2d\u0d2e\u0d2f\u0d30\u0d31\u0d32\u0d33\u0d34\u0d35\u0d36"
+ // B.....C.....D.....EF.....0.....1.....2.....3.....4.....5.....6.....78.....9.....
+ + "\u0d37\u0d38\u0d39 \u0d3d\u0d3e\u0d3f\u0d40\u0d41\u0d42\u0d43\u0d44 \u0d46\u0d47"
+ // A.....BC.....D.....E.....F.....0.....123456789ABCDEF0123456789AB.....C.....D.....
+ + "\u0d48 \u0d4a\u0d4b\u0d4c\u0d4d\u0d57abcdefghijklmnopqrstuvwxyz\u0d60\u0d61\u0d62"
+ // E.....F.....
+ + "\u0d63\u0d79",
+
+ /* A.3.9 Oriya National Language Locking Shift Table
+ 0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.B.....CD.EF.....0.....12 */
+ "\u0b01\u0b02\u0b03\u0b05\u0b06\u0b07\u0b08\u0b09\u0b0a\u0b0b\n\u0b0c \r \u0b0f\u0b10 "
+ // 3.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....E.....F.....01
+ + "\u0b13\u0b14\u0b15\u0b16\u0b17\u0b18\u0b19\u0b1a\uffff\u0b1b\u0b1c\u0b1d\u0b1e !"
+ // 2.....3.....4.....5.....6.....7.....89A.....B.....CD.....EF.....0123456789ABCD.....
+ + "\u0b1f\u0b20\u0b21\u0b22\u0b23\u0b24)(\u0b25\u0b26,\u0b27.\u0b280123456789:; \u0b2a"
+ // E.....F0.....1.....2.....3.....4.....56.....7.....89.....A.....B.....C.....D.....
+ + "\u0b2b?\u0b2c\u0b2d\u0b2e\u0b2f\u0b30 \u0b32\u0b33 \u0b35\u0b36\u0b37\u0b38\u0b39"
+ // E.....F.....0.....1.....2.....3.....4.....5.....6.....789.....A.....BCD.....E.....
+ + "\u0b3c\u0b3d\u0b3e\u0b3f\u0b40\u0b41\u0b42\u0b43\u0b44 \u0b47\u0b48 \u0b4b\u0b4c"
+ // F.....0.....123456789ABCDEF0123456789AB.....C.....D.....E.....F.....
+ + "\u0b4d\u0b56abcdefghijklmnopqrstuvwxyz\u0b57\u0b60\u0b61\u0b62\u0b63",
+
+ /* A.3.10 Punjabi National Language Locking Shift Table
+ 0.....1.....2.....3.....4.....5.....6.....7.....8.....9A.BCD.EF.....0.....123.....4.....*/
+ "\u0a01\u0a02\u0a03\u0a05\u0a06\u0a07\u0a08\u0a09\u0a0a \n \r \u0a0f\u0a10 \u0a13\u0a14"
+ // 5.....6.....7.....8.....9.....A.....B.....C.....D.....E.....F.....012.....3.....
+ + "\u0a15\u0a16\u0a17\u0a18\u0a19\u0a1a\uffff\u0a1b\u0a1c\u0a1d\u0a1e !\u0a1f\u0a20"
+ // 4.....5.....6.....7.....89A.....B.....CD.....EF.....0123456789ABCD.....E.....F0.....
+ + "\u0a21\u0a22\u0a23\u0a24)(\u0a25\u0a26,\u0a27.\u0a280123456789:; \u0a2a\u0a2b?\u0a2c"
+ // 1.....2.....3.....4.....56.....7.....89.....A.....BC.....D.....E.....F0.....1.....
+ + "\u0a2d\u0a2e\u0a2f\u0a30 \u0a32\u0a33 \u0a35\u0a36 \u0a38\u0a39\u0a3c \u0a3e\u0a3f"
+ // 2.....3.....4.....56789.....A.....BCD.....E.....F.....0.....123456789ABCDEF012345678
+ + "\u0a40\u0a41\u0a42 \u0a47\u0a48 \u0a4b\u0a4c\u0a4d\u0a51abcdefghijklmnopqrstuvwx"
+ // 9AB.....C.....D.....E.....F.....
+ + "yz\u0a70\u0a71\u0a72\u0a73\u0a74",
+
+ /* A.3.11 Tamil National Language Locking Shift Table
+ 01.....2.....3.....4.....5.....6.....7.....8.....9A.BCD.E.....F.....0.....12.....3..... */
+ " \u0b82\u0b83\u0b85\u0b86\u0b87\u0b88\u0b89\u0b8a \n \r\u0b8e\u0b8f\u0b90 \u0b92\u0b93"
+ // 4.....5.....6789.....A.....B.....CD.....EF.....012.....3456.....7.....89ABCDEF.....
+ + "\u0b94\u0b95 \u0b99\u0b9a\uffff \u0b9c \u0b9e !\u0b9f \u0ba3\u0ba4)( , .\u0ba8"
+ // 0123456789ABC.....D.....EF012.....3.....4.....5.....6.....7.....8.....9.....A.....
+ + "0123456789:;\u0ba9\u0baa ? \u0bae\u0baf\u0bb0\u0bb1\u0bb2\u0bb3\u0bb4\u0bb5\u0bb6"
+ // B.....C.....D.....EF0.....1.....2.....3.....4.....5678.....9.....A.....BC.....D.....
+ + "\u0bb7\u0bb8\u0bb9 \u0bbe\u0bbf\u0bc0\u0bc1\u0bc2 \u0bc6\u0bc7\u0bc8 \u0bca\u0bcb"
+ // E.....F.....0.....123456789ABCDEF0123456789AB.....C.....D.....E.....F.....
+ + "\u0bcc\u0bcd\u0bd0abcdefghijklmnopqrstuvwxyz\u0bd7\u0bf0\u0bf1\u0bf2\u0bf9",
+
+ /* A.3.12 Telugu National Language Locking Shift Table
+ 0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.B.....CD.E.....F.....0.....*/
+ "\u0c01\u0c02\u0c03\u0c05\u0c06\u0c07\u0c08\u0c09\u0c0a\u0c0b\n\u0c0c \r\u0c0e\u0c0f\u0c10"
+ // 12.....3.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....E.....
+ + " \u0c12\u0c13\u0c14\u0c15\u0c16\u0c17\u0c18\u0c19\u0c1a\uffff\u0c1b\u0c1c\u0c1d"
+ // F.....012.....3.....4.....5.....6.....7.....89A.....B.....CD.....EF.....0123456789AB
+ + "\u0c1e !\u0c1f\u0c20\u0c21\u0c22\u0c23\u0c24)(\u0c25\u0c26,\u0c27.\u0c280123456789:;"
+ // CD.....E.....F0.....1.....2.....3.....4.....5.....6.....7.....89.....A.....B.....
+ + " \u0c2a\u0c2b?\u0c2c\u0c2d\u0c2e\u0c2f\u0c30\u0c31\u0c32\u0c33 \u0c35\u0c36\u0c37"
+ // C.....D.....EF.....0.....1.....2.....3.....4.....5.....6.....78.....9.....A.....B
+ + "\u0c38\u0c39 \u0c3d\u0c3e\u0c3f\u0c40\u0c41\u0c42\u0c43\u0c44 \u0c46\u0c47\u0c48 "
+ // C.....D.....E.....F.....0.....123456789ABCDEF0123456789AB.....C.....D.....E.....
+ + "\u0c4a\u0c4b\u0c4c\u0c4d\u0c55abcdefghijklmnopqrstuvwxyz\u0c56\u0c60\u0c61\u0c62"
+ // F.....
+ + "\u0c63",
+
+ /* A.3.13 Urdu National Language Locking Shift Table
+ 0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.B.....C.....D.E.....F.....*/
+ "\u0627\u0622\u0628\u067b\u0680\u067e\u06a6\u062a\u06c2\u067f\n\u0679\u067d\r\u067a\u067c"
+ // 0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.....B.....C.....D.....
+ + "\u062b\u062c\u0681\u0684\u0683\u0685\u0686\u0687\u062d\u062e\u062f\uffff\u068c\u0688"
+ // E.....F.....012.....3.....4.....5.....6.....7.....89A.....B.....CD.....EF.....012345
+ + "\u0689\u068a !\u068f\u068d\u0630\u0631\u0691\u0693)(\u0699\u0632,\u0696.\u0698012345"
+ // 6789ABC.....D.....E.....F0.....1.....2.....3.....4.....5.....6.....7.....8.....
+ + "6789:;\u069a\u0633\u0634?\u0635\u0636\u0637\u0638\u0639\u0641\u0642\u06a9\u06aa"
+ // 9.....A.....B.....C.....D.....E.....F.....0.....1.....2.....3.....4.....5.....6.....
+ + "\u06ab\u06af\u06b3\u06b1\u0644\u0645\u0646\u06ba\u06bb\u06bc\u0648\u06c4\u06d5\u06c1"
+ // 7.....8.....9.....A.....B.....C.....D.....E.....F.....0.....123456789ABCDEF012345678
+ + "\u06be\u0621\u06cc\u06d0\u06d2\u064d\u0650\u064f\u0657\u0654abcdefghijklmnopqrstuvwx"
+ // 9AB.....C.....D.....E.....F.....
+ + "yz\u0655\u0651\u0653\u0656\u0670"
+ };
+
+ /**
+ * GSM default extension table plus national language single shift character tables.
+ */
+ private static final String[] sLanguageShiftTables = new String[]{
+ /* 6.2.1.1 GSM 7 bit Default Alphabet Extension Table
+ 0123456789A.....BCDEF0123456789ABCDEF0123456789ABCDEF.0123456789ABCDEF0123456789ABCDEF */
+ " \u000c ^ {} \\ [~] | "
+ // 0123456789ABCDEF012345.....6789ABCDEF0123456789ABCDEF
+ + " \u20ac ",
+
+ /* A.2.1 Turkish National Language Single Shift Table
+ 0123456789A.....BCDEF0123456789ABCDEF0123456789ABCDEF.0123456789ABCDEF01234567.....8 */
+ " \u000c ^ {} \\ [~] | \u011e "
+ // 9.....ABCDEF0123.....456789ABCDEF0123.....45.....67.....89.....ABCDEF0123.....
+ + "\u0130 \u015e \u00e7 \u20ac \u011f \u0131 \u015f"
+ // 456789ABCDEF
+ + " ",
+
+ /* A.2.2 Spanish National Language Single Shift Table
+ 0123456789.....A.....BCDEF0123456789ABCDEF0123456789ABCDEF.0123456789ABCDEF01.....23 */
+ " \u00e7\u000c ^ {} \\ [~] |\u00c1 "
+ // 456789.....ABCDEF.....012345.....6789ABCDEF01.....2345.....6789.....ABCDEF.....012
+ + " \u00cd \u00d3 \u00da \u00e1 \u20ac \u00ed \u00f3 "
+ // 345.....6789ABCDEF
+ + " \u00fa ",
+
+ /* A.2.3 Portuguese National Language Single Shift Table
+ 012345.....6789.....A.....B.....C.....DE.....F.....012.....3.....45.....6.....7.....8....*/
+ " \u00ea \u00e7\u000c\u00d4\u00f4 \u00c1\u00e1 \u03a6\u0393^\u03a9\u03a0\u03a8\u03a3"
+ // 9.....ABCDEF.....0123456789ABCDEF.0123456789ABCDEF01.....23456789.....ABCDE
+ + "\u0398 \u00ca {} \\ [~] |\u00c0 \u00cd "
+ // F.....012345.....6789AB.....C.....DEF01.....2345.....6789.....ABCDEF.....01234
+ + "\u00d3 \u00da \u00c3\u00d5 \u00c2 \u20ac \u00ed \u00f3 "
+ // 5.....6789AB.....C.....DEF.....
+ + "\u00fa \u00e3\u00f5 \u00e2",
+
+ /* A.2.4 Bengali National Language Single Shift Table
+ 01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */
+ "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u09e6\u09e7 \u09e8\u09e9"
+ // E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89A.....B.....C.....
+ + "\u09ea\u09eb\u09ec\u09ed\u09ee\u09ef\u09df\u09e0\u09e1\u09e2{}\u09e3\u09f2\u09f3"
+ // D.....E.....F.0.....1.....2.....3.....4.....56789ABCDEF0123456789ABCDEF
+ + "\u09f4\u09f5\\\u09f6\u09f7\u09f8\u09f9\u09fa [~] |ABCDEFGHIJKLMNO"
+ // 0123456789ABCDEF012345.....6789ABCDEF0123456789ABCDEF
+ + "PQRSTUVWXYZ \u20ac ",
+
+ /* A.2.5 Gujarati National Language Single Shift Table
+ 01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */
+ "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u0964\u0965 \u0ae6\u0ae7"
+ // E.....F.....0.....1.....2.....3.....4.....5.....6789ABCDEF.0123456789ABCDEF
+ + "\u0ae8\u0ae9\u0aea\u0aeb\u0aec\u0aed\u0aee\u0aef {} \\ [~] "
+ // 0123456789ABCDEF0123456789ABCDEF012345.....6789ABCDEF0123456789ABCDEF
+ + "|ABCDEFGHIJKLMNOPQRSTUVWXYZ \u20ac ",
+
+ /* A.2.6 Hindi National Language Single Shift Table
+ 01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */
+ "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u0964\u0965 \u0966\u0967"
+ // E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89A.....B.....C.....
+ + "\u0968\u0969\u096a\u096b\u096c\u096d\u096e\u096f\u0951\u0952{}\u0953\u0954\u0958"
+ // D.....E.....F.0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.....
+ + "\u0959\u095a\\\u095b\u095c\u095d\u095e\u095f\u0960\u0961\u0962\u0963\u0970\u0971"
+ // BCDEF0123456789ABCDEF0123456789ABCDEF012345.....6789ABCDEF0123456789ABCDEF
+ + " [~] |ABCDEFGHIJKLMNOPQRSTUVWXYZ \u20ac ",
+
+ /* A.2.7 Kannada National Language Single Shift Table
+ 01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */
+ "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u0964\u0965 \u0ce6\u0ce7"
+ // E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89A.....BCDEF.01234567
+ + "\u0ce8\u0ce9\u0cea\u0ceb\u0cec\u0ced\u0cee\u0cef\u0cde\u0cf1{}\u0cf2 \\ "
+ // 89ABCDEF0123456789ABCDEF0123456789ABCDEF012345.....6789ABCDEF0123456789ABCDEF
+ + " [~] |ABCDEFGHIJKLMNOPQRSTUVWXYZ \u20ac ",
+
+ /* A.2.8 Malayalam National Language Single Shift Table
+ 01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */
+ "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u0964\u0965 \u0d66\u0d67"
+ // E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89A.....B.....C.....
+ + "\u0d68\u0d69\u0d6a\u0d6b\u0d6c\u0d6d\u0d6e\u0d6f\u0d70\u0d71{}\u0d72\u0d73\u0d74"
+ // D.....E.....F.0.....1.....2.....3.....4.....56789ABCDEF0123456789ABCDEF0123456789A
+ + "\u0d75\u0d7a\\\u0d7b\u0d7c\u0d7d\u0d7e\u0d7f [~] |ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ // BCDEF012345.....6789ABCDEF0123456789ABCDEF
+ + " \u20ac ",
+
+ /* A.2.9 Oriya National Language Single Shift Table
+ 01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */
+ "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u0964\u0965 \u0b66\u0b67"
+ // E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89A.....B.....C.....DE
+ + "\u0b68\u0b69\u0b6a\u0b6b\u0b6c\u0b6d\u0b6e\u0b6f\u0b5c\u0b5d{}\u0b5f\u0b70\u0b71 "
+ // F.0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF012345.....6789ABCDEF0123456789A
+ + "\\ [~] |ABCDEFGHIJKLMNOPQRSTUVWXYZ \u20ac "
+ // BCDEF
+ + " ",
+
+ /* A.2.10 Punjabi National Language Single Shift Table
+ 01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */
+ "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u0964\u0965 \u0a66\u0a67"
+ // E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89A.....B.....C.....
+ + "\u0a68\u0a69\u0a6a\u0a6b\u0a6c\u0a6d\u0a6e\u0a6f\u0a59\u0a5a{}\u0a5b\u0a5c\u0a5e"
+ // D.....EF.0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF012345.....6789ABCDEF01
+ + "\u0a75 \\ [~] |ABCDEFGHIJKLMNOPQRSTUVWXYZ \u20ac "
+ // 23456789ABCDEF
+ + " ",
+
+ /* A.2.11 Tamil National Language Single Shift Table
+ NOTE: TS 23.038 V9.1.1 shows code 0x24 as \u0bef, corrected to \u0bee (typo)
+ 01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */
+ "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u0964\u0965 \u0be6\u0be7"
+ // E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89A.....B.....C.....
+ + "\u0be8\u0be9\u0bea\u0beb\u0bec\u0bed\u0bee\u0bef\u0bf3\u0bf4{}\u0bf5\u0bf6\u0bf7"
+ // D.....E.....F.0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF012345.....6789ABC
+ + "\u0bf8\u0bfa\\ [~] |ABCDEFGHIJKLMNOPQRSTUVWXYZ \u20ac "
+ // DEF0123456789ABCDEF
+ + " ",
+
+ /* A.2.12 Telugu National Language Single Shift Table
+ NOTE: TS 23.038 V9.1.1 shows code 0x22-0x23 as \u06cc\u06cd, corrected to \u0c6c\u0c6d
+ 01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789ABC.....D.....E.....F..... */
+ "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#* \u0c66\u0c67\u0c68\u0c69"
+ // 0.....1.....2.....3.....4.....5.....6.....7.....89A.....B.....C.....D.....E.....F.
+ + "\u0c6a\u0c6b\u0c6c\u0c6d\u0c6e\u0c6f\u0c58\u0c59{}\u0c78\u0c79\u0c7a\u0c7b\u0c7c\\"
+ // 0.....1.....2.....3456789ABCDEF0123456789ABCDEF0123456789ABCDEF012345.....6789ABCD
+ + "\u0c7d\u0c7e\u0c7f [~] |ABCDEFGHIJKLMNOPQRSTUVWXYZ \u20ac "
+ // EF0123456789ABCDEF
+ + " ",
+
+ /* A.2.13 Urdu National Language Single Shift Table
+ 01.....23.....4.....5.6.....789A.....BCDEF0123.....45.....6789.....A.....BC.....D..... */
+ "@\u00a3$\u00a5\u00bf\"\u00a4%&'\u000c*+ -/<=>\u00a1^\u00a1_#*\u0600\u0601 \u06f0\u06f1"
+ // E.....F.....0.....1.....2.....3.....4.....5.....6.....7.....89A.....B.....C.....
+ + "\u06f2\u06f3\u06f4\u06f5\u06f6\u06f7\u06f8\u06f9\u060c\u060d{}\u060e\u060f\u0610"
+ // D.....E.....F.0.....1.....2.....3.....4.....5.....6.....7.....8.....9.....A.....
+ + "\u0611\u0612\\\u0613\u0614\u061b\u061f\u0640\u0652\u0658\u066b\u066c\u0672\u0673"
+ // B.....CDEF.....0123456789ABCDEF0123456789ABCDEF012345.....6789ABCDEF0123456789ABCDEF
+ + "\u06cd[~]\u06d4|ABCDEFGHIJKLMNOPQRSTUVWXYZ \u20ac "
+ };
+
+ static {
+ Resources r = Resources.getSystem();
+ // See comments in frameworks/base/core/res/res/values/config.xml for allowed values
+ sEnabledSingleShiftTables = r.getIntArray(R.array.config_sms_enabled_single_shift_tables);
+ sEnabledLockingShiftTables = r.getIntArray(R.array.config_sms_enabled_locking_shift_tables);
+ int numTables = sLanguageTables.length;
+ int numShiftTables = sLanguageShiftTables.length;
+ if (numTables != numShiftTables) {
+ Log.e(TAG, "Error: language tables array length " + numTables +
+ " != shift tables array length " + numShiftTables);
+ }
+
+ if (sEnabledSingleShiftTables.length > 0) {
+ sHighestEnabledSingleShiftCode =
+ sEnabledSingleShiftTables[sEnabledSingleShiftTables.length-1];
+ } else {
+ sHighestEnabledSingleShiftCode = 0;
+ }
+
+ sCharsToGsmTables = new SparseIntArray[numTables];
+ for (int i = 0; i < numTables; i++) {
+ String table = sLanguageTables[i];
+
+ int tableLen = table.length();
+ if (tableLen != 0 && tableLen != 128) {
+ Log.e(TAG, "Error: language tables index " + i +
+ " length " + tableLen + " (expected 128 or 0)");
+ }
+
+ SparseIntArray charToGsmTable = new SparseIntArray(tableLen);
+ sCharsToGsmTables[i] = charToGsmTable;
+ for (int j = 0; j < tableLen; j++) {
+ char c = table.charAt(j);
+ charToGsmTable.put(c, j);
+ }
+ }
+
+ sCharsToShiftTables = new SparseIntArray[numTables];
+ for (int i = 0; i < numShiftTables; i++) {
+ String shiftTable = sLanguageShiftTables[i];
+
+ int shiftTableLen = shiftTable.length();
+ if (shiftTableLen != 0 && shiftTableLen != 128) {
+ Log.e(TAG, "Error: language shift tables index " + i +
+ " length " + shiftTableLen + " (expected 128 or 0)");
+ }
+
+ SparseIntArray charToShiftTable = new SparseIntArray(shiftTableLen);
+ sCharsToShiftTables[i] = charToShiftTable;
+ for (int j = 0; j < shiftTableLen; j++) {
+ char c = shiftTable.charAt(j);
+ if (c != ' ') {
+ charToShiftTable.put(c, j);
+ }
+ }
+ }
+ }
}
diff --git a/telephony/java/com/android/internal/telephony/ISms.aidl b/telephony/java/com/android/internal/telephony/ISms.aidl
index 90de5e1..735f986 100644
--- a/telephony/java/com/android/internal/telephony/ISms.aidl
+++ b/telephony/java/com/android/internal/telephony/ISms.aidl
@@ -170,4 +170,32 @@ interface ISms {
*/
boolean disableCellBroadcast(int messageIdentifier);
+ /**
+ * Enable reception of cell broadcast (SMS-CB) messages with the given
+ * message identifier range. Note that if two different clients enable
+ * a message identifier range, they must both disable it for the device
+ * to stop receiving those messages.
+ *
+ * @param startMessageId first message identifier as specified in TS 23.041
+ * @param endMessageId last message identifier as specified in TS 23.041
+ * @return true if successful, false otherwise
+ *
+ * @see #disableCellBroadcastRange(int, int)
+ */
+ boolean enableCellBroadcastRange(int startMessageId, int endMessageId);
+
+ /**
+ * Disable reception of cell broadcast (SMS-CB) messages with the given
+ * message identifier range. Note that if two different clients enable
+ * a message identifier range, they must both disable it for the device
+ * to stop receiving those messages.
+ *
+ * @param startMessageId first message identifier as specified in TS 23.041
+ * @param endMessageId last message identifier as specified in TS 23.041
+ * @return true if successful, false otherwise
+ *
+ * @see #enableCellBroadcastRange(int, int)
+ */
+ boolean disableCellBroadcastRange(int startMessageId, int endMessageId);
+
}
diff --git a/telephony/java/com/android/internal/telephony/IccPhoneBookInterfaceManager.java b/telephony/java/com/android/internal/telephony/IccPhoneBookInterfaceManager.java
index 2f22d74..45562ca 100644
--- a/telephony/java/com/android/internal/telephony/IccPhoneBookInterfaceManager.java
+++ b/telephony/java/com/android/internal/telephony/IccPhoneBookInterfaceManager.java
@@ -24,6 +24,7 @@ import android.os.Message;
import android.os.ServiceManager;
import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
/**
* SimPhoneBookInterfaceManager to provide an inter-process communication to
@@ -63,14 +64,14 @@ public abstract class IccPhoneBookInterfaceManager extends IIccPhoneBook.Stub {
" total " + recordSize[1] +
" #record " + recordSize[2]);
}
- mLock.notifyAll();
+ notifyPending(ar);
}
break;
case EVENT_UPDATE_DONE:
ar = (AsyncResult) msg.obj;
synchronized (mLock) {
success = (ar.exception == null);
- mLock.notifyAll();
+ notifyPending(ar);
}
break;
case EVENT_LOAD_DONE:
@@ -84,11 +85,20 @@ public abstract class IccPhoneBookInterfaceManager extends IIccPhoneBook.Stub {
records.clear();
}
}
- mLock.notifyAll();
+ notifyPending(ar);
}
break;
}
}
+
+ private void notifyPending(AsyncResult ar) {
+ if (ar.userObj == null) {
+ return;
+ }
+ AtomicBoolean status = (AtomicBoolean) ar.userObj;
+ status.set(true);
+ mLock.notifyAll();
+ }
};
public IccPhoneBookInterfaceManager(PhoneBase phone) {
@@ -150,15 +160,12 @@ public abstract class IccPhoneBookInterfaceManager extends IIccPhoneBook.Stub {
synchronized(mLock) {
checkThread();
success = false;
- Message response = mBaseHandler.obtainMessage(EVENT_UPDATE_DONE);
+ AtomicBoolean status = new AtomicBoolean(false);
+ Message response = mBaseHandler.obtainMessage(EVENT_UPDATE_DONE, status);
AdnRecord oldAdn = new AdnRecord(oldTag, oldPhoneNumber);
AdnRecord newAdn = new AdnRecord(newTag, newPhoneNumber);
adnCache.updateAdnBySearch(efid, oldAdn, newAdn, pin2, response);
- try {
- mLock.wait();
- } catch (InterruptedException e) {
- logd("interrupted while trying to update by search");
- }
+ waitForResult(status);
}
return success;
}
@@ -197,14 +204,11 @@ public abstract class IccPhoneBookInterfaceManager extends IIccPhoneBook.Stub {
synchronized(mLock) {
checkThread();
success = false;
- Message response = mBaseHandler.obtainMessage(EVENT_UPDATE_DONE);
+ AtomicBoolean status = new AtomicBoolean(false);
+ Message response = mBaseHandler.obtainMessage(EVENT_UPDATE_DONE, status);
AdnRecord newAdn = new AdnRecord(newTag, newPhoneNumber);
adnCache.updateAdnByIndex(efid, newAdn, index, pin2, response);
- try {
- mLock.wait();
- } catch (InterruptedException e) {
- logd("interrupted while trying to update by index");
- }
+ waitForResult(status);
}
return success;
}
@@ -243,15 +247,12 @@ public abstract class IccPhoneBookInterfaceManager extends IIccPhoneBook.Stub {
synchronized(mLock) {
checkThread();
- Message response = mBaseHandler.obtainMessage(EVENT_LOAD_DONE);
+ AtomicBoolean status = new AtomicBoolean(false);
+ Message response = mBaseHandler.obtainMessage(EVENT_LOAD_DONE, status);
adnCache.requestLoadAllAdnLike(efid, adnCache.extensionEfForEf(efid), response);
- try {
- mLock.wait();
- } catch (InterruptedException e) {
- logd("interrupted while trying to load from the SIM");
- }
+ waitForResult(status);
}
- return records;
+ return records;
}
protected void checkThread() {
@@ -265,6 +266,16 @@ public abstract class IccPhoneBookInterfaceManager extends IIccPhoneBook.Stub {
}
}
+ protected void waitForResult(AtomicBoolean status) {
+ while (!status.get()) {
+ try {
+ mLock.wait();
+ } catch (InterruptedException e) {
+ logd("interrupted while trying to update by search");
+ }
+ }
+ }
+
private int updateEfForIccType(int efid) {
// Check if we are trying to read ADN records
if (efid == IccConstants.EF_ADN) {
diff --git a/telephony/java/com/android/internal/telephony/IccSmsInterfaceManager.java b/telephony/java/com/android/internal/telephony/IccSmsInterfaceManager.java
index 5fef6de..9763265 100644
--- a/telephony/java/com/android/internal/telephony/IccSmsInterfaceManager.java
+++ b/telephony/java/com/android/internal/telephony/IccSmsInterfaceManager.java
@@ -112,7 +112,7 @@ public abstract class IccSmsInterfaceManager extends ISms.Stub {
*/
public void sendText(String destAddr, String scAddr,
String text, PendingIntent sentIntent, PendingIntent deliveryIntent) {
- mPhone.getContext().enforceCallingPermission(
+ mPhone.getContext().enforceCallingOrSelfPermission(
"android.permission.SEND_SMS",
"Sending SMS message");
if (Log.isLoggable("SMS", Log.VERBOSE)) {
diff --git a/telephony/java/com/android/internal/telephony/IccSmsInterfaceManagerProxy.java b/telephony/java/com/android/internal/telephony/IccSmsInterfaceManagerProxy.java
index 5049249..54de508 100644
--- a/telephony/java/com/android/internal/telephony/IccSmsInterfaceManagerProxy.java
+++ b/telephony/java/com/android/internal/telephony/IccSmsInterfaceManagerProxy.java
@@ -76,4 +76,13 @@ public class IccSmsInterfaceManagerProxy extends ISms.Stub {
return mIccSmsInterfaceManager.disableCellBroadcast(messageIdentifier);
}
+ public boolean enableCellBroadcastRange(int startMessageId, int endMessageId)
+ throws android.os.RemoteException {
+ return mIccSmsInterfaceManager.enableCellBroadcastRange(startMessageId, endMessageId);
+ }
+
+ public boolean disableCellBroadcastRange(int startMessageId, int endMessageId)
+ throws android.os.RemoteException {
+ return mIccSmsInterfaceManager.disableCellBroadcastRange(startMessageId, endMessageId);
+ }
}
diff --git a/telephony/java/com/android/internal/telephony/IccUtils.java b/telephony/java/com/android/internal/telephony/IccUtils.java
index 8e60e6e..a966f76 100644
--- a/telephony/java/com/android/internal/telephony/IccUtils.java
+++ b/telephony/java/com/android/internal/telephony/IccUtils.java
@@ -439,7 +439,6 @@ public class IccUtils {
int colorNumber = data[valueIndex++] & 0xFF;
int clutOffset = ((data[valueIndex++] & 0xFF) << 8)
| (data[valueIndex++] & 0xFF);
- length = length - 6;
int[] colorIndexArray = getCLUT(data, clutOffset, colorNumber);
if (true == transparency) {
diff --git a/telephony/java/com/android/internal/telephony/IntRangeManager.java b/telephony/java/com/android/internal/telephony/IntRangeManager.java
new file mode 100644
index 0000000..970bc44
--- /dev/null
+++ b/telephony/java/com/android/internal/telephony/IntRangeManager.java
@@ -0,0 +1,568 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.telephony;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+/**
+ * Clients can enable reception of SMS-CB messages for specific ranges of
+ * message identifiers (channels). This class keeps track of the currently
+ * enabled message identifiers and calls abstract methods to update the
+ * radio when the range of enabled message identifiers changes.
+ *
+ * An update is a call to {@link #startUpdate} followed by zero or more
+ * calls to {@link #addRange} followed by a call to {@link #finishUpdate}.
+ * Calls to {@link #enableRange} and {@link #disableRange} will perform
+ * an incremental update operation if the enabled ranges have changed.
+ * A full update operation (i.e. after a radio reset) can be performed
+ * by a call to {@link #updateRanges}.
+ *
+ * Clients are identified by String (the name associated with the User ID
+ * of the caller) so that a call to remove a range can be mapped to the
+ * client that enabled that range (or else rejected).
+ */
+public abstract class IntRangeManager {
+
+ /**
+ * Initial capacity for IntRange clients array list. There will be
+ * few cell broadcast listeners on a typical device, so this can be small.
+ */
+ private static final int INITIAL_CLIENTS_ARRAY_SIZE = 4;
+
+ /**
+ * One or more clients forming the continuous range [startId, endId].
+ * <p>When a client is added, the IntRange may merge with one or more
+ * adjacent IntRanges to form a single combined IntRange.
+ * <p>When a client is removed, the IntRange may divide into several
+ * non-contiguous IntRanges.
+ */
+ private class IntRange {
+ int startId;
+ int endId;
+ // sorted by earliest start id
+ final ArrayList<ClientRange> clients;
+
+ /**
+ * Create a new IntRange with a single client.
+ * @param startId the first id included in the range
+ * @param endId the last id included in the range
+ * @param client the client requesting the enabled range
+ */
+ IntRange(int startId, int endId, String client) {
+ this.startId = startId;
+ this.endId = endId;
+ clients = new ArrayList<ClientRange>(INITIAL_CLIENTS_ARRAY_SIZE);
+ clients.add(new ClientRange(startId, endId, client));
+ }
+
+ /**
+ * Create a new IntRange for an existing ClientRange.
+ * @param clientRange the initial ClientRange to add
+ */
+ IntRange(ClientRange clientRange) {
+ startId = clientRange.startId;
+ endId = clientRange.endId;
+ clients = new ArrayList<ClientRange>(INITIAL_CLIENTS_ARRAY_SIZE);
+ clients.add(clientRange);
+ }
+
+ /**
+ * Create a new IntRange from an existing IntRange. This is used for
+ * removing a ClientRange, because new IntRanges may need to be created
+ * for any gaps that open up after the ClientRange is removed. A copy
+ * is made of the elements of the original IntRange preceding the element
+ * that is being removed. The following elements will be added to this
+ * IntRange or to a new IntRange when a gap is found.
+ * @param intRange the original IntRange to copy elements from
+ * @param numElements the number of elements to copy from the original
+ */
+ IntRange(IntRange intRange, int numElements) {
+ this.startId = intRange.startId;
+ this.endId = intRange.endId;
+ this.clients = new ArrayList<ClientRange>(intRange.clients.size());
+ for (int i=0; i < numElements; i++) {
+ this.clients.add(intRange.clients.get(i));
+ }
+ }
+
+ /**
+ * Insert new ClientRange in order by start id.
+ * <p>If the new ClientRange is known to be sorted before or after the
+ * existing ClientRanges, or at a particular index, it can be added
+ * to the clients array list directly, instead of via this method.
+ * <p>Note that this can be changed from linear to binary search if the
+ * number of clients grows large enough that it would make a difference.
+ * @param range the new ClientRange to insert
+ */
+ void insert(ClientRange range) {
+ int len = clients.size();
+ for (int i=0; i < len; i++) {
+ ClientRange nextRange = clients.get(i);
+ if (range.startId <= nextRange.startId) {
+ // ignore duplicate ranges from the same client
+ if (!range.equals(nextRange)) {
+ clients.add(i, range);
+ }
+ return;
+ }
+ }
+ clients.add(range); // append to end of list
+ }
+ }
+
+ /**
+ * The message id range for a single client.
+ */
+ private class ClientRange {
+ final int startId;
+ final int endId;
+ final String client;
+
+ ClientRange(int startId, int endId, String client) {
+ this.startId = startId;
+ this.endId = endId;
+ this.client = client;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o != null && o instanceof ClientRange) {
+ ClientRange other = (ClientRange) o;
+ return startId == other.startId &&
+ endId == other.endId &&
+ client.equals(other.client);
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ return (startId * 31 + endId) * 31 + client.hashCode();
+ }
+ }
+
+ /**
+ * List of integer ranges, one per client, sorted by start id.
+ */
+ private ArrayList<IntRange> mRanges = new ArrayList<IntRange>();
+
+ protected IntRangeManager() {}
+
+ /**
+ * Enable a range for the specified client and update ranges
+ * if necessary. If {@link #finishUpdate} returns failure,
+ * false is returned and the range is not added.
+ *
+ * @param startId the first id included in the range
+ * @param endId the last id included in the range
+ * @param client the client requesting the enabled range
+ * @return true if successful, false otherwise
+ */
+ public synchronized boolean enableRange(int startId, int endId, String client) {
+ int len = mRanges.size();
+
+ // empty range list: add the initial IntRange
+ if (len == 0) {
+ if (tryAddSingleRange(startId, endId, true)) {
+ mRanges.add(new IntRange(startId, endId, client));
+ return true;
+ } else {
+ return false; // failed to update radio
+ }
+ }
+
+ for (int startIndex = 0; startIndex < len; startIndex++) {
+ IntRange range = mRanges.get(startIndex);
+ if (startId < range.startId) {
+ // test if new range completely precedes this range
+ // note that [1, 4] and [5, 6] coalesce to [1, 6]
+ if ((endId + 1) < range.startId) {
+ // insert new int range before previous first range
+ if (tryAddSingleRange(startId, endId, true)) {
+ mRanges.add(startIndex, new IntRange(startId, endId, client));
+ return true;
+ } else {
+ return false; // failed to update radio
+ }
+ } else if (endId <= range.endId) {
+ // extend the start of this range
+ if (tryAddSingleRange(startId, range.startId - 1, true)) {
+ range.startId = startId;
+ range.clients.add(0, new ClientRange(startId, endId, client));
+ return true;
+ } else {
+ return false; // failed to update radio
+ }
+ } else {
+ // find last range that can coalesce into the new combined range
+ for (int endIndex = startIndex+1; endIndex < len; endIndex++) {
+ IntRange endRange = mRanges.get(endIndex);
+ if ((endId + 1) < endRange.startId) {
+ // try to add entire new range
+ if (tryAddSingleRange(startId, endId, true)) {
+ range.startId = startId;
+ range.endId = endId;
+ // insert new ClientRange before existing ranges
+ range.clients.add(0, new ClientRange(startId, endId, client));
+ // coalesce range with following ranges up to endIndex-1
+ // remove each range after adding its elements, so the index
+ // of the next range to join is always startIndex+1.
+ // i is the index if no elements were removed: we only care
+ // about the number of loop iterations, not the value of i.
+ int joinIndex = startIndex + 1;
+ for (int i = joinIndex; i < endIndex; i++) {
+ IntRange joinRange = mRanges.get(joinIndex);
+ range.clients.addAll(joinRange.clients);
+ mRanges.remove(joinRange);
+ }
+ return true;
+ } else {
+ return false; // failed to update radio
+ }
+ } else if (endId <= endRange.endId) {
+ // add range from start id to start of last overlapping range,
+ // values from endRange.startId to endId are already enabled
+ if (tryAddSingleRange(startId, endRange.startId - 1, true)) {
+ range.startId = startId;
+ range.endId = endRange.endId;
+ // insert new ClientRange before existing ranges
+ range.clients.add(0, new ClientRange(startId, endId, client));
+ // coalesce range with following ranges up to endIndex
+ // remove each range after adding its elements, so the index
+ // of the next range to join is always startIndex+1.
+ // i is the index if no elements were removed: we only care
+ // about the number of loop iterations, not the value of i.
+ int joinIndex = startIndex + 1;
+ for (int i = joinIndex; i <= endIndex; i++) {
+ IntRange joinRange = mRanges.get(joinIndex);
+ range.clients.addAll(joinRange.clients);
+ mRanges.remove(joinRange);
+ }
+ return true;
+ } else {
+ return false; // failed to update radio
+ }
+ }
+ }
+
+ // endId extends past all existing IntRanges: combine them all together
+ if (tryAddSingleRange(startId, endId, true)) {
+ range.startId = startId;
+ range.endId = endId;
+ // insert new ClientRange before existing ranges
+ range.clients.add(0, new ClientRange(startId, endId, client));
+ // coalesce range with following ranges up to len-1
+ // remove each range after adding its elements, so the index
+ // of the next range to join is always startIndex+1.
+ // i is the index if no elements were removed: we only care
+ // about the number of loop iterations, not the value of i.
+ int joinIndex = startIndex + 1;
+ for (int i = joinIndex; i < len; i++) {
+ IntRange joinRange = mRanges.get(joinIndex);
+ range.clients.addAll(joinRange.clients);
+ mRanges.remove(joinRange);
+ }
+ return true;
+ } else {
+ return false; // failed to update radio
+ }
+ }
+ } else if ((startId + 1) <= range.endId) {
+ if (endId <= range.endId) {
+ // completely contained in existing range; no radio changes
+ range.insert(new ClientRange(startId, endId, client));
+ return true;
+ } else {
+ // find last range that can coalesce into the new combined range
+ int endIndex = startIndex;
+ for (int testIndex = startIndex+1; testIndex < len; testIndex++) {
+ IntRange testRange = mRanges.get(testIndex);
+ if ((endId + 1) < testRange.startId) {
+ break;
+ } else {
+ endIndex = testIndex;
+ }
+ }
+ // no adjacent IntRanges to combine
+ if (endIndex == startIndex) {
+ // add range from range.endId+1 to endId,
+ // values from startId to range.endId are already enabled
+ if (tryAddSingleRange(range.endId + 1, endId, true)) {
+ range.endId = endId;
+ range.insert(new ClientRange(startId, endId, client));
+ return true;
+ } else {
+ return false; // failed to update radio
+ }
+ }
+ // get last range to coalesce into start range
+ IntRange endRange = mRanges.get(endIndex);
+ // Values from startId to range.endId have already been enabled.
+ // if endId > endRange.endId, then enable range from range.endId+1 to endId,
+ // else enable range from range.endId+1 to endRange.startId-1, because
+ // values from endRange.startId to endId have already been added.
+ int newRangeEndId = (endId <= endRange.endId) ? endRange.startId - 1 : endId;
+ if (tryAddSingleRange(range.endId + 1, newRangeEndId, true)) {
+ range.endId = endId;
+ // insert new ClientRange in place
+ range.insert(new ClientRange(startId, endId, client));
+ // coalesce range with following ranges up to endIndex-1
+ // remove each range after adding its elements, so the index
+ // of the next range to join is always startIndex+1 (joinIndex).
+ // i is the index if no elements had been removed: we only care
+ // about the number of loop iterations, not the value of i.
+ int joinIndex = startIndex + 1;
+ for (int i = joinIndex; i < endIndex; i++) {
+ IntRange joinRange = mRanges.get(joinIndex);
+ range.clients.addAll(joinRange.clients);
+ mRanges.remove(joinRange);
+ }
+ return true;
+ } else {
+ return false; // failed to update radio
+ }
+ }
+ }
+ }
+
+ // append new range after existing IntRanges
+ if (tryAddSingleRange(startId, endId, true)) {
+ mRanges.add(new IntRange(startId, endId, client));
+ return true;
+ } else {
+ return false; // failed to update radio
+ }
+ }
+
+ /**
+ * Disable a range for the specified client and update ranges
+ * if necessary. If {@link #finishUpdate} returns failure,
+ * false is returned and the range is not removed.
+ *
+ * @param startId the first id included in the range
+ * @param endId the last id included in the range
+ * @param client the client requesting to disable the range
+ * @return true if successful, false otherwise
+ */
+ public synchronized boolean disableRange(int startId, int endId, String client) {
+ int len = mRanges.size();
+
+ for (int i=0; i < len; i++) {
+ IntRange range = mRanges.get(i);
+ if (startId < range.startId) {
+ return false; // not found
+ } else if (endId <= range.endId) {
+ // found the IntRange that encloses the client range, if any
+ // search for it in the clients list
+ ArrayList<ClientRange> clients = range.clients;
+
+ // handle common case of IntRange containing one ClientRange
+ int crLength = clients.size();
+ if (crLength == 1) {
+ ClientRange cr = clients.get(0);
+ if (cr.startId == startId && cr.endId == endId && cr.client.equals(client)) {
+ // disable range in radio then remove the entire IntRange
+ if (tryAddSingleRange(startId, endId, false)) {
+ mRanges.remove(i);
+ return true;
+ } else {
+ return false; // failed to update radio
+ }
+ } else {
+ return false; // not found
+ }
+ }
+
+ // several ClientRanges: remove one, potentially splitting into many IntRanges.
+ // Save the original start and end id for the original IntRange
+ // in case the radio update fails and we have to revert it. If the
+ // update succeeds, we remove the client range and insert the new IntRanges.
+ int largestEndId = Integer.MIN_VALUE; // largest end identifier found
+ boolean updateStarted = false;
+
+ for (int crIndex=0; crIndex < crLength; crIndex++) {
+ ClientRange cr = clients.get(crIndex);
+ if (cr.startId == startId && cr.endId == endId && cr.client.equals(client)) {
+ // found the ClientRange to remove, check if it's the last in the list
+ if (crIndex == crLength - 1) {
+ if (range.endId == largestEndId) {
+ // no channels to remove from radio; return success
+ clients.remove(crIndex);
+ return true;
+ } else {
+ // disable the channels at the end and lower the end id
+ if (tryAddSingleRange(largestEndId + 1, range.endId, false)) {
+ clients.remove(crIndex);
+ range.endId = largestEndId;
+ return true;
+ } else {
+ return false;
+ }
+ }
+ }
+
+ // copy the IntRange so that we can remove elements and modify the
+ // start and end id's in the copy, leaving the original unmodified
+ // until after the radio update succeeds
+ IntRange rangeCopy = new IntRange(range, crIndex);
+
+ if (crIndex == 0) {
+ // removing the first ClientRange, so we may need to increase
+ // the start id of the IntRange.
+ // We know there are at least two ClientRanges in the list,
+ // so clients.get(1) should always succeed.
+ int nextStartId = clients.get(1).startId;
+ if (nextStartId != range.startId) {
+ startUpdate();
+ updateStarted = true;
+ addRange(range.startId, nextStartId - 1, false);
+ rangeCopy.startId = nextStartId;
+ }
+ // init largestEndId
+ largestEndId = clients.get(1).endId;
+ }
+
+ // go through remaining ClientRanges, creating new IntRanges when
+ // there is a gap in the sequence. After radio update succeeds,
+ // remove the original IntRange and append newRanges to mRanges.
+ // Otherwise, leave the original IntRange in mRanges and return false.
+ ArrayList<IntRange> newRanges = new ArrayList<IntRange>();
+
+ IntRange currentRange = rangeCopy;
+ for (int nextIndex = crIndex + 1; nextIndex < crLength; nextIndex++) {
+ ClientRange nextCr = clients.get(nextIndex);
+ if (nextCr.startId > largestEndId + 1) {
+ if (!updateStarted) {
+ startUpdate();
+ updateStarted = true;
+ }
+ addRange(largestEndId + 1, nextCr.startId - 1, false);
+ currentRange.endId = largestEndId;
+ newRanges.add(currentRange);
+ currentRange = new IntRange(nextCr);
+ } else {
+ currentRange.clients.add(nextCr);
+ }
+ if (nextCr.endId > largestEndId) {
+ largestEndId = nextCr.endId;
+ }
+ }
+
+ // remove any channels between largestEndId and endId
+ if (largestEndId < endId) {
+ if (!updateStarted) {
+ startUpdate();
+ updateStarted = true;
+ }
+ addRange(largestEndId + 1, endId, false);
+ currentRange.endId = largestEndId;
+ }
+ newRanges.add(currentRange);
+
+ if (updateStarted && !finishUpdate()) {
+ return false; // failed to update radio
+ }
+
+ // replace the original IntRange with newRanges
+ mRanges.remove(i);
+ mRanges.addAll(i, newRanges);
+ return true;
+ } else {
+ // not the ClientRange to remove; save highest end ID seen so far
+ if (cr.endId > largestEndId) {
+ largestEndId = cr.endId;
+ }
+ }
+ }
+ }
+ }
+
+ return false; // not found
+ }
+
+ /**
+ * Perform a complete update operation (enable all ranges). Useful
+ * after a radio reset. Calls {@link #startUpdate}, followed by zero or
+ * more calls to {@link #addRange}, followed by {@link #finishUpdate}.
+ * @return true if successful, false otherwise
+ */
+ public boolean updateRanges() {
+ startUpdate();
+ Iterator<IntRange> iterator = mRanges.iterator();
+ if (iterator.hasNext()) {
+ IntRange range = iterator.next();
+ int start = range.startId;
+ int end = range.endId;
+ // accumulate ranges of [startId, endId]
+ while (iterator.hasNext()) {
+ IntRange nextNode = iterator.next();
+ // [startIdA, endIdA], [endIdA + 1, endIdB] -> [startIdA, endIdB]
+ if (nextNode.startId <= (end + 1)) {
+ if (nextNode.endId > end) {
+ end = nextNode.endId;
+ }
+ } else {
+ addRange(start, end, true);
+ start = nextNode.startId;
+ end = nextNode.endId;
+ }
+ }
+ // add final range
+ addRange(start, end, true);
+ }
+ return finishUpdate();
+ }
+
+ /**
+ * Enable or disable a single range of message identifiers.
+ * @param startId the first id included in the range
+ * @param endId the last id included in the range
+ * @param selected true to enable range, false to disable range
+ * @return true if successful, false otherwise
+ */
+ private boolean tryAddSingleRange(int startId, int endId, boolean selected) {
+ startUpdate();
+ addRange(startId, endId, selected);
+ return finishUpdate();
+ }
+
+ /**
+ * Called when the list of enabled ranges has changed. This will be
+ * followed by zero or more calls to {@link #addRange} followed by
+ * a call to {@link #finishUpdate}.
+ */
+ protected abstract void startUpdate();
+
+ /**
+ * Called after {@link #startUpdate} to indicate a range of enabled
+ * or disabled values.
+ *
+ * @param startId the first id included in the range
+ * @param endId the last id included in the range
+ * @param selected true to enable range, false to disable range
+ */
+ protected abstract void addRange(int startId, int endId, boolean selected);
+
+ /**
+ * Called to indicate the end of a range update started by the
+ * previous call to {@link #startUpdate}.
+ * @return true if successful, false otherwise
+ */
+ protected abstract boolean finishUpdate();
+}
diff --git a/telephony/java/com/android/internal/telephony/PhoneBase.java b/telephony/java/com/android/internal/telephony/PhoneBase.java
index 40a70a8..a0961ca 100644
--- a/telephony/java/com/android/internal/telephony/PhoneBase.java
+++ b/telephony/java/com/android/internal/telephony/PhoneBase.java
@@ -806,10 +806,10 @@ public abstract class PhoneBase extends Handler implements Phone {
mNotifier.notifyDataConnection(this, reason, apnType, getDataConnectionState(apnType));
}
- public void notifyDataConnection() {
+ public void notifyDataConnection(String reason) {
String types[] = getActiveApnTypes();
for (String apnType : types) {
- mNotifier.notifyDataConnection(this, null, apnType, getDataConnectionState(apnType));
+ mNotifier.notifyDataConnection(this, reason, apnType, getDataConnectionState(apnType));
}
}
diff --git a/telephony/java/com/android/internal/telephony/RIL.java b/telephony/java/com/android/internal/telephony/RIL.java
index 07780ed..c6ed405 100644
--- a/telephony/java/com/android/internal/telephony/RIL.java
+++ b/telephony/java/com/android/internal/telephony/RIL.java
@@ -45,7 +45,6 @@ import android.telephony.PhoneNumberUtils;
import android.telephony.SmsManager;
import android.telephony.SmsMessage;
import android.text.TextUtils;
-import android.util.Config;
import android.util.Log;
import com.android.internal.telephony.CallForwardInfo;
@@ -1238,7 +1237,7 @@ public final class RIL extends BaseCommands implements CommandsInterface {
rr.mp.writeInt(1);
rr.mp.writeInt(index);
- if (Config.LOGD) {
+ if (false) {
if (RILJ_LOGD) riljLog(rr.serialString() + "> "
+ requestToString(rr.mRequest)
+ " " + index);
@@ -1254,7 +1253,7 @@ public final class RIL extends BaseCommands implements CommandsInterface {
rr.mp.writeInt(1);
rr.mp.writeInt(index);
- if (Config.LOGD) {
+ if (false) {
if (RILJ_LOGD) riljLog(rr.serialString() + "> "
+ requestToString(rr.mRequest)
+ " " + index);
@@ -1273,7 +1272,7 @@ public final class RIL extends BaseCommands implements CommandsInterface {
rr.mp.writeString(pdu);
rr.mp.writeString(smsc);
- if (Config.LOGD) {
+ if (false) {
if (RILJ_LOGD) riljLog(rr.serialString() + "> "
+ requestToString(rr.mRequest)
+ " " + status);
@@ -1291,7 +1290,7 @@ public final class RIL extends BaseCommands implements CommandsInterface {
rr.mp.writeInt(status);
rr.mp.writeString(pdu);
- if (Config.LOGD) {
+ if (false) {
if (RILJ_LOGD) riljLog(rr.serialString() + "> "
+ requestToString(rr.mRequest)
+ " " + status);
diff --git a/telephony/java/com/android/internal/telephony/SMSDispatcher.java b/telephony/java/com/android/internal/telephony/SMSDispatcher.java
index 6af9b1c..76e719c 100755..100644
--- a/telephony/java/com/android/internal/telephony/SMSDispatcher.java
+++ b/telephony/java/com/android/internal/telephony/SMSDispatcher.java
@@ -32,18 +32,15 @@ import android.database.Cursor;
import android.database.SQLException;
import android.net.Uri;
import android.os.AsyncResult;
-import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.os.PowerManager;
-import android.os.StatFs;
import android.os.SystemProperties;
import android.provider.Telephony;
import android.provider.Telephony.Sms.Intents;
import android.provider.Settings;
import android.telephony.SmsMessage;
import android.telephony.ServiceState;
-import android.util.Config;
import android.util.Log;
import android.view.WindowManager;
@@ -303,7 +300,7 @@ public abstract class SMSDispatcher extends Handler {
switch (msg.what) {
case EVENT_NEW_SMS:
// A new SMS has been received by the device
- if (Config.LOGD) {
+ if (false) {
Log.d(TAG, "New SMS Message Received");
}
@@ -364,7 +361,7 @@ public abstract class SMSDispatcher extends Handler {
Log.e(TAG, "failed to send back RESULT_ERROR_LIMIT_EXCEEDED");
}
}
- if (Config.LOGD) {
+ if (false) {
Log.d(TAG, "EVENT_ALERT_TIMEOUT, message stop sending");
}
break;
@@ -476,7 +473,7 @@ public abstract class SMSDispatcher extends Handler {
PendingIntent sentIntent = tracker.mSentIntent;
if (ar.exception == null) {
- if (Config.LOGD) {
+ if (false) {
Log.d(TAG, "SMS send complete. Broadcasting "
+ "intent: " + sentIntent);
}
@@ -504,7 +501,7 @@ public abstract class SMSDispatcher extends Handler {
} catch (CanceledException ex) {}
}
} else {
- if (Config.LOGD) {
+ if (false) {
Log.d(TAG, "SMS send failed");
}
@@ -909,37 +906,6 @@ public abstract class SMSDispatcher extends Handler {
protected abstract void sendMultipartSms (SmsTracker tracker);
/**
- * Activate or deactivate cell broadcast SMS.
- *
- * @param activate
- * 0 = activate, 1 = deactivate
- * @param response
- * Callback message is empty on completion
- */
- public abstract void activateCellBroadcastSms(int activate, Message response);
-
- /**
- * Query the current configuration of cell broadcast SMS.
- *
- * @param response
- * Callback message contains the configuration from the modem on completion
- * @see #setCellBroadcastConfig
- */
- public abstract void getCellBroadcastSmsConfig(Message response);
-
- /**
- * Configure cell broadcast SMS.
- *
- * @param configValuesArray
- * The first element defines the number of triples that follow.
- * A triple is made up of the service category, the language identifier
- * and a boolean that specifies whether the category is set active.
- * @param response
- * Callback message is empty on completion
- */
- public abstract void setCellBroadcastConfig(int[] configValuesArray, Message response);
-
- /**
* Send an acknowledge message.
* @param success indicates that last message was successfully received.
* @param result result code indicating any error
@@ -1066,14 +1032,17 @@ public abstract class SMSDispatcher extends Handler {
protected abstract void handleBroadcastSms(AsyncResult ar);
- protected void dispatchBroadcastPdus(byte[][] pdus) {
- Intent intent = new Intent("android.provider.telephony.SMS_CB_RECEIVED");
- intent.putExtra("pdus", pdus);
-
- if (Config.LOGD)
+ protected void dispatchBroadcastPdus(byte[][] pdus, boolean isEmergencyMessage) {
+ if (isEmergencyMessage) {
+ Intent intent = new Intent(Intents.SMS_EMERGENCY_CB_RECEIVED_ACTION);
+ intent.putExtra("pdus", pdus);
+ Log.d(TAG, "Dispatching " + pdus.length + " emergency SMS CB pdus");
+ dispatch(intent, "android.permission.RECEIVE_EMERGENCY_BROADCAST");
+ } else {
+ Intent intent = new Intent(Intents.SMS_CB_RECEIVED_ACTION);
+ intent.putExtra("pdus", pdus);
Log.d(TAG, "Dispatching " + pdus.length + " SMS CB pdus");
-
- dispatch(intent, "android.permission.RECEIVE_SMS");
+ dispatch(intent, "android.permission.RECEIVE_SMS");
+ }
}
-
}
diff --git a/telephony/java/com/android/internal/telephony/SmsHeader.java b/telephony/java/com/android/internal/telephony/SmsHeader.java
index 7a65162..9492e0e 100644
--- a/telephony/java/com/android/internal/telephony/SmsHeader.java
+++ b/telephony/java/com/android/internal/telephony/SmsHeader.java
@@ -66,6 +66,8 @@ public class SmsHeader {
public static final int ELT_ID_HYPERLINK_FORMAT_ELEMENT = 0x21;
public static final int ELT_ID_REPLY_ADDRESS_ELEMENT = 0x22;
public static final int ELT_ID_ENHANCED_VOICE_MAIL_INFORMATION = 0x23;
+ public static final int ELT_ID_NATIONAL_LANGUAGE_SINGLE_SHIFT = 0x24;
+ public static final int ELT_ID_NATIONAL_LANGUAGE_LOCKING_SHIFT = 0x25;
public static final int PORT_WAP_PUSH = 2948;
public static final int PORT_WAP_WSP = 9200;
@@ -96,6 +98,12 @@ public class SmsHeader {
public ConcatRef concatRef;
public ArrayList<MiscElt> miscEltList = new ArrayList<MiscElt>();
+ /** 7 bit national language locking shift table, or 0 for GSM default 7 bit alphabet. */
+ public int languageTable;
+
+ /** 7 bit national language single shift table, or 0 for GSM default 7 bit extension table. */
+ public int languageShiftTable;
+
public SmsHeader() {}
/**
@@ -157,6 +165,12 @@ public class SmsHeader {
portAddrs.areEightBits = false;
smsHeader.portAddrs = portAddrs;
break;
+ case ELT_ID_NATIONAL_LANGUAGE_SINGLE_SHIFT:
+ smsHeader.languageShiftTable = inStream.read();
+ break;
+ case ELT_ID_NATIONAL_LANGUAGE_LOCKING_SHIFT:
+ smsHeader.languageTable = inStream.read();
+ break;
default:
MiscElt miscElt = new MiscElt();
miscElt.id = id;
@@ -212,6 +226,16 @@ public class SmsHeader {
outStream.write(portAddrs.origPort & 0x00FF);
}
}
+ if (smsHeader.languageShiftTable != 0) {
+ outStream.write(ELT_ID_NATIONAL_LANGUAGE_SINGLE_SHIFT);
+ outStream.write(1);
+ outStream.write(smsHeader.languageShiftTable);
+ }
+ if (smsHeader.languageTable != 0) {
+ outStream.write(ELT_ID_NATIONAL_LANGUAGE_LOCKING_SHIFT);
+ outStream.write(1);
+ outStream.write(smsHeader.languageTable);
+ }
for (MiscElt miscElt : smsHeader.miscEltList) {
outStream.write(miscElt.id);
outStream.write(miscElt.data.length);
@@ -243,6 +267,12 @@ public class SmsHeader {
builder.append(", areEightBits=" + portAddrs.areEightBits);
builder.append(" }");
}
+ if (languageShiftTable != 0) {
+ builder.append(", languageShiftTable=" + languageShiftTable);
+ }
+ if (languageTable != 0) {
+ builder.append(", languageTable=" + languageTable);
+ }
for (MiscElt miscElt : miscEltList) {
builder.append(", MiscElt ");
builder.append("{ id=" + miscElt.id);
diff --git a/telephony/java/com/android/internal/telephony/SmsMessageBase.java b/telephony/java/com/android/internal/telephony/SmsMessageBase.java
index cbd8606..fcd038c 100644
--- a/telephony/java/com/android/internal/telephony/SmsMessageBase.java
+++ b/telephony/java/com/android/internal/telephony/SmsMessageBase.java
@@ -117,6 +117,16 @@ public abstract class SmsMessageBase {
*/
public int codeUnitSize;
+ /**
+ * The GSM national language table to use, or 0 for the default 7-bit alphabet.
+ */
+ public int languageTable;
+
+ /**
+ * The GSM national language shift table to use, or 0 for the default 7-bit extension table.
+ */
+ public int languageShiftTable;
+
@Override
public String toString() {
return "TextEncodingDetails " +
@@ -124,6 +134,8 @@ public abstract class SmsMessageBase {
", codeUnitCount=" + codeUnitCount +
", codeUnitsRemaining=" + codeUnitsRemaining +
", codeUnitSize=" + codeUnitSize +
+ ", languageTable=" + languageTable +
+ ", languageShiftTable=" + languageShiftTable +
" }";
}
}
diff --git a/telephony/java/com/android/internal/telephony/WapPushOverSms.java b/telephony/java/com/android/internal/telephony/WapPushOverSms.java
index 7704667..e2779dc 100644..100755
--- a/telephony/java/com/android/internal/telephony/WapPushOverSms.java
+++ b/telephony/java/com/android/internal/telephony/WapPushOverSms.java
@@ -24,7 +24,6 @@ import android.content.Intent;
import android.content.ServiceConnection;
import android.provider.Telephony;
import android.provider.Telephony.Sms.Intents;
-import android.util.Config;
import android.util.Log;
import android.os.IBinder;
import android.os.RemoteException;
@@ -62,13 +61,13 @@ public class WapPushOverSms {
public void onServiceConnected(ComponentName name, IBinder service) {
mWapPushMan = IWapPushManager.Stub.asInterface(service);
- if (Config.DEBUG) Log.v(LOG_TAG, "wappush manager connected to " +
+ if (false) Log.v(LOG_TAG, "wappush manager connected to " +
mOwner.hashCode());
}
public void onServiceDisconnected(ComponentName name) {
mWapPushMan = null;
- if (Config.DEBUG) Log.v(LOG_TAG, "wappush manager disconnected.");
+ if (false) Log.v(LOG_TAG, "wappush manager disconnected.");
// WapPushManager must be always attached.
rebindWapPushManager();
}
@@ -101,7 +100,7 @@ public class WapPushOverSms {
try {
Thread.sleep(BIND_RETRY_INTERVAL);
} catch (InterruptedException e) {
- if (Config.DEBUG) Log.v(LOG_TAG, "sleep interrupted.");
+ if (false) Log.v(LOG_TAG, "sleep interrupted.");
}
}
}
@@ -135,7 +134,7 @@ public class WapPushOverSms {
*/
public int dispatchWapPdu(byte[] pdu) {
- if (Config.DEBUG) Log.d(LOG_TAG, "Rx: " + IccUtils.bytesToHexString(pdu));
+ if (false) Log.d(LOG_TAG, "Rx: " + IccUtils.bytesToHexString(pdu));
int index = 0;
int transactionId = pdu[index++] & 0xFF;
@@ -144,7 +143,7 @@ public class WapPushOverSms {
if ((pduType != WspTypeDecoder.PDU_TYPE_PUSH) &&
(pduType != WspTypeDecoder.PDU_TYPE_CONFIRMED_PUSH)) {
- if (Config.DEBUG) Log.w(LOG_TAG, "Received non-PUSH WAP PDU. Type = " + pduType);
+ if (false) Log.w(LOG_TAG, "Received non-PUSH WAP PDU. Type = " + pduType);
return Intents.RESULT_SMS_HANDLED;
}
@@ -157,7 +156,7 @@ public class WapPushOverSms {
* So it will be encoded in no more than 5 octets.
*/
if (pduDecoder.decodeUintvarInteger(index) == false) {
- if (Config.DEBUG) Log.w(LOG_TAG, "Received PDU. Header Length error.");
+ if (false) Log.w(LOG_TAG, "Received PDU. Header Length error.");
return Intents.RESULT_SMS_GENERIC_ERROR;
}
headerLength = (int)pduDecoder.getValue32();
@@ -178,7 +177,7 @@ public class WapPushOverSms {
* Length = Uintvar-integer
*/
if (pduDecoder.decodeContentType(index) == false) {
- if (Config.DEBUG) Log.w(LOG_TAG, "Received PDU. Header Content-Type error.");
+ if (false) Log.w(LOG_TAG, "Received PDU. Header Content-Type error.");
return Intents.RESULT_SMS_GENERIC_ERROR;
}
@@ -215,14 +214,14 @@ public class WapPushOverSms {
String contentType = ((mimeType == null) ?
Long.toString(binaryContentType) : mimeType);
- if (Config.DEBUG) Log.v(LOG_TAG, "appid found: " + wapAppId + ":" + contentType);
+ if (false) Log.v(LOG_TAG, "appid found: " + wapAppId + ":" + contentType);
try {
boolean processFurther = true;
IWapPushManager wapPushMan = mWapConn.getWapPushManager();
if (wapPushMan == null) {
- if (Config.DEBUG) Log.w(LOG_TAG, "wap push manager not found!");
+ if (false) Log.w(LOG_TAG, "wap push manager not found!");
} else {
Intent intent = new Intent();
intent.putExtra("transactionId", transactionId);
@@ -233,7 +232,7 @@ public class WapPushOverSms {
pduDecoder.getContentParameters());
int procRet = wapPushMan.processMessage(wapAppId, contentType, intent);
- if (Config.DEBUG) Log.v(LOG_TAG, "procRet:" + procRet);
+ if (false) Log.v(LOG_TAG, "procRet:" + procRet);
if ((procRet & WapPushManagerParams.MESSAGE_HANDLED) > 0
&& (procRet & WapPushManagerParams.FURTHER_PROCESSING) == 0) {
processFurther = false;
@@ -243,13 +242,13 @@ public class WapPushOverSms {
return Intents.RESULT_SMS_HANDLED;
}
} catch (RemoteException e) {
- if (Config.DEBUG) Log.w(LOG_TAG, "remote func failed...");
+ if (false) Log.w(LOG_TAG, "remote func failed...");
}
}
- if (Config.DEBUG) Log.v(LOG_TAG, "fall back to existing handler");
+ if (false) Log.v(LOG_TAG, "fall back to existing handler");
if (mimeType == null) {
- if (Config.DEBUG) Log.w(LOG_TAG, "Header Content-Type error.");
+ if (false) Log.w(LOG_TAG, "Header Content-Type error.");
return Intents.RESULT_SMS_GENERIC_ERROR;
}
diff --git a/telephony/java/com/android/internal/telephony/WspTypeDecoder.java b/telephony/java/com/android/internal/telephony/WspTypeDecoder.java
index c8dd718..73260fb 100644..100755
--- a/telephony/java/com/android/internal/telephony/WspTypeDecoder.java
+++ b/telephony/java/com/android/internal/telephony/WspTypeDecoder.java
@@ -194,6 +194,7 @@ public class WspTypeDecoder {
public static final String CONTENT_TYPE_B_PUSH_CO = "application/vnd.wap.coc";
public static final String CONTENT_TYPE_B_MMS = "application/vnd.wap.mms-message";
+ public static final String CONTENT_TYPE_B_PUSH_SYNCML_NOTI = "application/vnd.syncml.notification";
byte[] wspData;
int dataLength;
diff --git a/telephony/java/com/android/internal/telephony/cat/CatService.java b/telephony/java/com/android/internal/telephony/cat/CatService.java
index df47350..fb53686 100644
--- a/telephony/java/com/android/internal/telephony/cat/CatService.java
+++ b/telephony/java/com/android/internal/telephony/cat/CatService.java
@@ -30,7 +30,6 @@ import com.android.internal.telephony.IccCard;
import com.android.internal.telephony.IccFileHandler;
import com.android.internal.telephony.IccRecords;
-import android.util.Config;
import java.io.ByteArrayOutputStream;
import java.util.Locale;
@@ -382,7 +381,7 @@ public class CatService extends Handler implements AppInterface {
byte[] rawData = buf.toByteArray();
String hexString = IccUtils.bytesToHexString(rawData);
- if (Config.LOGD) {
+ if (false) {
CatLog.d(this, "TERMINAL RESPONSE: " + hexString);
}
diff --git a/telephony/java/com/android/internal/telephony/cat/ResponseData.java b/telephony/java/com/android/internal/telephony/cat/ResponseData.java
index 4846a3e..55a2b63 100644
--- a/telephony/java/com/android/internal/telephony/cat/ResponseData.java
+++ b/telephony/java/com/android/internal/telephony/cat/ResponseData.java
@@ -113,7 +113,7 @@ class GetInkeyInputResponseData extends ResponseData {
int size = mInData.length();
byte[] tempData = GsmAlphabet
- .stringToGsm7BitPacked(mInData);
+ .stringToGsm7BitPacked(mInData, 0, 0);
data = new byte[size];
// Since stringToGsm7BitPacked() set byte 0 in the
// returned byte array to the count of septets used...
diff --git a/telephony/java/com/android/internal/telephony/cdma/CDMAPhone.java b/telephony/java/com/android/internal/telephony/cdma/CDMAPhone.java
index 63b7dac..286515e 100755
--- a/telephony/java/com/android/internal/telephony/cdma/CDMAPhone.java
+++ b/telephony/java/com/android/internal/telephony/cdma/CDMAPhone.java
@@ -1125,7 +1125,8 @@ public class CDMAPhone extends PhoneBase {
* @param response Callback message is empty on completion
*/
public void activateCellBroadcastSms(int activate, Message response) {
- mSMS.activateCellBroadcastSms(activate, response);
+ Log.e(LOG_TAG, "[CDMAPhone] activateCellBroadcastSms() is obsolete; use SmsManager");
+ response.sendToTarget();
}
/**
@@ -1134,7 +1135,8 @@ public class CDMAPhone extends PhoneBase {
* @param response Callback message is empty on completion
*/
public void getCellBroadcastSmsConfig(Message response) {
- mSMS.getCellBroadcastSmsConfig(response);
+ Log.e(LOG_TAG, "[CDMAPhone] getCellBroadcastSmsConfig() is obsolete; use SmsManager");
+ response.sendToTarget();
}
/**
@@ -1143,7 +1145,8 @@ public class CDMAPhone extends PhoneBase {
* @param response Callback message is empty on completion
*/
public void setCellBroadcastSmsConfig(int[] configValuesArray, Message response) {
- mSMS.setCellBroadcastConfig(configValuesArray, response);
+ Log.e(LOG_TAG, "[CDMAPhone] setCellBroadcastSmsConfig() is obsolete; use SmsManager");
+ response.sendToTarget();
}
/**
diff --git a/telephony/java/com/android/internal/telephony/cdma/CdmaConnection.java b/telephony/java/com/android/internal/telephony/cdma/CdmaConnection.java
index 1a15393..8fb136e 100755
--- a/telephony/java/com/android/internal/telephony/cdma/CdmaConnection.java
+++ b/telephony/java/com/android/internal/telephony/cdma/CdmaConnection.java
@@ -26,7 +26,6 @@ import android.os.PowerManager;
import android.os.Registrant;
import android.os.SystemClock;
import android.os.SystemProperties;
-import android.util.Config;
import android.util.Log;
import android.text.TextUtils;
@@ -453,7 +452,7 @@ public class CdmaConnection extends Connection {
if (!disconnected) {
doDisconnect();
- if (Config.LOGD) Log.d(LOG_TAG,
+ if (false) Log.d(LOG_TAG,
"[CDMAConn] onDisconnect: cause=" + cause);
owner.phone.notifyDisconnect(this);
@@ -470,7 +469,7 @@ public class CdmaConnection extends Connection {
onLocalDisconnect() {
if (!disconnected) {
doDisconnect();
- if (Config.LOGD) Log.d(LOG_TAG,
+ if (false) Log.d(LOG_TAG,
"[CDMAConn] onLoalDisconnect" );
if (parent != null) {
diff --git a/telephony/java/com/android/internal/telephony/cdma/CdmaLteServiceStateTracker.java b/telephony/java/com/android/internal/telephony/cdma/CdmaLteServiceStateTracker.java
index aa56cca..d3bb6a5 100644
--- a/telephony/java/com/android/internal/telephony/cdma/CdmaLteServiceStateTracker.java
+++ b/telephony/java/com/android/internal/telephony/cdma/CdmaLteServiceStateTracker.java
@@ -401,7 +401,7 @@ public class CdmaLteServiceStateTracker extends CdmaServiceStateTracker {
}
if ((hasCdmaDataConnectionChanged || hasNetworkTypeChanged)) {
- phone.notifyDataConnection();
+ phone.notifyDataConnection(null);
}
if (hasRoamingOn) {
diff --git a/telephony/java/com/android/internal/telephony/cdma/CdmaSMSDispatcher.java b/telephony/java/com/android/internal/telephony/cdma/CdmaSMSDispatcher.java
index c0bfd23..07b0f4f 100644..100755
--- a/telephony/java/com/android/internal/telephony/cdma/CdmaSMSDispatcher.java
+++ b/telephony/java/com/android/internal/telephony/cdma/CdmaSMSDispatcher.java
@@ -33,7 +33,6 @@ import android.provider.Telephony;
import android.provider.Telephony.Sms.Intents;
import android.telephony.SmsManager;
import android.telephony.SmsMessage.MessageClass;
-import android.util.Config;
import android.util.Log;
import com.android.internal.telephony.CommandsInterface;
@@ -42,6 +41,7 @@ import com.android.internal.telephony.SmsHeader;
import com.android.internal.telephony.SmsMessageBase;
import com.android.internal.telephony.SmsMessageBase.TextEncodingDetails;
import com.android.internal.telephony.TelephonyProperties;
+import com.android.internal.telephony.WspTypeDecoder;
import com.android.internal.telephony.cdma.sms.SmsEnvelope;
import com.android.internal.telephony.cdma.sms.UserData;
import com.android.internal.util.HexDump;
@@ -51,6 +51,8 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
+import android.content.res.Resources;
+
final class CdmaSMSDispatcher extends SMSDispatcher {
private static final String TAG = "CDMA";
@@ -58,6 +60,9 @@ final class CdmaSMSDispatcher extends SMSDispatcher {
private byte[] mLastDispatchedSmsFingerprint;
private byte[] mLastAcknowledgedSmsFingerprint;
+ private boolean mCheckForDuplicatePortsInOmadmWapPush = Resources.getSystem().getBoolean(
+ com.android.internal.R.bool.config_duplicate_port_omadm_wappush);
+
CdmaSMSDispatcher(CDMAPhone phone) {
super(phone);
}
@@ -145,7 +150,7 @@ final class CdmaSMSDispatcher extends SMSDispatcher {
handleCdmaStatusReport(sms);
handled = true;
} else if ((sms.getUserData() == null)) {
- if (Config.LOGD) {
+ if (false) {
Log.d(TAG, "Received SMS without user data");
}
handled = true;
@@ -254,6 +259,13 @@ final class CdmaSMSDispatcher extends SMSDispatcher {
sourcePort |= 0xFF & pdu[index++];
destinationPort = (0xFF & pdu[index++]) << 8;
destinationPort |= 0xFF & pdu[index++];
+ // Some carriers incorrectly send duplicate port fields in omadm wap pushes.
+ // If configured, check for that here
+ if (mCheckForDuplicatePortsInOmadmWapPush) {
+ if (checkDuplicatePortOmadmWappush(pdu,index)) {
+ index = index + 4; // skip duplicate port fields
+ }
+ }
}
// Lookup all other related parts
@@ -274,7 +286,7 @@ final class CdmaSMSDispatcher extends SMSDispatcher {
if (cursorCount != totalSegments - 1) {
// We don't have all the parts yet, store this one away
ContentValues values = new ContentValues();
- values.put("date", new Long(0));
+ values.put("date", (long) 0);
values.put("pdu", HexDump.toHexString(pdu, index, pdu.length - index));
values.put("address", address);
values.put("reference_number", referenceNumber);
@@ -435,7 +447,7 @@ final class CdmaSMSDispatcher extends SMSDispatcher {
sentIntent.send(SmsManager.RESULT_ERROR_NO_SERVICE);
} catch (CanceledException ex) {}
}
- if (Config.LOGD) {
+ if (false) {
Log.d(TAG, "Block SMS in Emergency Callback mode");
}
return;
@@ -483,24 +495,6 @@ final class CdmaSMSDispatcher extends SMSDispatcher {
}
}
- /** {@inheritDoc} */
- @Override
- public void activateCellBroadcastSms(int activate, Message response) {
- mCm.setCdmaBroadcastActivation((activate == 0), response);
- }
-
- /** {@inheritDoc} */
- @Override
- public void getCellBroadcastSmsConfig(Message response) {
- mCm.getCdmaBroadcastConfig(response);
- }
-
- /** {@inheritDoc} */
- @Override
- public void setCellBroadcastConfig(int[] configValuesArray, Message response) {
- mCm.setCdmaBroadcastConfig(configValuesArray, response);
- }
-
protected void handleBroadcastSms(AsyncResult ar) {
// Not supported
Log.e(TAG, "Error! Not implemented for CDMA.");
@@ -521,4 +515,42 @@ final class CdmaSMSDispatcher extends SMSDispatcher {
return CommandsInterface.CDMA_SMS_FAIL_CAUSE_ENCODING_PROBLEM;
}
}
+
+ /**
+ * Optional check to see if the received WapPush is an OMADM notification with erroneous
+ * extra port fields.
+ * - Some carriers make this mistake.
+ * ex: MSGTYPE-TotalSegments-CurrentSegment
+ * -SourcePortDestPort-SourcePortDestPort-OMADM PDU
+ * @param origPdu The WAP-WDP PDU segment
+ * @param index Current Index while parsing the PDU.
+ * @return True if OrigPdu is OmaDM Push Message which has duplicate ports.
+ * False if OrigPdu is NOT OmaDM Push Message which has duplicate ports.
+ */
+ private boolean checkDuplicatePortOmadmWappush(byte[] origPdu, int index) {
+ index += 4;
+ byte[] omaPdu = new byte[origPdu.length - index];
+ System.arraycopy(origPdu, index, omaPdu, 0, omaPdu.length);
+
+ WspTypeDecoder pduDecoder = new WspTypeDecoder(omaPdu);
+ int wspIndex = 2;
+
+ // Process header length field
+ if (pduDecoder.decodeUintvarInteger(wspIndex) == false) {
+ return false;
+ }
+
+ wspIndex += pduDecoder.getDecodedDataLength(); // advance to next field
+
+ // Process content type field
+ if (pduDecoder.decodeContentType(wspIndex) == false) {
+ return false;
+ }
+
+ String mimeType = pduDecoder.getValueString();
+ if (mimeType != null && mimeType.equals(WspTypeDecoder.CONTENT_TYPE_B_PUSH_SYNCML_NOTI)) {
+ return true;
+ }
+ return false;
+ }
}
diff --git a/telephony/java/com/android/internal/telephony/cdma/CdmaServiceStateTracker.java b/telephony/java/com/android/internal/telephony/cdma/CdmaServiceStateTracker.java
index d259770..2cf4b88 100755
--- a/telephony/java/com/android/internal/telephony/cdma/CdmaServiceStateTracker.java
+++ b/telephony/java/com/android/internal/telephony/cdma/CdmaServiceStateTracker.java
@@ -999,7 +999,7 @@ public class CdmaServiceStateTracker extends ServiceStateTracker {
}
if (hasCdmaDataConnectionChanged || hasNetworkTypeChanged) {
- phone.notifyDataConnection();
+ phone.notifyDataConnection(null);
}
if (hasRoamingOn) {
diff --git a/telephony/java/com/android/internal/telephony/cdma/RuimPhoneBookInterfaceManager.java b/telephony/java/com/android/internal/telephony/cdma/RuimPhoneBookInterfaceManager.java
index ce33066..04ee2dd 100644
--- a/telephony/java/com/android/internal/telephony/cdma/RuimPhoneBookInterfaceManager.java
+++ b/telephony/java/com/android/internal/telephony/cdma/RuimPhoneBookInterfaceManager.java
@@ -16,6 +16,8 @@
package com.android.internal.telephony.cdma;
+import java.util.concurrent.atomic.AtomicBoolean;
+
import android.os.Message;
import android.util.Log;
@@ -56,14 +58,11 @@ public class RuimPhoneBookInterfaceManager extends IccPhoneBookInterfaceManager
recordSize = new int[3];
//Using mBaseHandler, no difference in EVENT_GET_SIZE_DONE handling
- Message response = mBaseHandler.obtainMessage(EVENT_GET_SIZE_DONE);
+ AtomicBoolean status = new AtomicBoolean(false);
+ Message response = mBaseHandler.obtainMessage(EVENT_GET_SIZE_DONE, status);
phone.getIccFileHandler().getEFLinearRecordSize(efid, response);
- try {
- mLock.wait();
- } catch (InterruptedException e) {
- logd("interrupted while trying to load from the RUIM");
- }
+ waitForResult(status);
}
return recordSize;
diff --git a/telephony/java/com/android/internal/telephony/cdma/RuimRecords.java b/telephony/java/com/android/internal/telephony/cdma/RuimRecords.java
index 719eff3..9af2d26 100644..100755
--- a/telephony/java/com/android/internal/telephony/cdma/RuimRecords.java
+++ b/telephony/java/com/android/internal/telephony/cdma/RuimRecords.java
@@ -16,10 +16,13 @@
package com.android.internal.telephony.cdma;
+import static com.android.internal.telephony.TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY;
+import static com.android.internal.telephony.TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC;
import android.os.AsyncResult;
import android.os.Handler;
import android.os.Message;
import android.os.Registrant;
+import android.os.SystemProperties;
import android.util.Log;
import com.android.internal.telephony.AdnRecord;
@@ -59,6 +62,7 @@ public final class RuimRecords extends IccRecords {
private static final int EVENT_RUIM_READY = 1;
private static final int EVENT_RADIO_OFF_OR_NOT_AVAILABLE = 2;
+ private static final int EVENT_GET_IMSI_DONE = 3;
private static final int EVENT_GET_DEVICE_IDENTITY_DONE = 4;
private static final int EVENT_GET_ICCID_DONE = 5;
private static final int EVENT_GET_CDMA_SUBSCRIPTION_DONE = 10;
@@ -115,6 +119,12 @@ public final class RuimRecords extends IccRecords {
adnCache.reset();
+ // Don't clean up PROPERTY_ICC_OPERATOR_ISO_COUNTRY and
+ // PROPERTY_ICC_OPERATOR_NUMERIC here. Since not all CDMA
+ // devices have RUIM, these properties should keep the original
+ // values, e.g. build time settings, when there is no RUIM but
+ // set new values when RUIM is available and loaded.
+
// recordsRequested is set to false indicating that the SIM
// read requests made so far are not valid. This is set to
// true only when fresh set of read requests are made.
@@ -202,6 +212,33 @@ public final class RuimRecords extends IccRecords {
break;
/* IO events */
+ case EVENT_GET_IMSI_DONE:
+ isRecordLoadResponse = true;
+
+ ar = (AsyncResult)msg.obj;
+ if (ar.exception != null) {
+ Log.e(LOG_TAG, "Exception querying IMSI, Exception:" + ar.exception);
+ break;
+ }
+
+ mImsi = (String) ar.result;
+
+ // IMSI (MCC+MNC+MSIN) is at least 6 digits, but not more
+ // than 15 (and usually 15).
+ if (mImsi != null && (mImsi.length() < 6 || mImsi.length() > 15)) {
+ Log.e(LOG_TAG, "invalid IMSI " + mImsi);
+ mImsi = null;
+ }
+
+ Log.d(LOG_TAG, "IMSI: " + mImsi.substring(0, 6) + "xxxxxxxxx");
+
+ String operatorNumeric = getRUIMOperatorNumeric();
+ if (operatorNumeric != null) {
+ if(operatorNumeric.length() <= 6){
+ MccTable.updateMccMncConfiguration(phone, operatorNumeric);
+ }
+ }
+ break;
case EVENT_GET_CDMA_SUBSCRIPTION_DONE:
ar = (AsyncResult)msg.obj;
@@ -292,6 +329,13 @@ public final class RuimRecords extends IccRecords {
// Further records that can be inserted are Operator/OEM dependent
+ String operator = getRUIMOperatorNumeric();
+ SystemProperties.set(PROPERTY_ICC_OPERATOR_NUMERIC, operator);
+
+ if (mImsi != null) {
+ SystemProperties.set(PROPERTY_ICC_OPERATOR_ISO_COUNTRY,
+ MccTable.countryCodeForMcc(Integer.parseInt(mImsi.substring(0,3))));
+ }
recordsLoadedRegistrants.notifyRegistrants(
new AsyncResult(null, null, null));
phone.mIccCard.broadcastIccStateChangedIntent(
@@ -318,6 +362,9 @@ public final class RuimRecords extends IccRecords {
Log.v(LOG_TAG, "RuimRecords:fetchRuimRecords " + recordsToLoad);
+ phone.mCM.getIMSI(obtainMessage(EVENT_GET_IMSI_DONE));
+ recordsToLoad++;
+
phone.getIccFileHandler().loadEFTransparent(EF_ICCID,
obtainMessage(EVENT_GET_ICCID_DONE));
recordsToLoad++;
diff --git a/telephony/java/com/android/internal/telephony/cdma/RuimSmsInterfaceManager.java b/telephony/java/com/android/internal/telephony/cdma/RuimSmsInterfaceManager.java
index 29f3bc1..9cd059d 100644
--- a/telephony/java/com/android/internal/telephony/cdma/RuimSmsInterfaceManager.java
+++ b/telephony/java/com/android/internal/telephony/cdma/RuimSmsInterfaceManager.java
@@ -203,6 +203,18 @@ public class RuimSmsInterfaceManager extends IccSmsInterfaceManager {
return false;
}
+ public boolean enableCellBroadcastRange(int startMessageId, int endMessageId) {
+ // Not implemented
+ Log.e(LOG_TAG, "Error! Not implemented for CDMA.");
+ return false;
+ }
+
+ public boolean disableCellBroadcastRange(int startMessageId, int endMessageId) {
+ // Not implemented
+ Log.e(LOG_TAG, "Error! Not implemented for CDMA.");
+ return false;
+ }
+
protected void log(String msg) {
Log.d(LOG_TAG, "[RuimSmsInterfaceManager] " + msg);
}
diff --git a/telephony/java/com/android/internal/telephony/cdma/SmsMessage.java b/telephony/java/com/android/internal/telephony/cdma/SmsMessage.java
index 4911644..be5c616 100644
--- a/telephony/java/com/android/internal/telephony/cdma/SmsMessage.java
+++ b/telephony/java/com/android/internal/telephony/cdma/SmsMessage.java
@@ -18,7 +18,7 @@ package com.android.internal.telephony.cdma;
import android.os.Parcel;
import android.os.SystemProperties;
-import android.util.Config;
+import android.telephony.PhoneNumberUtils;
import android.util.Log;
import com.android.internal.telephony.IccUtils;
import com.android.internal.telephony.SmsHeader;
@@ -694,7 +694,7 @@ public class SmsMessage extends SmsMessageBase {
if (mEnvelope.bearerData != null) {
mBearerData.numberOfMessages = 0x000000FF & mEnvelope.bearerData[0];
}
- if (Config.DEBUG) {
+ if (false) {
Log.d(LOG_TAG, "parseSms: get MWI " +
Integer.toString(mBearerData.numberOfMessages));
}
@@ -715,7 +715,7 @@ public class SmsMessage extends SmsMessageBase {
if (originatingAddress != null) {
originatingAddress.address = new String(originatingAddress.origBytes);
- if (Config.LOGV) Log.v(LOG_TAG, "SMS originating address: "
+ if (false) Log.v(LOG_TAG, "SMS originating address: "
+ originatingAddress.address);
}
@@ -723,7 +723,7 @@ public class SmsMessage extends SmsMessageBase {
scTimeMillis = mBearerData.msgCenterTimeStamp.toMillis(true);
}
- if (Config.LOGD) Log.d(LOG_TAG, "SMS SC timestamp: " + scTimeMillis);
+ if (false) Log.d(LOG_TAG, "SMS SC timestamp: " + scTimeMillis);
// Message Type (See 3GPP2 C.S0015-B, v2, 4.5.1)
if (mBearerData.messageType == BearerData.MESSAGE_TYPE_DELIVERY_ACK) {
@@ -748,9 +748,9 @@ public class SmsMessage extends SmsMessageBase {
}
if (messageBody != null) {
- if (Config.LOGV) Log.v(LOG_TAG, "SMS message body: '" + messageBody + "'");
+ if (false) Log.v(LOG_TAG, "SMS message body: '" + messageBody + "'");
parseMessageBody();
- } else if ((userData != null) && (Config.LOGV)) {
+ } else if ((userData != null) && (false)) {
Log.v(LOG_TAG, "SMS payload: '" + IccUtils.bytesToHexString(userData) + "'");
}
}
@@ -807,7 +807,12 @@ public class SmsMessage extends SmsMessageBase {
* mechanism, and avoid null pointer exceptions.
*/
- CdmaSmsAddress destAddr = CdmaSmsAddress.parse(destAddrStr);
+ /**
+ * North America Plus Code :
+ * Convert + code to 011 and dial out for international SMS
+ */
+ CdmaSmsAddress destAddr = CdmaSmsAddress.parse(
+ PhoneNumberUtils.cdmaCheckAndProcessPlusCode(destAddrStr));
if (destAddr == null) return null;
BearerData bearerData = new BearerData();
diff --git a/telephony/java/com/android/internal/telephony/cdma/sms/BearerData.java b/telephony/java/com/android/internal/telephony/cdma/sms/BearerData.java
index 7a45e15..e17d98d 100755
--- a/telephony/java/com/android/internal/telephony/cdma/sms/BearerData.java
+++ b/telephony/java/com/android/internal/telephony/cdma/sms/BearerData.java
@@ -501,7 +501,7 @@ public final class BearerData {
* stringToGsm7BitPacked, and potentially directly support
* access to the main bitwise stream from encode/decode.
*/
- byte[] fullData = GsmAlphabet.stringToGsm7BitPacked(msg, septetOffset, !force);
+ byte[] fullData = GsmAlphabet.stringToGsm7BitPacked(msg, septetOffset, !force, 0, 0);
Gsm7bitCodingResult result = new Gsm7bitCodingResult();
result.data = new byte[fullData.length - 1];
System.arraycopy(fullData, 1, result.data, 0, fullData.length - 1);
@@ -976,7 +976,8 @@ public final class BearerData {
int offsetSeptets = (offsetBits + 6) / 7;
numFields -= offsetSeptets;
int paddingBits = (offsetSeptets * 7) - offsetBits;
- String result = GsmAlphabet.gsm7BitPackedToString(data, offset, numFields, paddingBits);
+ String result = GsmAlphabet.gsm7BitPackedToString(data, offset, numFields, paddingBits,
+ 0, 0);
if (result == null) {
throw new CodingException("7bit GSM decoding failed");
}
diff --git a/telephony/java/com/android/internal/telephony/gsm/GSMPhone.java b/telephony/java/com/android/internal/telephony/gsm/GSMPhone.java
index d1758f2..1db9860 100644
--- a/telephony/java/com/android/internal/telephony/gsm/GSMPhone.java
+++ b/telephony/java/com/android/internal/telephony/gsm/GSMPhone.java
@@ -1434,16 +1434,35 @@ public class GSMPhone extends PhoneBase {
return this.mIccFileHandler;
}
+ /**
+ * Activate or deactivate cell broadcast SMS.
+ *
+ * @param activate 0 = activate, 1 = deactivate
+ * @param response Callback message is empty on completion
+ */
public void activateCellBroadcastSms(int activate, Message response) {
- Log.e(LOG_TAG, "Error! This functionality is not implemented for GSM.");
+ Log.e(LOG_TAG, "[GSMPhone] activateCellBroadcastSms() is obsolete; use SmsManager");
+ response.sendToTarget();
}
+ /**
+ * Query the current configuration of cdma cell broadcast SMS.
+ *
+ * @param response Callback message is empty on completion
+ */
public void getCellBroadcastSmsConfig(Message response) {
- Log.e(LOG_TAG, "Error! This functionality is not implemented for GSM.");
+ Log.e(LOG_TAG, "[GSMPhone] getCellBroadcastSmsConfig() is obsolete; use SmsManager");
+ response.sendToTarget();
}
- public void setCellBroadcastSmsConfig(int[] configValuesArray, Message response){
- Log.e(LOG_TAG, "Error! This functionality is not implemented for GSM.");
+ /**
+ * Configure cdma cell broadcast SMS.
+ *
+ * @param response Callback message is empty on completion
+ */
+ public void setCellBroadcastSmsConfig(int[] configValuesArray, Message response) {
+ Log.e(LOG_TAG, "[GSMPhone] setCellBroadcastSmsConfig() is obsolete; use SmsManager");
+ response.sendToTarget();
}
public boolean isCspPlmnEnabled() {
diff --git a/telephony/java/com/android/internal/telephony/gsm/GsmConnection.java b/telephony/java/com/android/internal/telephony/gsm/GsmConnection.java
index 0870d5b..c1ad7b3 100644
--- a/telephony/java/com/android/internal/telephony/gsm/GsmConnection.java
+++ b/telephony/java/com/android/internal/telephony/gsm/GsmConnection.java
@@ -23,7 +23,6 @@ import android.os.Message;
import android.os.PowerManager;
import android.os.Registrant;
import android.os.SystemClock;
-import android.util.Config;
import android.util.Log;
import android.telephony.PhoneNumberUtils;
import android.telephony.ServiceState;
@@ -410,7 +409,7 @@ public class GsmConnection extends Connection {
duration = SystemClock.elapsedRealtime() - connectTimeReal;
disconnected = true;
- if (Config.LOGD) Log.d(LOG_TAG,
+ if (false) Log.d(LOG_TAG,
"[GSMConn] onDisconnect: cause=" + cause);
owner.phone.notifyDisconnect(this);
diff --git a/telephony/java/com/android/internal/telephony/gsm/GsmDataConnection.java b/telephony/java/com/android/internal/telephony/gsm/GsmDataConnection.java
index 9695344..1f24b58 100644
--- a/telephony/java/com/android/internal/telephony/gsm/GsmDataConnection.java
+++ b/telephony/java/com/android/internal/telephony/gsm/GsmDataConnection.java
@@ -76,8 +76,6 @@ public class GsmDataConnection extends DataConnection {
+ "' APN: '" + mApn.apn
+ "' proxy: '" + mApn.proxy + "' port: '" + mApn.port);
- setHttpProxy (mApn.proxy, mApn.port);
-
createTime = -1;
lastFailTime = -1;
lastFailCause = FailCause.NONE;
@@ -152,38 +150,6 @@ public class GsmDataConnection extends DataConnection {
Log.d(LOG_TAG, "[" + getName() + "] " + s);
}
- private void setHttpProxy(String httpProxy, String httpPort) {
-
- if (DBG) log("set http proxy for"
- + "' APN: '" + mActiveApnType
- + "' proxy: '" + mApn.proxy + "' port: '" + mApn.port);
- if(TextUtils.equals(mActiveApnType, Phone.APN_TYPE_DEFAULT)) {
- if (httpProxy == null || httpProxy.length() == 0) {
- phone.setSystemProperty("net.gprs.http-proxy", null);
- return;
- }
-
- if (httpPort == null || httpPort.length() == 0) {
- httpPort = "8080"; // Default to port 8080
- }
-
- phone.setSystemProperty("net.gprs.http-proxy",
- "http://" + httpProxy + ":" + httpPort + "/");
- } else {
- if (httpProxy == null || httpProxy.length() == 0) {
- phone.setSystemProperty("net.gprs.http-proxy." + mActiveApnType, null);
- return;
- }
-
- if (httpPort == null || httpPort.length() == 0) {
- httpPort = "8080"; // Default to port 8080
- }
-
- phone.setSystemProperty("net.gprs.http-proxy." + mActiveApnType,
- "http://" + httpProxy + ":" + httpPort + "/");
- }
- }
-
private boolean isIpAddress(String address) {
if (address == null) return false;
diff --git a/telephony/java/com/android/internal/telephony/gsm/GsmSMSDispatcher.java b/telephony/java/com/android/internal/telephony/gsm/GsmSMSDispatcher.java
index 21a12f1..52ca453 100755..100644
--- a/telephony/java/com/android/internal/telephony/gsm/GsmSMSDispatcher.java
+++ b/telephony/java/com/android/internal/telephony/gsm/GsmSMSDispatcher.java
@@ -28,7 +28,6 @@ import android.provider.Telephony.Sms.Intents;
import android.telephony.ServiceState;
import android.telephony.SmsCbMessage;
import android.telephony.gsm.GsmCellLocation;
-import android.util.Config;
import android.util.Log;
import com.android.internal.telephony.BaseCommands;
@@ -70,9 +69,8 @@ final class GsmSMSDispatcher extends SMSDispatcher {
String pduString = (String) ar.result;
SmsMessage sms = SmsMessage.newFromCDS(pduString);
- int tpStatus = sms.getStatus();
-
if (sms != null) {
+ int tpStatus = sms.getStatus();
int messageRef = sms.messageRef;
for (int i = 0, count = deliveryPendingList.size(); i < count; i++) {
SmsTracker tracker = deliveryPendingList.get(i);
@@ -126,13 +124,13 @@ final class GsmSMSDispatcher extends SMSDispatcher {
if (sms.isMWISetMessage()) {
mGsmPhone.updateMessageWaitingIndicator(true);
handled = sms.isMwiDontStore();
- if (Config.LOGD) {
+ if (false) {
Log.d(TAG, "Received voice mail indicator set SMS shouldStore=" + !handled);
}
} else if (sms.isMWIClearMessage()) {
mGsmPhone.updateMessageWaitingIndicator(false);
handled = sms.isMwiDontStore();
- if (Config.LOGD) {
+ if (false) {
Log.d(TAG, "Received voice mail indicator clear SMS shouldStore=" + !handled);
}
}
@@ -202,6 +200,7 @@ final class GsmSMSDispatcher extends SMSDispatcher {
mRemainingMessages = msgCount;
+ TextEncodingDetails[] encodingForParts = new TextEncodingDetails[msgCount];
for (int i = 0; i < msgCount; i++) {
TextEncodingDetails details = SmsMessage.calculateLength(parts.get(i), false);
if (encoding != details.codeUnitSize
@@ -209,6 +208,7 @@ final class GsmSMSDispatcher extends SMSDispatcher {
|| encoding == android.telephony.SmsMessage.ENCODING_7BIT)) {
encoding = details.codeUnitSize;
}
+ encodingForParts[i] = details;
}
for (int i = 0; i < msgCount; i++) {
@@ -225,6 +225,10 @@ final class GsmSMSDispatcher extends SMSDispatcher {
concatRef.isEightBits = true;
SmsHeader smsHeader = new SmsHeader();
smsHeader.concatRef = concatRef;
+ if (encoding == android.telephony.SmsMessage.ENCODING_7BIT) {
+ smsHeader.languageTable = encodingForParts[i].languageTable;
+ smsHeader.languageShiftTable = encodingForParts[i].languageShiftTable;
+ }
PendingIntent sentIntent = null;
if (sentIntents != null && sentIntents.size() > i) {
@@ -238,7 +242,7 @@ final class GsmSMSDispatcher extends SMSDispatcher {
SmsMessage.SubmitPdu pdus = SmsMessage.getSubmitPdu(scAddress, destinationAddress,
parts.get(i), deliveryIntent != null, SmsHeader.toByteArray(smsHeader),
- encoding);
+ encoding, smsHeader.languageTable, smsHeader.languageShiftTable);
sendRawPdu(pdus.encodedScAddress, pdus.encodedMessage, sentIntent, deliveryIntent);
}
@@ -293,6 +297,7 @@ final class GsmSMSDispatcher extends SMSDispatcher {
mRemainingMessages = msgCount;
+ TextEncodingDetails[] encodingForParts = new TextEncodingDetails[msgCount];
for (int i = 0; i < msgCount; i++) {
TextEncodingDetails details = SmsMessage.calculateLength(parts.get(i), false);
if (encoding != details.codeUnitSize
@@ -300,6 +305,7 @@ final class GsmSMSDispatcher extends SMSDispatcher {
|| encoding == android.telephony.SmsMessage.ENCODING_7BIT)) {
encoding = details.codeUnitSize;
}
+ encodingForParts[i] = details;
}
for (int i = 0; i < msgCount; i++) {
@@ -310,6 +316,10 @@ final class GsmSMSDispatcher extends SMSDispatcher {
concatRef.isEightBits = false;
SmsHeader smsHeader = new SmsHeader();
smsHeader.concatRef = concatRef;
+ if (encoding == android.telephony.SmsMessage.ENCODING_7BIT) {
+ smsHeader.languageTable = encodingForParts[i].languageTable;
+ smsHeader.languageShiftTable = encodingForParts[i].languageShiftTable;
+ }
PendingIntent sentIntent = null;
if (sentIntents != null && sentIntents.size() > i) {
@@ -323,7 +333,7 @@ final class GsmSMSDispatcher extends SMSDispatcher {
SmsMessage.SubmitPdu pdus = SmsMessage.getSubmitPdu(scAddress, destinationAddress,
parts.get(i), deliveryIntent != null, SmsHeader.toByteArray(smsHeader),
- encoding);
+ encoding, smsHeader.languageTable, smsHeader.languageShiftTable);
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("smsc", pdus.encodedScAddress);
@@ -381,30 +391,6 @@ final class GsmSMSDispatcher extends SMSDispatcher {
}
}
- /** {@inheritDoc} */
- @Override
- public void activateCellBroadcastSms(int activate, Message response) {
- // Unless CBS is implemented for GSM, this point should be unreachable.
- Log.e(TAG, "Error! The functionality cell broadcast sms is not implemented for GSM.");
- response.recycle();
- }
-
- /** {@inheritDoc} */
- @Override
- public void getCellBroadcastSmsConfig(Message response){
- // Unless CBS is implemented for GSM, this point should be unreachable.
- Log.e(TAG, "Error! The functionality cell broadcast sms is not implemented for GSM.");
- response.recycle();
- }
-
- /** {@inheritDoc} */
- @Override
- public void setCellBroadcastConfig(int[] configValuesArray, Message response) {
- // Unless CBS is implemented for GSM, this point should be unreachable.
- Log.e(TAG, "Error! The functionality cell broadcast sms is not implemented for GSM.");
- response.recycle();
- }
-
private int resultToCause(int rc) {
switch (rc) {
case Activity.RESULT_OK:
@@ -496,23 +482,24 @@ final class GsmSMSDispatcher extends SMSDispatcher {
}
// This map holds incomplete concatenated messages waiting for assembly
- private HashMap<SmsCbConcatInfo, byte[][]> mSmsCbPageMap =
+ private final HashMap<SmsCbConcatInfo, byte[][]> mSmsCbPageMap =
new HashMap<SmsCbConcatInfo, byte[][]>();
+ @Override
protected void handleBroadcastSms(AsyncResult ar) {
try {
byte[][] pdus = null;
byte[] receivedPdu = (byte[])ar.result;
- if (Config.LOGD) {
+ if (false) {
for (int i = 0; i < receivedPdu.length; i += 8) {
StringBuilder sb = new StringBuilder("SMS CB pdu data: ");
for (int j = i; j < i + 8 && j < receivedPdu.length; j++) {
int b = receivedPdu[j] & 0xff;
if (b < 0x10) {
- sb.append("0");
+ sb.append('0');
}
- sb.append(Integer.toHexString(b)).append(" ");
+ sb.append(Integer.toHexString(b)).append(' ');
}
Log.d(TAG, sb.toString());
}
@@ -557,7 +544,8 @@ final class GsmSMSDispatcher extends SMSDispatcher {
pdus[0] = receivedPdu;
}
- dispatchBroadcastPdus(pdus);
+ boolean isEmergencyMessage = SmsCbHeader.isEmergencyMessage(header.messageIdentifier);
+ dispatchBroadcastPdus(pdus, isEmergencyMessage);
// Remove messages that are out of scope to prevent the map from
// growing indefinitely, containing incomplete messages that were
diff --git a/telephony/java/com/android/internal/telephony/gsm/GsmServiceStateTracker.java b/telephony/java/com/android/internal/telephony/gsm/GsmServiceStateTracker.java
index a7631cd..d3645fa 100644
--- a/telephony/java/com/android/internal/telephony/gsm/GsmServiceStateTracker.java
+++ b/telephony/java/com/android/internal/telephony/gsm/GsmServiceStateTracker.java
@@ -55,7 +55,6 @@ import android.telephony.ServiceState;
import android.telephony.SignalStrength;
import android.telephony.gsm.GsmCellLocation;
import android.text.TextUtils;
-import android.util.Config;
import android.util.EventLog;
import android.util.Log;
import android.util.TimeUtils;
@@ -916,7 +915,7 @@ final class GsmServiceStateTracker extends ServiceStateTracker {
}
if (hasRadioTechnologyChanged) {
- phone.notifyDataConnection(Phone.REASON_NW_TYPE_CHANGED, Phone.APN_TYPE_ALL);
+ phone.notifyDataConnection(Phone.REASON_NW_TYPE_CHANGED);
}
if (hasRoamingOn) {
@@ -1441,7 +1440,7 @@ final class GsmServiceStateTracker extends ServiceStateTracker {
}
SystemProperties.set("gsm.nitz.time", String.valueOf(c.getTimeInMillis()));
saveNitzTime(c.getTimeInMillis());
- if (DBG) {
+ if (false) {
long end = SystemClock.elapsedRealtime();
log("NITZ: end=" + end + " dur=" + (end - start));
}
diff --git a/telephony/java/com/android/internal/telephony/gsm/SimPhoneBookInterfaceManager.java b/telephony/java/com/android/internal/telephony/gsm/SimPhoneBookInterfaceManager.java
index 377f8f0..35ba0d1 100644
--- a/telephony/java/com/android/internal/telephony/gsm/SimPhoneBookInterfaceManager.java
+++ b/telephony/java/com/android/internal/telephony/gsm/SimPhoneBookInterfaceManager.java
@@ -16,6 +16,8 @@
package com.android.internal.telephony.gsm;
+import java.util.concurrent.atomic.AtomicBoolean;
+
import android.os.Message;
import android.util.Log;
@@ -56,14 +58,11 @@ public class SimPhoneBookInterfaceManager extends IccPhoneBookInterfaceManager {
recordSize = new int[3];
//Using mBaseHandler, no difference in EVENT_GET_SIZE_DONE handling
- Message response = mBaseHandler.obtainMessage(EVENT_GET_SIZE_DONE);
+ AtomicBoolean status = new AtomicBoolean(false);
+ Message response = mBaseHandler.obtainMessage(EVENT_GET_SIZE_DONE, status);
phone.getIccFileHandler().getEFLinearRecordSize(efid, response);
- try {
- mLock.wait();
- } catch (InterruptedException e) {
- logd("interrupted while trying to load from the SIM");
- }
+ waitForResult(status);
}
return recordSize;
diff --git a/telephony/java/com/android/internal/telephony/gsm/SimSmsInterfaceManager.java b/telephony/java/com/android/internal/telephony/gsm/SimSmsInterfaceManager.java
index 5abba6e..8d0e5d3 100644
--- a/telephony/java/com/android/internal/telephony/gsm/SimSmsInterfaceManager.java
+++ b/telephony/java/com/android/internal/telephony/gsm/SimSmsInterfaceManager.java
@@ -27,6 +27,7 @@ import android.util.Log;
import com.android.internal.telephony.IccConstants;
import com.android.internal.telephony.IccSmsInterfaceManager;
import com.android.internal.telephony.IccUtils;
+import com.android.internal.telephony.IntRangeManager;
import com.android.internal.telephony.SMSDispatcher;
import com.android.internal.telephony.SmsRawData;
@@ -53,6 +54,9 @@ public class SimSmsInterfaceManager extends IccSmsInterfaceManager {
private HashMap<Integer, HashSet<String>> mCellBroadcastSubscriptions =
new HashMap<Integer, HashSet<String>>();
+ private CellBroadcastRangeManager mCellBroadcastRangeManager =
+ new CellBroadcastRangeManager();
+
private static final int EVENT_LOAD_DONE = 1;
private static final int EVENT_UPDATE_DONE = 2;
private static final int EVENT_SET_BROADCAST_ACTIVATION_DONE = 3;
@@ -213,7 +217,15 @@ public class SimSmsInterfaceManager extends IccSmsInterfaceManager {
}
public boolean enableCellBroadcast(int messageIdentifier) {
- if (DBG) log("enableCellBroadcast");
+ return enableCellBroadcastRange(messageIdentifier, messageIdentifier);
+ }
+
+ public boolean disableCellBroadcast(int messageIdentifier) {
+ return disableCellBroadcastRange(messageIdentifier, messageIdentifier);
+ }
+
+ public boolean enableCellBroadcastRange(int startMessageId, int endMessageId) {
+ if (DBG) log("enableCellBroadcastRange");
Context context = mPhone.getContext();
@@ -223,30 +235,22 @@ public class SimSmsInterfaceManager extends IccSmsInterfaceManager {
String client = context.getPackageManager().getNameForUid(
Binder.getCallingUid());
- HashSet<String> clients = mCellBroadcastSubscriptions.get(messageIdentifier);
-
- if (clients == null) {
- // This is a new message identifier
- clients = new HashSet<String>();
- mCellBroadcastSubscriptions.put(messageIdentifier, clients);
- if (!updateCellBroadcastConfig()) {
- mCellBroadcastSubscriptions.remove(messageIdentifier);
- return false;
- }
+ if (!mCellBroadcastRangeManager.enableRange(startMessageId, endMessageId, client)) {
+ log("Failed to add cell broadcast subscription for MID range " + startMessageId
+ + " to " + endMessageId + " from client " + client);
+ return false;
}
- clients.add(client);
-
if (DBG)
- log("Added cell broadcast subscription for MID " + messageIdentifier
- + " from client " + client);
+ log("Added cell broadcast subscription for MID range " + startMessageId
+ + " to " + endMessageId + " from client " + client);
return true;
}
- public boolean disableCellBroadcast(int messageIdentifier) {
- if (DBG) log("disableCellBroadcast");
+ public boolean disableCellBroadcastRange(int startMessageId, int endMessageId) {
+ if (DBG) log("disableCellBroadcastRange");
Context context = mPhone.getContext();
@@ -256,39 +260,56 @@ public class SimSmsInterfaceManager extends IccSmsInterfaceManager {
String client = context.getPackageManager().getNameForUid(
Binder.getCallingUid());
- HashSet<String> clients = mCellBroadcastSubscriptions.get(messageIdentifier);
- if (clients != null && clients.remove(client)) {
- if (DBG)
- log("Removed cell broadcast subscription for MID " + messageIdentifier
- + " from client " + client);
-
- if (clients.isEmpty()) {
- mCellBroadcastSubscriptions.remove(messageIdentifier);
- updateCellBroadcastConfig();
- }
- return true;
+ if (!mCellBroadcastRangeManager.disableRange(startMessageId, endMessageId, client)) {
+ log("Failed to remove cell broadcast subscription for MID range " + startMessageId
+ + " to " + endMessageId + " from client " + client);
+ return false;
}
- return false;
+ if (DBG)
+ log("Removed cell broadcast subscription for MID range " + startMessageId
+ + " to " + endMessageId + " from client " + client);
+
+ return true;
}
- private boolean updateCellBroadcastConfig() {
- Set<Integer> messageIdentifiers = mCellBroadcastSubscriptions.keySet();
+ class CellBroadcastRangeManager extends IntRangeManager {
+ private ArrayList<SmsBroadcastConfigInfo> mConfigList =
+ new ArrayList<SmsBroadcastConfigInfo>();
+
+ /**
+ * Called when the list of enabled ranges has changed. This will be
+ * followed by zero or more calls to {@link #addRange} followed by
+ * a call to {@link #finishUpdate}.
+ */
+ protected void startUpdate() {
+ mConfigList.clear();
+ }
- if (messageIdentifiers.size() > 0) {
- SmsBroadcastConfigInfo[] configs =
- new SmsBroadcastConfigInfo[messageIdentifiers.size()];
- int i = 0;
+ /**
+ * Called after {@link #startUpdate} to indicate a range of enabled
+ * values.
+ * @param startId the first id included in the range
+ * @param endId the last id included in the range
+ */
+ protected void addRange(int startId, int endId, boolean selected) {
+ mConfigList.add(new SmsBroadcastConfigInfo(startId, endId,
+ SMS_CB_CODE_SCHEME_MIN, SMS_CB_CODE_SCHEME_MAX, selected));
+ }
- for (int messageIdentifier : messageIdentifiers) {
- configs[i++] = new SmsBroadcastConfigInfo(messageIdentifier, messageIdentifier,
- SMS_CB_CODE_SCHEME_MIN, SMS_CB_CODE_SCHEME_MAX, true);
+ /**
+ * Called to indicate the end of a range update started by the
+ * previous call to {@link #startUpdate}.
+ */
+ protected boolean finishUpdate() {
+ if (mConfigList.isEmpty()) {
+ return setCellBroadcastActivation(false);
+ } else {
+ SmsBroadcastConfigInfo[] configs =
+ mConfigList.toArray(new SmsBroadcastConfigInfo[mConfigList.size()]);
+ return setCellBroadcastConfig(configs) && setCellBroadcastActivation(true);
}
-
- return setCellBroadcastConfig(configs) && setCellBroadcastActivation(true);
- } else {
- return setCellBroadcastActivation(false);
}
}
@@ -314,7 +335,7 @@ public class SimSmsInterfaceManager extends IccSmsInterfaceManager {
private boolean setCellBroadcastActivation(boolean activate) {
if (DBG)
- log("Calling setCellBroadcastActivation(" + activate + ")");
+ log("Calling setCellBroadcastActivation(" + activate + ')');
synchronized (mLock) {
Message response = mHandler.obtainMessage(EVENT_SET_BROADCAST_ACTIVATION_DONE);
diff --git a/telephony/java/com/android/internal/telephony/gsm/SmsBroadcastConfigInfo.java b/telephony/java/com/android/internal/telephony/gsm/SmsBroadcastConfigInfo.java
index 45f50bc..66e7ce0 100644
--- a/telephony/java/com/android/internal/telephony/gsm/SmsBroadcastConfigInfo.java
+++ b/telephony/java/com/android/internal/telephony/gsm/SmsBroadcastConfigInfo.java
@@ -30,11 +30,11 @@ package com.android.internal.telephony.gsm;
* and 9.4.4.2.3 for UMTS.
* All other values can be treated as empty CBM data coding scheme.
*
- * selected false means message types specified in <fromServiceId, toServiceId>
- * and <fromCodeScheme, toCodeScheme>are not accepted, while true means accepted.
+ * selected false means message types specified in {@code <fromServiceId, toServiceId>}
+ * and {@code <fromCodeScheme, toCodeScheme>} are not accepted, while true means accepted.
*
*/
-public class SmsBroadcastConfigInfo {
+public final class SmsBroadcastConfigInfo {
private int fromServiceId;
private int toServiceId;
private int fromCodeScheme;
@@ -46,11 +46,11 @@ public class SmsBroadcastConfigInfo {
*/
public SmsBroadcastConfigInfo(int fromId, int toId, int fromScheme,
int toScheme, boolean selected) {
- setFromServiceId(fromId);
- setToServiceId(toId);
- setFromCodeScheme(fromScheme);
- setToCodeScheme(toScheme);
- this.setSelected(selected);
+ fromServiceId = fromId;
+ toServiceId = toId;
+ fromCodeScheme = fromScheme;
+ toCodeScheme = toScheme;
+ this.selected = selected;
}
/**
@@ -126,8 +126,8 @@ public class SmsBroadcastConfigInfo {
@Override
public String toString() {
return "SmsBroadcastConfigInfo: Id [" +
- getFromServiceId() + "," + getToServiceId() + "] Code [" +
- getFromCodeScheme() + "," + getToCodeScheme() + "] " +
- (isSelected() ? "ENABLED" : "DISABLED");
+ fromServiceId + ',' + toServiceId + "] Code [" +
+ fromCodeScheme + ',' + toCodeScheme + "] " +
+ (selected ? "ENABLED" : "DISABLED");
}
-} \ No newline at end of file
+}
diff --git a/telephony/java/com/android/internal/telephony/gsm/SmsCbHeader.java b/telephony/java/com/android/internal/telephony/gsm/SmsCbHeader.java
index 5f27cfc..8e6b79b 100644
--- a/telephony/java/com/android/internal/telephony/gsm/SmsCbHeader.java
+++ b/telephony/java/com/android/internal/telephony/gsm/SmsCbHeader.java
@@ -16,9 +16,44 @@
package com.android.internal.telephony.gsm;
-public class SmsCbHeader {
+import android.telephony.SmsCbConstants;
+
+public class SmsCbHeader implements SmsCbConstants {
+ /**
+ * Length of SMS-CB header
+ */
public static final int PDU_HEADER_LENGTH = 6;
+ /**
+ * GSM pdu format, as defined in 3gpp TS 23.041, section 9.4.1
+ */
+ public static final int FORMAT_GSM = 1;
+
+ /**
+ * UMTS pdu format, as defined in 3gpp TS 23.041, section 9.4.2
+ */
+ public static final int FORMAT_UMTS = 2;
+
+ /**
+ * GSM pdu format, as defined in 3gpp TS 23.041, section 9.4.1.3
+ */
+ public static final int FORMAT_ETWS_PRIMARY = 3;
+
+ /**
+ * Message type value as defined in 3gpp TS 25.324, section 11.1.
+ */
+ private static final int MESSAGE_TYPE_CBS_MESSAGE = 1;
+
+ /**
+ * Length of GSM pdus
+ */
+ public static final int PDU_LENGTH_GSM = 88;
+
+ /**
+ * Maximum length of ETWS primary message GSM pdus
+ */
+ public static final int PDU_LENGTH_ETWS = 56;
+
public final int geographicalScope;
public final int messageCode;
@@ -33,27 +68,147 @@ public class SmsCbHeader {
public final int nrOfPages;
+ public final int format;
+
+ public final boolean etwsEmergencyUserAlert;
+
+ public final boolean etwsPopup;
+
+ public final int etwsWarningType;
+
public SmsCbHeader(byte[] pdu) throws IllegalArgumentException {
if (pdu == null || pdu.length < PDU_HEADER_LENGTH) {
throw new IllegalArgumentException("Illegal PDU");
}
- geographicalScope = (pdu[0] & 0xc0) >> 6;
- messageCode = ((pdu[0] & 0x3f) << 4) | ((pdu[1] & 0xf0) >> 4);
- updateNumber = pdu[1] & 0x0f;
- messageIdentifier = (pdu[2] << 8) | pdu[3];
- dataCodingScheme = pdu[4];
+ if (pdu.length <= PDU_LENGTH_ETWS) {
+ format = FORMAT_ETWS_PRIMARY;
+ geographicalScope = -1; //not applicable
+ messageCode = -1;
+ updateNumber = -1;
+ messageIdentifier = ((pdu[2] & 0xff) << 8) | (pdu[3] & 0xff);
+ dataCodingScheme = -1;
+ pageIndex = -1;
+ nrOfPages = -1;
+ etwsEmergencyUserAlert = (pdu[4] & 0x1) != 0;
+ etwsPopup = (pdu[5] & 0x80) != 0;
+ etwsWarningType = (pdu[4] & 0xfe) >> 1;
+ } else if (pdu.length <= PDU_LENGTH_GSM) {
+ // GSM pdus are no more than 88 bytes
+ format = FORMAT_GSM;
+ geographicalScope = (pdu[0] & 0xc0) >> 6;
+ messageCode = ((pdu[0] & 0x3f) << 4) | ((pdu[1] & 0xf0) >> 4);
+ updateNumber = pdu[1] & 0x0f;
+ messageIdentifier = ((pdu[2] & 0xff) << 8) | (pdu[3] & 0xff);
+ dataCodingScheme = pdu[4] & 0xff;
+
+ // Check for invalid page parameter
+ int pageIndex = (pdu[5] & 0xf0) >> 4;
+ int nrOfPages = pdu[5] & 0x0f;
+
+ if (pageIndex == 0 || nrOfPages == 0 || pageIndex > nrOfPages) {
+ pageIndex = 1;
+ nrOfPages = 1;
+ }
+
+ this.pageIndex = pageIndex;
+ this.nrOfPages = nrOfPages;
+ etwsEmergencyUserAlert = false;
+ etwsPopup = false;
+ etwsWarningType = -1;
+ } else {
+ // UMTS pdus are always at least 90 bytes since the payload includes
+ // a number-of-pages octet and also one length octet per page
+ format = FORMAT_UMTS;
- // Check for invalid page parameter
- int pageIndex = (pdu[5] & 0xf0) >> 4;
- int nrOfPages = pdu[5] & 0x0f;
+ int messageType = pdu[0];
- if (pageIndex == 0 || nrOfPages == 0 || pageIndex > nrOfPages) {
+ if (messageType != MESSAGE_TYPE_CBS_MESSAGE) {
+ throw new IllegalArgumentException("Unsupported message type " + messageType);
+ }
+
+ messageIdentifier = ((pdu[1] & 0xff) << 8) | pdu[2] & 0xff;
+ geographicalScope = (pdu[3] & 0xc0) >> 6;
+ messageCode = ((pdu[3] & 0x3f) << 4) | ((pdu[4] & 0xf0) >> 4);
+ updateNumber = pdu[4] & 0x0f;
+ dataCodingScheme = pdu[5] & 0xff;
+
+ // We will always consider a UMTS message as having one single page
+ // since there's only one instance of the header, even though the
+ // actual payload may contain several pages.
pageIndex = 1;
nrOfPages = 1;
+ etwsEmergencyUserAlert = false;
+ etwsPopup = false;
+ etwsWarningType = -1;
}
+ }
+
+ /**
+ * Return whether the specified message ID is an emergency (PWS) message type.
+ * This method is static and takes an argument so that it can be used by
+ * CellBroadcastReceiver, which stores message ID's in SQLite rather than PDU.
+ * @param id the message identifier to check
+ * @return true if the message is emergency type; false otherwise
+ */
+ public static boolean isEmergencyMessage(int id) {
+ return id >= MESSAGE_ID_PWS_FIRST_IDENTIFIER && id <= MESSAGE_ID_PWS_LAST_IDENTIFIER;
+ }
+
+ /**
+ * Return whether the specified message ID is an ETWS emergency message type.
+ * This method is static and takes an argument so that it can be used by
+ * CellBroadcastReceiver, which stores message ID's in SQLite rather than PDU.
+ * @param id the message identifier to check
+ * @return true if the message is ETWS emergency type; false otherwise
+ */
+ public static boolean isEtwsMessage(int id) {
+ return (id & MESSAGE_ID_ETWS_TYPE_MASK) == MESSAGE_ID_ETWS_TYPE;
+ }
+
+ /**
+ * Return whether the specified message ID is a CMAS emergency message type.
+ * This method is static and takes an argument so that it can be used by
+ * CellBroadcastReceiver, which stores message ID's in SQLite rather than PDU.
+ * @param id the message identifier to check
+ * @return true if the message is CMAS emergency type; false otherwise
+ */
+ public static boolean isCmasMessage(int id) {
+ return id >= MESSAGE_ID_CMAS_FIRST_IDENTIFIER && id <= MESSAGE_ID_CMAS_LAST_IDENTIFIER;
+ }
+
+ /**
+ * Return whether the specified message code indicates an ETWS popup alert.
+ * This method is static and takes an argument so that it can be used by
+ * CellBroadcastReceiver, which stores message codes in SQLite rather than PDU.
+ * This method assumes that the message ID has already been checked for ETWS type.
+ *
+ * @param messageCode the message code to check
+ * @return true if the message code indicates a popup alert should be displayed
+ */
+ public static boolean isEtwsPopupAlert(int messageCode) {
+ return (messageCode & MESSAGE_CODE_ETWS_ACTIVATE_POPUP) != 0;
+ }
+
+ /**
+ * Return whether the specified message code indicates an ETWS emergency user alert.
+ * This method is static and takes an argument so that it can be used by
+ * CellBroadcastReceiver, which stores message codes in SQLite rather than PDU.
+ * This method assumes that the message ID has already been checked for ETWS type.
+ *
+ * @param messageCode the message code to check
+ * @return true if the message code indicates an emergency user alert
+ */
+ public static boolean isEtwsEmergencyUserAlert(int messageCode) {
+ return (messageCode & MESSAGE_CODE_ETWS_EMERGENCY_USER_ALERT) != 0;
+ }
- this.pageIndex = pageIndex;
- this.nrOfPages = nrOfPages;
+ @Override
+ public String toString() {
+ return "SmsCbHeader{GS=" + geographicalScope + ", messageCode=0x" +
+ Integer.toHexString(messageCode) + ", updateNumber=" + updateNumber +
+ ", messageIdentifier=0x" + Integer.toHexString(messageIdentifier) +
+ ", DCS=0x" + Integer.toHexString(dataCodingScheme) +
+ ", page " + pageIndex + " of " + nrOfPages + '}';
}
}
diff --git a/telephony/java/com/android/internal/telephony/gsm/SmsMessage.java b/telephony/java/com/android/internal/telephony/gsm/SmsMessage.java
index e24613f..3784e7c 100644
--- a/telephony/java/com/android/internal/telephony/gsm/SmsMessage.java
+++ b/telephony/java/com/android/internal/telephony/gsm/SmsMessage.java
@@ -19,7 +19,6 @@ package com.android.internal.telephony.gsm;
import android.os.Parcel;
import android.telephony.PhoneNumberUtils;
import android.text.format.Time;
-import android.util.Config;
import android.util.Log;
import com.android.internal.telephony.IccUtils;
import com.android.internal.telephony.EncodeException;
@@ -38,7 +37,6 @@ import static android.telephony.SmsMessage.ENCODING_UNKNOWN;
import static android.telephony.SmsMessage.MAX_USER_DATA_BYTES;
import static android.telephony.SmsMessage.MAX_USER_DATA_BYTES_WITH_HEADER;
import static android.telephony.SmsMessage.MAX_USER_DATA_SEPTETS;
-import static android.telephony.SmsMessage.MAX_USER_DATA_SEPTETS_WITH_HEADER;
import static android.telephony.SmsMessage.MessageClass;
/**
@@ -214,9 +212,7 @@ public class SmsMessage extends SmsMessageBase {
*/
public static int getTPLayerLengthForPDU(String pdu) {
int len = pdu.length() / 2;
- int smscLen = 0;
-
- smscLen = Integer.parseInt(pdu.substring(0, 2), 16);
+ int smscLen = Integer.parseInt(pdu.substring(0, 2), 16);
return len - smscLen - 1;
}
@@ -234,7 +230,7 @@ public class SmsMessage extends SmsMessageBase {
String destinationAddress, String message,
boolean statusReportRequested, byte[] header) {
return getSubmitPdu(scAddress, destinationAddress, message, statusReportRequested, header,
- ENCODING_UNKNOWN);
+ ENCODING_UNKNOWN, 0, 0);
}
@@ -244,6 +240,8 @@ public class SmsMessage extends SmsMessageBase {
*
* @param scAddress Service Centre address. Null means use default.
* @param encoding Encoding defined by constants in android.telephony.SmsMessage.ENCODING_*
+ * @param languageTable
+ * @param languageShiftTable
* @return a <code>SubmitPdu</code> containing the encoded SC
* address, if applicable, and the encoded message.
* Returns null on encode error.
@@ -251,7 +249,8 @@ public class SmsMessage extends SmsMessageBase {
*/
public static SubmitPdu getSubmitPdu(String scAddress,
String destinationAddress, String message,
- boolean statusReportRequested, byte[] header, int encoding) {
+ boolean statusReportRequested, byte[] header, int encoding,
+ int languageTable, int languageShiftTable) {
// Perform null parameter checks.
if (message == null || destinationAddress == null) {
@@ -272,7 +271,8 @@ public class SmsMessage extends SmsMessageBase {
}
try {
if (encoding == ENCODING_7BIT) {
- userData = GsmAlphabet.stringToGsm7BitPackedWithHeader(message, header);
+ userData = GsmAlphabet.stringToGsm7BitPackedWithHeader(message, header,
+ languageTable, languageShiftTable);
} else { //assume UCS-2
try {
userData = encodeUCS2(message, header);
@@ -458,7 +458,7 @@ public class SmsMessage extends SmsMessageBase {
if (statusReportRequested) {
// Set TP-Status-Report-Request bit.
mtiByte |= 0x20;
- if (Config.LOGD) Log.d(LOG_TAG, "SMS status report requested");
+ if (false) Log.d(LOG_TAG, "SMS status report requested");
}
bo.write(mtiByte);
@@ -686,70 +686,19 @@ public class SmsMessage extends SmsMessageBase {
return userDataHeader;
}
-/*
- XXX Not sure what this one is supposed to be doing, and no one is using
- it.
- String getUserDataGSM8bit() {
- // System.out.println("remainder of pdu:" +
- // HexDump.dumpHexString(pdu, cur, pdu.length - cur));
- int count = pdu[cur++] & 0xff;
- int size = pdu[cur++];
-
- // skip over header for now
- cur += size;
-
- if (pdu[cur - 1] == 0x01) {
- int tid = pdu[cur++] & 0xff;
- int type = pdu[cur++] & 0xff;
-
- size = pdu[cur++] & 0xff;
-
- int i = cur;
-
- while (pdu[i++] != '\0') {
- }
-
- int length = i - cur;
- String mimeType = new String(pdu, cur, length);
-
- cur += length;
-
- if (false) {
- System.out.println("tid = 0x" + HexDump.toHexString(tid));
- System.out.println("type = 0x" + HexDump.toHexString(type));
- System.out.println("header size = " + size);
- System.out.println("mimeType = " + mimeType);
- System.out.println("remainder of header:" +
- HexDump.dumpHexString(pdu, cur, (size - mimeType.length())));
- }
-
- cur += size - mimeType.length();
-
- // System.out.println("data count = " + count + " cur = " + cur
- // + " :" + HexDump.dumpHexString(pdu, cur, pdu.length - cur));
-
- MMSMessage msg = MMSMessage.parseEncoding(mContext, pdu, cur,
- pdu.length - cur);
- } else {
- System.out.println(new String(pdu, cur, pdu.length - cur - 1));
- }
-
- return IccUtils.bytesToHexString(pdu);
- }
-*/
-
/**
- * Interprets the user data payload as pack GSM 7bit characters, and
+ * Interprets the user data payload as packed GSM 7bit characters, and
* decodes them into a String.
*
* @param septetCount the number of septets in the user data payload
* @return a String with the decoded characters
*/
- String getUserDataGSM7Bit(int septetCount) {
+ String getUserDataGSM7Bit(int septetCount, int languageTable,
+ int languageShiftTable) {
String ret;
ret = GsmAlphabet.gsm7BitPackedToString(pdu, cur, septetCount,
- mUserDataSeptetPadding);
+ mUserDataSeptetPadding, languageTable, languageShiftTable);
cur += (septetCount * 7) / 8;
@@ -812,21 +761,9 @@ public class SmsMessage extends SmsMessageBase {
*/
public static TextEncodingDetails calculateLength(CharSequence msgBody,
boolean use7bitOnly) {
- TextEncodingDetails ted = new TextEncodingDetails();
- try {
- int septets = GsmAlphabet.countGsmSeptets(msgBody, !use7bitOnly);
- ted.codeUnitCount = septets;
- if (septets > MAX_USER_DATA_SEPTETS) {
- ted.msgCount = (septets + (MAX_USER_DATA_SEPTETS_WITH_HEADER - 1)) /
- MAX_USER_DATA_SEPTETS_WITH_HEADER;
- ted.codeUnitsRemaining = (ted.msgCount *
- MAX_USER_DATA_SEPTETS_WITH_HEADER) - septets;
- } else {
- ted.msgCount = 1;
- ted.codeUnitsRemaining = MAX_USER_DATA_SEPTETS - septets;
- }
- ted.codeUnitSize = ENCODING_7BIT;
- } catch (EncodeException ex) {
+ TextEncodingDetails ted = GsmAlphabet.countGsmSeptets(msgBody, use7bitOnly);
+ if (ted == null) {
+ ted = new TextEncodingDetails();
int octets = msgBody.length() * 2;
ted.codeUnitCount = msgBody.length();
if (octets > MAX_USER_DATA_BYTES) {
@@ -867,7 +804,7 @@ public class SmsMessage extends SmsMessageBase {
/** {@inheritDoc} */
@Override
public boolean isMWIClearMessage() {
- if (isMwi && (mwiSense == false)) {
+ if (isMwi && !mwiSense) {
return true;
}
@@ -878,7 +815,7 @@ public class SmsMessage extends SmsMessageBase {
/** {@inheritDoc} */
@Override
public boolean isMWISetMessage() {
- if (isMwi && (mwiSense == true)) {
+ if (isMwi && mwiSense) {
return true;
}
@@ -942,7 +879,7 @@ public class SmsMessage extends SmsMessageBase {
scAddress = p.getSCAddress();
if (scAddress != null) {
- if (Config.LOGD) Log.d(LOG_TAG, "SMS SC address: " + scAddress);
+ if (false) Log.d(LOG_TAG, "SMS SC address: " + scAddress);
}
// TODO(mkf) support reply path, user data header indicator
@@ -1024,7 +961,7 @@ public class SmsMessage extends SmsMessageBase {
originatingAddress = p.getAddress();
if (originatingAddress != null) {
- if (Config.LOGV) Log.v(LOG_TAG, "SMS originating address: "
+ if (false) Log.v(LOG_TAG, "SMS originating address: "
+ originatingAddress.address);
}
@@ -1036,14 +973,14 @@ public class SmsMessage extends SmsMessageBase {
// see TS 23.038
dataCodingScheme = p.getByte();
- if (Config.LOGV) {
+ if (false) {
Log.v(LOG_TAG, "SMS TP-PID:" + protocolIdentifier
+ " data coding scheme: " + dataCodingScheme);
}
scTimeMillis = p.getSCTimestampMillis();
- if (Config.LOGD) Log.d(LOG_TAG, "SMS SC timestamp: " + scTimeMillis);
+ if (false) Log.d(LOG_TAG, "SMS SC timestamp: " + scTimeMillis);
boolean hasUserDataHeader = (firstByte & 0x40) == 0x40;
@@ -1161,7 +1098,9 @@ public class SmsMessage extends SmsMessageBase {
break;
case ENCODING_7BIT:
- messageBody = p.getUserDataGSM7Bit(count);
+ messageBody = p.getUserDataGSM7Bit(count,
+ hasUserDataHeader ? userDataHeader.languageTable : 0,
+ hasUserDataHeader ? userDataHeader.languageShiftTable : 0);
break;
case ENCODING_16BIT:
@@ -1173,7 +1112,7 @@ public class SmsMessage extends SmsMessageBase {
break;
}
- if (Config.LOGV) Log.v(LOG_TAG, "SMS message body (raw): '" + messageBody + "'");
+ if (false) Log.v(LOG_TAG, "SMS message body (raw): '" + messageBody + "'");
if (messageBody != null) {
parseMessageBody();
diff --git a/telephony/java/com/android/internal/telephony/sip/SipPhone.java b/telephony/java/com/android/internal/telephony/sip/SipPhone.java
index 7373cbb..5471289 100755..100644
--- a/telephony/java/com/android/internal/telephony/sip/SipPhone.java
+++ b/telephony/java/com/android/internal/telephony/sip/SipPhone.java
@@ -40,6 +40,7 @@ import com.android.internal.telephony.PhoneNotifier;
import java.text.ParseException;
import java.util.List;
+import java.util.regex.Pattern;
/**
* {@hide}
@@ -386,8 +387,8 @@ public class SipPhone extends SipPhoneBase {
Connection dial(String originalNumber) throws SipException {
String calleeSipUri = originalNumber;
if (!calleeSipUri.contains("@")) {
- calleeSipUri = mProfile.getUriString().replaceFirst(
- mProfile.getUserName() + "@",
+ String replaceStr = Pattern.quote(mProfile.getUserName() + "@");
+ calleeSipUri = mProfile.getUriString().replaceFirst(replaceStr,
calleeSipUri + "@");
}
try {
diff --git a/telephony/tests/telephonytests/src/com/android/internal/telephony/GsmAlphabetTest.java b/telephony/tests/telephonytests/src/com/android/internal/telephony/GsmAlphabetTest.java
index 7011aeb..f9dc3a9 100644
--- a/telephony/tests/telephonytests/src/com/android/internal/telephony/GsmAlphabetTest.java
+++ b/telephony/tests/telephonytests/src/com/android/internal/telephony/GsmAlphabetTest.java
@@ -22,7 +22,6 @@ import junit.framework.TestCase;
import android.test.suitebuilder.annotation.LargeTest;
import android.test.suitebuilder.annotation.SmallTest;
-import android.test.suitebuilder.annotation.Suppress;
public class GsmAlphabetTest extends TestCase {
@@ -40,15 +39,16 @@ public class GsmAlphabetTest extends TestCase {
String message = "aaaaaaaaaabbbbbbbbbbcccccccccc";
byte[] userData = GsmAlphabet.stringToGsm7BitPackedWithHeader(message,
- SmsHeader.toByteArray(header));
- int septetCount = GsmAlphabet.countGsmSeptets(message, false);
+ SmsHeader.toByteArray(header), 0, 0);
+ int septetCount = GsmAlphabet.countGsmSeptetsUsingTables(message, true, 0, 0);
String parsedMessage = GsmAlphabet.gsm7BitPackedToString(
- userData, SmsHeader.toByteArray(header).length+2, septetCount, 1);
+ userData, SmsHeader.toByteArray(header).length+2, septetCount, 1, 0, 0);
assertEquals(message, parsedMessage);
}
// TODO: This method should *really* be a series of individual test methods.
- @LargeTest
+ // However, it's a SmallTest because it executes quickly.
+ @SmallTest
public void testBasic() throws Exception {
// '@' maps to char 0
assertEquals(0, GsmAlphabet.charToGsm('@'));
@@ -99,7 +99,7 @@ public class GsmAlphabetTest extends TestCase {
assertEquals('@', GsmAlphabet.gsmToChar(0));
- // `a (a with grave accent) maps to last GSM charater
+ // `a (a with grave accent) maps to last GSM character
assertEquals('\u00e0', GsmAlphabet.gsmToChar(0x7f));
assertEquals('\uffff',
@@ -118,8 +118,12 @@ public class GsmAlphabetTest extends TestCase {
assertEquals(' ', GsmAlphabet.gsmExtendedToChar(
GsmAlphabet.GSM_EXTENDED_ESCAPE));
- // Unmappable
- assertEquals(' ', GsmAlphabet.gsmExtendedToChar(0));
+ // Reserved for extension to extension table (mapped to space)
+ assertEquals(' ', GsmAlphabet.gsmExtendedToChar(GsmAlphabet.GSM_EXTENDED_ESCAPE));
+
+ // Unmappable (mapped to character in default or national locking shift table)
+ assertEquals('@', GsmAlphabet.gsmExtendedToChar(0));
+ assertEquals('\u00e0', GsmAlphabet.gsmExtendedToChar(0x7f));
//
// stringTo7BitPacked, gsm7BitPackedToString
@@ -130,7 +134,7 @@ public class GsmAlphabetTest extends TestCase {
// Check all alignment cases
for (int i = 0; i < 9; i++, testString.append('@')) {
- packed = GsmAlphabet.stringToGsm7BitPacked(testString.toString());
+ packed = GsmAlphabet.stringToGsm7BitPacked(testString.toString(), 0, 0);
assertEquals(testString.toString(),
GsmAlphabet.gsm7BitPackedToString(packed, 1, 0xff & packed[0]));
}
@@ -151,7 +155,7 @@ public class GsmAlphabetTest extends TestCase {
assertEquals(1, GsmAlphabet.countGsmSeptets(c));
}
- packed = GsmAlphabet.stringToGsm7BitPacked(testString.toString());
+ packed = GsmAlphabet.stringToGsm7BitPacked(testString.toString(), 0, 0);
assertEquals(testString.toString(),
GsmAlphabet.gsm7BitPackedToString(packed, 1, 0xff & packed[0]));
@@ -166,7 +170,7 @@ public class GsmAlphabetTest extends TestCase {
}
- packed = GsmAlphabet.stringToGsm7BitPacked(testString.toString());
+ packed = GsmAlphabet.stringToGsm7BitPacked(testString.toString(), 0, 0);
assertEquals(testString.toString(),
GsmAlphabet.gsm7BitPackedToString(packed, 1, 0xff & packed[0]));
@@ -177,7 +181,7 @@ public class GsmAlphabetTest extends TestCase {
testString.append('@');
}
- packed = GsmAlphabet.stringToGsm7BitPacked(testString.toString());
+ packed = GsmAlphabet.stringToGsm7BitPacked(testString.toString(), 0, 0);
assertEquals(testString.toString(),
GsmAlphabet.gsm7BitPackedToString(packed, 1, 0xff & packed[0]));
@@ -185,7 +189,7 @@ public class GsmAlphabetTest extends TestCase {
testString.append('@');
try {
- GsmAlphabet.stringToGsm7BitPacked(testString.toString());
+ GsmAlphabet.stringToGsm7BitPacked(testString.toString(), 0, 0);
fail("expected exception");
} catch (EncodeException ex) {
// exception expected
@@ -198,7 +202,7 @@ public class GsmAlphabetTest extends TestCase {
testString.append('{');
}
- packed = GsmAlphabet.stringToGsm7BitPacked(testString.toString());
+ packed = GsmAlphabet.stringToGsm7BitPacked(testString.toString(), 0, 0);
assertEquals(testString.toString(),
GsmAlphabet.gsm7BitPackedToString(packed, 1, 0xff & packed[0]));
@@ -206,17 +210,29 @@ public class GsmAlphabetTest extends TestCase {
testString.append('{');
try {
- GsmAlphabet.stringToGsm7BitPacked(testString.toString());
+ GsmAlphabet.stringToGsm7BitPacked(testString.toString(), 0, 0);
fail("expected exception");
} catch (EncodeException ex) {
// exception expected
}
+ // Reserved for extension to extension table (mapped to space)
+ packed = new byte[]{(byte)(0x1b | 0x80), 0x1b >> 1};
+ assertEquals(" ", GsmAlphabet.gsm7BitPackedToString(packed, 0, 2));
+
+ // Unmappable (mapped to character in default alphabet table)
+ packed[0] = 0x1b;
+ packed[1] = 0x00;
+ assertEquals("@", GsmAlphabet.gsm7BitPackedToString(packed, 0, 2));
+ packed[0] = (byte)(0x1b | 0x80);
+ packed[1] = (byte)(0x7f >> 1);
+ assertEquals("\u00e0", GsmAlphabet.gsm7BitPackedToString(packed, 0, 2));
+
//
// 8 bit unpacked format
//
// Note: we compare hex strings here
- // because Assert doesnt have array-comparisons
+ // because Assert doesn't have array comparisons
byte unpacked[];
@@ -308,6 +324,17 @@ public class GsmAlphabetTest extends TestCase {
assertEquals("a",
GsmAlphabet.gsm8BitUnpackedToString(unpacked, 1, unpacked.length - 1));
+
+ // Reserved for extension to extension table (mapped to space)
+ unpacked[0] = 0x1b;
+ unpacked[1] = 0x1b;
+ assertEquals(" ", GsmAlphabet.gsm8BitUnpackedToString(unpacked, 0, 2));
+
+ // Unmappable (mapped to character in default or national locking shift table)
+ unpacked[1] = 0x00;
+ assertEquals("@", GsmAlphabet.gsm8BitUnpackedToString(unpacked, 0, 2));
+ unpacked[1] = 0x7f;
+ assertEquals("\u00e0", GsmAlphabet.gsm8BitUnpackedToString(unpacked, 0, 2));
}
@SmallTest
diff --git a/telephony/tests/telephonytests/src/com/android/internal/telephony/GsmSmsCbTest.java b/telephony/tests/telephonytests/src/com/android/internal/telephony/GsmSmsCbTest.java
index 7136ea0..417aac4 100644
--- a/telephony/tests/telephonytests/src/com/android/internal/telephony/GsmSmsCbTest.java
+++ b/telephony/tests/telephonytests/src/com/android/internal/telephony/GsmSmsCbTest.java
@@ -18,6 +18,7 @@ package com.android.internal.telephony;
import android.telephony.SmsCbMessage;
import android.test.AndroidTestCase;
+import android.util.Log;
/**
* Test cases for basic SmsCbMessage operations
@@ -69,6 +70,36 @@ public class GsmSmsCbTest extends AndroidTestCase {
doTestGeographicalScopeValue(pdu, (byte)0xC0, SmsCbMessage.GEOGRAPHICAL_SCOPE_CELL_WIDE);
}
+ public void testGetGeographicalScopeUmts() {
+ byte[] pdu = {
+ (byte)0x01, (byte)0x00, (byte)0x32, (byte)0xC0, (byte)0x00, (byte)0x40,
+
+ (byte)0x01,
+
+ (byte)0x41, (byte)0xD0, (byte)0x71, (byte)0xDA, (byte)0x04, (byte)0x91,
+ (byte)0xCB, (byte)0xE6, (byte)0x70, (byte)0x9D, (byte)0x4D, (byte)0x07,
+ (byte)0x85, (byte)0xD9, (byte)0x70, (byte)0x74, (byte)0x58, (byte)0x5C,
+ (byte)0xA6, (byte)0x83, (byte)0xDA, (byte)0xE5, (byte)0xF9, (byte)0x3C,
+ (byte)0x7C, (byte)0x2E, (byte)0x83, (byte)0xEE, (byte)0x69, (byte)0x3A,
+ (byte)0x1A, (byte)0x34, (byte)0x0E, (byte)0xCB, (byte)0xE5, (byte)0xE9,
+ (byte)0xF0, (byte)0xB9, (byte)0x0C, (byte)0x92, (byte)0x97, (byte)0xE9,
+ (byte)0x75, (byte)0xB9, (byte)0x1B, (byte)0x04, (byte)0x0F, (byte)0x93,
+ (byte)0xC9, (byte)0x69, (byte)0xF7, (byte)0xB9, (byte)0xD1, (byte)0x68,
+ (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1,
+ (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3,
+ (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46,
+ (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
+ (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x00,
+
+ (byte)0x34
+ };
+
+ SmsCbMessage msg = SmsCbMessage.createFromPdu(pdu);
+
+ assertEquals("Unexpected geographical scope decoded",
+ SmsCbMessage.GEOGRAPHICAL_SCOPE_CELL_WIDE, msg.getGeographicalScope());
+ }
+
public void testGetMessageBody7Bit() {
byte[] pdu = {
(byte)0xC0, (byte)0x00, (byte)0x00, (byte)0x32, (byte)0x40, (byte)0x11, (byte)0x41,
@@ -92,6 +123,83 @@ public class GsmSmsCbTest extends AndroidTestCase {
msg.getMessageBody());
}
+ public void testGetMessageBody7BitUmts() {
+ byte[] pdu = {
+ (byte)0x01, (byte)0x00, (byte)0x32, (byte)0xC0, (byte)0x00, (byte)0x40,
+
+ (byte)0x01,
+
+ (byte)0x41, (byte)0xD0, (byte)0x71, (byte)0xDA, (byte)0x04, (byte)0x91,
+ (byte)0xCB, (byte)0xE6, (byte)0x70, (byte)0x9D, (byte)0x4D, (byte)0x07,
+ (byte)0x85, (byte)0xD9, (byte)0x70, (byte)0x74, (byte)0x58, (byte)0x5C,
+ (byte)0xA6, (byte)0x83, (byte)0xDA, (byte)0xE5, (byte)0xF9, (byte)0x3C,
+ (byte)0x7C, (byte)0x2E, (byte)0x83, (byte)0xEE, (byte)0x69, (byte)0x3A,
+ (byte)0x1A, (byte)0x34, (byte)0x0E, (byte)0xCB, (byte)0xE5, (byte)0xE9,
+ (byte)0xF0, (byte)0xB9, (byte)0x0C, (byte)0x92, (byte)0x97, (byte)0xE9,
+ (byte)0x75, (byte)0xB9, (byte)0x1B, (byte)0x04, (byte)0x0F, (byte)0x93,
+ (byte)0xC9, (byte)0x69, (byte)0xF7, (byte)0xB9, (byte)0xD1, (byte)0x68,
+ (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1,
+ (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3,
+ (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46,
+ (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
+ (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x00,
+
+ (byte)0x34
+ };
+ SmsCbMessage msg = SmsCbMessage.createFromPdu(pdu);
+
+ assertEquals("Unexpected 7-bit string decoded",
+ "A GSM default alphabet message with carriage return padding",
+ msg.getMessageBody());
+ }
+
+ public void testGetMessageBody7BitMultipageUmts() {
+ byte[] pdu = {
+ (byte)0x01, (byte)0x00, (byte)0x01, (byte)0xC0, (byte)0x00, (byte)0x40,
+
+ (byte)0x02,
+
+ (byte)0xC6, (byte)0xB4, (byte)0x7C, (byte)0x4E, (byte)0x07, (byte)0xC1,
+ (byte)0xC3, (byte)0xE7, (byte)0xF2, (byte)0xAA, (byte)0xD1, (byte)0x68,
+ (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1,
+ (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3,
+ (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46,
+ (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
+ (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A,
+ (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34,
+ (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68,
+ (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1,
+ (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3,
+ (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46,
+ (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
+ (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x00,
+
+ (byte)0x0A,
+
+ (byte)0xD3, (byte)0xF2, (byte)0xF8, (byte)0xED, (byte)0x26, (byte)0x83,
+ (byte)0xE0, (byte)0xE1, (byte)0x73, (byte)0xB9, (byte)0xD1, (byte)0x68,
+ (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1,
+ (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3,
+ (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46,
+ (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
+ (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A,
+ (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34,
+ (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x68,
+ (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1,
+ (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3,
+ (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46,
+ (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
+ (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x00,
+
+ (byte)0x0A
+ };
+ SmsCbMessage msg = SmsCbMessage.createFromPdu(pdu);
+
+ assertEquals("Unexpected multipage 7-bit string decoded",
+ "First page+Second page",
+ msg.getMessageBody());
+ }
+
public void testGetMessageBody7BitFull() {
byte[] pdu = {
(byte)0xC0, (byte)0x00, (byte)0x00, (byte)0x32, (byte)0x40, (byte)0x11, (byte)0x41,
@@ -117,6 +225,38 @@ public class GsmSmsCbTest extends AndroidTestCase {
msg.getMessageBody());
}
+ public void testGetMessageBody7BitFullUmts() {
+ byte[] pdu = {
+ (byte)0x01, (byte)0x00, (byte)0x32, (byte)0xC0, (byte)0x00, (byte)0x40,
+
+ (byte)0x01,
+
+ (byte)0x41, (byte)0xD0, (byte)0x71, (byte)0xDA, (byte)0x04, (byte)0x91,
+ (byte)0xCB, (byte)0xE6, (byte)0x70, (byte)0x9D, (byte)0x4D, (byte)0x07,
+ (byte)0x85, (byte)0xD9, (byte)0x70, (byte)0x74, (byte)0x58, (byte)0x5C,
+ (byte)0xA6, (byte)0x83, (byte)0xDA, (byte)0xE5, (byte)0xF9, (byte)0x3C,
+ (byte)0x7C, (byte)0x2E, (byte)0x83, (byte)0xC4, (byte)0xE5, (byte)0xB4,
+ (byte)0xFB, (byte)0x0C, (byte)0x2A, (byte)0xE3, (byte)0xC3, (byte)0x63,
+ (byte)0x3A, (byte)0x3B, (byte)0x0F, (byte)0xCA, (byte)0xCD, (byte)0x40,
+ (byte)0x63, (byte)0x74, (byte)0x58, (byte)0x1E, (byte)0x1E, (byte)0xD3,
+ (byte)0xCB, (byte)0xF2, (byte)0x39, (byte)0x88, (byte)0xFD, (byte)0x76,
+ (byte)0x9F, (byte)0x59, (byte)0xA0, (byte)0x76, (byte)0x39, (byte)0xEC,
+ (byte)0x4E, (byte)0xBB, (byte)0xCF, (byte)0x20, (byte)0x3A, (byte)0xBA,
+ (byte)0x2C, (byte)0x2F, (byte)0x83, (byte)0xD2, (byte)0x73, (byte)0x90,
+ (byte)0xFB, (byte)0x0D, (byte)0x82, (byte)0x87, (byte)0xC9, (byte)0xE4,
+ (byte)0xB4, (byte)0xFB, (byte)0x1C, (byte)0x02,
+
+ (byte)0x52
+ };
+ SmsCbMessage msg = SmsCbMessage.createFromPdu(pdu);
+
+ assertEquals(
+ "Unexpected 7-bit string decoded",
+ "A GSM default alphabet message being exactly 93 characters long, " +
+ "meaning there is no padding!",
+ msg.getMessageBody());
+ }
+
public void testGetMessageBody7BitWithLanguage() {
byte[] pdu = {
(byte)0xC0, (byte)0x00, (byte)0x00, (byte)0x32, (byte)0x04, (byte)0x11, (byte)0x41,
@@ -167,6 +307,38 @@ public class GsmSmsCbTest extends AndroidTestCase {
assertEquals("Unexpected language indicator decoded", "sv", msg.getLanguageCode());
}
+ public void testGetMessageBody7BitWithLanguageInBodyUmts() {
+ byte[] pdu = {
+ (byte)0x01, (byte)0x00, (byte)0x32, (byte)0xC0, (byte)0x00, (byte)0x10,
+
+ (byte)0x01,
+
+ (byte)0x73, (byte)0x7B, (byte)0x23, (byte)0x08, (byte)0x3A, (byte)0x4E,
+ (byte)0x9B, (byte)0x20, (byte)0x72, (byte)0xD9, (byte)0x1C, (byte)0xAE,
+ (byte)0xB3, (byte)0xE9, (byte)0xA0, (byte)0x30, (byte)0x1B, (byte)0x8E,
+ (byte)0x0E, (byte)0x8B, (byte)0xCB, (byte)0x74, (byte)0x50, (byte)0xBB,
+ (byte)0x3C, (byte)0x9F, (byte)0x87, (byte)0xCF, (byte)0x65, (byte)0xD0,
+ (byte)0x3D, (byte)0x4D, (byte)0x47, (byte)0x83, (byte)0xC6, (byte)0x61,
+ (byte)0xB9, (byte)0x3C, (byte)0x1D, (byte)0x3E, (byte)0x97, (byte)0x41,
+ (byte)0xF2, (byte)0x32, (byte)0xBD, (byte)0x2E, (byte)0x77, (byte)0x83,
+ (byte)0xE0, (byte)0x61, (byte)0x32, (byte)0x39, (byte)0xED, (byte)0x3E,
+ (byte)0x37, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1,
+ (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3,
+ (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46,
+ (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
+ (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x00,
+
+ (byte)0x37
+ };
+ SmsCbMessage msg = SmsCbMessage.createFromPdu(pdu);
+
+ assertEquals("Unexpected 7-bit string decoded",
+ "A GSM default alphabet message with carriage return padding",
+ msg.getMessageBody());
+
+ assertEquals("Unexpected language indicator decoded", "sv", msg.getLanguageCode());
+ }
+
public void testGetMessageBody8Bit() {
byte[] pdu = {
(byte)0xC0, (byte)0x00, (byte)0x00, (byte)0x32, (byte)0x44, (byte)0x11, (byte)0x41,
@@ -210,6 +382,81 @@ public class GsmSmsCbTest extends AndroidTestCase {
"A UCS2 message containing a \u0434 character", msg.getMessageBody());
}
+ public void testGetMessageBodyUcs2Umts() {
+ byte[] pdu = {
+ (byte)0x01, (byte)0x00, (byte)0x32, (byte)0xC0, (byte)0x00, (byte)0x48,
+
+ (byte)0x01,
+
+ (byte)0x00, (byte)0x41, (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x55,
+ (byte)0x00, (byte)0x43, (byte)0x00, (byte)0x53, (byte)0x00, (byte)0x32,
+ (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x6D, (byte)0x00, (byte)0x65,
+ (byte)0x00, (byte)0x73, (byte)0x00, (byte)0x73, (byte)0x00, (byte)0x61,
+ (byte)0x00, (byte)0x67, (byte)0x00, (byte)0x65, (byte)0x00, (byte)0x20,
+ (byte)0x00, (byte)0x63, (byte)0x00, (byte)0x6F, (byte)0x00, (byte)0x6E,
+ (byte)0x00, (byte)0x74, (byte)0x00, (byte)0x61, (byte)0x00, (byte)0x69,
+ (byte)0x00, (byte)0x6E, (byte)0x00, (byte)0x69, (byte)0x00, (byte)0x6E,
+ (byte)0x00, (byte)0x67, (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x61,
+ (byte)0x00, (byte)0x20, (byte)0x04, (byte)0x34, (byte)0x00, (byte)0x20,
+ (byte)0x00, (byte)0x63, (byte)0x00, (byte)0x68, (byte)0x00, (byte)0x61,
+ (byte)0x00, (byte)0x72, (byte)0x00, (byte)0x61, (byte)0x00, (byte)0x63,
+ (byte)0x00, (byte)0x74, (byte)0x00, (byte)0x65, (byte)0x00, (byte)0x72,
+ (byte)0x00, (byte)0x0D, (byte)0x00, (byte)0x0D,
+
+ (byte)0x4E
+ };
+ SmsCbMessage msg = SmsCbMessage.createFromPdu(pdu);
+
+ assertEquals("Unexpected 7-bit string decoded",
+ "A UCS2 message containing a \u0434 character", msg.getMessageBody());
+ }
+
+ public void testGetMessageBodyUcs2MultipageUmts() {
+ byte[] pdu = {
+ (byte)0x01, (byte)0x00, (byte)0x32, (byte)0xC0, (byte)0x00, (byte)0x48,
+
+ (byte)0x02,
+
+ (byte)0x00, (byte)0x41, (byte)0x00, (byte)0x41, (byte)0x00, (byte)0x41,
+ (byte)0x00, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+ (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+ (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+ (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+ (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+ (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+ (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+ (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+ (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+ (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+ (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+ (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+ (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+
+ (byte)0x06,
+
+ (byte)0x00, (byte)0x42, (byte)0x00, (byte)0x42, (byte)0x00, (byte)0x42,
+ (byte)0x00, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+ (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+ (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+ (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+ (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+ (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+ (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+ (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+ (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+ (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+ (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+ (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+ (byte)0x0D, (byte)0x0D, (byte)0x0D, (byte)0x0D,
+
+ (byte)0x06
+ };
+ SmsCbMessage msg = SmsCbMessage.createFromPdu(pdu);
+
+ assertEquals("Unexpected multipage UCS2 string decoded",
+ "AAABBB", msg.getMessageBody());
+ }
+
public void testGetMessageBodyUcs2WithLanguageInBody() {
byte[] pdu = {
(byte)0xC0, (byte)0x00, (byte)0x00, (byte)0x32, (byte)0x11, (byte)0x11, (byte)0x78,
@@ -234,6 +481,37 @@ public class GsmSmsCbTest extends AndroidTestCase {
assertEquals("Unexpected language indicator decoded", "xx", msg.getLanguageCode());
}
+ public void testGetMessageBodyUcs2WithLanguageInBodyUmts() {
+ byte[] pdu = {
+ (byte)0x01, (byte)0x00, (byte)0x32, (byte)0xC0, (byte)0x00, (byte)0x11,
+
+ (byte)0x01,
+
+ (byte)0x78, (byte)0x3C, (byte)0x00, (byte)0x41, (byte)0x00, (byte)0x20,
+ (byte)0x00, (byte)0x55, (byte)0x00, (byte)0x43, (byte)0x00, (byte)0x53,
+ (byte)0x00, (byte)0x32, (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x6D,
+ (byte)0x00, (byte)0x65, (byte)0x00, (byte)0x73, (byte)0x00, (byte)0x73,
+ (byte)0x00, (byte)0x61, (byte)0x00, (byte)0x67, (byte)0x00, (byte)0x65,
+ (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x63, (byte)0x00, (byte)0x6F,
+ (byte)0x00, (byte)0x6E, (byte)0x00, (byte)0x74, (byte)0x00, (byte)0x61,
+ (byte)0x00, (byte)0x69, (byte)0x00, (byte)0x6E, (byte)0x00, (byte)0x69,
+ (byte)0x00, (byte)0x6E, (byte)0x00, (byte)0x67, (byte)0x00, (byte)0x20,
+ (byte)0x00, (byte)0x61, (byte)0x00, (byte)0x20, (byte)0x04, (byte)0x34,
+ (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x63, (byte)0x00, (byte)0x68,
+ (byte)0x00, (byte)0x61, (byte)0x00, (byte)0x72, (byte)0x00, (byte)0x61,
+ (byte)0x00, (byte)0x63, (byte)0x00, (byte)0x74, (byte)0x00, (byte)0x65,
+ (byte)0x00, (byte)0x72, (byte)0x00, (byte)0x0D,
+
+ (byte)0x50
+ };
+ SmsCbMessage msg = SmsCbMessage.createFromPdu(pdu);
+
+ assertEquals("Unexpected 7-bit string decoded",
+ "A UCS2 message containing a \u0434 character", msg.getMessageBody());
+
+ assertEquals("Unexpected language indicator decoded", "xx", msg.getLanguageCode());
+ }
+
public void testGetMessageIdentifier() {
byte[] pdu = {
(byte)0xC0, (byte)0x00, (byte)0x30, (byte)0x39, (byte)0x40, (byte)0x11, (byte)0x41,
@@ -256,6 +534,35 @@ public class GsmSmsCbTest extends AndroidTestCase {
assertEquals("Unexpected message identifier decoded", 12345, msg.getMessageIdentifier());
}
+ public void testGetMessageIdentifierUmts() {
+ byte[] pdu = {
+ (byte)0x01, (byte)0x30, (byte)0x39, (byte)0x2A, (byte)0xA5, (byte)0x40,
+
+ (byte)0x01,
+
+ (byte)0x41, (byte)0xD0, (byte)0x71, (byte)0xDA, (byte)0x04, (byte)0x91,
+ (byte)0xCB, (byte)0xE6, (byte)0x70, (byte)0x9D, (byte)0x4D, (byte)0x07,
+ (byte)0x85, (byte)0xD9, (byte)0x70, (byte)0x74, (byte)0x58, (byte)0x5C,
+ (byte)0xA6, (byte)0x83, (byte)0xDA, (byte)0xE5, (byte)0xF9, (byte)0x3C,
+ (byte)0x7C, (byte)0x2E, (byte)0x83, (byte)0xEE, (byte)0x69, (byte)0x3A,
+ (byte)0x1A, (byte)0x34, (byte)0x0E, (byte)0xCB, (byte)0xE5, (byte)0xE9,
+ (byte)0xF0, (byte)0xB9, (byte)0x0C, (byte)0x92, (byte)0x97, (byte)0xE9,
+ (byte)0x75, (byte)0xB9, (byte)0x1B, (byte)0x04, (byte)0x0F, (byte)0x93,
+ (byte)0xC9, (byte)0x69, (byte)0xF7, (byte)0xB9, (byte)0xD1, (byte)0x68,
+ (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1,
+ (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3,
+ (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46,
+ (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
+ (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x00,
+
+ (byte)0x34
+ };
+
+ SmsCbMessage msg = SmsCbMessage.createFromPdu(pdu);
+
+ assertEquals("Unexpected message identifier decoded", 12345, msg.getMessageIdentifier());
+ }
+
public void testGetMessageCode() {
byte[] pdu = {
(byte)0x2A, (byte)0xA5, (byte)0x30, (byte)0x39, (byte)0x40, (byte)0x11, (byte)0x41,
@@ -278,6 +585,35 @@ public class GsmSmsCbTest extends AndroidTestCase {
assertEquals("Unexpected message code decoded", 682, msg.getMessageCode());
}
+ public void testGetMessageCodeUmts() {
+ byte[] pdu = {
+ (byte)0x01, (byte)0x30, (byte)0x39, (byte)0x2A, (byte)0xA5, (byte)0x40,
+
+ (byte)0x01,
+
+ (byte)0x41, (byte)0xD0, (byte)0x71, (byte)0xDA, (byte)0x04, (byte)0x91,
+ (byte)0xCB, (byte)0xE6, (byte)0x70, (byte)0x9D, (byte)0x4D, (byte)0x07,
+ (byte)0x85, (byte)0xD9, (byte)0x70, (byte)0x74, (byte)0x58, (byte)0x5C,
+ (byte)0xA6, (byte)0x83, (byte)0xDA, (byte)0xE5, (byte)0xF9, (byte)0x3C,
+ (byte)0x7C, (byte)0x2E, (byte)0x83, (byte)0xEE, (byte)0x69, (byte)0x3A,
+ (byte)0x1A, (byte)0x34, (byte)0x0E, (byte)0xCB, (byte)0xE5, (byte)0xE9,
+ (byte)0xF0, (byte)0xB9, (byte)0x0C, (byte)0x92, (byte)0x97, (byte)0xE9,
+ (byte)0x75, (byte)0xB9, (byte)0x1B, (byte)0x04, (byte)0x0F, (byte)0x93,
+ (byte)0xC9, (byte)0x69, (byte)0xF7, (byte)0xB9, (byte)0xD1, (byte)0x68,
+ (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1,
+ (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3,
+ (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46,
+ (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
+ (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x00,
+
+ (byte)0x34
+ };
+
+ SmsCbMessage msg = SmsCbMessage.createFromPdu(pdu);
+
+ assertEquals("Unexpected message code decoded", 682, msg.getMessageCode());
+ }
+
public void testGetUpdateNumber() {
byte[] pdu = {
(byte)0x2A, (byte)0xA5, (byte)0x30, (byte)0x39, (byte)0x40, (byte)0x11, (byte)0x41,
@@ -299,4 +635,78 @@ public class GsmSmsCbTest extends AndroidTestCase {
assertEquals("Unexpected update number decoded", 5, msg.getUpdateNumber());
}
+
+ public void testGetUpdateNumberUmts() {
+ byte[] pdu = {
+ (byte)0x01, (byte)0x30, (byte)0x39, (byte)0x2A, (byte)0xA5, (byte)0x40,
+
+ (byte)0x01,
+
+ (byte)0x41, (byte)0xD0, (byte)0x71, (byte)0xDA, (byte)0x04, (byte)0x91,
+ (byte)0xCB, (byte)0xE6, (byte)0x70, (byte)0x9D, (byte)0x4D, (byte)0x07,
+ (byte)0x85, (byte)0xD9, (byte)0x70, (byte)0x74, (byte)0x58, (byte)0x5C,
+ (byte)0xA6, (byte)0x83, (byte)0xDA, (byte)0xE5, (byte)0xF9, (byte)0x3C,
+ (byte)0x7C, (byte)0x2E, (byte)0x83, (byte)0xEE, (byte)0x69, (byte)0x3A,
+ (byte)0x1A, (byte)0x34, (byte)0x0E, (byte)0xCB, (byte)0xE5, (byte)0xE9,
+ (byte)0xF0, (byte)0xB9, (byte)0x0C, (byte)0x92, (byte)0x97, (byte)0xE9,
+ (byte)0x75, (byte)0xB9, (byte)0x1B, (byte)0x04, (byte)0x0F, (byte)0x93,
+ (byte)0xC9, (byte)0x69, (byte)0xF7, (byte)0xB9, (byte)0xD1, (byte)0x68,
+ (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3, (byte)0xD1,
+ (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46, (byte)0xA3,
+ (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D, (byte)0x46,
+ (byte)0xA3, (byte)0xD1, (byte)0x68, (byte)0x34, (byte)0x1A, (byte)0x8D,
+ (byte)0x46, (byte)0xA3, (byte)0xD1, (byte)0x00,
+
+ (byte)0x34
+ };
+
+ SmsCbMessage msg = SmsCbMessage.createFromPdu(pdu);
+
+ assertEquals("Unexpected update number decoded", 5, msg.getUpdateNumber());
+ }
+
+ /* ETWS Test message including header */
+ private static final byte[] etwsMessageNormal = IccUtils.hexStringToBytes("000011001101" +
+ "0D0A5BAE57CE770C531790E85C716CBF3044573065B930675730" +
+ "9707767A751F30025F37304463FA308C306B5099304830664E0B30553044FF086C178C615E81FF09" +
+ "0000000000000000000000000000");
+
+ private static final byte[] etwsMessageCancel = IccUtils.hexStringToBytes("000011001101" +
+ "0D0A5148307B3069002800310030003A0035" +
+ "00320029306E7DCA602557309707901F5831309253D66D883057307E3059FF086C178C615E81FF09" +
+ "00000000000000000000000000000000000000000000");
+
+ private static final byte[] etwsMessageTest = IccUtils.hexStringToBytes("000011031101" +
+ "0D0A5BAE57CE770C531790E85C716CBF3044" +
+ "573065B9306757309707300263FA308C306B5099304830664E0B30553044FF086C178C615E81FF09" +
+ "00000000000000000000000000000000000000000000");
+
+ // FIXME: add example of ETWS primary notification PDU
+
+ public void testEtwsMessageNormal() {
+ SmsCbMessage msg = SmsCbMessage.createFromPdu(etwsMessageNormal);
+ Log.d("GsmSmsCbTest", msg.toString());
+ assertEquals("GS mismatch", 0, msg.getGeographicalScope());
+ assertEquals("message code mismatch", 0, msg.getMessageCode());
+ assertEquals("update number mismatch", 0, msg.getUpdateNumber());
+ assertEquals("message ID mismatch", 0x1100, msg.getMessageIdentifier());
+ }
+
+ public void testEtwsMessageCancel() {
+ SmsCbMessage msg = SmsCbMessage.createFromPdu(etwsMessageCancel);
+ Log.d("GsmSmsCbTest", msg.toString());
+ assertEquals("GS mismatch", 0, msg.getGeographicalScope());
+ assertEquals("message code mismatch", 0, msg.getMessageCode());
+ assertEquals("update number mismatch", 0, msg.getUpdateNumber());
+ assertEquals("message ID mismatch", 0x1100, msg.getMessageIdentifier());
+ }
+
+ public void testEtwsMessageTest() {
+ SmsCbMessage msg = SmsCbMessage.createFromPdu(etwsMessageTest);
+ Log.d("GsmSmsCbTest", msg.toString());
+ assertEquals("GS mismatch", 0, msg.getGeographicalScope());
+ assertEquals("message code mismatch", 0, msg.getMessageCode());
+ assertEquals("update number mismatch", 0, msg.getUpdateNumber());
+ assertEquals("message ID mismatch", 0x1103, msg.getMessageIdentifier());
+ }
}
diff --git a/telephony/tests/telephonytests/src/com/android/internal/telephony/GsmSmsTest.java b/telephony/tests/telephonytests/src/com/android/internal/telephony/GsmSmsTest.java
index 215c6ce..41a719e 100644
--- a/telephony/tests/telephonytests/src/com/android/internal/telephony/GsmSmsTest.java
+++ b/telephony/tests/telephonytests/src/com/android/internal/telephony/GsmSmsTest.java
@@ -16,8 +16,6 @@
package com.android.internal.telephony;
-import com.android.internal.telephony.GsmAlphabet;
-import com.android.internal.telephony.SmsHeader;
import com.android.internal.telephony.gsm.SmsMessage;
import com.android.internal.util.HexDump;
@@ -209,8 +207,38 @@ public class GsmSmsTest extends AndroidTestCase {
sms.getMessageBody());
}
+ // GSM 7 bit tables in String form, Escape (0x1B) replaced with '@'
+ private static final String[] sBasicTables = {
+ // GSM 7 bit default alphabet
+ "@\u00a3$\u00a5\u00e8\u00e9\u00f9\u00ec\u00f2\u00c7\n\u00d8\u00f8\r\u00c5\u00e5\u0394_"
+ + "\u03a6\u0393\u039b\u03a9\u03a0\u03a8\u03a3\u0398\u039e@\u00c6\u00e6\u00df\u00c9"
+ + " !\"#\u00a4%&'()*+,-./0123456789:;<=>?\u00a1ABCDEFGHIJKLMNOPQRSTUVWXYZ\u00c4\u00d6"
+ + "\u00d1\u00dc\u00a7\u00bfabcdefghijklmnopqrstuvwxyz\u00e4\u00f6\u00f1\u00fc\u00e0",
+
+ // Turkish locking shift table
+ "@\u00a3$\u00a5\u20ac\u00e9\u00f9\u0131\u00f2\u00c7\n\u011e\u011f\r\u00c5\u00e5\u0394_"
+ + "\u03a6\u0393\u039b\u03a9\u03a0\u03a8\u03a3\u0398\u039e@\u015e\u015f\u00df\u00c9"
+ + " !\"#\u00a4%&'()*+,-./0123456789:;<=>?\u0130ABCDEFGHIJKLMNOPQRSTUVWXYZ\u00c4\u00d6"
+ + "\u00d1\u00dc\u00a7\u00e7abcdefghijklmnopqrstuvwxyz\u00e4\u00f6\u00f1\u00fc\u00e0",
+
+ // no locking shift table defined for Spanish
+ "",
+
+ // Portuguese locking shift table
+ "@\u00a3$\u00a5\u00ea\u00e9\u00fa\u00ed\u00f3\u00e7\n\u00d4\u00f4\r\u00c1\u00e1\u0394_"
+ + "\u00aa\u00c7\u00c0\u221e^\\\u20ac\u00d3|@\u00c2\u00e2\u00ca\u00c9 !\"#\u00ba%&'()"
+ + "*+,-./0123456789:;<=>?\u00cdABCDEFGHIJKLMNOPQRSTUVWXYZ\u00c3\u00d5\u00da\u00dc"
+ + "\u00a7~abcdefghijklmnopqrstuvwxyz\u00e3\u00f5`\u00fc\u00e0"
+ };
+
@SmallTest
public void testDecode() throws Exception {
+ decodeSingle(0); // default table
+ decodeSingle(1); // Turkish locking shift table
+ decodeSingle(3); // Portuguese locking shift table
+ }
+
+ private void decodeSingle(int language) throws Exception {
byte[] septets = new byte[(7 * 128 + 7) / 8];
int bitOffset = 0;
@@ -236,15 +264,168 @@ public class GsmSmsTest extends AndroidTestCase {
bitOffset += 7;
}
- String decoded = GsmAlphabet.gsm7BitPackedToString(septets, 0, 128);
- byte[] reEncoded = GsmAlphabet.stringToGsm7BitPacked(decoded);
+ String decoded = GsmAlphabet.gsm7BitPackedToString(septets, 0, 128, 0, language, 0);
+ byte[] reEncoded = GsmAlphabet.stringToGsm7BitPacked(decoded, language, 0);
+
+ assertEquals(sBasicTables[language], decoded);
// reEncoded has the count septets byte at the front
- assertEquals(reEncoded.length, septets.length + 1);
+ assertEquals(septets.length + 1, reEncoded.length);
for (int i = 0; i < septets.length; i++) {
- assertEquals(reEncoded[i + 1], septets[i]);
+ assertEquals(septets[i], reEncoded[i + 1]);
}
}
+ private static final int GSM_ESCAPE_CHARACTER = 0x1b;
+
+ private static final String[] sExtendedTables = {
+ // GSM 7 bit default alphabet extension table
+ "\f^{}\\[~]|\u20ac",
+
+ // Turkish single shift extension table
+ "\f^{}\\[~]|\u011e\u0130\u015e\u00e7\u20ac\u011f\u0131\u015f",
+
+ // Spanish single shift extension table
+ "\u00e7\f^{}\\[~]|\u00c1\u00cd\u00d3\u00da\u00e1\u20ac\u00ed\u00f3\u00fa",
+
+ // Portuguese single shift extension table
+ "\u00ea\u00e7\f\u00d4\u00f4\u00c1\u00e1\u03a6\u0393^\u03a9\u03a0\u03a8\u03a3\u0398\u00ca"
+ + "{}\\[~]|\u00c0\u00cd\u00d3\u00da\u00c3\u00d5\u00c2\u20ac\u00ed\u00f3\u00fa\u00e3"
+ + "\u00f5\u00e2"
+ };
+
+ private static final int[][] sExtendedTableIndexes = {
+ {0x0a, 0x14, 0x28, 0x29, 0x2f, 0x3c, 0x3d, 0x3e, 0x40, 0x65},
+ {0x0a, 0x14, 0x28, 0x29, 0x2f, 0x3c, 0x3d, 0x3e, 0x40, 0x47, 0x49, 0x53, 0x63,
+ 0x65, 0x67, 0x69, 0x73},
+ {0x09, 0x0a, 0x14, 0x28, 0x29, 0x2f, 0x3c, 0x3d, 0x3e, 0x40, 0x41, 0x49, 0x4f,
+ 0x55, 0x61, 0x65, 0x69, 0x6f, 0x75},
+ {0x05, 0x09, 0x0a, 0x0b, 0x0c, 0x0e, 0x0f, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+ 0x18, 0x19, 0x1f, 0x28, 0x29, 0x2f, 0x3c, 0x3d, 0x3e, 0x40, 0x41, 0x49,
+ 0x4f, 0x55, 0x5b, 0x5c, 0x61, 0x65, 0x69, 0x6f, 0x75, 0x7b, 0x7c, 0x7f}
+ };
+
+ @SmallTest
+ public void testDecodeExtended() throws Exception {
+ for (int language = 0; language < 3; language++) {
+ int[] tableIndex = sExtendedTableIndexes[language];
+ int numSeptets = tableIndex.length * 2; // two septets per extended char
+ byte[] septets = new byte[(7 * numSeptets + 7) / 8];
+
+ int bitOffset = 0;
+
+ for (int v : tableIndex) {
+ // escape character
+ int byteOffset = bitOffset / 8;
+ int shift = bitOffset % 8;
+
+ septets[byteOffset] |= GSM_ESCAPE_CHARACTER << shift;
+
+ if (shift > 1) {
+ septets[byteOffset + 1] = (byte) (GSM_ESCAPE_CHARACTER >> (8 - shift));
+ }
+
+ bitOffset += 7;
+
+ // extended table index
+ byteOffset = bitOffset / 8;
+ shift = bitOffset % 8;
+
+ septets[byteOffset] |= v << shift;
+
+ if (shift > 1) {
+ septets[byteOffset + 1] = (byte) (v >> (8 - shift));
+ }
+
+ bitOffset += 7;
+ }
+
+ String decoded = GsmAlphabet.gsm7BitPackedToString(septets, 0, numSeptets, 0,
+ 0, language);
+ byte[] reEncoded = GsmAlphabet.stringToGsm7BitPacked(decoded, 0, language);
+
+ assertEquals(sExtendedTables[language], decoded);
+
+ // reEncoded has the count septets byte at the front
+ assertEquals(septets.length + 1, reEncoded.length);
+
+ for (int i = 0; i < septets.length; i++) {
+ assertEquals(septets[i], reEncoded[i + 1]);
+ }
+ }
+ }
+
+ @SmallTest
+ public void testDecodeExtendedFallback() throws Exception {
+ // verify that unmapped characters in extension table fall back to locking shift table
+ for (int language = 0; language < 3; language++) {
+ int[] tableIndex = sExtendedTableIndexes[language];
+ int numChars = 128 - tableIndex.length;
+ int numSeptets = numChars * 2; // two septets per extended char
+ byte[] septets = new byte[(7 * numSeptets + 7) / 8];
+
+ int tableOffset = 0;
+ int bitOffset = 0;
+
+ StringBuilder defaultTable = new StringBuilder(128);
+ StringBuilder turkishTable = new StringBuilder(128);
+ StringBuilder portugueseTable = new StringBuilder(128);
+
+ for (char c = 0; c < 128; c++) {
+ // skip characters that are present in the current extension table
+ if (tableOffset < tableIndex.length && tableIndex[tableOffset] == c) {
+ tableOffset++;
+ continue;
+ }
+
+ // escape character
+ int byteOffset = bitOffset / 8;
+ int shift = bitOffset % 8;
+
+ septets[byteOffset] |= GSM_ESCAPE_CHARACTER << shift;
+
+ if (shift > 1) {
+ septets[byteOffset + 1] = (byte) (GSM_ESCAPE_CHARACTER >> (8 - shift));
+ }
+
+ bitOffset += 7;
+
+ // extended table index
+ byteOffset = bitOffset / 8;
+ shift = bitOffset % 8;
+
+ septets[byteOffset] |= c << shift;
+
+ if (shift > 1) {
+ septets[byteOffset + 1] = (byte) (c >> (8 - shift));
+ }
+
+ bitOffset += 7;
+
+ if (c == GsmAlphabet.GSM_EXTENDED_ESCAPE) {
+ // double Escape maps to space character
+ defaultTable.append(' ');
+ turkishTable.append(' ');
+ portugueseTable.append(' ');
+ } else {
+ // other unmapped chars map to the default or locking shift table
+ defaultTable.append(sBasicTables[0].charAt(c));
+ turkishTable.append(sBasicTables[1].charAt(c));
+ portugueseTable.append(sBasicTables[3].charAt(c));
+ }
+ }
+
+ String decoded = GsmAlphabet.gsm7BitPackedToString(septets, 0, numSeptets, 0,
+ 0, language);
+
+ assertEquals(defaultTable.toString(), decoded);
+
+ decoded = GsmAlphabet.gsm7BitPackedToString(septets, 0, numSeptets, 0, 1, language);
+ assertEquals(turkishTable.toString(), decoded);
+
+ decoded = GsmAlphabet.gsm7BitPackedToString(septets, 0, numSeptets, 0, 3, language);
+ assertEquals(portugueseTable.toString(), decoded);
+ }
+ }
}
diff --git a/telephony/tests/telephonytests/src/com/android/internal/telephony/IntRangeManagerTest.java b/telephony/tests/telephonytests/src/com/android/internal/telephony/IntRangeManagerTest.java
new file mode 100644
index 0000000..79dca39
--- /dev/null
+++ b/telephony/tests/telephonytests/src/com/android/internal/telephony/IntRangeManagerTest.java
@@ -0,0 +1,374 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.telephony;
+
+import android.test.AndroidTestCase;
+
+import com.android.internal.telephony.gsm.SmsBroadcastConfigInfo;
+
+import java.util.ArrayList;
+
+/**
+ * Test cases for the IntRangeManager class.
+ */
+public class IntRangeManagerTest extends AndroidTestCase {
+
+ private static final int SMS_CB_CODE_SCHEME_MIN = 0;
+ private static final int SMS_CB_CODE_SCHEME_MAX = 255;
+
+ private static final int FLAG_START_UPDATE_CALLED = 0x01;
+ private static final int FLAG_ADD_RANGE_CALLED = 0x02;
+ private static final int FLAG_FINISH_UPDATE_CALLED = 0x04;
+
+ private static final int ALL_FLAGS_SET = FLAG_START_UPDATE_CALLED | FLAG_ADD_RANGE_CALLED |
+ FLAG_FINISH_UPDATE_CALLED;
+
+ /** Dummy IntRangeManager for testing. */
+ class TestIntRangeManager extends IntRangeManager {
+ ArrayList<SmsBroadcastConfigInfo> mConfigList =
+ new ArrayList<SmsBroadcastConfigInfo>();
+
+ int flags;
+ boolean finishUpdateReturnValue = true;
+
+ /**
+ * Called when the list of enabled ranges has changed. This will be
+ * followed by zero or more calls to {@link #addRange} followed by
+ * a call to {@link #finishUpdate}.
+ */
+ protected void startUpdate() {
+ mConfigList.clear();
+ flags |= FLAG_START_UPDATE_CALLED;
+ }
+
+ /**
+ * Called after {@link #startUpdate} to indicate a range of enabled
+ * values.
+ * @param startId the first id included in the range
+ * @param endId the last id included in the range
+ */
+ protected void addRange(int startId, int endId, boolean selected) {
+ mConfigList.add(new SmsBroadcastConfigInfo(startId, endId,
+ SMS_CB_CODE_SCHEME_MIN, SMS_CB_CODE_SCHEME_MAX, selected));
+ flags |= FLAG_ADD_RANGE_CALLED;
+ }
+
+ /**
+ * Called to indicate the end of a range update started by the
+ * previous call to {@link #startUpdate}.
+ */
+ protected boolean finishUpdate() {
+ flags |= FLAG_FINISH_UPDATE_CALLED;
+ return finishUpdateReturnValue;
+ }
+
+ /** Reset the object for the next test case. */
+ void reset() {
+ flags = 0;
+ mConfigList.clear();
+ }
+ }
+
+ public void testEmptyRangeManager() {
+ TestIntRangeManager testManager = new TestIntRangeManager();
+ assertEquals("expecting empty configlist", 0, testManager.mConfigList.size());
+ }
+
+ private void checkConfigInfo(SmsBroadcastConfigInfo info, int fromServiceId,
+ int toServiceId, int fromCodeScheme, int toCodeScheme, boolean selected) {
+ assertEquals("fromServiceId", fromServiceId, info.getFromServiceId());
+ assertEquals("toServiceId", toServiceId, info.getToServiceId());
+ assertEquals("fromCodeScheme", fromCodeScheme, info.getFromCodeScheme());
+ assertEquals("toCodeScheme", toCodeScheme, info.getToCodeScheme());
+ assertEquals("selected", selected, info.isSelected());
+ }
+
+ public void testAddSingleChannel() {
+ TestIntRangeManager testManager = new TestIntRangeManager();
+ assertEquals("flags before test", 0, testManager.flags);
+ assertTrue("enabling range", testManager.enableRange(123, 123, "client1"));
+ assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+ assertEquals("configlist size", 1, testManager.mConfigList.size());
+ checkConfigInfo(testManager.mConfigList.get(0), 123, 123, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, true);
+ testManager.reset();
+ assertTrue("updating ranges", testManager.updateRanges());
+ assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+ assertEquals("configlist size", 1, testManager.mConfigList.size());
+ checkConfigInfo(testManager.mConfigList.get(0), 123, 123, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, true);
+ }
+
+ public void testRemoveSingleChannel() {
+ TestIntRangeManager testManager = new TestIntRangeManager();
+ assertTrue("enabling range", testManager.enableRange(123, 123, "client1"));
+ assertEquals("flags after enable", ALL_FLAGS_SET, testManager.flags);
+ assertEquals("configlist size", 1, testManager.mConfigList.size());
+ testManager.reset();
+ assertTrue("disabling range", testManager.disableRange(123, 123, "client1"));
+ assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+ assertEquals("configlist size", 1, testManager.mConfigList.size());
+ checkConfigInfo(testManager.mConfigList.get(0), 123, 123, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, false);
+ testManager.reset();
+ assertTrue("updating ranges", testManager.updateRanges());
+ assertEquals("flags after test", FLAG_START_UPDATE_CALLED | FLAG_FINISH_UPDATE_CALLED,
+ testManager.flags);
+ assertEquals("configlist size", 0, testManager.mConfigList.size());
+ }
+
+ public void testRemoveBadChannel() {
+ TestIntRangeManager testManager = new TestIntRangeManager();
+ assertFalse("disabling missing range", testManager.disableRange(123, 123, "client1"));
+ assertEquals("flags after test", 0, testManager.flags);
+ assertEquals("configlist size", 0, testManager.mConfigList.size());
+ }
+
+ public void testAddTwoChannels() {
+ TestIntRangeManager testManager = new TestIntRangeManager();
+ assertEquals("flags before test", 0, testManager.flags);
+ assertTrue("enabling range 1", testManager.enableRange(100, 120, "client1"));
+ assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+ assertEquals("configlist size", 1, testManager.mConfigList.size());
+ checkConfigInfo(testManager.mConfigList.get(0), 100, 120, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, true);
+ testManager.reset();
+ assertTrue("enabling range 2", testManager.enableRange(200, 250, "client2"));
+ assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+ assertEquals("configlist size", 1, testManager.mConfigList.size());
+ checkConfigInfo(testManager.mConfigList.get(0), 200, 250, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, true);
+ testManager.reset();
+ assertTrue("updating ranges", testManager.updateRanges());
+ assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+ assertEquals("configlist size", 2, testManager.mConfigList.size());
+ checkConfigInfo(testManager.mConfigList.get(0), 100, 120, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, true);
+ checkConfigInfo(testManager.mConfigList.get(1), 200, 250, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, true);
+ }
+
+ public void testOverlappingChannels() {
+ TestIntRangeManager testManager = new TestIntRangeManager();
+ assertEquals("flags before test", 0, testManager.flags);
+ assertTrue("enabling range 1", testManager.enableRange(100, 200, "client1"));
+ assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+ assertEquals("configlist size", 1, testManager.mConfigList.size());
+ checkConfigInfo(testManager.mConfigList.get(0), 100, 200, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, true);
+ testManager.reset();
+ assertTrue("enabling range 2", testManager.enableRange(150, 250, "client2"));
+ assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+ assertEquals("configlist size", 1, testManager.mConfigList.size());
+ checkConfigInfo(testManager.mConfigList.get(0), 201, 250, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, true);
+ testManager.reset();
+ assertTrue("updating ranges", testManager.updateRanges());
+ assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+ assertEquals("configlist size", 1, testManager.mConfigList.size());
+ checkConfigInfo(testManager.mConfigList.get(0), 100, 250, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, true);
+ testManager.reset();
+ assertTrue("disabling range 1", testManager.disableRange(100, 200, "client1"));
+ assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+ assertEquals("configlist size", 1, testManager.mConfigList.size());
+ checkConfigInfo(testManager.mConfigList.get(0), 100, 149, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, false);
+ testManager.reset();
+ assertTrue("disabling range 2", testManager.disableRange(150, 250, "client2"));
+ assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+ assertEquals("configlist size", 1, testManager.mConfigList.size());
+ checkConfigInfo(testManager.mConfigList.get(0), 150, 250, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, false);
+ testManager.reset();
+ assertTrue("updating ranges", testManager.updateRanges());
+ assertEquals("flags after test", FLAG_START_UPDATE_CALLED | FLAG_FINISH_UPDATE_CALLED,
+ testManager.flags);
+ assertEquals("configlist size", 0, testManager.mConfigList.size());
+ }
+
+ public void testOverlappingChannels2() {
+ TestIntRangeManager testManager = new TestIntRangeManager();
+ assertEquals("flags before test", 0, testManager.flags);
+ assertTrue("enabling range 1", testManager.enableRange(100, 200, "client1"));
+ assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+ assertEquals("configlist size", 1, testManager.mConfigList.size());
+ checkConfigInfo(testManager.mConfigList.get(0), 100, 200, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, true);
+ testManager.reset();
+ assertTrue("enabling range 2", testManager.enableRange(150, 250, "client2"));
+ assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+ assertEquals("configlist size", 1, testManager.mConfigList.size());
+ checkConfigInfo(testManager.mConfigList.get(0), 201, 250, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, true);
+ testManager.reset();
+ assertTrue("disabling range 2", testManager.disableRange(150, 250, "client2"));
+ assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+ assertEquals("configlist size", 1, testManager.mConfigList.size());
+ checkConfigInfo(testManager.mConfigList.get(0), 201, 250, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, false);
+ testManager.reset();
+ assertTrue("updating ranges", testManager.updateRanges());
+ assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+ assertEquals("configlist size", 1, testManager.mConfigList.size());
+ checkConfigInfo(testManager.mConfigList.get(0), 100, 200, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, true);
+ testManager.reset();
+ assertTrue("disabling range 1", testManager.disableRange(100, 200, "client1"));
+ assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+ assertEquals("configlist size", 1, testManager.mConfigList.size());
+ checkConfigInfo(testManager.mConfigList.get(0), 100, 200, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, false);
+ }
+
+ public void testMultipleOverlappingChannels() {
+ TestIntRangeManager testManager = new TestIntRangeManager();
+ assertEquals("flags before test", 0, testManager.flags);
+ assertTrue("enabling range 1", testManager.enableRange(67, 9999, "client1"));
+ assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+ assertEquals("configlist size", 1, testManager.mConfigList.size());
+ checkConfigInfo(testManager.mConfigList.get(0), 67, 9999, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, true);
+ testManager.reset();
+ assertTrue("enabling range 2", testManager.enableRange(150, 250, "client2"));
+ assertEquals("flags after test", 0, testManager.flags);
+ assertEquals("configlist size", 0, testManager.mConfigList.size());
+ testManager.reset();
+ assertTrue("enabling range 3", testManager.enableRange(25, 75, "client3"));
+ assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+ assertEquals("configlist size", 1, testManager.mConfigList.size());
+ checkConfigInfo(testManager.mConfigList.get(0), 25, 66, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, true);
+ testManager.reset();
+ assertTrue("enabling range 4", testManager.enableRange(12, 500, "client4"));
+ assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+ assertEquals("configlist size", 1, testManager.mConfigList.size());
+ checkConfigInfo(testManager.mConfigList.get(0), 12, 24, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, true);
+ testManager.reset();
+ assertTrue("enabling range 5", testManager.enableRange(8000, 9998, "client5"));
+ assertEquals("flags after test", 0, testManager.flags);
+ assertEquals("configlist size", 0, testManager.mConfigList.size());
+ testManager.reset();
+ assertTrue("enabling range 6", testManager.enableRange(50000, 65535, "client6"));
+ assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+ assertEquals("configlist size", 1, testManager.mConfigList.size());
+ checkConfigInfo(testManager.mConfigList.get(0), 50000, 65535, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, true);
+ testManager.reset();
+ assertTrue("updating ranges", testManager.updateRanges());
+ assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+ assertEquals("configlist size", 2, testManager.mConfigList.size());
+ checkConfigInfo(testManager.mConfigList.get(0), 12, 9999, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, true);
+ checkConfigInfo(testManager.mConfigList.get(1), 50000, 65535, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, true);
+ testManager.reset();
+ assertTrue("disabling range 1", testManager.disableRange(67, 9999, "client1"));
+ assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+ assertEquals("configlist size", 2, testManager.mConfigList.size());
+ checkConfigInfo(testManager.mConfigList.get(0), 501, 7999, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, false);
+ checkConfigInfo(testManager.mConfigList.get(1), 9999, 9999, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, false);
+ testManager.reset();
+ assertTrue("updating ranges", testManager.updateRanges());
+ assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+ assertEquals("configlist size", 3, testManager.mConfigList.size());
+ checkConfigInfo(testManager.mConfigList.get(0), 12, 500, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, true);
+ checkConfigInfo(testManager.mConfigList.get(1), 8000, 9998, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, true);
+ checkConfigInfo(testManager.mConfigList.get(2), 50000, 65535, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, true);
+ testManager.reset();
+ assertTrue("disabling range 4", testManager.disableRange(12, 500, "client4"));
+ assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+ assertEquals("configlist size", 3, testManager.mConfigList.size());
+ checkConfigInfo(testManager.mConfigList.get(0), 12, 24, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, false);
+ checkConfigInfo(testManager.mConfigList.get(1), 76, 149, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, false);
+ checkConfigInfo(testManager.mConfigList.get(2), 251, 500, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, false);
+ testManager.reset();
+ assertTrue("updating ranges", testManager.updateRanges());
+ assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+ assertEquals("configlist size", 4, testManager.mConfigList.size());
+ checkConfigInfo(testManager.mConfigList.get(0), 25, 75, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, true);
+ checkConfigInfo(testManager.mConfigList.get(1), 150, 250, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, true);
+ checkConfigInfo(testManager.mConfigList.get(2), 8000, 9998, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, true);
+ checkConfigInfo(testManager.mConfigList.get(3), 50000, 65535, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, true);
+ testManager.reset();
+ assertTrue("disabling range 5", testManager.disableRange(8000, 9998, "client5"));
+ assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+ assertEquals("configlist size", 1, testManager.mConfigList.size());
+ checkConfigInfo(testManager.mConfigList.get(0), 8000, 9998, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, false);
+ testManager.reset();
+ assertTrue("updating ranges", testManager.updateRanges());
+ assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+ assertEquals("configlist size", 3, testManager.mConfigList.size());
+ checkConfigInfo(testManager.mConfigList.get(0), 25, 75, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, true);
+ checkConfigInfo(testManager.mConfigList.get(1), 150, 250, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, true);
+ checkConfigInfo(testManager.mConfigList.get(2), 50000, 65535, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, true);
+ testManager.reset();
+ assertTrue("disabling range 6", testManager.disableRange(50000, 65535, "client6"));
+ assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+ assertEquals("configlist size", 1, testManager.mConfigList.size());
+ checkConfigInfo(testManager.mConfigList.get(0), 50000, 65535, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, false);
+ testManager.reset();
+ assertTrue("updating ranges", testManager.updateRanges());
+ assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+ assertEquals("configlist size", 2, testManager.mConfigList.size());
+ checkConfigInfo(testManager.mConfigList.get(0), 25, 75, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, true);
+ checkConfigInfo(testManager.mConfigList.get(1), 150, 250, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, true);
+ testManager.reset();
+ assertTrue("disabling range 2", testManager.disableRange(150, 250, "client2"));
+ assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+ assertEquals("configlist size", 1, testManager.mConfigList.size());
+ checkConfigInfo(testManager.mConfigList.get(0), 150, 250, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, false);
+ testManager.reset();
+ assertTrue("updating ranges", testManager.updateRanges());
+ assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+ assertEquals("configlist size", 1, testManager.mConfigList.size());
+ checkConfigInfo(testManager.mConfigList.get(0), 25, 75, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, true);
+ testManager.reset();
+ assertTrue("disabling range 3", testManager.disableRange(25, 75, "client3"));
+ assertEquals("flags after test", ALL_FLAGS_SET, testManager.flags);
+ assertEquals("configlist size", 1, testManager.mConfigList.size());
+ checkConfigInfo(testManager.mConfigList.get(0), 25, 75, SMS_CB_CODE_SCHEME_MIN,
+ SMS_CB_CODE_SCHEME_MAX, false);
+ testManager.reset();
+ assertTrue("updating ranges", testManager.updateRanges());
+ assertEquals("flags after test", FLAG_START_UPDATE_CALLED | FLAG_FINISH_UPDATE_CALLED,
+ testManager.flags);
+ assertEquals("configlist size", 0, testManager.mConfigList.size());
+ }
+}
diff --git a/telephony/tests/telephonytests/src/com/android/internal/telephony/PhoneNumberUtilsTest.java b/telephony/tests/telephonytests/src/com/android/internal/telephony/PhoneNumberUtilsTest.java
index c4a6f53..6e9d0f9d 100644
--- a/telephony/tests/telephonytests/src/com/android/internal/telephony/PhoneNumberUtilsTest.java
+++ b/telephony/tests/telephonytests/src/com/android/internal/telephony/PhoneNumberUtilsTest.java
@@ -502,16 +502,17 @@ public class PhoneNumberUtilsTest extends AndroidTestCase {
@SmallTest
public void testFormatNumberToE164() {
- assertEquals("+16502910000", PhoneNumberUtils.formatNumberToE164("650 2910000", "us"));
- assertNull(PhoneNumberUtils.formatNumberToE164("1234567", "us"));
- assertEquals("+18004664114", PhoneNumberUtils.formatNumberToE164("800-GOOG-114", "us"));
+ // Note: ISO 3166-1 only allows upper case country codes.
+ assertEquals("+16502910000", PhoneNumberUtils.formatNumberToE164("650 2910000", "US"));
+ assertNull(PhoneNumberUtils.formatNumberToE164("1234567", "US"));
+ assertEquals("+18004664114", PhoneNumberUtils.formatNumberToE164("800-GOOG-114", "US"));
}
@SmallTest
public void testFormatNumber() {
- assertEquals("(650) 291-0000", PhoneNumberUtils.formatNumber("650 2910000", "us"));
- assertEquals("123-4567", PhoneNumberUtils.formatNumber("1234567", "us"));
- assertEquals("(800) 466-4114", PhoneNumberUtils.formatNumber("800-GOOG-114", "us"));
+ assertEquals("(650) 291-0000", PhoneNumberUtils.formatNumber("650 2910000", "US"));
+ assertEquals("123-4567", PhoneNumberUtils.formatNumber("1234567", "US"));
+ assertEquals("(800) 466-4114", PhoneNumberUtils.formatNumber("800-GOOG-114", "US"));
}
diff --git a/telephony/tests/telephonytests/src/com/android/internal/telephony/SmsMessageBodyTest.java b/telephony/tests/telephonytests/src/com/android/internal/telephony/SmsMessageBodyTest.java
index b214887..170bd9b 100644
--- a/telephony/tests/telephonytests/src/com/android/internal/telephony/SmsMessageBodyTest.java
+++ b/telephony/tests/telephonytests/src/com/android/internal/telephony/SmsMessageBodyTest.java
@@ -19,21 +19,57 @@ package com.android.internal.telephony;
import android.telephony.SmsMessage;
import android.telephony.TelephonyManager;
import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.LargeTest;
+import android.test.suitebuilder.annotation.MediumTest;
import android.test.suitebuilder.annotation.SmallTest;
+import android.util.Log;
+import java.util.Random;
+
+import static android.telephony.SmsMessage.MAX_USER_DATA_BYTES;
+import static android.telephony.SmsMessage.MAX_USER_DATA_BYTES_WITH_HEADER;
import static android.telephony.SmsMessage.MAX_USER_DATA_SEPTETS;
+import static android.telephony.SmsMessage.MAX_USER_DATA_SEPTETS_WITH_HEADER;
+/**
+ * Test cases to verify selection of the optimal 7 bit encoding tables
+ * (for all combinations of enabled national language tables) for messages
+ * containing Turkish, Spanish, Portuguese, Greek, and other symbols
+ * present in the GSM default and national language tables defined in
+ * 3GPP TS 23.038. Also verifies correct SMS encoding for CDMA, which only
+ * supports the GSM 7 bit default alphabet, ASCII 8 bit, and UCS-2.
+ * Tests both encoding variations: unsupported characters mapped to space,
+ * and unsupported characters force entire message to UCS-2.
+ */
public class SmsMessageBodyTest extends AndroidTestCase {
+ private static final String TAG = "SmsMessageBodyTest";
+ // ASCII chars in the GSM 7 bit default alphabet
private static final String sAsciiChars = "@$_ !\"#%&'()*+,-./0123456789" +
":;<=>?ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\n\r";
- private static final String sGsmBasicChars = "\u00a3\u00a5\u00e8\u00e9" +
- "\u00f9\u00ec\u00f2\u00c7\u00d8\u00f8\u00c5\u00e5\u0394\u03a6" +
- "\u0393\u039b\u03a9\u03a0\u03a8\u03a3\u0398\u00c6\u00e6" +
- "\u00df\u00c9\u00a4\u00a1\u00c4\u00d6\u00d1\u00dc\u00a7\u00bf" +
- "\u00e4\u00f6\u00f1\u00fc\u00e0";
- private static final String sGsmExtendedAsciiChars = "{|}\\[~]^\f";
+
+ // Unicode chars in the GSM 7 bit default alphabet and both locking shift tables
+ private static final String sGsmDefaultChars = "\u00a3\u00a5\u00e9\u00c7\u0394\u00c9" +
+ "\u00dc\u00a7\u00fc\u00e0";
+
+ // Unicode chars in the GSM 7 bit default table and Turkish locking shift tables
+ private static final String sGsmDefaultAndTurkishTables = "\u00f9\u00f2\u00c5\u00e5\u00df" +
+ "\u00a4\u00c4\u00d6\u00d1\u00e4\u00f6\u00f1";
+
+ // Unicode chars in the GSM 7 bit default table but not the locking shift tables
+ private static final String sGsmDefaultTableOnly = "\u00e8\u00ec\u00d8\u00f8\u00c6\u00e6" +
+ "\u00a1\u00bf";
+
+ // ASCII chars in the GSM default extension table
+ private static final String sGsmExtendedAsciiChars = "{}[]\f";
+
+ // chars in GSM default extension table and Portuguese locking shift table
+ private static final String sGsmExtendedPortugueseLocking = "^\\|~";
+
+ // Euro currency symbol
private static final String sGsmExtendedEuroSymbol = "\u20ac";
+
+ // CJK ideographs, Hiragana, Katakana, full width letters, Cyrillic, etc.
private static final String sUnicodeChars = "\u4e00\u4e01\u4e02\u4e03" +
"\u4e04\u4e05\u4e06\u4e07\u4e08\u4e09\u4e0a\u4e0b\u4e0c\u4e0d" +
"\u4e0e\u4e0f\u3041\u3042\u3043\u3044\u3045\u3046\u3047\u3048" +
@@ -43,6 +79,86 @@ public class SmsMessageBodyTest extends AndroidTestCase {
"\u0400\u0401\u0402\u0403\u0404\u0405\u0406\u0407\u0408" +
"\u00a2\u00a9\u00ae\u2122";
+ // chars in Turkish single shift and locking shift tables
+ private static final String sTurkishChars = "\u0131\u011e\u011f\u015e\u015f\u0130";
+
+ // chars in Spanish single shift table and Portuguese single and locking shift tables
+ private static final String sPortugueseAndSpanishChars = "\u00c1\u00e1\u00cd\u00ed"
+ + "\u00d3\u00f3\u00da\u00fa";
+
+ // chars in all national language tables but not in the standard GSM alphabets
+ private static final String sNationalLanguageTablesOnly = "\u00e7";
+
+ // chars in Portuguese single shift and locking shift tables
+ private static final String sPortugueseChars = "\u00ea\u00d4\u00f4\u00c0\u00c2\u00e2"
+ + "\u00ca\u00c3\u00d5\u00e3\u00f5";
+
+ // chars in Portuguese locking shift table only
+ private static final String sPortugueseLockingShiftChars = "\u00aa\u221e\u00ba`";
+
+ // Greek letters in GSM alphabet missing from Portuguese locking and single shift tables
+ private static final String sGreekLettersNotInPortugueseTables = "\u039b\u039e";
+
+ // Greek letters in GSM alphabet and Portuguese single shift (but not locking shift) table
+ private static final String sGreekLettersInPortugueseShiftTable =
+ "\u03a6\u0393\u03a9\u03a0\u03a8\u03a3\u0398";
+
+ // List of classes of characters in SMS tables
+ private static final String[] sCharacterClasses = {
+ sGsmExtendedAsciiChars,
+ sGsmExtendedPortugueseLocking,
+ sGsmDefaultChars,
+ sGsmDefaultAndTurkishTables,
+ sGsmDefaultTableOnly,
+ sGsmExtendedEuroSymbol,
+ sUnicodeChars,
+ sTurkishChars,
+ sPortugueseChars,
+ sPortugueseLockingShiftChars,
+ sPortugueseAndSpanishChars,
+ sGreekLettersNotInPortugueseTables,
+ sGreekLettersInPortugueseShiftTable,
+ sNationalLanguageTablesOnly,
+ sAsciiChars
+ };
+
+ private static final int sNumCharacterClasses = sCharacterClasses.length;
+
+ // For each character class, whether it is present in a particular char table.
+ // First three entries are locking shift tables, followed by four single shift tables
+ private static final boolean[][] sCharClassPresenceInTables = {
+ // ASCII chars in all GSM extension tables
+ {false, false, false, true, true, true, true},
+ // ASCII chars in all GSM extension tables and Portuguese locking shift table
+ {false, false, true, true, true, true, true},
+ // non-ASCII chars in GSM default alphabet and all locking tables
+ {true, true, true, false, false, false, false},
+ // non-ASCII chars in GSM default alphabet and Turkish locking shift table
+ {true, true, false, false, false, false, false},
+ // non-ASCII chars in GSM default alphabet table only
+ {true, false, false, false, false, false, false},
+ // Euro symbol is present in several tables
+ {false, true, true, true, true, true, true},
+ // Unicode characters not present in any 7 bit tables
+ {false, false, false, false, false, false, false},
+ // Characters specific to Turkish language
+ {false, true, false, false, true, false, false},
+ // Characters in Portuguese single shift and locking shift tables
+ {false, false, true, false, false, false, true},
+ // Characters in Portuguese locking shift table only
+ {false, false, true, false, false, false, false},
+ // Chars in Spanish single shift and Portuguese single and locking shift tables
+ {false, false, true, false, false, true, true},
+ // Greek letters in GSM default alphabet missing from Portuguese tables
+ {true, true, false, false, false, false, false},
+ // Greek letters in GSM alphabet and Portuguese single shift table
+ {true, true, false, false, false, false, true},
+ // Chars in all national language tables but not the standard GSM tables
+ {false, true, true, false, true, true, true},
+ // ASCII chars in GSM default alphabet
+ {true, true, true, false, false, false, false}
+ };
+
private static final int sTestLengthCount = 12;
private static final int[] sSeptetTestLengths =
@@ -60,11 +176,92 @@ public class SmsMessageBodyTest extends AndroidTestCase {
private static final int[] sUnicodeUnitsRemaining =
{ 70, 69, 68, 35, 1, 0, 63, 34, 1, 0, 66, 41};
+ // Combinations of enabled GSM national language single shift tables
+ private static final int[][] sEnabledSingleShiftTables = {
+ {}, // GSM default alphabet only
+ {1}, // Turkish (single shift only)
+ {1}, // Turkish (single and locking shift)
+ {2}, // Spanish
+ {3}, // Portuguese (single shift only)
+ {3}, // Portuguese (single and locking shift)
+ {1, 2}, // Turkish + Spanish (single shift only)
+ {1, 2}, // Turkish + Spanish (single and locking shift)
+ {1, 3}, // Turkish + Portuguese (single shift only)
+ {1, 3}, // Turkish + Portuguese (single and locking shift)
+ {2, 3}, // Spanish + Portuguese (single shift only)
+ {2, 3}, // Spanish + Portuguese (single and locking shift)
+ {1, 2, 3}, // Turkish, Spanish, Portuguese (single shift only)
+ {1, 2, 3}, // Turkish, Spanish, Portuguese (single and locking shift)
+ {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13} // all language tables
+ };
+
+ // Combinations of enabled GSM national language locking shift tables
+ private static final int[][] sEnabledLockingShiftTables = {
+ {}, // GSM default alphabet only
+ {}, // Turkish (single shift only)
+ {1}, // Turkish (single and locking shift)
+ {}, // Spanish (no locking shift table)
+ {}, // Portuguese (single shift only)
+ {3}, // Portuguese (single and locking shift)
+ {}, // Turkish + Spanish (single shift only)
+ {1}, // Turkish + Spanish (single and locking shift)
+ {}, // Turkish + Portuguese (single shift only)
+ {1, 3}, // Turkish + Portuguese (single and locking shift)
+ {}, // Spanish + Portuguese (single shift only)
+ {3}, // Spanish + Portuguese (single and locking shift)
+ {}, // Turkish, Spanish, Portuguese (single shift only)
+ {1, 3}, // Turkish, Spanish, Portuguese (single and locking shift)
+ {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13} // all language tables
+ };
+
+ // LanguagePair counter indexes to check for each entry above
+ private static final int[][] sLanguagePairIndexesByEnabledIndex = {
+ {0}, // default tables only
+ {0, 1}, // Turkish (single shift only)
+ {0, 1, 4, 5}, // Turkish (single and locking shift)
+ {0, 2}, // Spanish
+ {0, 3}, // Portuguese (single shift only)
+ {0, 3, 8, 11}, // Portuguese (single and locking shift)
+ {0, 1, 2}, // Turkish + Spanish (single shift only)
+ {0, 1, 2, 4, 5, 6}, // Turkish + Spanish (single and locking shift)
+ {0, 1, 3}, // Turkish + Portuguese (single shift only)
+ {0, 1, 3, 4, 5, 7, 8, 9, 11}, // Turkish + Portuguese (single and locking shift)
+ {0, 2, 3}, // Spanish + Portuguese (single shift only)
+ {0, 2, 3, 8, 10, 11}, // Spanish + Portuguese (single and locking shift)
+ {0, 1, 2, 3}, // all languages (single shift only)
+ {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, // all languages (single and locking shift)
+ {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11} // all languages (no Indic chars in test)
+ };
+
+ /**
+ * User data header requires one octet for length. Count as one septet, because
+ * all combinations of header elements below will have at least one free bit
+ * when padding to the nearest septet boundary.
+ */
+ private static final int UDH_SEPTET_COST_LENGTH = 1;
+
+ /**
+ * Using a non-default language locking shift table OR single shift table
+ * requires a user data header of 3 octets, or 4 septets, plus UDH length.
+ */
+ private static final int UDH_SEPTET_COST_ONE_SHIFT_TABLE = 4;
+
+ /**
+ * Using a non-default language locking shift table AND single shift table
+ * requires a user data header of 6 octets, or 7 septets, plus UDH length.
+ */
+ private static final int UDH_SEPTET_COST_TWO_SHIFT_TABLES = 7;
+
+ /**
+ * Multi-part messages require a user data header of 5 octets, or 6 septets,
+ * plus UDH length.
+ */
+ private static final int UDH_SEPTET_COST_CONCATENATED_MESSAGE = 6;
@SmallTest
public void testCalcLengthAscii() throws Exception {
StringBuilder sb = new StringBuilder(320);
- int[] values = {0, 0, 0, SmsMessage.ENCODING_7BIT};
+ int[] values = {0, 0, 0, SmsMessage.ENCODING_7BIT, 0, 0};
int startPos = 0;
int asciiCharsLen = sAsciiChars.length();
@@ -94,20 +291,10 @@ public class SmsMessageBodyTest extends AndroidTestCase {
}
@SmallTest
- public void testCalcLength7bitGsm() throws Exception {
- // TODO
- }
-
- @SmallTest
- public void testCalcLength7bitGsmExtended() throws Exception {
- // TODO
- }
-
- @SmallTest
public void testCalcLengthUnicode() throws Exception {
StringBuilder sb = new StringBuilder(160);
- int[] values = {0, 0, 0, SmsMessage.ENCODING_16BIT};
- int[] values7bit = {1, 0, 0, SmsMessage.ENCODING_7BIT};
+ int[] values = {0, 0, 0, SmsMessage.ENCODING_16BIT, 0, 0};
+ int[] values7bit = {1, 0, 0, SmsMessage.ENCODING_7BIT, 0, 0};
int startPos = 0;
int unicodeCharsLen = sUnicodeChars.length();
@@ -139,6 +326,229 @@ public class SmsMessageBodyTest extends AndroidTestCase {
}
}
+ private static class LanguagePair {
+ // index is 2 for Portuguese locking shift because there is no Spanish locking shift table
+ private final int langTableIndex;
+ private final int langShiftTableIndex;
+ int length;
+ int missingChars7bit;
+
+ LanguagePair(int langTable, int langShiftTable) {
+ langTableIndex = langTable;
+ langShiftTableIndex = langShiftTable;
+ }
+
+ void clear() {
+ length = 0;
+ missingChars7bit = 0;
+ }
+
+ void addChar(boolean[] charClassTableRow) {
+ if (charClassTableRow[langTableIndex]) {
+ length++;
+ } else if (charClassTableRow[3 + langShiftTableIndex]) {
+ length += 2;
+ } else {
+ length++; // use ' ' for unmapped char in 7 bit only mode
+ missingChars7bit++;
+ }
+ }
+ }
+
+ private static class CounterHelper {
+ LanguagePair[] mCounters;
+ int[] mStatsCounters;
+ int mUnicodeCounter;
+
+ CounterHelper() {
+ mCounters = new LanguagePair[12];
+ mStatsCounters = new int[12];
+ for (int i = 0; i < 12; i++) {
+ mCounters[i] = new LanguagePair(i/4, i%4);
+ }
+ }
+
+ void clear() {
+ // Note: don't clear stats counters
+ for (int i = 0; i < 12; i++) {
+ mCounters[i].clear();
+ }
+ }
+
+ void addChar(int charClass) {
+ boolean[] charClassTableRow = sCharClassPresenceInTables[charClass];
+ for (int i = 0; i < 12; i++) {
+ mCounters[i].addChar(charClassTableRow);
+ }
+ }
+
+ void fillData(int enabledLangsIndex, boolean use7bitOnly, int[] values, int length) {
+ int[] languagePairs = sLanguagePairIndexesByEnabledIndex[enabledLangsIndex];
+ int minNumSeptets = Integer.MAX_VALUE;
+ int minNumSeptetsWithHeader = Integer.MAX_VALUE;
+ int minNumMissingChars = Integer.MAX_VALUE;
+ int langIndex = -1;
+ int langShiftIndex = -1;
+ for (int i : languagePairs) {
+ LanguagePair pair = mCounters[i];
+ int udhLength = 0;
+ if (i != 0) {
+ udhLength = UDH_SEPTET_COST_LENGTH;
+ if (i < 4 || i % 4 == 0) {
+ udhLength += UDH_SEPTET_COST_ONE_SHIFT_TABLE;
+ } else {
+ udhLength += UDH_SEPTET_COST_TWO_SHIFT_TABLES;
+ }
+ }
+ int numSeptetsWithHeader;
+ if (pair.length > (MAX_USER_DATA_SEPTETS - udhLength)) {
+ if (udhLength == 0) {
+ udhLength = UDH_SEPTET_COST_LENGTH;
+ }
+ udhLength += UDH_SEPTET_COST_CONCATENATED_MESSAGE;
+ int septetsPerPart = MAX_USER_DATA_SEPTETS - udhLength;
+ int msgCount = (pair.length + septetsPerPart - 1) / septetsPerPart;
+ numSeptetsWithHeader = udhLength * msgCount + pair.length;
+ } else {
+ numSeptetsWithHeader = udhLength + pair.length;
+ }
+
+ if (use7bitOnly) {
+ if (pair.missingChars7bit < minNumMissingChars || (pair.missingChars7bit ==
+ minNumMissingChars && numSeptetsWithHeader < minNumSeptetsWithHeader)) {
+ minNumSeptets = pair.length;
+ minNumSeptetsWithHeader = numSeptetsWithHeader;
+ minNumMissingChars = pair.missingChars7bit;
+ langIndex = pair.langTableIndex;
+ langShiftIndex = pair.langShiftTableIndex;
+ }
+ } else {
+ if (pair.missingChars7bit == 0 && numSeptetsWithHeader < minNumSeptetsWithHeader) {
+ minNumSeptets = pair.length;
+ minNumSeptetsWithHeader = numSeptetsWithHeader;
+ langIndex = pair.langTableIndex;
+ langShiftIndex = pair.langShiftTableIndex;
+ }
+ }
+ }
+ if (langIndex == -1) {
+ // nothing matches, use values for Unicode
+ int byteCount = length * 2;
+ if (byteCount > MAX_USER_DATA_BYTES) {
+ values[0] = (byteCount + MAX_USER_DATA_BYTES_WITH_HEADER - 1) /
+ MAX_USER_DATA_BYTES_WITH_HEADER;
+ values[2] = ((values[0] * MAX_USER_DATA_BYTES_WITH_HEADER) - byteCount) / 2;
+ } else {
+ values[0] = 1;
+ values[2] = (MAX_USER_DATA_BYTES - byteCount) / 2;
+ }
+ values[1] = length;
+ values[3] = SmsMessage.ENCODING_16BIT;
+ values[4] = 0;
+ values[5] = 0;
+ mUnicodeCounter++;
+ } else {
+ int udhLength = 0;
+ if (langIndex != 0 || langShiftIndex != 0) {
+ udhLength = UDH_SEPTET_COST_LENGTH;
+ if (langIndex == 0 || langShiftIndex == 0) {
+ udhLength += UDH_SEPTET_COST_ONE_SHIFT_TABLE;
+ } else {
+ udhLength += UDH_SEPTET_COST_TWO_SHIFT_TABLES;
+ }
+ }
+ int msgCount;
+ if (minNumSeptets > (MAX_USER_DATA_SEPTETS - udhLength)) {
+ if (udhLength == 0) {
+ udhLength = UDH_SEPTET_COST_LENGTH;
+ }
+ udhLength += UDH_SEPTET_COST_CONCATENATED_MESSAGE;
+ int septetsPerPart = MAX_USER_DATA_SEPTETS - udhLength;
+ msgCount = (minNumSeptets + septetsPerPart - 1) / septetsPerPart;
+ } else {
+ msgCount = 1;
+ }
+ values[0] = msgCount;
+ values[1] = minNumSeptets;
+ values[2] = (values[0] * (MAX_USER_DATA_SEPTETS - udhLength)) - minNumSeptets;
+ values[3] = SmsMessage.ENCODING_7BIT;
+ values[4] = (langIndex == 2 ? 3 : langIndex); // Portuguese is code 3, index 2
+ values[5] = langShiftIndex;
+ assertEquals("minNumSeptetsWithHeader", minNumSeptetsWithHeader,
+ udhLength * msgCount + minNumSeptets);
+ mStatsCounters[langIndex * 4 + langShiftIndex]++;
+ }
+ }
+
+ void printStats() {
+ Log.d(TAG, "Unicode selection count: " + mUnicodeCounter);
+ for (int i = 0; i < 12; i++) {
+ Log.d(TAG, "Language pair index " + i + " count: " + mStatsCounters[i]);
+ }
+ }
+ }
+
+ @LargeTest
+ public void testCalcLengthMixed7bit() throws Exception {
+ StringBuilder sb = new StringBuilder(320);
+ CounterHelper ch = new CounterHelper();
+ Random r = new Random(0x4321); // use the same seed for reproducibility
+ int[] expectedValues = new int[6];
+ int[] origLockingShiftTables = GsmAlphabet.getEnabledLockingShiftTables();
+ int[] origSingleShiftTables = GsmAlphabet.getEnabledSingleShiftTables();
+ int enabledLanguagesTestCases = sEnabledSingleShiftTables.length;
+ long startTime = System.currentTimeMillis();
+
+ // Repeat for 10 test runs
+ for (int run = 0; run < 10; run++) {
+ sb.setLength(0);
+ ch.clear();
+ int unicodeOnlyCount = 0;
+
+ // Test incrementally from 1 to 320 character random messages
+ for (int i = 1; i < 320; i++) {
+ // 1% chance to add from each special character class, else add an ASCII char
+ int charClass = r.nextInt(100);
+ if (charClass >= sNumCharacterClasses) {
+ charClass = sNumCharacterClasses - 1; // last class is ASCII
+ }
+ int classLength = sCharacterClasses[charClass].length();
+ char nextChar = sCharacterClasses[charClass].charAt(r.nextInt(classLength));
+ sb.append(nextChar);
+ ch.addChar(charClass);
+
+// if (i % 20 == 0) {
+// Log.d(TAG, "test string: " + sb);
+// }
+
+ // Test string against all combinations of enabled languages
+ boolean unicodeOnly = true;
+ for (int j = 0; j < enabledLanguagesTestCases; j++) {
+ GsmAlphabet.setEnabledSingleShiftTables(sEnabledSingleShiftTables[j]);
+ GsmAlphabet.setEnabledLockingShiftTables(sEnabledLockingShiftTables[j]);
+ ch.fillData(j, false, expectedValues, i);
+ if (expectedValues[3] == SmsMessage.ENCODING_7BIT) {
+ unicodeOnly = false;
+ }
+ callGsmLengthMethods(sb, false, expectedValues);
+ // test 7 bit only mode
+ ch.fillData(j, true, expectedValues, i);
+ callGsmLengthMethods(sb, true, expectedValues);
+ }
+ // after 10 iterations with a Unicode-only string, skip to next test string
+ // so we can spend more time testing strings that do encode into 7 bits.
+ if (unicodeOnly && ++unicodeOnlyCount == 10) {
+// Log.d(TAG, "Unicode only: skipping to next test string");
+ break;
+ }
+ }
+ }
+ ch.printStats();
+ Log.d(TAG, "Completed in " + (System.currentTimeMillis() - startTime) + " ms");
+ GsmAlphabet.setEnabledLockingShiftTables(origLockingShiftTables);
+ GsmAlphabet.setEnabledSingleShiftTables(origSingleShiftTables);
+ }
+
private void callGsmLengthMethods(CharSequence msgBody, boolean use7bitOnly,
int[] expectedValues)
{
@@ -164,6 +574,8 @@ public class SmsMessageBodyTest extends AndroidTestCase {
assertEquals("codeUnitCount", expectedValues[1], ted.codeUnitCount);
assertEquals("codeUnitsRemaining", expectedValues[2], ted.codeUnitsRemaining);
assertEquals("codeUnitSize", expectedValues[3], ted.codeUnitSize);
+ assertEquals("languageTable", expectedValues[4], ted.languageTable);
+ assertEquals("languageShiftTable", expectedValues[5], ted.languageShiftTable);
}
private void callCdmaLengthMethods(CharSequence msgBody, boolean use7bitOnly,