summaryrefslogtreecommitdiffstats
path: root/src/com/android/providers
diff options
context:
space:
mode:
authorDmitri Plotnikov <dplotnikov@google.com>2010-03-18 16:35:17 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2010-03-18 16:35:17 -0700
commit8ebd00a718bb868818b8dfaab10d66481a49d730 (patch)
treeedf97412529348e0356396c5b3f4b1adcf390237 /src/com/android/providers
parent26f889cf57b1dc918835eda0fcdcf5a11f566f39 (diff)
parentb2e27298ae54ec2215eadf98ecc100aedba98d1a (diff)
downloadpackages_providers_ContactsProvider-8ebd00a718bb868818b8dfaab10d66481a49d730.zip
packages_providers_ContactsProvider-8ebd00a718bb868818b8dfaab10d66481a49d730.tar.gz
packages_providers_ContactsProvider-8ebd00a718bb868818b8dfaab10d66481a49d730.tar.bz2
Merge "Storing legacy contact status in the database."
Diffstat (limited to 'src/com/android/providers')
-rw-r--r--src/com/android/providers/contacts/ContactsDatabaseHelper.java62
-rw-r--r--src/com/android/providers/contacts/ContactsProvider2.java48
2 files changed, 80 insertions, 30 deletions
diff --git a/src/com/android/providers/contacts/ContactsDatabaseHelper.java b/src/com/android/providers/contacts/ContactsDatabaseHelper.java
index 0034928..dfb88e2 100644
--- a/src/com/android/providers/contacts/ContactsDatabaseHelper.java
+++ b/src/com/android/providers/contacts/ContactsDatabaseHelper.java
@@ -73,7 +73,7 @@ import java.util.Locale;
/* package */ class ContactsDatabaseHelper extends SQLiteOpenHelper {
private static final String TAG = "ContactsDatabaseHelper";
- private static final int DATABASE_VERSION = 306;
+ private static final int DATABASE_VERSION = 307;
private static final String DATABASE_NAME = "contacts2.db";
private static final String DATABASE_PRESENCE = "presence_db";
@@ -96,6 +96,7 @@ import java.util.Locale;
public static final String CONTACT_ENTITIES = "contact_entities_view";
public static final String CONTACT_ENTITIES_RESTRICTED = "contact_entities_view_restricted";
public static final String STATUS_UPDATES = "status_updates";
+ public static final String PROPERTIES = "properties";
public static final String DATA_JOIN_MIMETYPES = "data "
+ "JOIN mimetypes ON (data.mimetype_id = mimetypes._id)";
@@ -142,6 +143,7 @@ import java.util.Locale;
public static final String GROUPS_JOIN_PACKAGES = "groups "
+ "LEFT OUTER JOIN packages ON (groups.package_id = packages._id)";
+
public static final String ACTIVITIES = "activities";
public static final String ACTIVITIES_JOIN_MIMETYPES = "activities "
@@ -442,6 +444,11 @@ import java.util.Locale;
String CONCRETE_STATUS_ICON = ALIAS + "." + StatusUpdates.STATUS_ICON;
}
+ public interface PropertiesColumns {
+ String PROPERTY_KEY = "property_key";
+ String PROPERTY_VALUE = "property_value";
+ }
+
/** In-memory cache of previously found MIME-type mappings */
private final HashMap<String, Long> mMimetypeCache = new HashMap<String, Long>();
/** In-memory cache of previously found package name mappings */
@@ -922,6 +929,11 @@ import java.util.Locale;
StatusUpdates.STATUS_ICON + " INTEGER" +
");");
+ db.execSQL("CREATE TABLE " + Tables.PROPERTIES + " (" +
+ PropertiesColumns.PROPERTY_KEY + " TEXT PRIMARY KEY, " +
+ PropertiesColumns.PROPERTY_VALUE + " TEXT " +
+ ");");
+
createContactsViews(db);
createGroupsView(db);
createContactEntitiesView(db);
@@ -1445,6 +1457,11 @@ import java.util.Locale;
oldVersion = 306;
}
+ if (oldVersion == 306) {
+ upgradeToVersion307(db);
+ oldVersion = 307;
+ }
+
if (upgradeViewsAndTriggers) {
createContactsViews(db);
createGroupsView(db);
@@ -1892,9 +1909,9 @@ import java.util.Locale;
public static final String SELECTION =
DataColumns.MIMETYPE_ID + "=?" +
- " AND " + Data._ID + " NOT IN " +
- "(SELECT " + NameLookupColumns.DATA_ID + " FROM " + Tables.NAME_LOOKUP + ")" +
- " AND " + Data.DATA1 + " NOT NULL";
+ " AND " + Data._ID + " NOT IN " +
+ "(SELECT " + NameLookupColumns.DATA_ID + " FROM " + Tables.NAME_LOOKUP + ")" +
+ " AND " + Data.DATA1 + " NOT NULL";
public static final String COLUMNS[] = {
Data._ID,
@@ -2034,6 +2051,13 @@ import java.util.Locale;
}
}
+ private void upgradeToVersion307(SQLiteDatabase db) {
+ db.execSQL("CREATE TABLE properties (" +
+ "property_key TEXT PRIMARY_KEY, " +
+ "property_value TEXT" +
+ ");");
+ }
+
private void rebuildNameLookup(SQLiteDatabase db) {
db.execSQL("DROP INDEX IF EXISTS name_lookup_index");
insertNameLookup(db);
@@ -2823,6 +2847,36 @@ import java.util.Locale;
}
/**
+ * Returns the value from the {@link Tables#PROPERTIES} table.
+ */
+ public String getProperty(String key, String defaultValue) {
+ Cursor cursor = getReadableDatabase().query(Tables.PROPERTIES,
+ new String[]{PropertiesColumns.PROPERTY_VALUE},
+ PropertiesColumns.PROPERTY_KEY + "=?",
+ new String[]{key}, null, null, null);
+ String value = null;
+ try {
+ if (cursor.moveToFirst()) {
+ value = cursor.getString(0);
+ }
+ } finally {
+ cursor.close();
+ }
+
+ return value != null ? value : defaultValue;
+ }
+
+ /**
+ * Stores a key-value pair in the {@link Tables#PROPERTIES} table.
+ */
+ public void setProperty(String key, String value) {
+ ContentValues values = new ContentValues();
+ values.put(PropertiesColumns.PROPERTY_KEY, key);
+ values.put(PropertiesColumns.PROPERTY_VALUE, value);
+ getWritableDatabase().replace(Tables.PROPERTIES, null, values);
+ }
+
+ /**
* Check if {@link Binder#getCallingUid()} should be allowed access to
* {@link RawContacts#IS_RESTRICTED} data.
*/
diff --git a/src/com/android/providers/contacts/ContactsProvider2.java b/src/com/android/providers/contacts/ContactsProvider2.java
index 68fbda7..c9cfbac 100644
--- a/src/com/android/providers/contacts/ContactsProvider2.java
+++ b/src/com/android/providers/contacts/ContactsProvider2.java
@@ -148,12 +148,12 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun
private static final int DEFAULT_MAX_SUGGESTIONS = 5;
/**
- * Shared preference key for the legacy contact import version. The need for a version
+ * Property key for the legacy contact import version. The need for a version
* as opposed to a boolean flag is that if we discover bugs in the contact import process,
* we can trigger re-import by incrementing the import version.
*/
- private static final String PREF_CONTACTS_IMPORTED = "contacts_imported_v1";
- private static final int PREF_CONTACTS_IMPORT_VERSION = 1;
+ private static final String PROPERTY_CONTACTS_IMPORTED = "contacts_imported_v1";
+ private static final int PROPERTY_CONTACTS_IMPORT_VERSION = 1;
private static final String PREF_LOCALE = "locale";
private static final String AGGREGATE_CONTACTS = "sync.contacts.aggregate";
@@ -1852,17 +1852,17 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun
mContactAggregator = new ContactAggregator(this, mDbHelper);
mContactAggregator.setEnabled(SystemProperties.getBoolean(AGGREGATE_CONTACTS, true));
- final SQLiteDatabase db = mDbHelper.getReadableDatabase();
+ mDb = mDbHelper.getWritableDatabase();
initForDefaultLocale();
- mSetPrimaryStatement = db.compileStatement(
+ mSetPrimaryStatement = mDb.compileStatement(
"UPDATE " + Tables.DATA +
" SET " + Data.IS_PRIMARY + "=(_id=?)" +
" WHERE " + DataColumns.MIMETYPE_ID + "=?" +
" AND " + Data.RAW_CONTACT_ID + "=?");
- mSetSuperPrimaryStatement = db.compileStatement(
+ mSetSuperPrimaryStatement = mDb.compileStatement(
"UPDATE " + Tables.DATA +
" SET " + Data.IS_SUPER_PRIMARY + "=(" + Data._ID + "=?)" +
" WHERE " + DataColumns.MIMETYPE_ID + "=?" +
@@ -1874,7 +1874,7 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun
" FROM " + Tables.RAW_CONTACTS +
" WHERE " + RawContacts._ID + "=?))");
- mRawContactDisplayNameUpdate = db.compileStatement(
+ mRawContactDisplayNameUpdate = mDb.compileStatement(
"UPDATE " + Tables.RAW_CONTACTS +
" SET " +
RawContacts.DISPLAY_NAME_SOURCE + "=?," +
@@ -1886,7 +1886,7 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun
RawContacts.SORT_KEY_ALTERNATIVE + "=?" +
" WHERE " + RawContacts._ID + "=?");
- mLastStatusUpdate = db.compileStatement(
+ mLastStatusUpdate = mDb.compileStatement(
"UPDATE " + Tables.CONTACTS +
" SET " + ContactsColumns.LAST_STATUS_UPDATE_ID + "=" +
"(SELECT " + DataColumns.CONCRETE_ID +
@@ -1903,14 +1903,14 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun
" LIMIT 1)" +
" WHERE " + ContactsColumns.CONCRETE_ID + "=?");
- mNameLookupInsert = db.compileStatement("INSERT OR IGNORE INTO " + Tables.NAME_LOOKUP + "("
+ mNameLookupInsert = mDb.compileStatement("INSERT OR IGNORE INTO " + Tables.NAME_LOOKUP + "("
+ NameLookupColumns.RAW_CONTACT_ID + "," + NameLookupColumns.DATA_ID + ","
+ NameLookupColumns.NAME_TYPE + "," + NameLookupColumns.NORMALIZED_NAME
+ ") VALUES (?,?,?,?)");
- mNameLookupDelete = db.compileStatement("DELETE FROM " + Tables.NAME_LOOKUP + " WHERE "
+ mNameLookupDelete = mDb.compileStatement("DELETE FROM " + Tables.NAME_LOOKUP + " WHERE "
+ NameLookupColumns.DATA_ID + "=?");
- mStatusUpdateInsert = db.compileStatement(
+ mStatusUpdateInsert = mDb.compileStatement(
"INSERT INTO " + Tables.STATUS_UPDATES + "("
+ StatusUpdatesColumns.DATA_ID + ", "
+ StatusUpdates.STATUS + ","
@@ -1919,7 +1919,7 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun
+ StatusUpdates.STATUS_LABEL + ")" +
" VALUES (?,?,?,?,?)");
- mStatusUpdateReplace = db.compileStatement(
+ mStatusUpdateReplace = mDb.compileStatement(
"INSERT OR REPLACE INTO " + Tables.STATUS_UPDATES + "("
+ StatusUpdatesColumns.DATA_ID + ", "
+ StatusUpdates.STATUS_TIMESTAMP + ","
@@ -1929,27 +1929,27 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun
+ StatusUpdates.STATUS_LABEL + ")" +
" VALUES (?,?,?,?,?,?)");
- mStatusUpdateAutoTimestamp = db.compileStatement(
+ mStatusUpdateAutoTimestamp = mDb.compileStatement(
"UPDATE " + Tables.STATUS_UPDATES +
" SET " + StatusUpdates.STATUS_TIMESTAMP + "=?,"
+ StatusUpdates.STATUS + "=?" +
" WHERE " + StatusUpdatesColumns.DATA_ID + "=?"
+ " AND " + StatusUpdates.STATUS + "!=?");
- mStatusAttributionUpdate = db.compileStatement(
+ mStatusAttributionUpdate = mDb.compileStatement(
"UPDATE " + Tables.STATUS_UPDATES +
" SET " + StatusUpdates.STATUS_RES_PACKAGE + "=?,"
+ StatusUpdates.STATUS_ICON + "=?,"
+ StatusUpdates.STATUS_LABEL + "=?" +
" WHERE " + StatusUpdatesColumns.DATA_ID + "=?");
- mStatusUpdateDelete = db.compileStatement(
+ mStatusUpdateDelete = mDb.compileStatement(
"DELETE FROM " + Tables.STATUS_UPDATES +
" WHERE " + StatusUpdatesColumns.DATA_ID + "=?");
// When setting NAME_VERIFIED to 1 on a raw contact, reset it to 0
// on all other raw contacts in the same aggregate
- mResetNameVerifiedForOtherRawContacts = db.compileStatement(
+ mResetNameVerifiedForOtherRawContacts = mDb.compileStatement(
"UPDATE " + Tables.RAW_CONTACTS +
" SET " + RawContacts.NAME_VERIFIED + "=0" +
" WHERE " + RawContacts.CONTACT_ID + "=(" +
@@ -1989,7 +1989,7 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun
importLegacyContactsAsync();
}
- return (db != null);
+ return (mDb != null);
}
/**
@@ -2088,8 +2088,8 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun
}
protected boolean isLegacyContactImportNeeded() {
- SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
- return prefs.getInt(PREF_CONTACTS_IMPORTED, 0) < PREF_CONTACTS_IMPORT_VERSION;
+ int version = Integer.parseInt(mDbHelper.getProperty(PROPERTY_CONTACTS_IMPORTED, "0"));
+ return version < PROPERTY_CONTACTS_IMPORT_VERSION;
}
protected LegacyContactImporter getLegacyContactImporter() {
@@ -2130,10 +2130,9 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun
(NotificationManager)getContext().getSystemService(Context.NOTIFICATION_SERVICE);
nm.cancel(LEGACY_IMPORT_FAILED_NOTIFICATION);
- SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
- Editor editor = prefs.edit();
- editor.putInt(PREF_CONTACTS_IMPORTED, PREF_CONTACTS_IMPORT_VERSION);
- editor.commit();
+ // Store a property in the database indicating that the conversion process succeeded
+ mDbHelper.setProperty(PROPERTY_CONTACTS_IMPORTED,
+ String.valueOf(PROPERTY_CONTACTS_IMPORT_VERSION));
setProviderStatus(ProviderStatus.STATUS_NORMAL);
mAccessLatch.countDown();
mAccessLatch = null;
@@ -3936,9 +3935,6 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun
}
public void onAccountsUpdated(Account[] accounts) {
- mDb = mDbHelper.getWritableDatabase();
- if (mDb == null) return;
-
HashSet<Account> existingAccounts = new HashSet<Account>();
boolean hasUnassignedContacts[] = new boolean[]{false};
mDb.beginTransaction();