bug 2236535: find a way to update the stale canonical_addresses entries with new SMS/MMS number.

- allow updating the canonical_address with a new number.

Change-Id: Ia91fad4a76d6ea49a23379dae755ec54f61823ab
diff --git a/src/com/android/providers/telephony/MmsSmsProvider.java b/src/com/android/providers/telephony/MmsSmsProvider.java
index 3db9600..8b21e8e 100644
--- a/src/com/android/providers/telephony/MmsSmsProvider.java
+++ b/src/com/android/providers/telephony/MmsSmsProvider.java
@@ -99,6 +99,11 @@
      */
     public static final String TABLE_PENDING_MSG = "pending_msgs";
 
+    /**
+     * the name of the table that is used to store the canonical addresses for both SMS and MMS.
+     */
+    private static final String TABLE_CANONICAL_ADDRESSES = "canonical_addresses";
+
     // These constants are used to construct union queries across the
     // MMS and SMS base tables.
 
@@ -132,6 +137,13 @@
         ThreadsColumns.MESSAGE_COUNT
     };
 
+    private static final String[] CANONICAL_ADDRESSES_COLUMNS_1 =
+            new String[] { CanonicalAddressesColumns.ADDRESS };
+
+    private static final String[] CANONICAL_ADDRESSES_COLUMNS_2 =
+            new String[] { CanonicalAddressesColumns._ID,
+                    CanonicalAddressesColumns.ADDRESS };
+
     // These are all the columns that appear in the MMS and SMS
     // message tables.
     private static final String[] UNION_COLUMNS =
@@ -293,15 +305,21 @@
                 String extraSelection = "_id=" + uri.getPathSegments().get(1);
                 String finalSelection = TextUtils.isEmpty(selection)
                         ? extraSelection : extraSelection + " AND " + selection;
-                cursor = db.query("canonical_addresses",
-                        new String[] {"address"}, finalSelection, selectionArgs,
-                        null, null, sortOrder);
+                cursor = db.query(TABLE_CANONICAL_ADDRESSES,
+                        CANONICAL_ADDRESSES_COLUMNS_1,
+                        finalSelection,
+                        selectionArgs,
+                        null, null,
+                        sortOrder);
                 break;
             }
             case URI_CANONICAL_ADDRESSES:
-                cursor = db.query("canonical_addresses",
-                        new String[] {"_id", "address"}, selection, selectionArgs,
-                        null, null, sortOrder);
+                cursor = db.query(TABLE_CANONICAL_ADDRESSES,
+                        CANONICAL_ADDRESSES_COLUMNS_2,
+                        selection,
+                        selectionArgs,
+                        null, null,
+                        sortOrder);
                 break;
             case URI_SEARCH:
                 if (       sortOrder != null
@@ -1116,9 +1134,20 @@
                 affectedRows = updateConversation(threadIdString, values,
                         selection, selectionArgs);
                 break;
+
             case URI_PENDING_MSG:
                 affectedRows = db.update(TABLE_PENDING_MSG, values, selection, null);
                 break;
+
+            case URI_CANONICAL_ADDRESS: {
+                String extraSelection = "_id=" + uri.getPathSegments().get(1);
+                String finalSelection = TextUtils.isEmpty(selection)
+                        ? extraSelection : extraSelection + " AND " + selection;
+
+                affectedRows = db.update(TABLE_CANONICAL_ADDRESSES, values, finalSelection, null);
+                break;
+            }
+
             default:
                 throw new UnsupportedOperationException(
                         NO_DELETES_INSERTS_OR_UPDATES);