From af8fd8db695e538de5250af8c9d0f6c19d260a01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Mon, 23 Nov 2015 12:57:26 +0100 Subject: No need to delete by raw contact id --- .../keychain/util/ContactHelper.java | 38 +++++----------------- 1 file changed, 8 insertions(+), 30 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java index 2284cc626..ab9587910 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java @@ -516,22 +516,22 @@ public class ContactHelper { deletedKeys.remove(masterKeyId); - // get raw contact to this master key id - long rawContactId = findRawContactId(resolver, masterKeyId); - Log.d(Constants.TAG, "rawContactId: " + rawContactId); - ArrayList ops = new ArrayList<>(); // Do not store expired or revoked or unverified keys in contact db - and // remove them if they already exist. Secret keys do not reach this point if (isExpired || isRevoked || !isVerified) { - Log.d(Constants.TAG, "Expired or revoked or unverified: Deleting rawContactId " - + rawContactId); - if (rawContactId != -1) { - deleteRawContactById(resolver, rawContactId); + Log.d(Constants.TAG, "Expired or revoked or unverified: Deleting masterKeyId " + + masterKeyId); + if (masterKeyId != -1) { + deleteRawContactByMasterKeyId(resolver, masterKeyId); } } else if (userIdSplit.name != null) { + // get raw contact to this master key id + long rawContactId = findRawContactId(resolver, masterKeyId); + Log.d(Constants.TAG, "rawContactId: " + rawContactId); + // Create a new rawcontact with corresponding key if it does not exist yet if (rawContactId == -1) { Log.d(Constants.TAG, "Insert new raw contact with masterKeyId " + masterKeyId); @@ -709,28 +709,6 @@ public class ContactHelper { return delete; } - /** - * Deletes raw contacts from ContactsContract.RawContacts based on rawContactId. Does not - * delete contacts from the "me" contact defined in ContactsContract.Profile - * - * @param resolver - * @param rawContactId - * @return number of rows deleted - */ - private static int deleteRawContactById(ContentResolver resolver, long rawContactId) { - // CALLER_IS_SYNCADAPTER allows us to actually wipe the RawContact from the device, otherwise - // would be just flagged for deletion - Uri deleteUri = ContactsContract.RawContacts.CONTENT_URI.buildUpon(). - appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").build(); - - return resolver.delete(deleteUri, - ContactsContract.RawContacts.ACCOUNT_TYPE + "=? AND " + - ContactsContract.RawContacts._ID + "=?", - new String[]{ - Constants.ACCOUNT_TYPE, Long.toString(rawContactId) - }); - } - /** * Deletes raw contacts from ContactsContract.RawContacts based on masterKeyId. Does not * delete contacts from the "me" contact defined in ContactsContract.Profile -- cgit v1.2.3