From 8587aa61211d288d05b5fb2ddf02d69cabe6a9e2 Mon Sep 17 00:00:00 2001 From: Marc Blank Date: Fri, 18 Sep 2009 20:36:15 -0700 Subject: [PATCH] Make EmailProvider more threadsafe w/r/t transactions * Since transactions can be nested, get rid of pointless/dangerous flag for indicating we're in a transaction. * Fixes #2131847 Change-Id: I2955e8a7659533e8ee9e71b949a042570466df45 --- .../android/email/provider/EmailProvider.java | 25 +++++-------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/src/com/android/email/provider/EmailProvider.java b/src/com/android/email/provider/EmailProvider.java index b3941c96c..0aa427766 100644 --- a/src/com/android/email/provider/EmailProvider.java +++ b/src/com/android/email/provider/EmailProvider.java @@ -510,7 +510,6 @@ public class EmailProvider extends ContentProvider { private SQLiteDatabase mDatabase; private SQLiteDatabase mBodyDatabase; - private boolean mInTransaction = false; public synchronized SQLiteDatabase getDatabase(Context context) { if (mDatabase != null) { @@ -632,9 +631,7 @@ public class EmailProvider extends ContentProvider { // Bodies are auto-deleted here; Attachments are auto-deleted via trigger messageDeletion = true; - if (!mInTransaction) { - db.beginTransaction(); - } + db.beginTransaction(); break; } switch (match) { @@ -687,15 +684,11 @@ public class EmailProvider extends ContentProvider { // Delete any orphaned Body records db.execSQL(DELETE_ORPHAN_BODIES); } - if (!mInTransaction) { - db.setTransactionSuccessful(); - } + db.setTransactionSuccessful(); } } finally { if (messageDeletion) { - if (!mInTransaction) { - db.endTransaction(); - } + db.endTransaction(); } } getContext().getContentResolver().notifyChange(uri, null); @@ -919,9 +912,7 @@ public class EmailProvider extends ContentProvider { switch (match) { case MAILBOX_ID_ADD_TO_FIELD: case ACCOUNT_ID_ADD_TO_FIELD: - if (!mInTransaction) { - db.beginTransaction(); - } + db.beginTransaction(); id = uri.getPathSegments().get(1); String field = values.getAsString(EmailContent.FIELD_COLUMN_NAME); Long add = values.getAsLong(EmailContent.ADD_COLUMN_NAME); @@ -944,10 +935,8 @@ public class EmailProvider extends ContentProvider { } finally { c.close(); } - if (!mInTransaction) { - db.setTransactionSuccessful(); - db.endTransaction(); - } + db.setTransactionSuccessful(); + db.endTransaction(); break; case BODY_ID: case MESSAGE_ID: @@ -996,14 +985,12 @@ public class EmailProvider extends ContentProvider { Context context = getContext(); SQLiteDatabase db = getDatabase(context); db.beginTransaction(); - mInTransaction = true; try { ContentProviderResult[] results = super.applyBatch(operations); db.setTransactionSuccessful(); return results; } finally { db.endTransaction(); - mInTransaction = false; } } }