summaryrefslogtreecommitdiffstats
path: root/src/com/android/providers/contacts/ContactsDatabaseHelper.java
diff options
context:
space:
mode:
authorZheng Fu <zhengfu@google.com>2015-01-07 11:35:29 -0800
committerZheng Fu <zhengfu@google.com>2015-01-30 13:23:24 -0800
commitaa7951f3147076cbcb70ec85bb4351600378806a (patch)
treeefb6369a2987caffc92bac6c25675182cbaf9349 /src/com/android/providers/contacts/ContactsDatabaseHelper.java
parent7e0ac8313f2b1dd3a0786810b22a7c7711d39e17 (diff)
downloadpackages_providers_ContactsProvider-aa7951f3147076cbcb70ec85bb4351600378806a.zip
packages_providers_ContactsProvider-aa7951f3147076cbcb70ec85bb4351600378806a.tar.gz
packages_providers_ContactsProvider-aa7951f3147076cbcb70ec85bb4351600378806a.tar.bz2
Handle DB schema migration to facilitate android contacts backup
Add backup_id column to raw_contacts table and hash_id column to data table. Add unique index on backup_id and account_id of raw_contacts table. Add index on hash_id of data table. Update the raw_contacts and data view to add the new columns. Bug: 18930508 Change-Id: I571c1115e7fb21e23b1956aaca8a80cf9d026e59
Diffstat (limited to 'src/com/android/providers/contacts/ContactsDatabaseHelper.java')
-rw-r--r--src/com/android/providers/contacts/ContactsDatabaseHelper.java39
1 files changed, 37 insertions, 2 deletions
diff --git a/src/com/android/providers/contacts/ContactsDatabaseHelper.java b/src/com/android/providers/contacts/ContactsDatabaseHelper.java
index e1a47cb..d8f9330 100644
--- a/src/com/android/providers/contacts/ContactsDatabaseHelper.java
+++ b/src/com/android/providers/contacts/ContactsDatabaseHelper.java
@@ -116,10 +116,11 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper {
* 600-699 Ice Cream Sandwich
* 700-799 Jelly Bean
* 800-899 Kitkat
- * 900-999 L
+ * 900-999 Lollipop
+ * 1000-1100 M
* </pre>
*/
- static final int DATABASE_VERSION = 910;
+ static final int DATABASE_VERSION = 1000;
public interface Tables {
public static final String CONTACTS = "contacts";
@@ -1197,6 +1198,7 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper {
RawContactsColumns.ACCOUNT_ID + " INTEGER REFERENCES " +
Tables.ACCOUNTS + "(" + AccountsColumns._ID + ")," +
RawContacts.SOURCE_ID + " TEXT," +
+ RawContacts.BACKUP_ID + " TEXT," +
RawContacts.RAW_CONTACT_IS_READ_ONLY + " INTEGER NOT NULL DEFAULT 0," +
RawContacts.VERSION + " INTEGER NOT NULL DEFAULT 1," +
RawContacts.DIRTY + " INTEGER NOT NULL DEFAULT 0," +
@@ -1245,6 +1247,12 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper {
RawContactsColumns.ACCOUNT_ID +
");");
+ db.execSQL("CREATE UNIQUE INDEX IF NOT EXISTS raw_contacts_backup_id_account_id_index ON " +
+ Tables.RAW_CONTACTS + " (" +
+ RawContacts.BACKUP_ID + ", " +
+ RawContactsColumns.ACCOUNT_ID +
+ ");");
+
db.execSQL("CREATE TABLE " + Tables.STREAM_ITEMS + " (" +
StreamItems._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
StreamItems.RAW_CONTACT_ID + " INTEGER NOT NULL, " +
@@ -1307,6 +1315,7 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper {
DataColumns.PACKAGE_ID + " INTEGER REFERENCES package(_id)," +
DataColumns.MIMETYPE_ID + " INTEGER REFERENCES mimetype(_id) NOT NULL," +
Data.RAW_CONTACT_ID + " INTEGER REFERENCES raw_contacts(_id) NOT NULL," +
+ Data.HASH_ID + " TEXT," +
Data.IS_READ_ONLY + " INTEGER NOT NULL DEFAULT 0," +
Data.IS_PRIMARY + " INTEGER NOT NULL DEFAULT 0," +
Data.IS_SUPER_PRIMARY + " INTEGER NOT NULL DEFAULT 0," +
@@ -1344,6 +1353,14 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper {
Data.DATA1 +
");");
+ /**
+ * For contact backup restore queries.
+ */
+ db.execSQL("CREATE INDEX IF NOT EXISTS data_hash_id_index ON " + Tables.DATA + " (" +
+ Data.HASH_ID +
+ ");");
+
+
// Private phone numbers table used for lookup
db.execSQL("CREATE TABLE " + Tables.PHONE_LOOKUP + " (" +
PhoneLookupColumns.DATA_ID
@@ -1883,6 +1900,7 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper {
String dataSelect = "SELECT "
+ DataColumns.CONCRETE_ID + " AS " + Data._ID + ","
+ + Data.HASH_ID + ", "
+ Data.RAW_CONTACT_ID + ", "
+ RawContactsColumns.CONCRETE_CONTACT_ID + " AS " + RawContacts.CONTACT_ID + ", "
+ syncColumns + ", "
@@ -1944,6 +1962,7 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper {
+ RawContactsColumns.PHONEBOOK_BUCKET_ALTERNATIVE + ", "
+ dbForProfile() + " AS " + RawContacts.RAW_CONTACT_IS_USER_PROFILE + ", "
+ rawContactOptionColumns + ", "
+ + RawContacts.BACKUP_ID + ", "
+ syncColumns
+ " FROM " + Tables.RAW_CONTACTS
+ " JOIN " + Tables.ACCOUNTS + " ON ("
@@ -2802,6 +2821,11 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper {
upgradeToVersion910(db);
oldVersion = 910;
}
+ if (oldVersion < 1000) {
+ upgradeToVersion1000(db);
+ upgradeViewsAndTriggers = true;
+ oldVersion = 1000;
+ }
if (upgradeViewsAndTriggers) {
createContactsViews(db);
@@ -4230,6 +4254,17 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper {
}
}
+ /**
+ * Add backup_id column to raw_contacts table and hash_id column to data table.
+ */
+ private void upgradeToVersion1000(SQLiteDatabase db) {
+ db.execSQL("ALTER TABLE raw_contacts ADD backup_id TEXT;");
+ db.execSQL("ALTER TABLE data ADD hash_id TEXT;");
+ db.execSQL("CREATE UNIQUE INDEX IF NOT EXISTS raw_contacts_backup_id_account_id_index ON " +
+ "raw_contacts (backup_id, account_id);");
+ db.execSQL("CREATE INDEX IF NOT EXISTS data_hash_id_index ON data (hash_id);");
+ }
+
public String extractHandleFromEmailAddress(String email) {
Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(email);
if (tokens.length == 0) {