bug #2553905: handle upgrading the "seen" column in sms/mms db better.

- when upgrading the sms and pdu tables from Donut, we add a new column called "seen". That's used to compute the statusbar notifications. "seen=0" means we need to throw up a notification. The bug is that we were adding the "seen" column with value=0,  which makes the MMS app notify for all messages that are in the SMS/MMS database after the upgrade. Obviously that's no good. So, add some logic in the upgrade code to set the 'seen' value the same as the 'read' value for each message in the table. That will made the app notify only the unread messages.

Change-Id: I1bb5a10c84d165c5fb463628b35c4c49ed36f1d3
diff --git a/src/com/android/providers/telephony/MmsSmsDatabaseHelper.java b/src/com/android/providers/telephony/MmsSmsDatabaseHelper.java
index 187ee30..c26e855 100644
--- a/src/com/android/providers/telephony/MmsSmsDatabaseHelper.java
+++ b/src/com/android/providers/telephony/MmsSmsDatabaseHelper.java
@@ -1254,6 +1254,21 @@
     private void upgradeDatabaseToVersion51(SQLiteDatabase db) {
         db.execSQL("ALTER TABLE sms add COLUMN seen INTEGER DEFAULT 0");
         db.execSQL("ALTER TABLE pdu add COLUMN seen INTEGER DEFAULT 0");
+
+        try {
+            // update the existing sms and pdu tables so the new "seen" column is the same as
+            // the "read" column for each row.
+            ContentValues contentValues = new ContentValues();
+            contentValues.put("seen", 1);
+            int count = db.update("sms", contentValues, "read=1", null);
+            Log.d(TAG, "[MmsSmsDb] upgradeDatabaseToVersion51: updated " + count +
+                    " rows in sms table to have READ=1");
+            count = db.update("pdu", contentValues, "read=1", null);
+            Log.d(TAG, "[MmsSmsDb] upgradeDatabaseToVersion51: updated " + count +
+                    " rows in pdu table to have READ=1");
+        } catch (Exception ex) {
+            Log.e(TAG, "[MmsSmsDb] upgradeDatabaseToVersion51 caught ", ex);
+        }
     }
 
     private void updateThreadsAttachmentColumn(SQLiteDatabase db) {