Android.database.sqlite.SQLiteException when searching words through voice search

Bug 6476357

Mms provider search query would choke on quoted words. Use selection arguments
instead of string building to pass in search string.

Change-Id: Ida45cc0a16366779012c264ffbda021985f01fa6
diff --git a/src/com/android/providers/telephony/MmsSmsProvider.java b/src/com/android/providers/telephony/MmsSmsProvider.java
index 19a612c..839e9ff 100644
--- a/src/com/android/providers/telephony/MmsSmsProvider.java
+++ b/src/com/android/providers/telephony/MmsSmsProvider.java
@@ -165,6 +165,10 @@
 
     private static final String[] EMPTY_STRING_ARRAY = new String[0];
 
+    private static final String[] SEARCH_STRING = new String[1];
+    private static final String SEARCH_QUERY = "SELECT snippet(words, '', ' ', '', 1, 1) as " +
+            "snippet FROM words WHERE index_text MATCH ? ORDER BY snippet LIMIT 50;";
+
     private static final String SMS_CONVERSATION_CONSTRAINT = "(" +
             Sms.TYPE + " != " + Sms.MESSAGE_TYPE_DRAFT + ")";
 
@@ -348,12 +352,11 @@
                         sortOrder);
                 break;
             case URI_SEARCH_SUGGEST: {
-                String searchString = uri.getQueryParameter("pattern");
+                SEARCH_STRING[0] = uri.getQueryParameter("pattern") + '*' ;
 
                 // find the words which match the pattern using the snippet function.  The
                 // snippet function parameters mainly describe how to format the result.
                 // See http://www.sqlite.org/fts3.html#section_4_2 for details.
-                String query = String.format("SELECT snippet(words, '', ' ', '', 1, 1) as snippet FROM words WHERE index_text MATCH '%s*' ORDER BY snippet LIMIT 50;", searchString);
                 if (       sortOrder != null
                         || selection != null
                         || selectionArgs != null
@@ -363,7 +366,7 @@
                             "with this query");
                 }
 
-                cursor = db.rawQuery(query, null);
+                cursor = db.rawQuery(SEARCH_QUERY, SEARCH_STRING);
                 break;
             }
             case URI_MESSAGE_ID_TO_THREAD: {