use Proxy.NO_PROXY instead of null value for no proxy
This commit is contained in:
@@ -24,6 +24,9 @@ import java.net.Proxy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Vector;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
|
||||
/**
|
||||
* Search two or more types of server for online keys.
|
||||
*/
|
||||
@@ -31,8 +34,8 @@ public class CloudSearch {
|
||||
|
||||
private final static long SECONDS = 1000;
|
||||
|
||||
public static ArrayList<ImportKeysListEntry> search(final String query, Preferences.CloudSearchPrefs cloudPrefs,
|
||||
final Proxy proxy)
|
||||
public static ArrayList<ImportKeysListEntry> search(
|
||||
@NonNull final String query, Preferences.CloudSearchPrefs cloudPrefs, @NonNull final Proxy proxy)
|
||||
throws Keyserver.CloudSearchFailureException {
|
||||
final ArrayList<Keyserver> servers = new ArrayList<>();
|
||||
|
||||
@@ -68,7 +71,7 @@ public class CloudSearch {
|
||||
// wait for either all the searches to come back, or 10 seconds. If using proxy, wait 30 seconds.
|
||||
synchronized (results) {
|
||||
try {
|
||||
if (proxy != null) {
|
||||
if (proxy == Proxy.NO_PROXY) {
|
||||
results.wait(30 * SECONDS);
|
||||
} else {
|
||||
results.wait(10 * SECONDS);
|
||||
|
||||
@@ -46,6 +46,8 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import de.measite.minidns.Client;
|
||||
import de.measite.minidns.Question;
|
||||
import de.measite.minidns.Record;
|
||||
@@ -226,7 +228,7 @@ public class HkpKeyserver extends Keyserver {
|
||||
return client;
|
||||
}
|
||||
|
||||
private String query(String request, Proxy proxy) throws QueryFailedException, HttpError {
|
||||
private String query(String request, @NonNull Proxy proxy) throws QueryFailedException, HttpError {
|
||||
try {
|
||||
URL url = new URL(getUrlPrefix() + mHost + ":" + mPort + request);
|
||||
Log.d(Constants.TAG, "hkp keyserver query: " + url + " Proxy: " + proxy);
|
||||
@@ -243,7 +245,7 @@ public class HkpKeyserver extends Keyserver {
|
||||
} catch (IOException e) {
|
||||
Log.e(Constants.TAG, "IOException at HkpKeyserver", e);
|
||||
throw new QueryFailedException("Keyserver '" + mHost + "' is unavailable. Check your Internet connection!" +
|
||||
(proxy == null ? "" : " Using proxy " + proxy));
|
||||
(proxy == Proxy.NO_PROXY ? "" : " Using proxy " + proxy));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -373,7 +375,7 @@ public class HkpKeyserver extends Keyserver {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get(String keyIdHex, Proxy proxy) throws QueryFailedException {
|
||||
public String get(String keyIdHex, @NonNull Proxy proxy) throws QueryFailedException {
|
||||
String request = "/pks/lookup?op=get&options=mr&search=" + keyIdHex;
|
||||
Log.d(Constants.TAG, "hkp keyserver get: " + request + " using Proxy: " + proxy);
|
||||
String data;
|
||||
|
||||
@@ -133,7 +133,7 @@ public class ImportOperation extends BaseOperation<ImportKeyringParcel> {
|
||||
@NonNull
|
||||
private ImportKeyResult serialKeyRingImport(Iterator<ParcelableKeyRing> entries, int num,
|
||||
String keyServerUri, Progressable progressable,
|
||||
Proxy proxy) {
|
||||
@NonNull Proxy proxy) {
|
||||
if (progressable != null) {
|
||||
progressable.setProgress(R.string.progress_importing, 0, 100);
|
||||
}
|
||||
@@ -197,8 +197,7 @@ public class ImportOperation extends BaseOperation<ImportKeyringParcel> {
|
||||
if (entry.mExpectedFingerprint != null) {
|
||||
log.add(LogType.MSG_IMPORT_FETCH_KEYSERVER, 2, "0x" +
|
||||
entry.mExpectedFingerprint.substring(24));
|
||||
data = keyServer.get("0x" + entry.mExpectedFingerprint, proxy)
|
||||
.getBytes();
|
||||
data = keyServer.get("0x" + entry.mExpectedFingerprint, proxy).getBytes();
|
||||
} else {
|
||||
log.add(LogType.MSG_IMPORT_FETCH_KEYSERVER, 2, entry.mKeyIdHex);
|
||||
data = keyServer.get(entry.mKeyIdHex, proxy).getBytes();
|
||||
@@ -400,8 +399,7 @@ public class ImportOperation extends BaseOperation<ImportKeyringParcel> {
|
||||
return new ImportKeyResult(null,
|
||||
RequiredInputParcel.createOrbotRequiredOperation(), cryptoInput);
|
||||
}
|
||||
proxy = Preferences.getPreferences(mContext).getProxyPrefs().parcelableProxy
|
||||
.getProxy();
|
||||
proxy = Preferences.getPreferences(mContext).getProxyPrefs().getProxy();
|
||||
} else {
|
||||
proxy = cryptoInput.getParcelableProxy().getProxy();
|
||||
}
|
||||
@@ -444,8 +442,7 @@ public class ImportOperation extends BaseOperation<ImportKeyringParcel> {
|
||||
ArrayList<ParcelableKeyRing> list = new ArrayList<>();
|
||||
list.add(pkRing);
|
||||
|
||||
return serialKeyRingImport(list.iterator(), 1, keyServer,
|
||||
ignoreProgressable, proxy);
|
||||
return serialKeyRingImport(list.iterator(), 1, keyServer, ignoreProgressable, proxy);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -95,10 +95,10 @@ public class UploadOperation extends BaseOperation<UploadKeyringParcel> {
|
||||
|
||||
if (proxyIsTor) {
|
||||
log.add(LogType.MSG_UPLOAD_PROXY_TOR, 1);
|
||||
} else if (proxy != null && proxy != Proxy.NO_PROXY) {
|
||||
log.add(LogType.MSG_UPLOAD_PROXY, 1, proxy.toString());
|
||||
} else {
|
||||
} else if (proxy == Proxy.NO_PROXY) {
|
||||
log.add(LogType.MSG_UPLOAD_PROXY_DIRECT, 1);
|
||||
} else {
|
||||
log.add(LogType.MSG_UPLOAD_PROXY, 1, proxy.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,13 +17,14 @@
|
||||
|
||||
package org.sufficientlysecure.keychain.util;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Proxy;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
/**
|
||||
* used to simply transport java.net.Proxy objects created using InetSockets between services/activities
|
||||
*/
|
||||
@@ -48,10 +49,10 @@ public class ParcelableProxy implements Parcelable {
|
||||
return new ParcelableProxy(null, -1, null);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@NonNull
|
||||
public Proxy getProxy() {
|
||||
if (mProxyHost == null) {
|
||||
return null;
|
||||
return Proxy.NO_PROXY;
|
||||
}
|
||||
/*
|
||||
* InetSocketAddress.createUnresolved so we can use this method even in the main thread
|
||||
|
||||
@@ -23,6 +23,7 @@ import android.content.SharedPreferences;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
@@ -325,6 +326,7 @@ public class Preferences {
|
||||
else this.parcelableProxy = new ParcelableProxy(hostName, port, type);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Proxy getProxy() {
|
||||
return parcelableProxy.getProxy();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user