summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorZheng Fu <zhengfu@google.com>2014-09-04 16:26:29 -0700
committerZheng Fu <zhengfu@google.com>2014-09-15 21:22:49 +0000
commit84e66f5469168132e0ef8efc5e6f08f21608b383 (patch)
treeb8d78c89a5f02f56861d37060bce453c364ec7ea /src/com
parentc00a5e2d1d1820e11d7f3961e6e809a6954e5154 (diff)
downloadpackages_providers_ContactsProvider-84e66f5469168132e0ef8efc5e6f08f21608b383.zip
packages_providers_ContactsProvider-84e66f5469168132e0ef8efc5e6f08f21608b383.tar.gz
packages_providers_ContactsProvider-84e66f5469168132e0ef8efc5e6f08f21608b383.tar.bz2
DO NOT MERGE 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 (cherry picked from commit 96ddeddc52c85710a10cd8266c054ff1b1c5a52b)
Diffstat (limited to 'src/com')
-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}.
*