CloudSearch: Add error message when no source selected

This commit is contained in:
Andrea Torlaschi
2016-07-27 22:05:42 +02:00
parent d947db2569
commit 7b7efa1a73
6 changed files with 58 additions and 46 deletions

View File

@@ -17,6 +17,8 @@
package org.sufficientlysecure.keychain.keyimport; package org.sufficientlysecure.keychain.keyimport;
import android.support.annotation.NonNull;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.Preferences; import org.sufficientlysecure.keychain.util.Preferences;
@@ -25,8 +27,6 @@ import java.net.Proxy;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Vector; import java.util.Vector;
import android.support.annotation.NonNull;
/** /**
* Search two or more types of server for online keys. * Search two or more types of server for online keys.
*/ */
@@ -37,8 +37,8 @@ public class CloudSearch {
public static ArrayList<ImportKeysListEntry> search( public static ArrayList<ImportKeysListEntry> search(
@NonNull final String query, Preferences.CloudSearchPrefs cloudPrefs, @NonNull Proxy proxy) @NonNull final String query, Preferences.CloudSearchPrefs cloudPrefs, @NonNull Proxy proxy)
throws Keyserver.CloudSearchFailureException { throws Keyserver.CloudSearchFailureException {
final ArrayList<Keyserver> servers = new ArrayList<>();
final ArrayList<Keyserver> servers = new ArrayList<>();
// it's a Vector for sync, multiple threads might report problems // it's a Vector for sync, multiple threads might report problems
final Vector<Keyserver.CloudSearchFailureException> problems = new Vector<>(); final Vector<Keyserver.CloudSearchFailureException> problems = new Vector<>();
@@ -51,8 +51,11 @@ public class CloudSearch {
if (cloudPrefs.searchFacebook) { if (cloudPrefs.searchFacebook) {
servers.add(new FacebookKeyserver(proxy)); servers.add(new FacebookKeyserver(proxy));
} }
final ImportKeysList results = new ImportKeysList(servers.size());
int numberOfServers = servers.size();
final ImportKeysList results = new ImportKeysList(numberOfServers);
if (numberOfServers > 0) {
ArrayList<Thread> searchThreads = new ArrayList<>(); ArrayList<Thread> searchThreads = new ArrayList<>();
for (final Keyserver keyserver : servers) { for (final Keyserver keyserver : servers) {
Runnable r = new Runnable() { Runnable r = new Runnable() {
@@ -74,11 +77,7 @@ public class CloudSearch {
// wait for either all the searches to come back, or 10 seconds. If using proxy, wait 30 seconds. // wait for either all the searches to come back, or 10 seconds. If using proxy, wait 30 seconds.
synchronized (results) { synchronized (results) {
try { try {
if (proxy == Proxy.NO_PROXY) { results.wait((proxy == Proxy.NO_PROXY ? 30 : 10) * SECONDS);
results.wait(30 * SECONDS);
} else {
results.wait(10 * SECONDS);
}
for (Thread thread : searchThreads) { for (Thread thread : searchThreads) {
// kill threads that haven't returned yet // kill threads that haven't returned yet
thread.interrupt(); thread.interrupt();
@@ -92,6 +91,9 @@ public class CloudSearch {
results.outstandingSuppliers() + "failed to complete."; results.outstandingSuppliers() + "failed to complete.";
problems.add(new Keyserver.QueryFailedException(message)); problems.add(new Keyserver.QueryFailedException(message));
} }
} else {
problems.add(new Keyserver.QueryNoEnabledSourceException());
}
if (!problems.isEmpty()) { if (!problems.isEmpty()) {
for (Keyserver.CloudSearchFailureException e : problems) { for (Keyserver.CloudSearchFailureException e : problems) {

View File

@@ -64,6 +64,10 @@ public abstract class Keyserver {
private static final long serialVersionUID = 2703768928624654518L; private static final long serialVersionUID = 2703768928624654518L;
} }
public static class QueryNoEnabledSourceException extends QueryNeedsRepairException {
private static final long serialVersionUID = 2703768928624654519L;
}
public static class AddKeyException extends Exception { public static class AddKeyException extends Exception {
private static final long serialVersionUID = -507574859137295530L; private static final long serialVersionUID = -507574859137295530L;
} }

View File

@@ -175,6 +175,9 @@ public class ImportKeysListCloudLoader
} else if (e instanceof Keyserver.QueryTooShortOrTooManyResponsesException) { } else if (e instanceof Keyserver.QueryTooShortOrTooManyResponsesException) {
error = GetKeyResult.RESULT_ERROR_TOO_SHORT_OR_TOO_MANY_RESPONSES; error = GetKeyResult.RESULT_ERROR_TOO_SHORT_OR_TOO_MANY_RESPONSES;
logType = OperationResult.LogType.MSG_GET_QUERY_TOO_SHORT_OR_TOO_MANY_RESPONSES; logType = OperationResult.LogType.MSG_GET_QUERY_TOO_SHORT_OR_TOO_MANY_RESPONSES;
} else if (e instanceof Keyserver.QueryNoEnabledSourceException) {
error = GetKeyResult.RESULT_ERROR_NO_ENABLED_SOURCE;
logType = OperationResult.LogType.MSG_GET_NO_ENABLED_SOURCE;
} }
OperationResult.OperationLog log = new OperationResult.OperationLog(); OperationResult.OperationLog log = new OperationResult.OperationLog();
log.add(logType, 0); log.add(logType, 0);

View File

@@ -51,6 +51,7 @@ public class GetKeyResult extends InputPendingResult {
public static final int RESULT_ERROR_TOO_SHORT_OR_TOO_MANY_RESPONSES = RESULT_ERROR + (5 << 4); public static final int RESULT_ERROR_TOO_SHORT_OR_TOO_MANY_RESPONSES = RESULT_ERROR + (5 << 4);
public static final int RESULT_ERROR_QUERY_FAILED = RESULT_ERROR + (6 << 4); public static final int RESULT_ERROR_QUERY_FAILED = RESULT_ERROR + (6 << 4);
public static final int RESULT_ERROR_FILE_NOT_FOUND = RESULT_ERROR + (7 << 4); public static final int RESULT_ERROR_FILE_NOT_FOUND = RESULT_ERROR + (7 << 4);
public static final int RESULT_ERROR_NO_ENABLED_SOURCE = RESULT_ERROR + (8 << 4);
public GetKeyResult(Parcel source) { public GetKeyResult(Parcel source) {
super(source); super(source);

View File

@@ -818,6 +818,7 @@ public abstract class OperationResult implements Parcelable {
MSG_GET_QUERY_TOO_SHORT_OR_TOO_MANY_RESPONSES (LogLevel.ERROR, R.string.msg_get_query_too_short_or_too_many_responses), MSG_GET_QUERY_TOO_SHORT_OR_TOO_MANY_RESPONSES (LogLevel.ERROR, R.string.msg_get_query_too_short_or_too_many_responses),
MSG_GET_QUERY_FAILED (LogLevel.ERROR, R.string.msg_download_query_failed), MSG_GET_QUERY_FAILED (LogLevel.ERROR, R.string.msg_download_query_failed),
MSG_GET_FILE_NOT_FOUND (LogLevel.ERROR, R.string.msg_get_file_not_found), MSG_GET_FILE_NOT_FOUND (LogLevel.ERROR, R.string.msg_get_file_not_found),
MSG_GET_NO_ENABLED_SOURCE (LogLevel.ERROR, R.string.msg_get_no_enabled_source),
MSG_DEL_ERROR_EMPTY (LogLevel.ERROR, R.string.msg_del_error_empty), MSG_DEL_ERROR_EMPTY (LogLevel.ERROR, R.string.msg_del_error_empty),
MSG_DEL_ERROR_MULTI_SECRET (LogLevel.ERROR, R.string.msg_del_error_multi_secret), MSG_DEL_ERROR_MULTI_SECRET (LogLevel.ERROR, R.string.msg_del_error_multi_secret),

View File

@@ -1440,6 +1440,7 @@
<string name="msg_get_too_many_responses">"Key search query returned too many candidates. Please refine your query!"</string> <string name="msg_get_too_many_responses">"Key search query returned too many candidates. Please refine your query!"</string>
<string name="msg_get_query_too_short">"Search query too short. Please refine your query!"</string> <string name="msg_get_query_too_short">"Search query too short. Please refine your query!"</string>
<string name="msg_get_query_too_short_or_too_many_responses">"Either no keys or too many have been found. Please improve your query!"</string> <string name="msg_get_query_too_short_or_too_many_responses">"Either no keys or too many have been found. Please improve your query!"</string>
<string name="msg_get_no_enabled_source">"Enable at least one source for downloading!"</string>
<string name="msg_download_query_failed">"An error occurred when searching for keys."</string> <string name="msg_download_query_failed">"An error occurred when searching for keys."</string>