diff options
author | Zheng Fu <zhengfu@google.com> | 2015-07-10 15:14:25 -0700 |
---|---|---|
committer | Zheng Fu <zhengfu@google.com> | 2015-07-10 15:50:53 -0700 |
commit | cc9ce6b1c8f9d7c4d8b4da96003ce74ccaa636cc (patch) | |
tree | 2ab50c1e2e79713c20535ff244d5520f24a56774 /src/com/android | |
parent | 5ca831dc33dfa16821647e14e377c484df823c80 (diff) | |
download | packages_providers_ContactsProvider-cc9ce6b1c8f9d7c4d8b4da96003ce74ccaa636cc.zip packages_providers_ContactsProvider-cc9ce6b1c8f9d7c4d8b4da96003ce74ccaa636cc.tar.gz packages_providers_ContactsProvider-cc9ce6b1c8f9d7c4d8b4da96003ce74ccaa636cc.tar.bz2 |
Dealing with some edge cases with soft deleted contacts.
1. Exlude soft deleted contacts for aggregator algorithm upgrade.
2. Make sure to update the contacts.name_raw_contact_id column for
soft deleted raw contact.
Bug:22378846
Change-Id: I53a48ced645f9b00b708b4b9d88518a529834f89
Diffstat (limited to 'src/com/android')
3 files changed, 11 insertions, 6 deletions
diff --git a/src/com/android/providers/contacts/ContactsProvider2.java b/src/com/android/providers/contacts/ContactsProvider2.java index 02e9c52..80f7c5b 100644 --- a/src/com/android/providers/contacts/ContactsProvider2.java +++ b/src/com/android/providers/contacts/ContactsProvider2.java @@ -3739,17 +3739,20 @@ public class ContactsProvider2 extends AbstractContactsProvider // because it's in a trigger. Consider removing trigger and replacing with java code. // This has to happen before the raw contact is deleted since it relies on the number // of raw contacts. - ContactsTableUtil.deleteContactIfSingleton(db, rawContactId); + if (ContactsTableUtil.deleteContactIfSingleton(db, rawContactId) == 0) { + mAggregator.get().updateAggregateData(mTransactionContext.get(), contactId); + } db.delete(Tables.PRESENCE, PresenceColumns.RAW_CONTACT_ID + "=" + rawContactId, null); int count = db.delete(Tables.RAW_CONTACTS, RawContacts._ID + "=" + rawContactId, null); - mAggregator.get().updateAggregateData(mTransactionContext.get(), contactId); mTransactionContext.get().markRawContactChangedOrDeletedOrInserted(rawContactId); return count; } - ContactsTableUtil.deleteContactIfSingleton(db, rawContactId); + if (ContactsTableUtil.deleteContactIfSingleton(db, rawContactId) == 0) { + mAggregator.get().updateAggregateData(mTransactionContext.get(), contactId); + } return markRawContactAsDeleted(db, rawContactId, callerIsSyncAdapter); } diff --git a/src/com/android/providers/contacts/aggregation/AbstractContactAggregator.java b/src/com/android/providers/contacts/aggregation/AbstractContactAggregator.java index cfbad32..c18c1d6 100644 --- a/src/com/android/providers/contacts/aggregation/AbstractContactAggregator.java +++ b/src/com/android/providers/contacts/aggregation/AbstractContactAggregator.java @@ -602,7 +602,8 @@ public abstract class AbstractContactAggregator { final int count; final Cursor cursor = db.rawQuery("SELECT " + RawContacts._ID + " FROM " + Tables.RAW_CONTACTS + - " WHERE " + RawContactsColumns.AGGREGATION_NEEDED + "=1", null); + " WHERE " + RawContactsColumns.AGGREGATION_NEEDED + "=1 AND " + + RawContacts.DELETED + "=0", null); try { count = cursor.getCount(); cursor.moveToPosition(-1); diff --git a/src/com/android/providers/contacts/database/ContactsTableUtil.java b/src/com/android/providers/contacts/database/ContactsTableUtil.java index dbc3d3e..bb29f90 100644 --- a/src/com/android/providers/contacts/database/ContactsTableUtil.java +++ b/src/com/android/providers/contacts/database/ContactsTableUtil.java @@ -118,7 +118,7 @@ public class ContactsTableUtil { * Delete the aggregate contact if it has no constituent raw contacts other than the supplied * one. */ - public static void deleteContactIfSingleton(SQLiteDatabase db, long rawContactId) { + public static int deleteContactIfSingleton(SQLiteDatabase db, long rawContactId) { // This query will find a contact id if the contact has a raw contacts other than the one // passed in. final String sql = "select " + ContactsContract.RawContacts.CONTACT_ID + ", count(1)" @@ -136,11 +136,12 @@ public class ContactsTableUtil { if (numRawContacts == 1) { // Only one raw contact, we can delete the parent. - deleteContact(db, contactId); + return deleteContact(db, contactId); } } } finally { MoreCloseables.closeQuietly(cursor); } + return 0; } } |