Loading core/java/android/net/Proxy.java +71 −7 Original line number Diff line number Diff line Loading @@ -98,6 +98,61 @@ final public class Proxy { return getDefaultPort(); } /** * Return the proxy host set by the user. * @param ctx A Context used to get the settings for the proxy host. * @return String containing the host name. If the user did not set a host * name it returns the default host. A null value means that no * host is to be used. * WIFI addition by Revoked test */ static final public String getWifiHost(Context ctx) { ContentResolver contentResolver = ctx.getContentResolver(); Assert.assertNotNull(contentResolver); String host = Settings.Secure.getString( contentResolver, Settings.Secure.HTTP_PROXY_WIFI); if (host != null && !host.equals("")) { int i = host.indexOf(':'); if (i == -1) { if (DEBUG) { Assert.assertTrue(host.length() == 0); } return null; } return host.substring(0, i); } return null; } /** * Return the proxy port set by the user. * @param ctx A Context used to get the settings for the proxy port. * @return The port number to use or -1 if no proxy is to be used. * WIFI addition by Revoked test */ static final public int getWifiPort(Context ctx) { ContentResolver contentResolver = ctx.getContentResolver(); Assert.assertNotNull(contentResolver); String host = Settings.Secure.getString( contentResolver, Settings.Secure.HTTP_PROXY_WIFI); if (host != null) { int i = host.indexOf(':'); if (i == -1) { if (DEBUG) { Assert.assertTrue(host.length() == 0); } return -1; } if (DEBUG) { Assert.assertTrue(i < host.length()); } return Integer.parseInt(host.substring(i+1)); } return 0; } /** * Return the default proxy host specified by the carrier. * @return String containing the host name or null if there is no proxy for Loading Loading @@ -132,7 +187,7 @@ final public class Proxy { /** * Returns the preferred proxy to be used by clients. This is a wrapper * around {@link android.net.Proxy#getHost()}. No proxy will be returned * for localhost, and Settings.Secure.HTTP_PROXY_WIFI_ONLY will be checked * for localhost, and Settings.Secure.HTTP_PROXY_WIFI_ON will be checked * if the user is on wifi. * * @param context the context which will be passed to Loading @@ -147,14 +202,22 @@ final public class Proxy { */ static final public HttpHost getPreferredHttpHost(Context context, String url) { String proxyHost = null; int proxyPort = 0; if (!isLocalHost(url)) { if (isProxyForWifiOnly(context) && !isNetworkWifi(context)) { return null; if (!isNetworkWifi(context)) { proxyHost = Proxy.getHost(context); proxyPort = Proxy.getPort(context); } else if (isProxyForWifiOn(context) && isNetworkWifi(context)) { proxyHost = Proxy.getWifiHost(context); proxyPort = Proxy.getWifiPort(context); } final String proxyHost = Proxy.getHost(context); if (proxyHost != null) { return new HttpHost(proxyHost, Proxy.getPort(context), "http"); return new HttpHost(proxyHost, proxyPort, "http"); } } Loading Loading @@ -210,10 +273,11 @@ final public class Proxy { * @return if we should only proxy while on wifi * @hide */ static final public boolean isProxyForWifiOnly(Context ctx) { static final public boolean isProxyForWifiOn(Context ctx) { boolean ret = Settings.Secure.getInt(ctx.getContentResolver(), Settings.Secure.HTTP_PROXY_WIFI_ONLY, 1) != 0; Settings.Secure.HTTP_PROXY_WIFI_ON, 1) != 0; return ret; } }; core/java/android/provider/Settings.java +6 −2 Original line number Diff line number Diff line Loading @@ -2855,10 +2855,14 @@ public final class Settings { public static final String HTTP_PROXY = "http_proxy"; /** * If proxy should be active on wifi only * If proxy should be active on wifi * @hide */ public static final String HTTP_PROXY_WIFI_ONLY = "http_proxy_wifi_only"; public static final String HTTP_PROXY_WIFI_ON = "http_proxy_wifi_on"; /** * Initialise necessary variables for wifi proxy support. */ public static final String HTTP_PROXY_WIFI = "http_proxy_wifi"; /** * Whether the package installer should allow installation of apps downloaded from Loading Loading
core/java/android/net/Proxy.java +71 −7 Original line number Diff line number Diff line Loading @@ -98,6 +98,61 @@ final public class Proxy { return getDefaultPort(); } /** * Return the proxy host set by the user. * @param ctx A Context used to get the settings for the proxy host. * @return String containing the host name. If the user did not set a host * name it returns the default host. A null value means that no * host is to be used. * WIFI addition by Revoked test */ static final public String getWifiHost(Context ctx) { ContentResolver contentResolver = ctx.getContentResolver(); Assert.assertNotNull(contentResolver); String host = Settings.Secure.getString( contentResolver, Settings.Secure.HTTP_PROXY_WIFI); if (host != null && !host.equals("")) { int i = host.indexOf(':'); if (i == -1) { if (DEBUG) { Assert.assertTrue(host.length() == 0); } return null; } return host.substring(0, i); } return null; } /** * Return the proxy port set by the user. * @param ctx A Context used to get the settings for the proxy port. * @return The port number to use or -1 if no proxy is to be used. * WIFI addition by Revoked test */ static final public int getWifiPort(Context ctx) { ContentResolver contentResolver = ctx.getContentResolver(); Assert.assertNotNull(contentResolver); String host = Settings.Secure.getString( contentResolver, Settings.Secure.HTTP_PROXY_WIFI); if (host != null) { int i = host.indexOf(':'); if (i == -1) { if (DEBUG) { Assert.assertTrue(host.length() == 0); } return -1; } if (DEBUG) { Assert.assertTrue(i < host.length()); } return Integer.parseInt(host.substring(i+1)); } return 0; } /** * Return the default proxy host specified by the carrier. * @return String containing the host name or null if there is no proxy for Loading Loading @@ -132,7 +187,7 @@ final public class Proxy { /** * Returns the preferred proxy to be used by clients. This is a wrapper * around {@link android.net.Proxy#getHost()}. No proxy will be returned * for localhost, and Settings.Secure.HTTP_PROXY_WIFI_ONLY will be checked * for localhost, and Settings.Secure.HTTP_PROXY_WIFI_ON will be checked * if the user is on wifi. * * @param context the context which will be passed to Loading @@ -147,14 +202,22 @@ final public class Proxy { */ static final public HttpHost getPreferredHttpHost(Context context, String url) { String proxyHost = null; int proxyPort = 0; if (!isLocalHost(url)) { if (isProxyForWifiOnly(context) && !isNetworkWifi(context)) { return null; if (!isNetworkWifi(context)) { proxyHost = Proxy.getHost(context); proxyPort = Proxy.getPort(context); } else if (isProxyForWifiOn(context) && isNetworkWifi(context)) { proxyHost = Proxy.getWifiHost(context); proxyPort = Proxy.getWifiPort(context); } final String proxyHost = Proxy.getHost(context); if (proxyHost != null) { return new HttpHost(proxyHost, Proxy.getPort(context), "http"); return new HttpHost(proxyHost, proxyPort, "http"); } } Loading Loading @@ -210,10 +273,11 @@ final public class Proxy { * @return if we should only proxy while on wifi * @hide */ static final public boolean isProxyForWifiOnly(Context ctx) { static final public boolean isProxyForWifiOn(Context ctx) { boolean ret = Settings.Secure.getInt(ctx.getContentResolver(), Settings.Secure.HTTP_PROXY_WIFI_ONLY, 1) != 0; Settings.Secure.HTTP_PROXY_WIFI_ON, 1) != 0; return ret; } };
core/java/android/provider/Settings.java +6 −2 Original line number Diff line number Diff line Loading @@ -2855,10 +2855,14 @@ public final class Settings { public static final String HTTP_PROXY = "http_proxy"; /** * If proxy should be active on wifi only * If proxy should be active on wifi * @hide */ public static final String HTTP_PROXY_WIFI_ONLY = "http_proxy_wifi_only"; public static final String HTTP_PROXY_WIFI_ON = "http_proxy_wifi_on"; /** * Initialise necessary variables for wifi proxy support. */ public static final String HTTP_PROXY_WIFI = "http_proxy_wifi"; /** * Whether the package installer should allow installation of apps downloaded from Loading