CloudSearch: Add error message when no source selected
This commit is contained in:
parent
d947db2569
commit
7b7efa1a73
|
@ -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,46 +51,48 @@ 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());
|
|
||||||
|
|
||||||
ArrayList<Thread> searchThreads = new ArrayList<>();
|
int numberOfServers = servers.size();
|
||||||
for (final Keyserver keyserver : servers) {
|
final ImportKeysList results = new ImportKeysList(numberOfServers);
|
||||||
Runnable r = new Runnable() {
|
|
||||||
@Override
|
if (numberOfServers > 0) {
|
||||||
public void run() {
|
ArrayList<Thread> searchThreads = new ArrayList<>();
|
||||||
try {
|
for (final Keyserver keyserver : servers) {
|
||||||
results.addAll(keyserver.search(query));
|
Runnable r = new Runnable() {
|
||||||
} catch (Keyserver.CloudSearchFailureException e) {
|
@Override
|
||||||
problems.add(e);
|
public void run() {
|
||||||
|
try {
|
||||||
|
results.addAll(keyserver.search(query));
|
||||||
|
} catch (Keyserver.CloudSearchFailureException e) {
|
||||||
|
problems.add(e);
|
||||||
|
}
|
||||||
|
results.finishedAdding(); // notifies if all searchers done
|
||||||
}
|
}
|
||||||
results.finishedAdding(); // notifies if all searchers done
|
};
|
||||||
}
|
Thread searchThread = new Thread(r);
|
||||||
};
|
searchThreads.add(searchThread);
|
||||||
Thread searchThread = new Thread(r);
|
searchThread.start();
|
||||||
searchThreads.add(searchThread);
|
|
||||||
searchThread.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
// wait for either all the searches to come back, or 10 seconds. If using proxy, wait 30 seconds.
|
|
||||||
synchronized (results) {
|
|
||||||
try {
|
|
||||||
if (proxy == Proxy.NO_PROXY) {
|
|
||||||
results.wait(30 * SECONDS);
|
|
||||||
} else {
|
|
||||||
results.wait(10 * SECONDS);
|
|
||||||
}
|
|
||||||
for (Thread thread : searchThreads) {
|
|
||||||
// kill threads that haven't returned yet
|
|
||||||
thread.interrupt();
|
|
||||||
}
|
|
||||||
} catch (InterruptedException ignored) {
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (results.outstandingSuppliers() > 0) {
|
// wait for either all the searches to come back, or 10 seconds. If using proxy, wait 30 seconds.
|
||||||
String message = "Launched " + servers.size() + " cloud searchers, but " +
|
synchronized (results) {
|
||||||
results.outstandingSuppliers() + "failed to complete.";
|
try {
|
||||||
problems.add(new Keyserver.QueryFailedException(message));
|
results.wait((proxy == Proxy.NO_PROXY ? 30 : 10) * SECONDS);
|
||||||
|
for (Thread thread : searchThreads) {
|
||||||
|
// kill threads that haven't returned yet
|
||||||
|
thread.interrupt();
|
||||||
|
}
|
||||||
|
} catch (InterruptedException ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (results.outstandingSuppliers() > 0) {
|
||||||
|
String message = "Launched " + servers.size() + " cloud searchers, but " +
|
||||||
|
results.outstandingSuppliers() + "failed to complete.";
|
||||||
|
problems.add(new Keyserver.QueryFailedException(message));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
problems.add(new Keyserver.QueryNoEnabledSourceException());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!problems.isEmpty()) {
|
if (!problems.isEmpty()) {
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -44,13 +44,14 @@ public class GetKeyResult extends InputPendingResult {
|
||||||
super(log, requiredInput, cryptoInputParcel);
|
super(log, requiredInput, cryptoInputParcel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final int RESULT_ERROR_NO_VALID_KEYS = RESULT_ERROR + (1<<4);
|
public static final int RESULT_ERROR_NO_VALID_KEYS = RESULT_ERROR + (1 << 4);
|
||||||
public static final int RESULT_ERROR_NO_PGP_PARTS = RESULT_ERROR + (2<<4);
|
public static final int RESULT_ERROR_NO_PGP_PARTS = RESULT_ERROR + (2 << 4);
|
||||||
public static final int RESULT_ERROR_QUERY_TOO_SHORT = RESULT_ERROR + (3<<4);
|
public static final int RESULT_ERROR_QUERY_TOO_SHORT = RESULT_ERROR + (3 << 4);
|
||||||
public static final int RESULT_ERROR_TOO_MANY_RESPONSES = RESULT_ERROR + (4<<4);
|
public static final int RESULT_ERROR_TOO_MANY_RESPONSES = RESULT_ERROR + (4 << 4);
|
||||||
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);
|
||||||
|
|
|
@ -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),
|
||||||
|
|
|
@ -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>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue