aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util
diff options
context:
space:
mode:
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java54
1 files changed, 48 insertions, 6 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..1413273e8 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;
@@ -357,7 +386,7 @@ public class ContactHelper {
// Do not store expired or revoked keys in contact db - and remove them if they already exist
if (isExpired || isRevoked) {
- Log.d(Constants.TAG, "Expired or revoked: Deleting " + rawContactId);
+ Log.d(Constants.TAG, "Expired or revoked: Deleting rawContactId " + rawContactId);
if (rawContactId != -1) {
deleteRawContactById(resolver, rawContactId);
}
@@ -394,12 +423,15 @@ public class ContactHelper {
/**
* Delete all raw contacts associated to OpenKeychain.
- * <p/>
- * 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 +439,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 +452,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)