From 17181cbc19090c69d639d6ac8628581950639d09 Mon Sep 17 00:00:00 2001 From: Adithya Abraham Philip Date: Tue, 17 Mar 2015 19:07:28 +0530 Subject: contacts work on all supported api levels --- .../keychain/KeychainApplication.java | 29 ++++++++++------------ 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/KeychainApplication.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/KeychainApplication.java index a4dc12a37..d26ccbe57 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/KeychainApplication.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/KeychainApplication.java @@ -118,24 +118,21 @@ public class KeychainApplication extends Application { * @param context */ public static void setupAccountAsNeeded(Context context) { - // only enabled for Jelly Bean because we need some newer methods in our sync adapter - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { - try { - AccountManager manager = AccountManager.get(context); - Account[] accounts = manager.getAccountsByType(Constants.ACCOUNT_TYPE); - if (accounts == null || accounts.length == 0) { - Account account = new Account(Constants.ACCOUNT_NAME, Constants.ACCOUNT_TYPE); - if (manager.addAccountExplicitly(account, null, null)) { - ContentResolver.setIsSyncable(account, ContactsContract.AUTHORITY, 1); - ContentResolver.setSyncAutomatically(account, ContactsContract.AUTHORITY, true); - } else { - Log.e(Constants.TAG, "Adding account failed!"); - } + try { + AccountManager manager = AccountManager.get(context); + Account[] accounts = manager.getAccountsByType(Constants.ACCOUNT_TYPE); + if (accounts == null || accounts.length == 0) { + Account account = new Account(Constants.ACCOUNT_NAME, Constants.ACCOUNT_TYPE); + if (manager.addAccountExplicitly(account, null, null)) { + ContentResolver.setIsSyncable(account, ContactsContract.AUTHORITY, 1); + ContentResolver.setSyncAutomatically(account, ContactsContract.AUTHORITY, true); + } 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(); } + } catch (SecurityException e) { + Log.e(Constants.TAG, "SecurityException when adding the account", e); + Toast.makeText(context, R.string.reinstall_openkeychain, Toast.LENGTH_LONG).show(); } } -- cgit v1.2.3 From 74c474e3e26c428153f15b7fab6b29738e882682 Mon Sep 17 00:00:00 2001 From: Max Mertens Date: Wed, 18 Mar 2015 17:49:57 +0100 Subject: Show HKP server results first in key cloud search. Fixes #1066 --- .../sufficientlysecure/keychain/keyimport/ImportKeysList.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/ImportKeysList.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/ImportKeysList.java index 02cb502d0..ed096e9dc 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/ImportKeysList.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/ImportKeysList.java @@ -70,6 +70,7 @@ public class ImportKeysList extends ArrayList { modified = true; } + boolean incomingFromHkpServer = true; // we’re going to want to try to fetch the key from everywhere we found it, so remember // all the origins for (String origin : incoming.getOrigins()) { @@ -78,13 +79,19 @@ public class ImportKeysList extends ArrayList { // to work properly, Keybase-sourced entries need to pass along the extra if (KeybaseKeyserver.ORIGIN.equals(origin)) { existing.setExtraData(incoming.getExtraData()); + incomingFromHkpServer = false; } } + ArrayList incomingIDs = incoming.getUserIds(); ArrayList existingIDs = existing.getUserIds(); for (String incomingID : incomingIDs) { if (!existingIDs.contains(incomingID)) { - existingIDs.add(incomingID); + if (incomingFromHkpServer) { + existingIDs.add(0, incomingID); + } else { + existingIDs.add(incomingID); + } modified = true; } } -- cgit v1.2.3 From aab32b81b9b54e1a978006f33718a9525772ce53 Mon Sep 17 00:00:00 2001 From: Max Mertens Date: Wed, 18 Mar 2015 22:23:35 +0100 Subject: Added comments for server result sorting in key search --- .../org/sufficientlysecure/keychain/keyimport/ImportKeysList.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/ImportKeysList.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/ImportKeysList.java index ed096e9dc..03439228b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/ImportKeysList.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/ImportKeysList.java @@ -70,6 +70,7 @@ public class ImportKeysList extends ArrayList { modified = true; } + // keep track if this key result is from a HKP keyserver boolean incomingFromHkpServer = true; // we’re going to want to try to fetch the key from everywhere we found it, so remember // all the origins @@ -79,6 +80,7 @@ public class ImportKeysList extends ArrayList { // to work properly, Keybase-sourced entries need to pass along the extra if (KeybaseKeyserver.ORIGIN.equals(origin)) { existing.setExtraData(incoming.getExtraData()); + // one of the origins is not a HKP keyserver incomingFromHkpServer = false; } } @@ -87,6 +89,10 @@ public class ImportKeysList extends ArrayList { ArrayList existingIDs = existing.getUserIds(); for (String incomingID : incomingIDs) { if (!existingIDs.contains(incomingID)) { + // prepend HKP server results to the start of the list, + // so that the UI (for cloud key search, which is picking the first list item) + // shows the right main email address, as mail addresses returned by HKP servers + // are preferred over keybase.io IDs if (incomingFromHkpServer) { existingIDs.add(0, incomingID); } else { -- cgit v1.2.3