diff options
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/ContactSyncAdapterService.java | 13 |
1 files changed, 10 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 4107e3167..cdfe2f1ce 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/ContactSyncAdapterService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/ContactSyncAdapterService.java @@ -17,6 +17,7 @@ package org.sufficientlysecure.keychain.service; +import android.Manifest; import android.accounts.Account; import android.app.PendingIntent; import android.app.Service; @@ -26,12 +27,14 @@ import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.SyncResult; +import android.content.pm.PackageManager; import android.os.Bundle; import android.os.IBinder; import android.preference.PreferenceActivity; import android.provider.ContactsContract; import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationManagerCompat; +import android.support.v4.content.ContextCompat; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.KeychainApplication; @@ -152,9 +155,7 @@ public class ContactSyncAdapterService extends Service { public static void enableContactsSync(Context context) { Account account = KeychainApplication.createAccountIfNecessary(context); - if (account == null) { - // nothing we can do return; } @@ -163,12 +164,18 @@ public class ContactSyncAdapterService extends Service { } public static void deleteIfSyncDisabled(Context context) { + if (!(ContextCompat.checkSelfPermission(context, Manifest.permission.READ_CONTACTS) + == PackageManager.PERMISSION_GRANTED)) { + return; + } + 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)) { + if (!ContentResolver.getSyncAutomatically(account, ContactsContract.AUTHORITY)) { new ContactHelper(context).deleteAllContacts(); } } |