mirror of
https://github.com/M66B/FairEmail.git
synced 2026-03-26 19:05:23 +01:00
Debug: proxy connections
This commit is contained in:
@@ -48,8 +48,12 @@ import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.InterfaceAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.Proxy;
|
||||
import java.net.ProxySelector;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.SocketException;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.UnknownHostException;
|
||||
@@ -906,4 +910,32 @@ public class ConnectionHelper {
|
||||
Log.w(ex);
|
||||
}
|
||||
}
|
||||
|
||||
static void setupProxy(Context context) {
|
||||
if (!BuildConfig.DEBUG)
|
||||
return;
|
||||
|
||||
// https://docs.oracle.com/javase/8/docs/technotes/guides/net/proxies.html
|
||||
ProxySelector.setDefault(new ProxySelector() {
|
||||
@Override
|
||||
public List<Proxy> select(URI uri) {
|
||||
// new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("", 0));
|
||||
Log.i("PROXY uri=" + uri);
|
||||
return Arrays.asList(Proxy.NO_PROXY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectFailed(URI uri, SocketAddress sa, IOException ex) {
|
||||
Log.e("PROXY uri=" + uri + " sa=" + sa, ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static Socket getSocket(String host, int port) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
Proxy proxy = ProxySelector.getDefault().select(URI.create("socket://" + host + ":" + port)).get(0);
|
||||
return new Socket(proxy);
|
||||
} else
|
||||
return new Socket();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user