From f678a8e67ace74ea285dcec9727d0117e23a5c73 Mon Sep 17 00:00:00 2001 From: Makoto Onuki Date: Fri, 10 Sep 2010 13:06:07 -0700 Subject: [PATCH] Clean-ups for EmailProvider - Don't allow manual modification of unreadCount/messageCount (We used to check only unreadCount in update().) - Do the integrity check at the very first in update(). I think the old place was really problematic because we opened the database in a few lines above and kept it in a local variable. Change-Id: I2bf5de4e4e45b40c11b951dd2255f8193c26f1aa --- .../android/email/provider/EmailProvider.java | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/com/android/email/provider/EmailProvider.java b/src/com/android/email/provider/EmailProvider.java index 6e8579e1b..5cb2d31d0 100644 --- a/src/com/android/email/provider/EmailProvider.java +++ b/src/com/android/email/provider/EmailProvider.java @@ -1042,6 +1042,8 @@ public class EmailProvider extends ContentProvider { Log.v(TAG, "EmailProvider.insert: uri=" + uri + ", match is " + match); } + removeAutoColumnsFromContentValues(match, values); + Uri resultUri = null; try { @@ -1241,6 +1243,13 @@ public class EmailProvider extends ContentProvider { @Override public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { if (Email.DEBUG_THREAD_CHECK) Email.warnIfUiThread(); + + // Handle this special case the fastest possible way + if (uri == INTEGRITY_CHECK_URI) { + checkDatabases(); + return 0; + } + int match = sURIMatcher.match(uri); Context context = getContext(); // See the comment at delete(), above @@ -1252,17 +1261,7 @@ public class EmailProvider extends ContentProvider { Log.v(TAG, "EmailProvider.update: uri=" + uri + ", match is " + match); } - // We do NOT allow setting of unreadCount via the provider - // This column is maintained via triggers - if (match == MAILBOX_ID || match == MAILBOX) { - values.remove(MailboxColumns.UNREAD_COUNT); - } - - // Handle this special case the fastest possible way - if (uri == INTEGRITY_CHECK_URI) { - checkDatabases(); - return 0; - } + removeAutoColumnsFromContentValues(match, values); String id; try { @@ -1345,6 +1344,15 @@ public class EmailProvider extends ContentProvider { return result; } + private static void removeAutoColumnsFromContentValues(int match, ContentValues values) { + // We do NOT allow setting of unreadCount/messageCount via the provider + // These columns are maintained via triggers + if (match == MAILBOX_ID || match == MAILBOX) { + values.remove(MailboxColumns.UNREAD_COUNT); + values.remove(MailboxColumns.MESSAGE_COUNT); + } + } + /* (non-Javadoc) * @see android.content.ContentProvider#applyBatch(android.content.ContentProviderOperation) */