Merge "Make unit tests not crash"
diff --git a/src/com/android/providers/contacts/ContactsDatabaseHelper.java b/src/com/android/providers/contacts/ContactsDatabaseHelper.java
index f451b2c..1f6c966 100644
--- a/src/com/android/providers/contacts/ContactsDatabaseHelper.java
+++ b/src/com/android/providers/contacts/ContactsDatabaseHelper.java
@@ -17,7 +17,6 @@
package com.android.providers.contacts;
import com.android.common.content.SyncStateContentProviderHelper;
-import com.android.providers.contacts.ContactsDatabaseHelper.DbProperties;
import com.android.providers.contacts.aggregation.util.CommonNicknameCache;
import com.android.providers.contacts.util.NeededForTesting;
import com.google.android.collect.Sets;
@@ -701,10 +700,9 @@
}
/** In-memory cache of previously found MIME-type mappings */
- // TODO Use ConcurrentHashMap?
private final HashMap<String, Long> mMimetypeCache = new HashMap<String, Long>();
- /** In-memory cache of previously found package name mappings */
- // TODO Use ConcurrentHashMap?
+
+ /** TODO Remove it */
private final HashMap<String, Long> mPackageCache = new HashMap<String, Long>();
private long mMimeTypeIdEmail;
@@ -4123,6 +4121,13 @@
}
}
+ public void invalidateAllCache() {
+ Log.w(TAG, "invalidateAllCache: [" + getClass().getSimpleName() + "]");
+
+ mMimetypeCache.clear();
+ mPackageCache.clear();
+ }
+
/**
* Gets all accounts in the accounts table.
*/
diff --git a/src/com/android/providers/contacts/ContactsProvider2.java b/src/com/android/providers/contacts/ContactsProvider2.java
index 7473718..dfbfebe 100644
--- a/src/com/android/providers/contacts/ContactsProvider2.java
+++ b/src/com/android/providers/contacts/ContactsProvider2.java
@@ -2118,7 +2118,7 @@
@Override
public void onBegin() {
if (VERBOSE_LOGGING) {
- Log.v(TAG, "onBeginTransaction");
+ Log.v(TAG, "onBeginTransaction: " + (inProfileMode() ? "profile" : "contacts"));
}
if (inProfileMode()) {
mProfileAggregator.clearPendingAggregations();
@@ -2132,7 +2132,7 @@
@Override
public void onCommit() {
if (VERBOSE_LOGGING) {
- Log.v(TAG, "beforeTransactionCommit");
+ Log.v(TAG, "beforeTransactionCommit: " + (inProfileMode() ? "profile" : "contacts"));
}
flushTransactionalChanges();
mAggregator.get().aggregateInTransaction(mTransactionContext.get(), mActiveDb.get());
@@ -2154,7 +2154,13 @@
@Override
public void onRollback() {
- // Not used.
+ if (VERBOSE_LOGGING) {
+ Log.v(TAG, "beforeTransactionRollback: " + (inProfileMode() ? "profile" : "contacts"));
+ }
+ // mDbHelper may not be pointing at the "right" db helper due to a bug,
+ // so we invalidate both for now.
+ mContactsHelper.invalidateAllCache();
+ mProfileHelper.invalidateAllCache();
}
private void updateSearchIndexInTransaction() {
diff --git a/src/com/android/providers/contacts/ProfileProvider.java b/src/com/android/providers/contacts/ProfileProvider.java
index 8aa653d..360909f 100644
--- a/src/com/android/providers/contacts/ProfileProvider.java
+++ b/src/com/android/providers/contacts/ProfileProvider.java
@@ -140,11 +140,13 @@
return mDelegate.getLocale();
}
+ @Override
public void onBegin() {
mDelegate.switchToProfileMode();
mDelegate.onBegin();
}
+ @Override
public void onCommit() {
mDelegate.switchToProfileMode();
mDelegate.onCommit();