aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main
diff options
context:
space:
mode:
authorAdithya Abraham Philip <adithyaphilip@gmail.com>2015-03-10 03:28:12 +0530
committerAdithya Abraham Philip <adithyaphilip@gmail.com>2015-03-10 03:28:12 +0530
commit224f243c7988d2e21606d3461ae0712ceb0f1207 (patch)
tree4c7ee63a87f165218d810500c324040522f32946 /OpenKeychain/src/main
parente3547b497932a1c0219c11d586858754c82d19da (diff)
downloadopen-keychain-224f243c7988d2e21606d3461ae0712ceb0f1207.tar.gz
open-keychain-224f243c7988d2e21606d3461ae0712ceb0f1207.tar.bz2
open-keychain-224f243c7988d2e21606d3461ae0712ceb0f1207.zip
added CALLER_IS_SYNCADAPTER parameter to delete queries
Diffstat (limited to 'OpenKeychain/src/main')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java50
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)