summaryrefslogtreecommitdiffstats
path: root/src/com/android/providers/contacts/ContactsDatabaseHelper.java
diff options
context:
space:
mode:
authorMakoto Onuki <omakoto@google.com>2012-01-17 12:32:12 -0800
committerMakoto Onuki <omakoto@google.com>2012-01-17 12:35:43 -0800
commit1c56fb38aab8d1beb7eb436814d991f5eea08b46 (patch)
tree10ac632e6640f5162c07460e600f6775cf12c884 /src/com/android/providers/contacts/ContactsDatabaseHelper.java
parentd915acad15363cd4efde5230531adbd9e76284ce (diff)
downloadpackages_providers_ContactsProvider-1c56fb38aab8d1beb7eb436814d991f5eea08b46.zip
packages_providers_ContactsProvider-1c56fb38aab8d1beb7eb436814d991f5eea08b46.tar.gz
packages_providers_ContactsProvider-1c56fb38aab8d1beb7eb436814d991f5eea08b46.tar.bz2
Fix crash at upgrade step 504 due to account ID cache
The account ID column didn't exist at this point, so we should skip the cache initialization. Bug 5868343 Change-Id: I5fd479f882abbce2be7bf1278656e8e4b83bc106
Diffstat (limited to 'src/com/android/providers/contacts/ContactsDatabaseHelper.java')
-rw-r--r--src/com/android/providers/contacts/ContactsDatabaseHelper.java30
1 files changed, 23 insertions, 7 deletions
diff --git a/src/com/android/providers/contacts/ContactsDatabaseHelper.java b/src/com/android/providers/contacts/ContactsDatabaseHelper.java
index ccebf05..bfa317d 100644
--- a/src/com/android/providers/contacts/ContactsDatabaseHelper.java
+++ b/src/com/android/providers/contacts/ContactsDatabaseHelper.java
@@ -787,7 +787,15 @@ import java.util.concurrent.ConcurrentHashMap;
com.android.internal.R.bool.config_use_strict_phone_number_comparation);
}
- private void refreshDatabaseCaches(SQLiteDatabase db) {
+ /**
+ * Clear all the cached database information and re-initialize it.
+ *
+ * @param db target database
+ * @param accountTableHasId {@code true} if the "accounts" table exists and has the ID column.
+ * This is normally {@code true}, but needs to be false during database upgrade until
+ * step 626, where the account ID was introduced.
+ */
+ private void refreshDatabaseCaches(SQLiteDatabase db, boolean accountTableHasId) {
mStatusUpdateDelete = null;
mStatusUpdateReplace = null;
mStatusUpdateInsert = null;
@@ -806,13 +814,21 @@ import java.util.concurrent.ConcurrentHashMap;
mAggregationModeQuery = null;
mContactInDefaultDirectoryQuery = null;
- initializeCache(db);
+ initializeCache(db, accountTableHasId);
}
- private void initializeCache(SQLiteDatabase db) {
+ /**
+ * (Re-)initialize the cached database information.
+ *
+ * @param db target database
+ * @param accountTableHasId See {@link #refreshDatabaseCaches}.
+ */
+ private void initializeCache(SQLiteDatabase db, boolean accountTableHasId) {
mMimetypeCache.clear();
mPackageCache.clear();
- refreshAccountCache(db);
+ if (accountTableHasId) {
+ refreshAccountCache(db);
+ }
// TODO: This could be optimized into one query instead of 7
// Also: We shouldn't have those fields in the first place. This should just be
@@ -829,7 +845,7 @@ import java.util.concurrent.ConcurrentHashMap;
@Override
public void onOpen(SQLiteDatabase db) {
- refreshDatabaseCaches(db);
+ refreshDatabaseCaches(db, true);
mSyncState.onDatabaseOpened(db);
@@ -3402,7 +3418,7 @@ import java.util.concurrent.ConcurrentHashMap;
}
private void upgradeToVersion504(SQLiteDatabase db) {
- initializeCache(db);
+ initializeCache(db, false);
// Find all names with prefixes and recreate display name
Cursor cursor = db.rawQuery(
@@ -3924,7 +3940,7 @@ import java.util.concurrent.ConcurrentHashMap;
db.execSQL("DELETE FROM " + Tables.DIRECTORIES + ";");
db.execSQL("DELETE FROM " + Tables.SEARCH_INDEX + ";");
- initializeCache(db);
+ initializeCache(db, true);
// Note: we are not removing reference data from Tables.NICKNAME_LOOKUP
}