SMS isn't converted to MMS even after 7 segments of messages

Bug 6903793

Resurrect the mms_config.xml setting "smsToMmsTextThreshold" to allow
overlays to specify an sms->mms conversion after a certain number
of sms segments have been created. Tested on mysid, yakju, and sojus. All
three have different settings for this feature. Also tested bug fixed by
https://googleplex-android-review.googlesource.com/#/c/103729/.

Change-Id: Ibcfd235edbaa264fede6e48f84f04345d16368fa
diff --git a/res/xml/mms_config.xml b/res/xml/mms_config.xml
index 988458b..78567e2 100644
--- a/res/xml/mms_config.xml
+++ b/res/xml/mms_config.xml
@@ -57,15 +57,17 @@
          to indicate no limit. -->
     <int name="recipientLimit">-1</int>
 
-    <!-- Maximum number of SMS message segments in a long text message before converting
-         the SMS message to an MMS message. -->
-    <int name="smsToMmsTextThreshold">4</int>
-
     <!-- If true, The text message over 160 characters will be sent in multi part.
          If false, The text message over 160 characters will be sent
          via multi media message. -->
     <bool name="enableMultipartSMS">true</bool>
 
+    <!-- If enableMultipartSMS is true and smsToMmsTextThreshold > 1, then multi-part SMS messages
+         will be converted into a single mms message. For example, if the mms_config.xml file
+         specifies <int name="smsToMmsTextThreshold">7</int>, then on the 8th sms segment, the
+         message will be converted to an mms. -->
+    <int name="smsToMmsTextThreshold">-1</int>
+
     <!-- If true, The mms support slide duration.
          If false, The mms does not support slide duration and we have to
          set duration value. -->
diff --git a/src/com/android/mms/MmsConfig.java b/src/com/android/mms/MmsConfig.java
index ee4392b..faab630 100755
--- a/src/com/android/mms/MmsConfig.java
+++ b/src/com/android/mms/MmsConfig.java
@@ -70,6 +70,12 @@
     // as an mms message. This feature exists for carriers that don't support multi-part sms's.
     private static boolean mEnableMultipartSMS = true;
 
+    // If mEnableMultipartSMS is true and mSmsToMmsTextThreshold > 1, then multi-part SMS messages
+    // will be converted into a single mms message. For example, if the mms_config.xml file
+    // specifies <int name="smsToMmsTextThreshold">4</int>, then on the 5th sms segment, the
+    // message will be converted to an mms.
+    private static int mSmsToMmsTextThreshold = -1;
+
     private static boolean mEnableSlideDuration = true;
     private static boolean mEnableMMSReadReports = true;        // key: "enableMMSReadReports"
     private static boolean mEnableSMSDeliveryReports = true;    // key: "enableSMSDeliveryReports"
@@ -100,6 +106,10 @@
         loadMmsSettings(context);
     }
 
+    public static int getSmsToMmsTextThreshold() {
+        return mSmsToMmsTextThreshold;
+    }
+
     public static boolean getMmsEnabled() {
         return mMmsEnabled == 1 ? true : false;
     }
@@ -337,6 +347,8 @@
                             mAliasRuleMinChars = Integer.parseInt(text);
                         } else if ("aliasMaxChars".equalsIgnoreCase(value)) {
                             mAliasRuleMaxChars = Integer.parseInt(text);
+                        } else if ("smsToMmsTextThreshold".equalsIgnoreCase(value)) {
+                            mSmsToMmsTextThreshold = Integer.parseInt(text);
                         } else if ("maxMessageTextSize".equalsIgnoreCase(value)) {
                             mMaxTextLength = Integer.parseInt(text);
                         } else if ("maxSubjectLength".equalsIgnoreCase(value)) {
diff --git a/src/com/android/mms/data/WorkingMessage.java b/src/com/android/mms/data/WorkingMessage.java
index d6bd3b1..14dd7b4 100755
--- a/src/com/android/mms/data/WorkingMessage.java
+++ b/src/com/android/mms/data/WorkingMessage.java
@@ -469,26 +469,23 @@
         mStatusListener.onAttachmentChanged();  // have to call whether succeeded or failed,
                                                 // because a replace that fails, removes the slide
 
-        if (!MmsConfig.getMultipartSmsEnabled()) {
-            if (!append && mAttachmentType == TEXT && type == TEXT) {
-                int[] params = SmsMessage.calculateLength(getText(), false);
-                /* SmsMessage.calculateLength returns an int[4] with:
-                *   int[0] being the number of SMS's required,
-                *   int[1] the number of code units used,
-                *   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.
-                */
-                int msgCount = params[0];
+        if (!append && mAttachmentType == TEXT && type == TEXT) {
+            int[] params = SmsMessage.calculateLength(getText(), false);
+            /* SmsMessage.calculateLength returns an int[4] with:
+             *   int[0] being the number of SMS's required,
+             *   int[1] the number of code units used,
+             *   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.
+             */
+            int smsSegmentCount = params[0];
 
-                if (msgCount > 1) {
-                    // The provider doesn't support multi-part sms's so as soon as the user types
-                    // an sms longer than one segment, we have to turn the message into an mms.
-                    setLengthRequiresMms(true, false);
-                } else {
-                    updateState(HAS_ATTACHMENT, hasAttachment(), true);
-                }
+            if (!MmsConfig.getMultipartSmsEnabled()) {
+                // The provider doesn't support multi-part sms's so as soon as the user types
+                // an sms longer than one segment, we have to turn the message into an mms.
+                setLengthRequiresMms(smsSegmentCount > 1, false);
             } else {
-                updateState(HAS_ATTACHMENT, hasAttachment(), true);
+                int threshold = MmsConfig.getSmsToMmsTextThreshold();
+                setLengthRequiresMms(threshold > 0 && smsSegmentCount > threshold, false);
             }
         } else {
             // Set HAS_ATTACHMENT if we need it.
diff --git a/src/com/android/mms/ui/ComposeMessageActivity.java b/src/com/android/mms/ui/ComposeMessageActivity.java
index 2ba2ef2..638c7bc 100644
--- a/src/com/android/mms/ui/ComposeMessageActivity.java
+++ b/src/com/android/mms/ui/ComposeMessageActivity.java
@@ -552,6 +552,9 @@
             // The provider doesn't support multi-part sms's so as soon as the user types
             // an sms longer than one segment, we have to turn the message into an mms.
             mWorkingMessage.setLengthRequiresMms(msgCount > 1, true);
+        } else {
+            int threshold = MmsConfig.getSmsToMmsTextThreshold();
+            mWorkingMessage.setLengthRequiresMms(threshold > 0 && msgCount > threshold, true);
         }
 
         // Show the counter only if: