Allow fragmentText to be called for singleton CDMA messages.

Corrects for previous partner changes, addressing issue:

http://buganizer/issue?id=2063332

Change-Id: I49e564d81c5db3e92a6bad973f21a02a7302875d
diff --git a/telephony/java/android/telephony/SmsMessage.java b/telephony/java/android/telephony/SmsMessage.java
index 0617dad..056eee2 100644
--- a/telephony/java/android/telephony/SmsMessage.java
+++ b/telephony/java/android/telephony/SmsMessage.java
@@ -309,8 +309,13 @@
         while (pos < textLen) {
             int nextPos = 0;  // Counts code units.
             if (ted.codeUnitSize == ENCODING_7BIT) {
-                // For multi-segment messages, CDMA 7bit equals GSM 7bit encoding (EMS mode).
-                nextPos = GsmAlphabet.findGsmSeptetLimitIndex(text, pos, limit);
+                if (activePhone == PHONE_TYPE_CDMA && ted.msgCount == 1) {
+                    // For a singleton CDMA message, the encoding must be ASCII...
+                    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);
+                }
             } else {  // Assume unicode.
                 nextPos = pos + Math.min(limit / 2, textLen - pos);
             }
diff --git a/telephony/java/com/android/internal/telephony/SmsMessageBase.java b/telephony/java/com/android/internal/telephony/SmsMessageBase.java
index 6177c8a..e73039b 100644
--- a/telephony/java/com/android/internal/telephony/SmsMessageBase.java
+++ b/telephony/java/com/android/internal/telephony/SmsMessageBase.java
@@ -116,6 +116,16 @@
          * android.telephony.SmsMessage ENCODING_*).
          */
         public int codeUnitSize;
+
+        @Override
+        public String toString() {
+            return "TextEncodingDetails " +
+                    "{ msgCount=" + msgCount +
+                    ", codeUnitCount=" + codeUnitCount +
+                    ", codeUnitsRemaining=" + codeUnitsRemaining +
+                    ", codeUnitSize=" + codeUnitSize +
+                    " }";
+        }
     }
 
     // TODO(): This class is duplicated in SmsMessage.java. Refactor accordingly.
diff --git a/tests/AndroidTests/src/com/android/unit_tests/CdmaSmsTest.java b/tests/AndroidTests/src/com/android/unit_tests/CdmaSmsTest.java
index 3255c8b..98d4c25 100644
--- a/tests/AndroidTests/src/com/android/unit_tests/CdmaSmsTest.java
+++ b/tests/AndroidTests/src/com/android/unit_tests/CdmaSmsTest.java
@@ -32,6 +32,8 @@
 
 import android.util.Log;
 
+import java.util.ArrayList;
+
 public class CdmaSmsTest extends AndroidTestCase {
     private final static String LOG_TAG = "XXX CdmaSmsTest XXX";
 
@@ -815,4 +817,30 @@
         BearerData revBearerData = BearerData.decode(encodedSms);
         assertEquals(userData.payloadStr, revBearerData.userData.payloadStr);
     }
+
+    @SmallTest
+    public void testFragmentText() throws Exception {
+        // Valid 160 character ASCII text.
+        String text1 = "123456789012345678901234567890123456789012345678901234567890" +
+                "1234567890123456789012345678901234567890123456789012345678901234567890" +
+                "12345678901234567890123456789[";
+        TextEncodingDetails ted = SmsMessage.calculateLength(text1, false);
+        assertEquals(ted.msgCount, 1);
+        assertEquals(ted.codeUnitCount, 160);
+        assertEquals(ted.codeUnitSize, 1);
+        ArrayList<String> fragments = android.telephony.SmsMessage.fragmentText(text1);
+        assertEquals(fragments.size(), 1);
+        // Valid 160 character GSM text -- the last character is
+        // non-ASCII, and so this will currently generate a singleton
+        // EMS message, which is not necessarily supported by Verizon.
+        String text2 = "123456789012345678901234567890123456789012345678901234567890" +
+                "1234567890123456789012345678901234567890123456789012345678901234567890" +
+                "12345678901234567890123456789\u00a3";  // Trailing pound-currency sign.
+        ted = SmsMessage.calculateLength(text2, false);
+        assertEquals(ted.msgCount, 1);
+        assertEquals(ted.codeUnitCount, 160);
+        assertEquals(ted.codeUnitSize, 1);
+        fragments = android.telephony.SmsMessage.fragmentText(text2);
+        assertEquals(fragments.size(), 1);
+    }
 }