From 7d05a22ae5d55f3f088a2d3461d29911812a6dc1 Mon Sep 17 00:00:00 2001 From: Adithya Abraham Philip Date: Mon, 21 Dec 2015 01:28:28 +0530 Subject: fixed key update preference not turning off --- .../keychain/KeychainApplication.java | 29 ++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 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 3390fb729..57fce633e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/KeychainApplication.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/KeychainApplication.java @@ -17,6 +17,8 @@ package org.sufficientlysecure.keychain; +import android.accounts.Account; +import android.accounts.AccountManager; import android.app.Application; import android.content.Context; import android.content.Intent; @@ -25,6 +27,7 @@ import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Environment; +import android.widget.Toast; import org.spongycastle.jce.provider.BouncyCastleProvider; import org.sufficientlysecure.keychain.provider.KeychainDatabase; @@ -90,8 +93,13 @@ public class KeychainApplication extends Application { FormattingUtils.getColorFromAttr(getApplicationContext(), R.attr.colorPrimary)); // Add OpenKeychain account to Android to link contacts with keys and keyserver sync - KeyserverSyncAdapterService.enableKeyserverSync(this); - ContactSyncAdapterService.enableContactsSync(this); + createAccountIfNecessary(); + + // if first time, enable keyserver and contact sync + if (Preferences.getPreferences(this).isFirstTime()) { + KeyserverSyncAdapterService.enableKeyserverSync(this); + ContactSyncAdapterService.enableContactsSync(this); + } // Update keyserver list as needed Preferences.getPreferences(this).upgradePreferences(this); @@ -108,6 +116,23 @@ public class KeychainApplication extends Application { } } + private void createAccountIfNecessary() { + try { + AccountManager manager = AccountManager.get(this); + Account[] accounts = manager.getAccountsByType(Constants.ACCOUNT_TYPE); + + Account account = new Account(Constants.ACCOUNT_NAME, Constants.ACCOUNT_TYPE); + if (accounts.length == 0) { + if (!manager.addAccountExplicitly(account, null, null)) { + Log.d(Constants.TAG, "account already exists, the account is null, or another error occured"); + } + } + } catch (SecurityException e) { + Log.e(Constants.TAG, "SecurityException when adding the account", e); + Toast.makeText(this, R.string.reinstall_openkeychain, Toast.LENGTH_LONG).show(); + } + } + public static HashMap qrCodeCache = new HashMap<>(); @Override -- cgit v1.2.3