From d5ef5903570e533a501abe6a8e3d533fdb5318fc Mon Sep 17 00:00:00 2001 From: Flavio Lerda Date: Wed, 10 Aug 2011 00:44:38 +0100 Subject: 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 --- .../providers/contacts/ContactsProvider2.java | 6 ++++- .../providers/contacts/ContactsProvider2Test.java | 27 +++++++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) 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.OpenableColumns; 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 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun 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 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { ContentValues expectedValues = new ContentValues(); expectedValues.put(StreamItems.RAW_CONTACT_ID, rawContactId); - expectedValues.put(StreamItems.TEXT, "hacking"); + expectedValues.put(StreamItems.TEXT, "

hacking

\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, "& test '", StatusUpdates.CAPABILITY_HAS_VOICE); + + ContentValues expectedValues = new ContentValues(); + expectedValues.put(StreamItems.RAW_CONTACT_ID, rawContactId); + expectedValues.put(StreamItems.TEXT, "

& <b> test &#39;

\n"); assertStoredValues(RawContacts.CONTENT_URI.buildUpon() .appendPath(String.valueOf(rawContactId)) .appendPath(RawContacts.StreamItems.CONTENT_DIRECTORY).build(), @@ -3720,7 +3741,7 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { ContentValues expectedValues = new ContentValues(); expectedValues.put(StreamItems.RAW_CONTACT_ID, rawContactId); - expectedValues.put(StreamItems.TEXT, "finished hacking"); + expectedValues.put(StreamItems.TEXT, "

finished hacking

\n"); assertStoredValues(RawContacts.CONTENT_URI.buildUpon() .appendPath(String.valueOf(rawContactId)) .appendPath(RawContacts.StreamItems.CONTENT_DIRECTORY).build(), -- cgit v1.1