The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.net; |
| 18 | |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 19 | import android.annotation.SdkConstant; |
| 20 | import android.annotation.SdkConstant.SdkConstantType; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | import android.content.Context; |
Robert Greenwalt | d192dad | 2010-09-14 09:18:02 -0700 | [diff] [blame] | 22 | import android.text.TextUtils; |
Robert Greenwalt | d192dad | 2010-09-14 09:18:02 -0700 | [diff] [blame] | 23 | import android.util.Log; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | |
Jason Monk | 602b232 | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 25 | import java.net.InetSocketAddress; |
| 26 | import java.net.ProxySelector; |
| 27 | import java.net.URI; |
Narayan Kamath | 2b4378f | 2014-11-03 15:54:34 +0000 | [diff] [blame] | 28 | import java.util.List; |
Jason Monk | 602b232 | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 29 | import java.util.regex.Matcher; |
| 30 | import java.util.regex.Pattern; |
| 31 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | /** |
| 33 | * A convenience class for accessing the user and default proxy |
| 34 | * settings. |
| 35 | */ |
Oscar Montemayor | 16fb791 | 2010-08-02 09:38:48 -0700 | [diff] [blame] | 36 | public final class Proxy { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 38 | private static final String TAG = "Proxy"; |
Dave Bort | fb83907 | 2009-04-09 15:12:58 -0700 | [diff] [blame] | 39 | |
Jason Monk | 602b232 | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 40 | private static final ProxySelector sDefaultProxySelector; |
Jason Monk | 602b232 | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 41 | |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 42 | /** |
Paul Jensen | ad82342 | 2015-03-11 11:51:46 -0400 | [diff] [blame] | 43 | * Used to notify an app that's caching the proxy that either the default |
| 44 | * connection has changed or any connection's proxy has changed. The new |
| 45 | * proxy should be queried using {@link ConnectivityManager#getDefaultProxy()}. |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 46 | * |
| 47 | * <p class="note">This is a protected intent that can only be sent by the system |
| 48 | */ |
| 49 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 50 | public static final String PROXY_CHANGE_ACTION = "android.intent.action.PROXY_CHANGE"; |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 51 | /** |
| 52 | * Intent extra included with {@link #PROXY_CHANGE_ACTION} intents. |
| 53 | * It describes the new proxy being used (as a {@link ProxyInfo} object). |
Paul Jensen | ad82342 | 2015-03-11 11:51:46 -0400 | [diff] [blame] | 54 | * @deprecated Because {@code PROXY_CHANGE_ACTION} is sent whenever the proxy |
| 55 | * for any network on the system changes, applications should always use |
| 56 | * {@link ConnectivityManager#getDefaultProxy()} or |
| 57 | * {@link ConnectivityManager#getLinkProperties(Network)}.{@link LinkProperties#getHttpProxy()} |
| 58 | * to get the proxy for the Network(s) they are using. |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 59 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 60 | @Deprecated |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 61 | public static final String EXTRA_PROXY_INFO = "android.intent.extra.PROXY_INFO"; |
Oscar Montemayor | 16fb791 | 2010-08-02 09:38:48 -0700 | [diff] [blame] | 62 | |
Yuhao Zheng | 9070484 | 2014-02-28 17:22:45 -0800 | [diff] [blame] | 63 | /** @hide */ |
| 64 | public static final int PROXY_VALID = 0; |
| 65 | /** @hide */ |
| 66 | public static final int PROXY_HOSTNAME_EMPTY = 1; |
| 67 | /** @hide */ |
| 68 | public static final int PROXY_HOSTNAME_INVALID = 2; |
| 69 | /** @hide */ |
| 70 | public static final int PROXY_PORT_EMPTY = 3; |
| 71 | /** @hide */ |
| 72 | public static final int PROXY_PORT_INVALID = 4; |
| 73 | /** @hide */ |
| 74 | public static final int PROXY_EXCLLIST_INVALID = 5; |
| 75 | |
Robert Greenwalt | d192dad | 2010-09-14 09:18:02 -0700 | [diff] [blame] | 76 | private static ConnectivityManager sConnectivityManager = null; |
| 77 | |
Oscar Montemayor | 16fb791 | 2010-08-02 09:38:48 -0700 | [diff] [blame] | 78 | // Hostname / IP REGEX validation |
| 79 | // Matches blank input, ips, and domain names |
| 80 | private static final String NAME_IP_REGEX = |
| 81 | "[a-zA-Z0-9]+(\\-[a-zA-Z0-9]+)*(\\.[a-zA-Z0-9]+(\\-[a-zA-Z0-9]+)*)*"; |
| 82 | |
| 83 | private static final String HOSTNAME_REGEXP = "^$|^" + NAME_IP_REGEX + "$"; |
| 84 | |
| 85 | private static final Pattern HOSTNAME_PATTERN; |
| 86 | |
Yuhao Zheng | 3dce5af | 2014-03-03 15:47:06 -0800 | [diff] [blame] | 87 | private static final String EXCL_REGEX = |
| 88 | "[a-zA-Z0-9*]+(\\-[a-zA-Z0-9*]+)*(\\.[a-zA-Z0-9*]+(\\-[a-zA-Z0-9*]+)*)*"; |
| 89 | |
| 90 | private static final String EXCLLIST_REGEXP = "^$|^" + EXCL_REGEX + "(," + EXCL_REGEX + ")*$"; |
Oscar Montemayor | 16fb791 | 2010-08-02 09:38:48 -0700 | [diff] [blame] | 91 | |
| 92 | private static final Pattern EXCLLIST_PATTERN; |
| 93 | |
| 94 | static { |
| 95 | HOSTNAME_PATTERN = Pattern.compile(HOSTNAME_REGEXP); |
| 96 | EXCLLIST_PATTERN = Pattern.compile(EXCLLIST_REGEXP); |
Jason Monk | 602b232 | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 97 | sDefaultProxySelector = ProxySelector.getDefault(); |
Oscar Montemayor | 16fb791 | 2010-08-02 09:38:48 -0700 | [diff] [blame] | 98 | } |
| 99 | |
Oscar Montemayor | 16fb791 | 2010-08-02 09:38:48 -0700 | [diff] [blame] | 100 | /** |
| 101 | * Return the proxy object to be used for the URL given as parameter. |
| 102 | * @param ctx A Context used to get the settings for the proxy host. |
| 103 | * @param url A URL to be accessed. Used to evaluate exclusion list. |
| 104 | * @return Proxy (java.net) object containing the host name. If the |
| 105 | * user did not set a hostname it returns the default host. |
| 106 | * A null value means that no host is to be used. |
| 107 | * {@hide} |
| 108 | */ |
| 109 | public static final java.net.Proxy getProxy(Context ctx, String url) { |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 110 | String host = ""; |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 111 | if ((url != null) && !isLocalHost(host)) { |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 112 | URI uri = URI.create(url); |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 113 | ProxySelector proxySelector = ProxySelector.getDefault(); |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 114 | |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 115 | List<java.net.Proxy> proxyList = proxySelector.select(uri); |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 116 | |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 117 | if (proxyList.size() > 0) { |
| 118 | return proxyList.get(0); |
Oscar Montemayor | 16fb791 | 2010-08-02 09:38:48 -0700 | [diff] [blame] | 119 | } |
Oscar Montemayor | 16fb791 | 2010-08-02 09:38:48 -0700 | [diff] [blame] | 120 | } |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 121 | return java.net.Proxy.NO_PROXY; |
Oscar Montemayor | 16fb791 | 2010-08-02 09:38:48 -0700 | [diff] [blame] | 122 | } |
| 123 | |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 124 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | /** |
| 126 | * Return the proxy host set by the user. |
| 127 | * @param ctx A Context used to get the settings for the proxy host. |
| 128 | * @return String containing the host name. If the user did not set a host |
| 129 | * name it returns the default host. A null value means that no |
| 130 | * host is to be used. |
Robert Greenwalt | 778c0ba | 2010-12-14 11:55:36 -0800 | [diff] [blame] | 131 | * @deprecated Use standard java vm proxy values to find the host, port |
| 132 | * and exclusion list. This call ignores the exclusion list. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 133 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 134 | @Deprecated |
Oscar Montemayor | 16fb791 | 2010-08-02 09:38:48 -0700 | [diff] [blame] | 135 | public static final String getHost(Context ctx) { |
Robert Greenwalt | d192dad | 2010-09-14 09:18:02 -0700 | [diff] [blame] | 136 | java.net.Proxy proxy = getProxy(ctx, null); |
| 137 | if (proxy == java.net.Proxy.NO_PROXY) return null; |
Oscar Montemayor | 16fb791 | 2010-08-02 09:38:48 -0700 | [diff] [blame] | 138 | try { |
Robert Greenwalt | d192dad | 2010-09-14 09:18:02 -0700 | [diff] [blame] | 139 | return ((InetSocketAddress)(proxy.address())).getHostName(); |
| 140 | } catch (Exception e) { |
| 141 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Return the proxy port set by the user. |
| 147 | * @param ctx A Context used to get the settings for the proxy port. |
| 148 | * @return The port number to use or -1 if no proxy is to be used. |
Robert Greenwalt | 778c0ba | 2010-12-14 11:55:36 -0800 | [diff] [blame] | 149 | * @deprecated Use standard java vm proxy values to find the host, port |
| 150 | * and exclusion list. This call ignores the exclusion list. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 151 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 152 | @Deprecated |
Oscar Montemayor | 16fb791 | 2010-08-02 09:38:48 -0700 | [diff] [blame] | 153 | public static final int getPort(Context ctx) { |
Robert Greenwalt | d192dad | 2010-09-14 09:18:02 -0700 | [diff] [blame] | 154 | java.net.Proxy proxy = getProxy(ctx, null); |
| 155 | if (proxy == java.net.Proxy.NO_PROXY) return -1; |
Oscar Montemayor | 16fb791 | 2010-08-02 09:38:48 -0700 | [diff] [blame] | 156 | try { |
Robert Greenwalt | d192dad | 2010-09-14 09:18:02 -0700 | [diff] [blame] | 157 | return ((InetSocketAddress)(proxy.address())).getPort(); |
| 158 | } catch (Exception e) { |
| 159 | return -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | /** |
| 164 | * Return the default proxy host specified by the carrier. |
| 165 | * @return String containing the host name or null if there is no proxy for |
| 166 | * this carrier. |
Robert Greenwalt | 778c0ba | 2010-12-14 11:55:36 -0800 | [diff] [blame] | 167 | * @deprecated Use standard java vm proxy values to find the host, port and |
| 168 | * exclusion list. This call ignores the exclusion list and no |
| 169 | * longer reports only mobile-data apn-based proxy values. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 171 | @Deprecated |
Oscar Montemayor | 16fb791 | 2010-08-02 09:38:48 -0700 | [diff] [blame] | 172 | public static final String getDefaultHost() { |
Robert Greenwalt | 778c0ba | 2010-12-14 11:55:36 -0800 | [diff] [blame] | 173 | String host = System.getProperty("http.proxyHost"); |
| 174 | if (TextUtils.isEmpty(host)) return null; |
| 175 | return host; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | /** |
| 179 | * Return the default proxy port specified by the carrier. |
| 180 | * @return The port number to be used with the proxy host or -1 if there is |
| 181 | * no proxy for this carrier. |
Robert Greenwalt | 778c0ba | 2010-12-14 11:55:36 -0800 | [diff] [blame] | 182 | * @deprecated Use standard java vm proxy values to find the host, port and |
| 183 | * exclusion list. This call ignores the exclusion list and no |
| 184 | * longer reports only mobile-data apn-based proxy values. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 185 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 186 | @Deprecated |
Oscar Montemayor | 16fb791 | 2010-08-02 09:38:48 -0700 | [diff] [blame] | 187 | public static final int getDefaultPort() { |
Robert Greenwalt | 778c0ba | 2010-12-14 11:55:36 -0800 | [diff] [blame] | 188 | if (getDefaultHost() == null) return -1; |
| 189 | try { |
| 190 | return Integer.parseInt(System.getProperty("http.proxyPort")); |
| 191 | } catch (NumberFormatException e) { |
| 192 | return -1; |
| 193 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 194 | } |
| 195 | |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 196 | private static final boolean isLocalHost(String host) { |
| 197 | if (host == null) { |
Andreas Sandblad | 2986f85 | 2010-06-16 13:10:49 +0200 | [diff] [blame] | 198 | return false; |
| 199 | } |
Andreas Sandblad | 2986f85 | 2010-06-16 13:10:49 +0200 | [diff] [blame] | 200 | try { |
Andreas Sandblad | 2986f85 | 2010-06-16 13:10:49 +0200 | [diff] [blame] | 201 | if (host != null) { |
Elliott Hughes | 6b7af60 | 2010-11-04 16:46:00 -0700 | [diff] [blame] | 202 | if (host.equalsIgnoreCase("localhost")) { |
Andreas Sandblad | 2986f85 | 2010-06-16 13:10:49 +0200 | [diff] [blame] | 203 | return true; |
| 204 | } |
Robert Greenwalt | e590373 | 2011-02-22 16:00:42 -0800 | [diff] [blame] | 205 | if (NetworkUtils.numericToInetAddress(host).isLoopbackAddress()) { |
| 206 | return true; |
Elliott Hughes | 6b7af60 | 2010-11-04 16:46:00 -0700 | [diff] [blame] | 207 | } |
Andreas Sandblad | 2986f85 | 2010-06-16 13:10:49 +0200 | [diff] [blame] | 208 | } |
Andreas Sandblad | 2986f85 | 2010-06-16 13:10:49 +0200 | [diff] [blame] | 209 | } catch (IllegalArgumentException iex) { |
Andreas Sandblad | 2986f85 | 2010-06-16 13:10:49 +0200 | [diff] [blame] | 210 | } |
Andreas Sandblad | 2986f85 | 2010-06-16 13:10:49 +0200 | [diff] [blame] | 211 | return false; |
| 212 | } |
| 213 | |
Oscar Montemayor | 16fb791 | 2010-08-02 09:38:48 -0700 | [diff] [blame] | 214 | /** |
| 215 | * Validate syntax of hostname, port and exclusion list entries |
| 216 | * {@hide} |
| 217 | */ |
Yuhao Zheng | 9070484 | 2014-02-28 17:22:45 -0800 | [diff] [blame] | 218 | public static int validate(String hostname, String port, String exclList) { |
Oscar Montemayor | 16fb791 | 2010-08-02 09:38:48 -0700 | [diff] [blame] | 219 | Matcher match = HOSTNAME_PATTERN.matcher(hostname); |
| 220 | Matcher listMatch = EXCLLIST_PATTERN.matcher(exclList); |
| 221 | |
Yuhao Zheng | 9070484 | 2014-02-28 17:22:45 -0800 | [diff] [blame] | 222 | if (!match.matches()) return PROXY_HOSTNAME_INVALID; |
Oscar Montemayor | 16fb791 | 2010-08-02 09:38:48 -0700 | [diff] [blame] | 223 | |
Yuhao Zheng | 9070484 | 2014-02-28 17:22:45 -0800 | [diff] [blame] | 224 | if (!listMatch.matches()) return PROXY_EXCLLIST_INVALID; |
Oscar Montemayor | 16fb791 | 2010-08-02 09:38:48 -0700 | [diff] [blame] | 225 | |
Yuhao Zheng | 9070484 | 2014-02-28 17:22:45 -0800 | [diff] [blame] | 226 | if (hostname.length() > 0 && port.length() == 0) return PROXY_PORT_EMPTY; |
Oscar Montemayor | 16fb791 | 2010-08-02 09:38:48 -0700 | [diff] [blame] | 227 | |
| 228 | if (port.length() > 0) { |
Yuhao Zheng | 9070484 | 2014-02-28 17:22:45 -0800 | [diff] [blame] | 229 | if (hostname.length() == 0) return PROXY_HOSTNAME_EMPTY; |
Oscar Montemayor | 16fb791 | 2010-08-02 09:38:48 -0700 | [diff] [blame] | 230 | int portVal = -1; |
| 231 | try { |
| 232 | portVal = Integer.parseInt(port); |
| 233 | } catch (NumberFormatException ex) { |
Yuhao Zheng | 9070484 | 2014-02-28 17:22:45 -0800 | [diff] [blame] | 234 | return PROXY_PORT_INVALID; |
Oscar Montemayor | 16fb791 | 2010-08-02 09:38:48 -0700 | [diff] [blame] | 235 | } |
Yuhao Zheng | 9070484 | 2014-02-28 17:22:45 -0800 | [diff] [blame] | 236 | if (portVal <= 0 || portVal > 0xFFFF) return PROXY_PORT_INVALID; |
Oscar Montemayor | 16fb791 | 2010-08-02 09:38:48 -0700 | [diff] [blame] | 237 | } |
Yuhao Zheng | 9070484 | 2014-02-28 17:22:45 -0800 | [diff] [blame] | 238 | return PROXY_VALID; |
Oscar Montemayor | 16fb791 | 2010-08-02 09:38:48 -0700 | [diff] [blame] | 239 | } |
Robert Greenwalt | d192dad | 2010-09-14 09:18:02 -0700 | [diff] [blame] | 240 | |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 241 | /** @hide */ |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 242 | public static final void setHttpProxySystemProperty(ProxyInfo p) { |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 243 | String host = null; |
| 244 | String port = null; |
| 245 | String exclList = null; |
Jason Monk | 83520b9 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 246 | Uri pacFileUrl = Uri.EMPTY; |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 247 | if (p != null) { |
| 248 | host = p.getHost(); |
| 249 | port = Integer.toString(p.getPort()); |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 250 | exclList = p.getExclusionListAsString(); |
Jason Monk | 83520b9 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 251 | pacFileUrl = p.getPacFileUrl(); |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 252 | } |
Jason Monk | 602b232 | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 253 | setHttpProxySystemProperty(host, port, exclList, pacFileUrl); |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | /** @hide */ |
Jason Monk | 602b232 | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 257 | public static final void setHttpProxySystemProperty(String host, String port, String exclList, |
Jason Monk | 83520b9 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 258 | Uri pacFileUrl) { |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 259 | if (exclList != null) exclList = exclList.replace(",", "|"); |
| 260 | if (false) Log.d(TAG, "setHttpProxySystemProperty :"+host+":"+port+" - "+exclList); |
| 261 | if (host != null) { |
| 262 | System.setProperty("http.proxyHost", host); |
| 263 | System.setProperty("https.proxyHost", host); |
| 264 | } else { |
| 265 | System.clearProperty("http.proxyHost"); |
| 266 | System.clearProperty("https.proxyHost"); |
| 267 | } |
| 268 | if (port != null) { |
| 269 | System.setProperty("http.proxyPort", port); |
| 270 | System.setProperty("https.proxyPort", port); |
| 271 | } else { |
| 272 | System.clearProperty("http.proxyPort"); |
| 273 | System.clearProperty("https.proxyPort"); |
| 274 | } |
| 275 | if (exclList != null) { |
| 276 | System.setProperty("http.nonProxyHosts", exclList); |
| 277 | System.setProperty("https.nonProxyHosts", exclList); |
| 278 | } else { |
| 279 | System.clearProperty("http.nonProxyHosts"); |
| 280 | System.clearProperty("https.nonProxyHosts"); |
| 281 | } |
Jason Monk | 83520b9 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 282 | if (!Uri.EMPTY.equals(pacFileUrl)) { |
Jason Monk | 9ced3cd | 2013-08-12 16:42:38 -0400 | [diff] [blame] | 283 | ProxySelector.setDefault(new PacProxySelector()); |
Jason Monk | 602b232 | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 284 | } else { |
| 285 | ProxySelector.setDefault(sDefaultProxySelector); |
| 286 | } |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 287 | } |
Oscar Montemayor | 16fb791 | 2010-08-02 09:38:48 -0700 | [diff] [blame] | 288 | } |