diff options
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; } } |