Fields Summary |
---|
private static final boolean | DEBUG |
private static final String | TAG |
private static final ProxySelector | sDefaultProxySelector |
public static final String | PROXY_CHANGE_ACTIONUsed to notify an app that's caching the default connection proxy
that either the default connection or its proxy has changed.
The intent will have the following extra value:
- EXTRA_PROXY_INFO - The ProxyProperties for the proxy. Non-null,
though if the proxy is undefined the host string
will be empty.
This is a protected intent that can only be sent by the system |
public static final String | EXTRA_PROXY_INFOIntent extra included with {@link #PROXY_CHANGE_ACTION} intents.
It describes the new proxy being used (as a {@link ProxyInfo} object). |
public static final int | PROXY_VALID |
public static final int | PROXY_HOSTNAME_EMPTY |
public static final int | PROXY_HOSTNAME_INVALID |
public static final int | PROXY_PORT_EMPTY |
public static final int | PROXY_PORT_INVALID |
public static final int | PROXY_EXCLLIST_INVALID |
private static ConnectivityManager | sConnectivityManager |
private static final String | NAME_IP_REGEX |
private static final String | HOSTNAME_REGEXP |
private static final Pattern | HOSTNAME_PATTERN |
private static final String | EXCL_REGEX |
private static final String | EXCLLIST_REGEXP |
private static final Pattern | EXCLLIST_PATTERN |
Methods Summary |
---|
public static final java.lang.String | getDefaultHost()Return the default proxy host specified by the carrier.
String host = System.getProperty("http.proxyHost");
if (TextUtils.isEmpty(host)) return null;
return host;
|
public static final int | getDefaultPort()Return the default proxy port specified by the carrier.
if (getDefaultHost() == null) return -1;
try {
return Integer.parseInt(System.getProperty("http.proxyPort"));
} catch (NumberFormatException e) {
return -1;
}
|
public static final java.lang.String | getHost(android.content.Context ctx)Return the proxy host set by the user.
java.net.Proxy proxy = getProxy(ctx, null);
if (proxy == java.net.Proxy.NO_PROXY) return null;
try {
return ((InetSocketAddress)(proxy.address())).getHostName();
} catch (Exception e) {
return null;
}
|
public static final int | getPort(android.content.Context ctx)Return the proxy port set by the user.
java.net.Proxy proxy = getProxy(ctx, null);
if (proxy == java.net.Proxy.NO_PROXY) return -1;
try {
return ((InetSocketAddress)(proxy.address())).getPort();
} catch (Exception e) {
return -1;
}
|
public static final org.apache.http.HttpHost | getPreferredHttpHost(android.content.Context context, java.lang.String url)Returns the preferred proxy to be used by clients. This is a wrapper
around {@link android.net.Proxy#getHost()}.
java.net.Proxy prefProxy = getProxy(context, url);
if (prefProxy.equals(java.net.Proxy.NO_PROXY)) {
return null;
} else {
InetSocketAddress sa = (InetSocketAddress)prefProxy.address();
return new HttpHost(sa.getHostName(), sa.getPort(), "http");
}
|
public static final java.net.Proxy | getProxy(android.content.Context ctx, java.lang.String url)Return the proxy object to be used for the URL given as parameter.
HOSTNAME_PATTERN = Pattern.compile(HOSTNAME_REGEXP);
EXCLLIST_PATTERN = Pattern.compile(EXCLLIST_REGEXP);
sDefaultProxySelector = ProxySelector.getDefault();
String host = "";
if ((url != null) && !isLocalHost(host)) {
URI uri = URI.create(url);
ProxySelector proxySelector = ProxySelector.getDefault();
List<java.net.Proxy> proxyList = proxySelector.select(uri);
if (proxyList.size() > 0) {
return proxyList.get(0);
}
}
return java.net.Proxy.NO_PROXY;
|
private static final boolean | isLocalHost(java.lang.String host)
if (host == null) {
return false;
}
try {
if (host != null) {
if (host.equalsIgnoreCase("localhost")) {
return true;
}
if (NetworkUtils.numericToInetAddress(host).isLoopbackAddress()) {
return true;
}
}
} catch (IllegalArgumentException iex) {
}
return false;
|
public static final void | setHttpProxySystemProperty(java.lang.String host, java.lang.String port, java.lang.String exclList, Uri pacFileUrl)
if (exclList != null) exclList = exclList.replace(",", "|");
if (false) Log.d(TAG, "setHttpProxySystemProperty :"+host+":"+port+" - "+exclList);
if (host != null) {
System.setProperty("http.proxyHost", host);
System.setProperty("https.proxyHost", host);
} else {
System.clearProperty("http.proxyHost");
System.clearProperty("https.proxyHost");
}
if (port != null) {
System.setProperty("http.proxyPort", port);
System.setProperty("https.proxyPort", port);
} else {
System.clearProperty("http.proxyPort");
System.clearProperty("https.proxyPort");
}
if (exclList != null) {
System.setProperty("http.nonProxyHosts", exclList);
System.setProperty("https.nonProxyHosts", exclList);
} else {
System.clearProperty("http.nonProxyHosts");
System.clearProperty("https.nonProxyHosts");
}
if (!Uri.EMPTY.equals(pacFileUrl)) {
ProxySelector.setDefault(new PacProxySelector());
} else {
ProxySelector.setDefault(sDefaultProxySelector);
}
|
public static final void | setHttpProxySystemProperty(ProxyInfo p)
String host = null;
String port = null;
String exclList = null;
Uri pacFileUrl = Uri.EMPTY;
if (p != null) {
host = p.getHost();
port = Integer.toString(p.getPort());
exclList = p.getExclusionListAsString();
pacFileUrl = p.getPacFileUrl();
}
setHttpProxySystemProperty(host, port, exclList, pacFileUrl);
|
public static int | validate(java.lang.String hostname, java.lang.String port, java.lang.String exclList)Validate syntax of hostname, port and exclusion list entries
{@hide}
Matcher match = HOSTNAME_PATTERN.matcher(hostname);
Matcher listMatch = EXCLLIST_PATTERN.matcher(exclList);
if (!match.matches()) return PROXY_HOSTNAME_INVALID;
if (!listMatch.matches()) return PROXY_EXCLLIST_INVALID;
if (hostname.length() > 0 && port.length() == 0) return PROXY_PORT_EMPTY;
if (port.length() > 0) {
if (hostname.length() == 0) return PROXY_HOSTNAME_EMPTY;
int portVal = -1;
try {
portVal = Integer.parseInt(port);
} catch (NumberFormatException ex) {
return PROXY_PORT_INVALID;
}
if (portVal <= 0 || portVal > 0xFFFF) return PROXY_PORT_INVALID;
}
return PROXY_VALID;
|