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
This commit is contained in:
Marc Blank 2009-09-18 20:36:15 -07:00
parent 9d43de5d12
commit 8587aa6121

View File

@ -510,7 +510,6 @@ public class EmailProvider extends ContentProvider {
private SQLiteDatabase mDatabase; private SQLiteDatabase mDatabase;
private SQLiteDatabase mBodyDatabase; private SQLiteDatabase mBodyDatabase;
private boolean mInTransaction = false;
public synchronized SQLiteDatabase getDatabase(Context context) { public synchronized SQLiteDatabase getDatabase(Context context) {
if (mDatabase != null) { if (mDatabase != null) {
@ -632,9 +631,7 @@ public class EmailProvider extends ContentProvider {
// Bodies are auto-deleted here; Attachments are auto-deleted via trigger // Bodies are auto-deleted here; Attachments are auto-deleted via trigger
messageDeletion = true; messageDeletion = true;
if (!mInTransaction) { db.beginTransaction();
db.beginTransaction();
}
break; break;
} }
switch (match) { switch (match) {
@ -687,15 +684,11 @@ public class EmailProvider extends ContentProvider {
// Delete any orphaned Body records // Delete any orphaned Body records
db.execSQL(DELETE_ORPHAN_BODIES); db.execSQL(DELETE_ORPHAN_BODIES);
} }
if (!mInTransaction) { db.setTransactionSuccessful();
db.setTransactionSuccessful();
}
} }
} finally { } finally {
if (messageDeletion) { if (messageDeletion) {
if (!mInTransaction) { db.endTransaction();
db.endTransaction();
}
} }
} }
getContext().getContentResolver().notifyChange(uri, null); getContext().getContentResolver().notifyChange(uri, null);
@ -919,9 +912,7 @@ public class EmailProvider extends ContentProvider {
switch (match) { switch (match) {
case MAILBOX_ID_ADD_TO_FIELD: case MAILBOX_ID_ADD_TO_FIELD:
case ACCOUNT_ID_ADD_TO_FIELD: case ACCOUNT_ID_ADD_TO_FIELD:
if (!mInTransaction) { db.beginTransaction();
db.beginTransaction();
}
id = uri.getPathSegments().get(1); id = uri.getPathSegments().get(1);
String field = values.getAsString(EmailContent.FIELD_COLUMN_NAME); String field = values.getAsString(EmailContent.FIELD_COLUMN_NAME);
Long add = values.getAsLong(EmailContent.ADD_COLUMN_NAME); Long add = values.getAsLong(EmailContent.ADD_COLUMN_NAME);
@ -944,10 +935,8 @@ public class EmailProvider extends ContentProvider {
} finally { } finally {
c.close(); c.close();
} }
if (!mInTransaction) { db.setTransactionSuccessful();
db.setTransactionSuccessful(); db.endTransaction();
db.endTransaction();
}
break; break;
case BODY_ID: case BODY_ID:
case MESSAGE_ID: case MESSAGE_ID:
@ -996,14 +985,12 @@ public class EmailProvider extends ContentProvider {
Context context = getContext(); Context context = getContext();
SQLiteDatabase db = getDatabase(context); SQLiteDatabase db = getDatabase(context);
db.beginTransaction(); db.beginTransaction();
mInTransaction = true;
try { try {
ContentProviderResult[] results = super.applyBatch(operations); ContentProviderResult[] results = super.applyBatch(operations);
db.setTransactionSuccessful(); db.setTransactionSuccessful();
return results; return results;
} finally { } finally {
db.endTransaction(); db.endTransaction();
mInTransaction = false;
} }
} }
} }