diff options
author | Dominik Schürmann <dominik@dominikschuermann.de> | 2015-03-10 01:45:28 +0100 |
---|---|---|
committer | Dominik Schürmann <dominik@dominikschuermann.de> | 2015-03-10 01:45:28 +0100 |
commit | b74fa6c662ae050b4259eeef6c47cfa07a8cca0f (patch) | |
tree | acae5851013d0e5f0375bb96a1721e0afe143600 /OpenKeychain/src/main/java/org/sufficientlysecure | |
parent | bce0fe62217e1f174559354b1a0dc06fd9663385 (diff) | |
parent | 224f243c7988d2e21606d3461ae0712ceb0f1207 (diff) | |
download | open-keychain-b74fa6c662ae050b4259eeef6c47cfa07a8cca0f.tar.gz open-keychain-b74fa6c662ae050b4259eeef6c47cfa07a8cca0f.tar.bz2 open-keychain-b74fa6c662ae050b4259eeef6c47cfa07a8cca0f.zip |
Merge pull request #1121 from adithyaphilip/rawcontact-deletion
Fixed contact deletion Issue #1120
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java | 50 |
1 files changed, 47 insertions, 3 deletions
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 08c7c02fb..07144e264 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java @@ -267,6 +267,35 @@ public class ContactHelper { return null; } + /** + * returns the CONTACT_ID of the raw contact to which a masterKeyId is associated, if the + * raw contact has not been marked for deletion + * + * @param resolver + * @param masterKeyId + * @return CONTACT_ID (id of aggregated contact) linked to masterKeyId + */ + public static long findContactId(ContentResolver resolver, long masterKeyId) { + long contactId = -1; + Cursor raw = resolver.query(ContactsContract.RawContacts.CONTENT_URI, + new String[]{ + ContactsContract.RawContacts.CONTACT_ID + }, + ContactsContract.RawContacts.ACCOUNT_TYPE + "=? AND " + + ContactsContract.RawContacts.SOURCE_ID + "=? AND " + + ContactsContract.RawContacts.DELETED + "=?", + new String[]{//"0" for "not deleted" + Constants.ACCOUNT_TYPE, Long.toString(masterKeyId), "0" + }, null); + if (raw != null) { + if (raw.moveToNext()) { + contactId = raw.getLong(0); + } + raw.close(); + } + return contactId; + } + public static Bitmap getCachedPhotoByMasterKeyId(ContentResolver contentResolver, long masterKeyId) { if (masterKeyId == -1) { return null; @@ -398,8 +427,13 @@ public class ContactHelper { * TODO: Does this work? */ private static int debugDeleteRawContacts(ContentResolver resolver) { + //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(); + Log.d(Constants.TAG, "Deleting all raw contacts associated to OK..."); - return resolver.delete(ContactsContract.RawContacts.CONTENT_URI, + return resolver.delete(deleteUri, ContactsContract.RawContacts.ACCOUNT_TYPE + "=?", new String[]{ Constants.ACCOUNT_TYPE @@ -407,7 +441,12 @@ public class ContactHelper { } private static int deleteRawContactById(ContentResolver resolver, long rawContactId) { - return resolver.delete(ContactsContract.RawContacts.CONTENT_URI, + //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) @@ -415,7 +454,12 @@ public class ContactHelper { } private static int deleteRawContactByMasterKeyId(ContentResolver resolver, long masterKeyId) { - return resolver.delete(ContactsContract.RawContacts.CONTENT_URI, + //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.SOURCE_ID + "=?", new String[]{ Constants.ACCOUNT_TYPE, Long.toString(masterKeyId) |