aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2015-03-10 04:56:51 +0100
committerVincent Breitmoser <valodim@mugenguild.com>2015-03-10 04:56:51 +0100
commit531697ffe79384f214033bd4096aa0b177e5517d (patch)
treec48bc03238a5d444f1714bb82684d962b499d076 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util
parent3b7f21d98a667abec9cb9ddf855893b3a1ffdb8b (diff)
parentb3257e0ffa53f93d550d71c1a5ffcecb4f4df0e5 (diff)
downloadopen-keychain-531697ffe79384f214033bd4096aa0b177e5517d.tar.gz
open-keychain-531697ffe79384f214033bd4096aa0b177e5517d.tar.bz2
open-keychain-531697ffe79384f214033bd4096aa0b177e5517d.zip
Merge remote-tracking branch 'origin/development' into linked-identities
Conflicts: OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyFragment.java OpenKeychain/src/main/res/layout/view_key_fragment.xml
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)