diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/HkpKeyserver.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/HkpKeyserver.java index f14978b39..202b750e4 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/HkpKeyserver.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/HkpKeyserver.java @@ -200,12 +200,12 @@ public class HkpKeyserver extends Keyserver { } @Override - public ArrayList search(String query) throws QueryException, TooManyResponses, - InsufficientQuery { + public ArrayList search(String query) throws QueryException, + QueryNeedsRepairException { ArrayList results = new ArrayList(); if (query.length() < 3) { - throw new InsufficientQuery(); + throw new QueryTooShortException(); } String encodedQuery; @@ -226,9 +226,9 @@ public class HkpKeyserver extends Keyserver { if (e.getData().toLowerCase(Locale.US).contains("no keys found")) { return results; } else if (e.getData().toLowerCase(Locale.US).contains("too many")) { - throw new TooManyResponses(); + throw new TooManyResponsesException(); } else if (e.getData().toLowerCase(Locale.US).contains("insufficient")) { - throw new InsufficientQuery(); + throw new QueryTooShortException(); } } throw new QueryException("querying server(s) for '" + mHost + "' failed"); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/KeybaseKeyserver.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/KeybaseKeyserver.java index 5b66b50c5..ec4b61671 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/KeybaseKeyserver.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/KeybaseKeyserver.java @@ -34,8 +34,8 @@ public class KeybaseKeyserver extends Keyserver { private String mQuery; @Override - public ArrayList search(String query) throws QueryException, TooManyResponses, - InsufficientQuery { + public ArrayList search(String query) throws QueryException, + QueryNeedsRepairException { ArrayList results = new ArrayList(); if (query.startsWith("0x")) { @@ -84,6 +84,7 @@ public class KeybaseKeyserver extends Keyserver { } private ImportKeysListEntry makeEntry(JSONObject match) throws QueryException, JSONException { + final ImportKeysListEntry entry = new ImportKeysListEntry(); entry.setQuery(mQuery); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/Keyserver.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/Keyserver.java index 19591eda8..7313a159b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/Keyserver.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/Keyserver.java @@ -32,20 +32,23 @@ public abstract class Keyserver { } } - public static class TooManyResponses extends Exception { + public static class QueryNeedsRepairException extends Exception { + private static final long serialVersionUID = 2693768928624654512L; + } + + public static class TooManyResponsesException extends QueryNeedsRepairException { private static final long serialVersionUID = 2703768928624654513L; } - public static class InsufficientQuery extends Exception { - private static final long serialVersionUID = 2703768928624654514L; + public static class QueryTooShortException extends QueryNeedsRepairException { } public static class AddKeyException extends Exception { private static final long serialVersionUID = -507574859137295530L; } - abstract List search(String query) throws QueryException, TooManyResponses, - InsufficientQuery; + abstract List search(String query) throws QueryException, + QueryNeedsRepairException; abstract String get(String keyIdHex) throws QueryException; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java index e93d717e1..9c05dcc65 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java @@ -273,38 +273,28 @@ public class ImportKeysListFragment extends ListFragment implements break; case LOADER_ID_SERVER_QUERY: + case LOADER_ID_KEYBASE: + // TODO: possibly fine-tune message building for these two cases if (error == null) { AppMsg.makeText( getActivity(), getResources().getQuantityString(R.plurals.keys_found, mAdapter.getCount(), mAdapter.getCount()), AppMsg.STYLE_INFO ).show(); - } else if (error instanceof Keyserver.InsufficientQuery) { + } else if (error instanceof Keyserver.QueryTooShortException) { AppMsg.makeText(getActivity(), R.string.error_keyserver_insufficient_query, AppMsg.STYLE_ALERT).show(); } else if (error instanceof Keyserver.QueryException) { - AppMsg.makeText(getActivity(), R.string.error_keyserver_query, - AppMsg.STYLE_ALERT).show(); - } else if (error instanceof Keyserver.TooManyResponses) { + String alert = getActivity().getString(R.string.error_searching_keys); + alert = alert + " (" + error.getLocalizedMessage() + ")"; + AppMsg.makeText(getActivity(), alert, AppMsg.STYLE_ALERT).show(); + } else if (error instanceof Keyserver.TooManyResponsesException) { AppMsg.makeText(getActivity(), R.string.error_keyserver_too_many_responses, AppMsg.STYLE_ALERT).show(); } break; - case LOADER_ID_KEYBASE: - - if (error == null) { - AppMsg.makeText( - getActivity(), getResources().getQuantityString(R.plurals.keys_found, - mAdapter.getCount(), mAdapter.getCount()), - AppMsg.STYLE_INFO - ).show(); - } else if (error instanceof Keyserver.QueryException) { - AppMsg.makeText(getActivity(), R.string.error_keyserver_query, - AppMsg.STYLE_ALERT).show(); - } - default: break; } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListKeybaseLoader.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListKeybaseLoader.java index 0fdc019d0..3f15e64f0 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListKeybaseLoader.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListKeybaseLoader.java @@ -94,14 +94,10 @@ public class ImportKeysListKeybaseLoader mEntryList.addAll(searchResult); mEntryListWrapper = new AsyncTaskResultWrapper>(mEntryList, null); - } catch (Keyserver.InsufficientQuery e) { - mEntryListWrapper = new AsyncTaskResultWrapper>(mEntryList, e); } catch (Keyserver.QueryException e) { mEntryListWrapper = new AsyncTaskResultWrapper>(mEntryList, e); - } catch (Keyserver.TooManyResponses e) { + } catch (Keyserver.QueryNeedsRepairException e) { mEntryListWrapper = new AsyncTaskResultWrapper>(mEntryList, e); } - } - } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListServerLoader.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListServerLoader.java index 1b8d7d30e..4b2af14a9 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListServerLoader.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListServerLoader.java @@ -116,11 +116,9 @@ public class ImportKeysListServerLoader mEntryList.addAll(searchResult); } mEntryListWrapper = new AsyncTaskResultWrapper>(mEntryList, null); - } catch (Keyserver.InsufficientQuery e) { - mEntryListWrapper = new AsyncTaskResultWrapper>(mEntryList, e); } catch (Keyserver.QueryException e) { mEntryListWrapper = new AsyncTaskResultWrapper>(mEntryList, e); - } catch (Keyserver.TooManyResponses e) { + } catch (Keyserver.QueryNeedsRepairException e) { mEntryListWrapper = new AsyncTaskResultWrapper>(mEntryList, e); } } diff --git a/OpenKeychain/src/main/res/values/strings.xml b/OpenKeychain/src/main/res/values/strings.xml index 4d39b6273..1ba8a6d2d 100644 --- a/OpenKeychain/src/main/res/values/strings.xml +++ b/OpenKeychain/src/main/res/values/strings.xml @@ -295,9 +295,9 @@ You need Android 4.1 to use Android\'s NFC Beam feature! NFC is not available on your device! Nothing to import! - Insufficient server query - Querying keyserver failed - Too many possible keys. Please refine your query! + Key search query too short + Unrecoverable error searching for keys at server + Key search query returned too many candidates; Please refine query File has no content A generic error occurred, please create a new bug report for OpenKeychain.