Convert status updates to HTML.

Since stream items text is HTML but status updates are text only,
convert the text to HTML when inserting a status update into the stream
items.

Bug: 5122642
Change-Id: I61e3d9802e527c6977e7d29660ffd137ae899dae
diff --git a/src/com/android/providers/contacts/ContactsProvider2.java b/src/com/android/providers/contacts/ContactsProvider2.java
index 49e7ab5..3ec0931 100644
--- a/src/com/android/providers/contacts/ContactsProvider2.java
+++ b/src/com/android/providers/contacts/ContactsProvider2.java
@@ -136,6 +136,8 @@
 import android.provider.SyncStateContract;
 import android.telephony.PhoneNumberUtils;
 import android.telephony.TelephonyManager;
+import android.text.Html;
+import android.text.SpannableString;
 import android.text.TextUtils;
 import android.util.Log;
 
@@ -3037,7 +3039,9 @@
                 if (rawContactId != -1 && !TextUtils.isEmpty(status)) {
                     ContentValues streamItemValues = new ContentValues();
                     streamItemValues.put(StreamItems.RAW_CONTACT_ID, rawContactId);
-                    streamItemValues.put(StreamItems.TEXT, status);
+                    // Status updates are text only but stream items are HTML.
+                    streamItemValues.put(StreamItems.TEXT,
+                            Html.toHtml(new SpannableString(status)));
                     streamItemValues.put(StreamItems.COMMENTS, "");
                     streamItemValues.put(StreamItems.RES_PACKAGE, resPackage);
                     streamItemValues.put(StreamItems.RES_ICON, iconResource);
diff --git a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java
index d9dd358..d8a5854 100644
--- a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java
+++ b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java
@@ -16,7 +16,6 @@
 
 package com.android.providers.contacts;
 
-import com.android.common.contacts.DataUsageStatUpdater;
 import com.android.internal.util.ArrayUtils;
 import com.android.providers.contacts.ContactsDatabaseHelper.AggregationExceptionColumns;
 import com.android.providers.contacts.ContactsDatabaseHelper.DataUsageStatColumns;
@@ -3697,7 +3696,29 @@
 
         ContentValues expectedValues = new ContentValues();
         expectedValues.put(StreamItems.RAW_CONTACT_ID, rawContactId);
-        expectedValues.put(StreamItems.TEXT, "hacking");
+        expectedValues.put(StreamItems.TEXT, "<p>hacking</p>\n");
+        assertStoredValues(RawContacts.CONTENT_URI.buildUpon()
+                .appendPath(String.valueOf(rawContactId))
+                .appendPath(RawContacts.StreamItems.CONTENT_DIRECTORY).build(),
+                expectedValues);
+    }
+
+    public void testStreamItemInsertedOnStatusUpdate_HtmlQuoting() {
+
+        // This method of creating a raw contact automatically inserts a status update with
+        // the status message "hacking".
+        ContentValues values = new ContentValues();
+        long rawContactId = createRawContact(values, "18004664411",
+                "goog411@acme.com", StatusUpdates.INVISIBLE, 4, 1, 0,
+                StatusUpdates.CAPABILITY_HAS_VOICE);
+
+        // Insert a new status update for the raw contact.
+        insertStatusUpdate(Im.PROTOCOL_GOOGLE_TALK, null, "goog411@acme.com",
+                StatusUpdates.INVISIBLE, "& <b> test &#39;", StatusUpdates.CAPABILITY_HAS_VOICE);
+
+        ContentValues expectedValues = new ContentValues();
+        expectedValues.put(StreamItems.RAW_CONTACT_ID, rawContactId);
+        expectedValues.put(StreamItems.TEXT, "<p>&amp; &lt;b&gt; test &amp;#39;</p>\n");
         assertStoredValues(RawContacts.CONTENT_URI.buildUpon()
                 .appendPath(String.valueOf(rawContactId))
                 .appendPath(RawContacts.StreamItems.CONTENT_DIRECTORY).build(),
@@ -3720,7 +3741,7 @@
 
         ContentValues expectedValues = new ContentValues();
         expectedValues.put(StreamItems.RAW_CONTACT_ID, rawContactId);
-        expectedValues.put(StreamItems.TEXT, "finished hacking");
+        expectedValues.put(StreamItems.TEXT, "<p>finished hacking</p>\n");
         assertStoredValues(RawContacts.CONTENT_URI.buildUpon()
                 .appendPath(String.valueOf(rawContactId))
                 .appendPath(RawContacts.StreamItems.CONTENT_DIRECTORY).build(),