summaryrefslogtreecommitdiffstats
path: root/telephony
diff options
context:
space:
mode:
authorAndroid (Google) Code Review <android-gerrit@google.com>2009-06-11 11:42:06 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2009-06-11 11:42:06 -0700
commit97857f8618fb9ee49345414895bcbe3e1452a155 (patch)
treecd37448f0c8a3d40528ceb9c29b7456206264f15 /telephony
parent4bb1a37fb127819284a5481e0f7509ac2948903b (diff)
parent0b77453076a22569f24318d194b378b68f11a63e (diff)
downloadframeworks_base-97857f8618fb9ee49345414895bcbe3e1452a155.zip
frameworks_base-97857f8618fb9ee49345414895bcbe3e1452a155.tar.gz
frameworks_base-97857f8618fb9ee49345414895bcbe3e1452a155.tar.bz2
am 0b774530: Merge change 3015 into donut
Merge commit '0b77453076a22569f24318d194b378b68f11a63e' * commit '0b77453076a22569f24318d194b378b68f11a63e': make sms calculateLength radio-independent
Diffstat (limited to 'telephony')
-rw-r--r--telephony/java/android/telephony/SmsMessage.java34
-rw-r--r--telephony/java/com/android/internal/telephony/cdma/SmsMessage.java11
-rw-r--r--telephony/java/com/android/internal/telephony/cdma/sms/BearerData.java50
-rw-r--r--telephony/java/com/android/internal/telephony/cdma/sms/UserData.java8
-rw-r--r--telephony/java/com/android/internal/telephony/gsm/SmsMessage.java16
5 files changed, 94 insertions, 25 deletions
diff --git a/telephony/java/android/telephony/SmsMessage.java b/telephony/java/android/telephony/SmsMessage.java
index f9b95b2..b60da5a 100644
--- a/telephony/java/android/telephony/SmsMessage.java
+++ b/telephony/java/android/telephony/SmsMessage.java
@@ -224,25 +224,29 @@ public class SmsMessage {
/**
* Calculates the number of SMS's required to encode the message body and
- * the number of characters remaining until the next message, given the
- * current encoding.
+ * the number of characters remaining until the next message.
*
- * @param messageBody the message to encode
- * @param use7bitOnly if true, characters that are not part of the GSM
- * alphabet are counted as a single space char. If false, a
- * messageBody containing non-GSM alphabet characters is calculated
- * for 16-bit encoding.
+ * @param msgBody the message to encode
+ * @param use7bitOnly if true, characters that are not part of the
+ * radio-specific 7-bit encoding are counted as single
+ * space chars. If false, and if the messageBody contains
+ * non-7-bit encodable characters, length is calculated
+ * using a 16-bit encoding.
* @return an int[4] with int[0] being the number of SMS's required, int[1]
* the number of code units used, and int[2] is the number of code
* units remaining until the next message. int[3] is the encoding
* type that should be used for the message.
*/
- public static int[] calculateLength(CharSequence messageBody, boolean use7bitOnly) {
+ public static int[] calculateLength(CharSequence msgBody, boolean use7bitOnly) {
+ int activePhone = TelephonyManager.getDefault().getPhoneType();
int ret[] = new int[4];
- try {
- // Try GSM alphabet
- int septets = GsmAlphabet.countGsmSeptets(messageBody, !use7bitOnly);
+ int septets = (PHONE_TYPE_CDMA == activePhone) ?
+ com.android.internal.telephony.cdma.SmsMessage.calc7bitEncodedLength(msgBody,
+ use7bitOnly) :
+ com.android.internal.telephony.gsm.SmsMessage.calc7bitEncodedLength(msgBody,
+ use7bitOnly);
+ if (septets != -1) {
ret[1] = septets;
if (septets > MAX_USER_DATA_SEPTETS) {
ret[0] = (septets / MAX_USER_DATA_SEPTETS_WITH_HEADER) + 1;
@@ -253,12 +257,10 @@ public class SmsMessage {
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();
+ } else {
+ int octets = msgBody.length() * 2;
+ ret[1] = msgBody.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;
ret[2] = (MAX_USER_DATA_BYTES_WITH_HEADER
- (octets % MAX_USER_DATA_BYTES_WITH_HEADER))/2;
diff --git a/telephony/java/com/android/internal/telephony/cdma/SmsMessage.java b/telephony/java/com/android/internal/telephony/cdma/SmsMessage.java
index 9152559..bbdd0dd 100644
--- a/telephony/java/com/android/internal/telephony/cdma/SmsMessage.java
+++ b/telephony/java/com/android/internal/telephony/cdma/SmsMessage.java
@@ -357,6 +357,17 @@ public class SmsMessage extends SmsMessageBase {
}
/**
+ * Calculate the number of septets needed to encode the message.
+ *
+ * @param messageBody the message to encode
+ * @param force ignore (but still count) illegal characters if true
+ * @return septet count, or -1 on failure
+ */
+ public static int calc7bitEncodedLength(CharSequence msgBody, boolean force) {
+ return BearerData.calc7bitEncodedLength(msgBody.toString(), force);
+ }
+
+ /**
* Note: This function is a GSM specific functionality which is not supported in CDMA mode.
*/
public int getProtocolIdentifier() {
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 ab65b0a..3c45aa4 100644
--- a/telephony/java/com/android/internal/telephony/cdma/sms/BearerData.java
+++ b/telephony/java/com/android/internal/telephony/cdma/sms/BearerData.java
@@ -385,7 +385,17 @@ public final class BearerData{
outStream.skip(3);
}
- private static byte[] encode7bitAscii(String msg)
+ private static class SeptetData {
+ byte data[];
+ int septetCount;
+
+ SeptetData(byte[] data, int septetCount) {
+ this.data = data;
+ this.septetCount = septetCount;
+ }
+ }
+
+ private static SeptetData encode7bitAscii(String msg, boolean force)
throws CodingException
{
try {
@@ -396,23 +406,43 @@ public final class BearerData{
// Test ourselves for ASCII membership, since Java seems not to care.
if ((charCode < UserData.PRINTABLE_ASCII_MIN_INDEX) ||
(charCode > UserData.PRINTABLE_ASCII_MAX_INDEX)) {
- throw new CodingException("illegal ASCII code (" + charCode + ")");
+ if (force) {
+ outStream.write(7, UserData.UNENCODABLE_7_BIT_CHAR);
+ } else {
+ throw new CodingException("illegal ASCII code (" + charCode + ")");
+ }
+ } else {
+ outStream.write(7, expandedData[i]);
}
- outStream.write(7, expandedData[i]);
}
- return outStream.toByteArray();
- } catch (java.io.UnsupportedEncodingException ex) {
+ return new SeptetData(outStream.toByteArray(), expandedData.length);
+ } catch (java.io.UnsupportedEncodingException ex) {
throw new CodingException("7bit ASCII encode failed: " + ex);
- } catch (BitwiseOutputStream.AccessException ex) {
+ } catch (BitwiseOutputStream.AccessException ex) {
throw new CodingException("7bit ASCII encode failed: " + ex);
}
}
+ /**
+ * Calculate the number of septets needed to encode the message.
+ *
+ * @param force ignore (but still count) illegal characters if true
+ * @return septet count, or -1 on failure
+ */
+ public static int calc7bitEncodedLength(String msg, boolean force) {
+ try {
+ SeptetData data = encode7bitAscii(msg, force);
+ return data.septetCount;
+ } catch (CodingException ex) {
+ return -1;
+ }
+ }
+
private static byte[] encodeUtf16(String msg)
throws CodingException
{
try {
- return msg.getBytes("utf-16be"); // XXX(do not submit) -- make sure decode matches
+ return msg.getBytes("utf-16be");
} catch (java.io.UnsupportedEncodingException ex) {
throw new CodingException("UTF-16 encode failed: " + ex);
}
@@ -462,7 +492,8 @@ public final class BearerData{
if (uData.msgEncoding == UserData.ENCODING_GSM_7BIT_ALPHABET) {
payloadData = encode7bitGsm(uData.payloadStr);
} else if (uData.msgEncoding == UserData.ENCODING_7BIT_ASCII) {
- payloadData = encode7bitAscii(uData.payloadStr);
+ SeptetData septetData = encode7bitAscii(uData.payloadStr, true);
+ payloadData = septetData.data;
} else if (uData.msgEncoding == UserData.ENCODING_UNICODE_16) {
payloadData = encodeUtf16(uData.payloadStr);
} else {
@@ -478,7 +509,8 @@ public final class BearerData{
uData.payloadStr = "";
}
try {
- payloadData = encode7bitAscii(uData.payloadStr);
+ SeptetData septetData = encode7bitAscii(uData.payloadStr, false);
+ payloadData = septetData.data;
uData.msgEncoding = UserData.ENCODING_7BIT_ASCII;
} catch (CodingException ex) {
payloadData = encodeUtf16(uData.payloadStr);
diff --git a/telephony/java/com/android/internal/telephony/cdma/sms/UserData.java b/telephony/java/com/android/internal/telephony/cdma/sms/UserData.java
index 7c37bc2..8d4e769 100644
--- a/telephony/java/com/android/internal/telephony/cdma/sms/UserData.java
+++ b/telephony/java/com/android/internal/telephony/cdma/sms/UserData.java
@@ -50,6 +50,14 @@ public class UserData {
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~'};
/**
+ * Character to use when forced to encode otherwise unencodable
+ * characters, meaning those not in the respective ASCII or GSM
+ * 7-bit encoding tables. Current choice is SPACE, which is 0x20
+ * in both the GSM-7bit and ASCII-7bit encodings.
+ */
+ static final byte UNENCODABLE_7_BIT_CHAR = 0x20;
+
+ /**
* Only elements between these indices in the ASCII table are printable.
*/
public static final int PRINTABLE_ASCII_MIN_INDEX = 0x20;
diff --git a/telephony/java/com/android/internal/telephony/gsm/SmsMessage.java b/telephony/java/com/android/internal/telephony/gsm/SmsMessage.java
index 6435be5..a15bbdf 100644
--- a/telephony/java/com/android/internal/telephony/gsm/SmsMessage.java
+++ b/telephony/java/com/android/internal/telephony/gsm/SmsMessage.java
@@ -739,6 +739,22 @@ public class SmsMessage extends SmsMessageBase{
}
}
+ /**
+ * Calculate the number of septets needed to encode the message.
+ *
+ * @param messageBody the message to encode
+ * @param force ignore (but still count) illegal characters if true
+ * @return septet count, or -1 on failure
+ */
+ public static int calc7bitEncodedLength(CharSequence messageBody, boolean force) {
+ try {
+ return GsmAlphabet.countGsmSeptets(messageBody, !force);
+ } catch (EncodeException ex) {
+ /* Just fall through to the -1 error result below. */
+ }
+ return -1;
+ }
+
/** {@inheritDoc} */
public int getProtocolIdentifier() {
return protocolIdentifier;