summaryrefslogtreecommitdiffstats
path: root/src/com/android/providers/contacts/ProfileProvider.java
diff options
context:
space:
mode:
authorMakoto Onuki <omakoto@google.com>2012-05-09 12:28:02 -0700
committerMakoto Onuki <omakoto@google.com>2012-06-25 15:29:04 -0700
commitae32283e7fc5b749df96523d8bb343b9068b65ba (patch)
tree49221991943aa54d4cfbefc7eb7c42bccf0cb8a0 /src/com/android/providers/contacts/ProfileProvider.java
parent3faa79cff9387924eee7dfa950e75d23453cbf90 (diff)
downloadpackages_providers_ContactsProvider-ae32283e7fc5b749df96523d8bb343b9068b65ba.tar.gz
packages_providers_ContactsProvider-ae32283e7fc5b749df96523d8bb343b9068b65ba.tar.bz2
packages_providers_ContactsProvider-ae32283e7fc5b749df96523d8bb343b9068b65ba.zip
Fix transaction handling in the provider
Fixed issues that will happen when a batch operation for applyBatch() contain operations for both the contacts db and the profile db. - Make sure to set the right transaction listener when starting a transaction. There were cases where we started a transaction on the contacts db but passsing the profile provider as the listener, and vice versa. - Make sure transaction callbacks operate on the correct DB. There were cases where ContactsProvider2.onCommit() and its sbilings would operate on the profile DB, not on the contacts db. - Change the transaction finishing order. When we start transactions on both the contacts and the profile DB, we do so on the contacts db first, and then on the profile db. But when we clsoe them, we did it in the same order, which could potentially cause a deadlock. Now we close them in the reverse order; the profile db first, then the contacts db. - Remove mActiveDb. This wasn't set in switchTo{Profile,Contact}Mode(), but was lazily initialized. But I wasn't too sure if I always set the right db at the right timing. Looks like I forgot to do so in a few cases. Let's just remove it and always explicitly get the database from the current db helper. Bug 6250673 Change-Id: Idd18fc173596c973d0ff8b6e1b2456715c0f14f8
Diffstat (limited to 'src/com/android/providers/contacts/ProfileProvider.java')
-rw-r--r--src/com/android/providers/contacts/ProfileProvider.java19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/com/android/providers/contacts/ProfileProvider.java b/src/com/android/providers/contacts/ProfileProvider.java
index d97760d6..ba10e8bd 100644
--- a/src/com/android/providers/contacts/ProfileProvider.java
+++ b/src/com/android/providers/contacts/ProfileProvider.java
@@ -81,7 +81,6 @@ public class ProfileProvider extends AbstractContactsProvider {
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
String sortOrder, CancellationSignal cancellationSignal) {
enforceReadPermission(uri);
- mDelegate.substituteDb(getDatabaseHelper().getReadableDatabase());
return mDelegate.queryLocal(uri, projection, selection, selectionArgs, sortOrder, -1,
cancellationSignal);
}
@@ -112,10 +111,8 @@ public class ProfileProvider extends AbstractContactsProvider {
public AssetFileDescriptor openAssetFile(Uri uri, String mode) throws FileNotFoundException {
if (mode != null && mode.contains("w")) {
enforceWritePermission();
- mDelegate.substituteDb(getDatabaseHelper().getWritableDatabase());
} else {
enforceReadPermission(uri);
- mDelegate.substituteDb(getDatabaseHelper().getReadableDatabase());
}
return mDelegate.openAssetFileLocal(uri, mode);
}
@@ -124,7 +121,6 @@ public class ProfileProvider extends AbstractContactsProvider {
ContactsTransaction transaction = getCurrentTransaction();
SQLiteDatabase db = getDatabaseHelper().getWritableDatabase();
transaction.startTransactionForDb(db, ContactsProvider2.PROFILE_DB_TAG, this);
- mDelegate.substituteDb(db);
}
@Override
@@ -142,20 +138,17 @@ public class ProfileProvider extends AbstractContactsProvider {
@Override
public void onBegin() {
- mDelegate.switchToProfileMode();
- mDelegate.onBegin();
+ mDelegate.onBeginTransactionInternal(true);
}
@Override
public void onCommit() {
- mDelegate.switchToProfileMode();
- mDelegate.onCommit();
+ mDelegate.onCommitTransactionInternal(true);
}
@Override
public void onRollback() {
- mDelegate.switchToProfileMode();
- mDelegate.onRollback();
+ mDelegate.onRollbackTransactionInternal(true);
}
@Override
@@ -167,4 +160,10 @@ public class ProfileProvider extends AbstractContactsProvider {
public String getType(Uri uri) {
return mDelegate.getType(uri);
}
+
+ /** Use only for debug logging */
+ @Override
+ public String toString() {
+ return "ProfileProvider";
+ }
}