summaryrefslogtreecommitdiffstats
path: root/src/com/android/providers/contacts/aggregation
diff options
context:
space:
mode:
authorZheng Fu <zhengfu@google.com>2014-09-04 16:26:29 -0700
committerMakoto Onuki <omakoto@google.com>2014-09-10 00:17:59 +0000
commit96ddeddc52c85710a10cd8266c054ff1b1c5a52b (patch)
tree3718b98a65f84d3f90c5bc8c6513b51a42af6ac0 /src/com/android/providers/contacts/aggregation
parent7dbd8145ead7949c62ea4467a1bb00419a3f9b65 (diff)
downloadpackages_providers_ContactsProvider-96ddeddc52c85710a10cd8266c054ff1b1c5a52b.zip
packages_providers_ContactsProvider-96ddeddc52c85710a10cd8266c054ff1b1c5a52b.tar.gz
packages_providers_ContactsProvider-96ddeddc52c85710a10cd8266c054ff1b1c5a52b.tar.bz2
Remove default settings during contacts aggregation.
Set is_super_primary to 0 for all the shared mime-types's data between aggregated contacts. Bug:5080996 Change-Id: Ie65259c11d719b343f234e5fccf883491e7992a7
Diffstat (limited to 'src/com/android/providers/contacts/aggregation')
-rw-r--r--src/com/android/providers/contacts/aggregation/ContactAggregator.java53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/com/android/providers/contacts/aggregation/ContactAggregator.java b/src/com/android/providers/contacts/aggregation/ContactAggregator.java
index 390871c..e4044c2 100644
--- a/src/com/android/providers/contacts/aggregation/ContactAggregator.java
+++ b/src/com/android/providers/contacts/aggregation/ContactAggregator.java
@@ -797,6 +797,7 @@ public class ContactAggregator {
mAggregatedPresenceDelete.execute();
}
+ clearSuperPrimarySetting(db, contactId, rawContactId);
setContactIdAndMarkAggregated(rawContactId, contactId);
computeAggregateData(db, contactId, mContactUpdate);
mContactUpdate.bindLong(ContactReplaceSqlStatement.CONTACT_ID, contactId);
@@ -815,6 +816,58 @@ public class ContactAggregator {
}
/**
+ * Find out which mime-types are shared by raw contact of {@code rawContactId} and raw contacts
+ * of {@code contactId}. Clear the is_super_primary settings for these mime-types.
+ */
+ private void clearSuperPrimarySetting(SQLiteDatabase db, long contactId, long rawContactId) {
+ final String[] args = {String.valueOf(contactId), String.valueOf(rawContactId)};
+
+ // Find out which mime-types are shared by raw contact of rawContactId and raw contacts
+ // of contactId
+ int index = 0;
+ final StringBuilder mimeTypeCondition = new StringBuilder();
+ mimeTypeCondition.append(" AND " + DataColumns.MIMETYPE_ID + " IN (");
+
+ final Cursor c = db.rawQuery(
+ "SELECT DISTINCT(a." + DataColumns.MIMETYPE_ID + ")" +
+ " FROM (SELECT " + DataColumns.MIMETYPE_ID + " FROM " + Tables.DATA + " WHERE " +
+ Data.RAW_CONTACT_ID + " IN (SELECT " + RawContacts._ID + " FROM " +
+ Tables.RAW_CONTACTS + " WHERE " + RawContacts.CONTACT_ID + "=?1)) AS a" +
+ " JOIN (SELECT " + DataColumns.MIMETYPE_ID + " FROM " + Tables.DATA + " WHERE "
+ + Data.RAW_CONTACT_ID + "=?2) AS b" +
+ " ON a." + DataColumns.MIMETYPE_ID + "=b." + DataColumns.MIMETYPE_ID,
+ args);
+ try {
+ c.moveToPosition(-1);
+ while (c.moveToNext()) {
+ if (index > 0) {
+ mimeTypeCondition.append(',');
+ }
+ mimeTypeCondition.append(c.getLong((0)));
+ index++;
+ }
+ } finally {
+ c.close();
+ }
+
+ // Clear is_super_primary setting for all the mime-types exist in both raw contact
+ // of rawContactId and raw contacts of contactId
+ String superPrimaryUpdateSql = "UPDATE " + Tables.DATA +
+ " SET " + Data.IS_SUPER_PRIMARY + "=0" +
+ " WHERE (" + Data.RAW_CONTACT_ID +
+ " IN (SELECT " + RawContacts._ID + " FROM " + Tables.RAW_CONTACTS +
+ " WHERE " + RawContacts.CONTACT_ID + "=?1)" +
+ " OR " + Data.RAW_CONTACT_ID + "=?2)";
+
+ if (index > 0) {
+ mimeTypeCondition.append(')');
+ superPrimaryUpdateSql += mimeTypeCondition.toString();
+ }
+
+ db.execSQL(superPrimaryUpdateSql, args);
+ }
+
+ /**
* @return true if the raw contact of {@code rawContactId} can be joined into the existing
* contact of {@code of contactId}.
*