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
This commit is contained in:
parent
7183724276
commit
f678a8e67a
@ -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)
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user