aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service
diff options
context:
space:
mode:
authorAdithya Abraham Philip <adithyaphilip@gmail.com>2016-02-06 02:14:32 +0530
committerAdithya Abraham Philip <adithyaphilip@gmail.com>2016-02-06 02:31:44 +0530
commitd2cf56f42ed0b37f9a51418c0eefdc951abe10e5 (patch)
tree75dda98111cc15eef8fdca548bc518255f0cd705 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service
parentcbf6f15d91f53f460584d959fcd16440c9309be1 (diff)
downloadopen-keychain-d2cf56f42ed0b37f9a51418c0eefdc951abe10e5.tar.gz
open-keychain-d2cf56f42ed0b37f9a51418c0eefdc951abe10e5.tar.bz2
open-keychain-d2cf56f42ed0b37f9a51418c0eefdc951abe10e5.zip
delete linked contacts on turning off contact sync
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/ContactSyncAdapterService.java21
1 files changed, 18 insertions, 3 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/ContactSyncAdapterService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/ContactSyncAdapterService.java
index 2985c2030..4107e3167 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/ContactSyncAdapterService.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/ContactSyncAdapterService.java
@@ -18,7 +18,6 @@
package org.sufficientlysecure.keychain.service;
import android.accounts.Account;
-import android.accounts.AccountManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.AbstractThreadedSyncAdapter;
@@ -35,6 +34,7 @@ import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;
import org.sufficientlysecure.keychain.Constants;
+import org.sufficientlysecure.keychain.KeychainApplication;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.ui.SettingsActivity;
import org.sufficientlysecure.keychain.util.ContactHelper;
@@ -151,10 +151,25 @@ public class ContactSyncAdapterService extends Service {
}
public static void enableContactsSync(Context context) {
- AccountManager manager = AccountManager.get(context);
- Account account = manager.getAccountsByType(Constants.ACCOUNT_TYPE)[0];
+ Account account = KeychainApplication.createAccountIfNecessary(context);
+
+ if (account == null) {
+ // nothing we can do
+ return;
+ }
ContentResolver.setIsSyncable(account, ContactsContract.AUTHORITY, 1);
ContentResolver.setSyncAutomatically(account, ContactsContract.AUTHORITY, true);
}
+
+ public static void deleteIfSyncDisabled(Context context) {
+ Account account = KeychainApplication.createAccountIfNecessary(context);
+ if (account == null) {
+ return;
+ }
+ // if user has disabled automatic sync, delete linked OpenKeychain contacts
+ if(!ContentResolver.getSyncAutomatically(account, ContactsContract.AUTHORITY)) {
+ new ContactHelper(context).deleteAllContacts();
+ }
+ }
}