Snap for 10147226 from 268ca205f3d2648191eacffd6685fa550fe3bb4c to udc-release

Change-Id: I66ca0fd7431b2fb0314d404af4f1904989873eec
diff --git a/src/com/android/messaging/ui/conversation/LaunchConversationActivity.java b/src/com/android/messaging/ui/conversation/LaunchConversationActivity.java
index 5500ae8..c869839 100644
--- a/src/com/android/messaging/ui/conversation/LaunchConversationActivity.java
+++ b/src/com/android/messaging/ui/conversation/LaunchConversationActivity.java
@@ -37,6 +37,8 @@
 
 import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * Launches ConversationActivity for sending a message to, or viewing messages from, a specific
@@ -46,6 +48,7 @@
  */
 public class LaunchConversationActivity extends Activity implements
         LaunchConversationData.LaunchConversationDataListener {
+    private static final int MAX_RECIPIENT_LENGTH = 100;
     static final String SMS_BODY = "sms_body";
     static final String ADDRESS = "address";
     final Binding<LaunchConversationData> mBinding = BindingBase.createBinding(this);
@@ -76,6 +79,9 @@
                     recipients = new String[] { intent.getStringExtra(Intent.EXTRA_EMAIL) };
                 }
             }
+            if (recipients != null) {
+                recipients = trimInvalidRecipients(recipients);
+            }
             mSmsBody = intent.getStringExtra(SMS_BODY);
             if (TextUtils.isEmpty(mSmsBody)) {
                 // Used by intents sent from the web YouTube (and perhaps others).
@@ -103,6 +109,20 @@
         finish();
     }
 
+    private String[] trimInvalidRecipients(String[] recipients) {
+        List<String> trimmedRecipients = new ArrayList<>();
+        for (String recipient : recipients) {
+            if (recipient.length() < MAX_RECIPIENT_LENGTH) {
+                trimmedRecipients.add(recipient);
+            }
+        }
+        if (trimmedRecipients.size() > 0) {
+            return trimmedRecipients.toArray(new String[0]);
+        } else {
+            return null;
+        }
+    }
+
     private String getBody(final Uri uri) {
         if (uri == null) {
             return null;