diff options
author | Jake Hamby <jhamby@google.com> | 2011-11-14 18:05:51 -0800 |
---|---|---|
committer | Jake Hamby <jhamby@google.com> | 2011-11-14 18:30:01 -0800 |
commit | 87d14a1756f2ff4abdc107de35d06739245a606e (patch) | |
tree | 97122631ac8d15a028e44d9da4c72d4086f96287 /telephony | |
parent | d5897dc7985e511c194f839d4b340fed2d63b41c (diff) | |
download | frameworks_base-87d14a1756f2ff4abdc107de35d06739245a606e.zip frameworks_base-87d14a1756f2ff4abdc107de35d06739245a606e.tar.gz frameworks_base-87d14a1756f2ff4abdc107de35d06739245a606e.tar.bz2 |
Fix 3GPP SMS send failure for 7-bit national language tables.
Fix a NullPointerException when sending a single-part SMS containing
characters in one of the enabled national language tables.
Also added a few log messages for several error cases to help with
debugging any future problems in the SMS dispatcher.
Bug: 5553544
Change-Id: I61c1cbe297b2e222027f0db7c833df6a03c2974a
Diffstat (limited to 'telephony')
3 files changed, 52 insertions, 11 deletions
diff --git a/telephony/java/com/android/internal/telephony/SmsHeader.java b/telephony/java/com/android/internal/telephony/SmsHeader.java index 9492e0e..c32388f 100644 --- a/telephony/java/com/android/internal/telephony/SmsHeader.java +++ b/telephony/java/com/android/internal/telephony/SmsHeader.java @@ -190,7 +190,9 @@ public class SmsHeader { public static byte[] toByteArray(SmsHeader smsHeader) { if ((smsHeader.portAddrs == null) && (smsHeader.concatRef == null) && - (smsHeader.miscEltList.size() == 0)) { + (smsHeader.miscEltList.isEmpty()) && + (smsHeader.languageShiftTable == 0) && + (smsHeader.languageTable == 0)) { return null; } diff --git a/telephony/java/com/android/internal/telephony/gsm/GsmSMSDispatcher.java b/telephony/java/com/android/internal/telephony/gsm/GsmSMSDispatcher.java index c1553d8..093c220 100644 --- a/telephony/java/com/android/internal/telephony/gsm/GsmSMSDispatcher.java +++ b/telephony/java/com/android/internal/telephony/gsm/GsmSMSDispatcher.java @@ -197,7 +197,11 @@ public final class GsmSMSDispatcher extends SMSDispatcher { byte[] data, PendingIntent sentIntent, PendingIntent deliveryIntent) { SmsMessage.SubmitPdu pdu = SmsMessage.getSubmitPdu( scAddr, destAddr, destPort, data, (deliveryIntent != null)); - sendRawPdu(pdu.encodedScAddress, pdu.encodedMessage, sentIntent, deliveryIntent); + if (pdu != null) { + sendRawPdu(pdu.encodedScAddress, pdu.encodedMessage, sentIntent, deliveryIntent); + } else { + Log.e(TAG, "GsmSMSDispatcher.sendData(): getSubmitPdu() returned null"); + } } /** {@inheritDoc} */ @@ -206,7 +210,11 @@ public final class GsmSMSDispatcher extends SMSDispatcher { PendingIntent sentIntent, PendingIntent deliveryIntent) { SmsMessage.SubmitPdu pdu = SmsMessage.getSubmitPdu( scAddr, destAddr, text, (deliveryIntent != null)); - sendRawPdu(pdu.encodedScAddress, pdu.encodedMessage, sentIntent, deliveryIntent); + if (pdu != null) { + sendRawPdu(pdu.encodedScAddress, pdu.encodedMessage, sentIntent, deliveryIntent); + } else { + Log.e(TAG, "GsmSMSDispatcher.sendText(): getSubmitPdu() returned null"); + } } /** {@inheritDoc} */ @@ -224,7 +232,11 @@ public final class GsmSMSDispatcher extends SMSDispatcher { SmsMessage.SubmitPdu pdu = SmsMessage.getSubmitPdu(scAddress, destinationAddress, message, deliveryIntent != null, SmsHeader.toByteArray(smsHeader), encoding, smsHeader.languageTable, smsHeader.languageShiftTable); - sendRawPdu(pdu.encodedScAddress, pdu.encodedMessage, sentIntent, deliveryIntent); + if (pdu != null) { + sendRawPdu(pdu.encodedScAddress, pdu.encodedMessage, sentIntent, deliveryIntent); + } else { + Log.e(TAG, "GsmSMSDispatcher.sendNewSubmitPdu(): getSubmitPdu() returned null"); + } } /** {@inheritDoc} */ diff --git a/telephony/java/com/android/internal/telephony/gsm/SmsMessage.java b/telephony/java/com/android/internal/telephony/gsm/SmsMessage.java index 2da9642..d9a5f5d 100644 --- a/telephony/java/com/android/internal/telephony/gsm/SmsMessage.java +++ b/telephony/java/com/android/internal/telephony/gsm/SmsMessage.java @@ -16,22 +16,22 @@ package com.android.internal.telephony.gsm; -import android.os.Parcel; import android.telephony.PhoneNumberUtils; import android.text.format.Time; import android.util.Log; -import com.android.internal.telephony.IccUtils; + import com.android.internal.telephony.EncodeException; import com.android.internal.telephony.GsmAlphabet; +import com.android.internal.telephony.IccUtils; import com.android.internal.telephony.SmsHeader; import com.android.internal.telephony.SmsMessageBase; import java.io.ByteArrayOutputStream; import java.io.UnsupportedEncodingException; +import static android.telephony.SmsMessage.ENCODING_16BIT; import static android.telephony.SmsMessage.ENCODING_7BIT; import static android.telephony.SmsMessage.ENCODING_8BIT; -import static android.telephony.SmsMessage.ENCODING_16BIT; import static android.telephony.SmsMessage.ENCODING_KSC5601; import static android.telephony.SmsMessage.ENCODING_UNKNOWN; import static android.telephony.SmsMessage.MAX_USER_DATA_BYTES; @@ -240,18 +240,43 @@ public class SmsMessage extends SmsMessageBase { return null; } + if (encoding == ENCODING_UNKNOWN) { + // Find the best encoding to use + TextEncodingDetails ted = calculateLength(message, false); + encoding = ted.codeUnitSize; + languageTable = ted.languageTable; + languageShiftTable = ted.languageShiftTable; + + if (encoding == ENCODING_7BIT && (languageTable != 0 || languageShiftTable != 0)) { + if (header != null) { + SmsHeader smsHeader = SmsHeader.fromByteArray(header); + if (smsHeader.languageTable != languageTable + || smsHeader.languageShiftTable != languageShiftTable) { + Log.w(LOG_TAG, "Updating language table in SMS header: " + + smsHeader.languageTable + " -> " + languageTable + ", " + + smsHeader.languageShiftTable + " -> " + languageShiftTable); + smsHeader.languageTable = languageTable; + smsHeader.languageShiftTable = languageShiftTable; + header = SmsHeader.toByteArray(smsHeader); + } + } else { + SmsHeader smsHeader = new SmsHeader(); + smsHeader.languageTable = languageTable; + smsHeader.languageShiftTable = languageShiftTable; + header = SmsHeader.toByteArray(smsHeader); + } + } + } + SubmitPdu ret = new SubmitPdu(); // MTI = SMS-SUBMIT, UDHI = header != null byte mtiByte = (byte)(0x01 | (header != null ? 0x40 : 0x00)); ByteArrayOutputStream bo = getSubmitPduHead( scAddress, destinationAddress, mtiByte, statusReportRequested, ret); + // User Data (and length) byte[] userData; - if (encoding == ENCODING_UNKNOWN) { - // First, try encoding it with the GSM alphabet - encoding = ENCODING_7BIT; - } try { if (encoding == ENCODING_7BIT) { userData = GsmAlphabet.stringToGsm7BitPackedWithHeader(message, header, @@ -283,6 +308,7 @@ public class SmsMessage extends SmsMessageBase { if (encoding == ENCODING_7BIT) { if ((0xff & userData[0]) > MAX_USER_DATA_SEPTETS) { // Message too long + Log.e(LOG_TAG, "Message too long (" + (0xff & userData[0]) + " septets)"); return null; } // TP-Data-Coding-Scheme @@ -297,6 +323,7 @@ public class SmsMessage extends SmsMessageBase { } else { // assume UCS-2 if ((0xff & userData[0]) > MAX_USER_DATA_BYTES) { // Message too long + Log.e(LOG_TAG, "Message too long (" + (0xff & userData[0]) + " bytes)"); return null; } // TP-Data-Coding-Scheme |