Methods Summary |
---|
public void | connectFailed(java.net.URI uri, java.net.SocketAddress address, java.io.IOException failure)
|
private static java.util.List | parseResponse(java.lang.String response)
String[] split = response.split(";");
List<Proxy> ret = Lists.newArrayList();
for (String s : split) {
String trimmed = s.trim();
if (trimmed.equals("DIRECT")) {
ret.add(java.net.Proxy.NO_PROXY);
} else if (trimmed.startsWith(PROXY)) {
Proxy proxy = proxyFromHostPort(Type.HTTP, trimmed.substring(PROXY.length()));
if (proxy != null) {
ret.add(proxy);
}
} else if (trimmed.startsWith(SOCKS)) {
Proxy proxy = proxyFromHostPort(Type.SOCKS, trimmed.substring(SOCKS.length()));
if (proxy != null) {
ret.add(proxy);
}
}
}
if (ret.size() == 0) {
ret.add(java.net.Proxy.NO_PROXY);
}
return ret;
|
private static java.net.Proxy | proxyFromHostPort(java.net.Proxy.Type type, java.lang.String hostPortString)
try {
String[] hostPort = hostPortString.split(":");
String host = hostPort[0];
int port = Integer.parseInt(hostPort[1]);
return new Proxy(type, InetSocketAddress.createUnresolved(host, port));
} catch (NumberFormatException|ArrayIndexOutOfBoundsException e) {
Log.d(TAG, "Unable to parse proxy " + hostPortString + " " + e);
return null;
}
|
public java.util.List | select(java.net.URI uri)
if (mProxyService == null) {
mProxyService = IProxyService.Stub.asInterface(
ServiceManager.getService(PROXY_SERVICE));
}
if (mProxyService == null) {
Log.e(TAG, "select: no proxy service return NO_PROXY");
return Lists.newArrayList(java.net.Proxy.NO_PROXY);
}
String response = null;
String urlString;
try {
urlString = uri.toURL().toString();
} catch (MalformedURLException e) {
urlString = uri.getHost();
}
try {
response = mProxyService.resolvePacFile(uri.getHost(), urlString);
} catch (RemoteException e) {
e.printStackTrace();
}
if (response == null) {
return mDefaultList;
}
return parseResponse(response);
|