From eda53d42de111bbba199060e77881fa044a71c7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Mon, 23 Nov 2015 11:43:44 +0100 Subject: Disable contact sync by default on Android >= 6 --- .../keychain/KeychainApplication.java | 35 +++------------------- 1 file changed, 4 insertions(+), 31 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/KeychainApplication.java') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/KeychainApplication.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/KeychainApplication.java index 5d97dac8a..f7655f569 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/KeychainApplication.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/KeychainApplication.java @@ -17,10 +17,7 @@ package org.sufficientlysecure.keychain; -import android.accounts.Account; -import android.accounts.AccountManager; import android.app.Application; -import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; @@ -28,12 +25,11 @@ import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Environment; -import android.provider.ContactsContract; -import android.widget.Toast; import org.spongycastle.jce.provider.BouncyCastleProvider; import org.sufficientlysecure.keychain.provider.KeychainDatabase; import org.sufficientlysecure.keychain.provider.TemporaryFileProvider; +import org.sufficientlysecure.keychain.service.ContactSyncAdapterService; import org.sufficientlysecure.keychain.service.KeyserverSyncAdapterService; import org.sufficientlysecure.keychain.ui.ConsolidateDialogActivity; import org.sufficientlysecure.keychain.ui.util.FormattingUtils; @@ -93,7 +89,9 @@ public class KeychainApplication extends Application { brandGlowEffect(getApplicationContext(), FormattingUtils.getColorFromAttr(getApplicationContext(), R.attr.colorPrimary)); - setupAccountAsNeeded(this); + // Add OpenKeychain account to Android to link contacts with keys and keyserver sync + KeyserverSyncAdapterService.enableKeyserverSync(this); + ContactSyncAdapterService.initContactsSync(this); // Update keyserver list as needed Preferences.getPreferences(this).upgradePreferences(this); @@ -136,31 +134,6 @@ public class KeychainApplication extends Application { } } - /** - * Add OpenKeychain account to Android to link contacts with keys and keyserver sync - */ - public static void setupAccountAsNeeded(Context context) { - try { - AccountManager manager = AccountManager.get(context); - Account[] accounts = manager.getAccountsByType(Constants.ACCOUNT_TYPE); - - if (accounts.length == 0) { - Account account = new Account(Constants.ACCOUNT_NAME, Constants.ACCOUNT_TYPE); - if (manager.addAccountExplicitly(account, null, null)) { - // for contact sync - ContentResolver.setIsSyncable(account, ContactsContract.AUTHORITY, 1); - ContentResolver.setSyncAutomatically(account, ContactsContract.AUTHORITY, true); - KeyserverSyncAdapterService.enableKeyserverSync(context); - } else { - Log.e(Constants.TAG, "Adding account failed!"); - } - } - } catch (SecurityException e) { - Log.e(Constants.TAG, "SecurityException when adding the account", e); - Toast.makeText(context, R.string.reinstall_openkeychain, Toast.LENGTH_LONG).show(); - } - } - static void brandGlowEffect(Context context, int brandColor) { // no hack on Android 5 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { -- cgit v1.2.3