Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1 | /* |
Wink Saville | 6e80997 | 2010-09-21 09:15:35 -0700 | [diff] [blame] | 2 | * Copyright (C) 2010 The Android Open Source Project |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 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 | |
| 19 | |
Mathew Inwood | 53f089f | 2018-08-08 14:44:44 +0100 | [diff] [blame] | 20 | import android.annotation.UnsupportedAppUsage; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 21 | import android.os.Parcel; |
| 22 | import android.os.Parcelable; |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 23 | import android.text.TextUtils; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 24 | |
Robert Greenwalt | 70af574 | 2010-09-03 13:02:05 -0700 | [diff] [blame] | 25 | import java.net.InetSocketAddress; |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 26 | import java.net.URLConnection; |
| 27 | import java.util.List; |
Elliott Hughes | cb64d43 | 2013-08-02 10:00:44 -0700 | [diff] [blame] | 28 | import java.util.Locale; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 29 | |
| 30 | /** |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 31 | * Describes a proxy configuration. |
| 32 | * |
Narayan Kamath | 3bdd327 | 2014-11-27 18:17:35 +0000 | [diff] [blame] | 33 | * Proxy configurations are already integrated within the {@code java.net} and |
| 34 | * Apache HTTP stack. So {@link URLConnection} and Apache's {@code HttpClient} will use |
| 35 | * them automatically. |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 36 | * |
| 37 | * Other HTTP stacks will need to obtain the proxy info from |
| 38 | * {@link Proxy#PROXY_CHANGE_ACTION} broadcast as the extra {@link Proxy#EXTRA_PROXY_INFO}. |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 39 | */ |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 40 | public class ProxyInfo implements Parcelable { |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 41 | |
Irina Dumitrescu | 18622d3 | 2018-12-05 16:19:47 +0000 | [diff] [blame] | 42 | private final String mHost; |
| 43 | private final int mPort; |
| 44 | private final String mExclusionList; |
| 45 | private final String[] mParsedExclusionList; |
| 46 | private final Uri mPacFileUrl; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 47 | |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 48 | /** |
| 49 | *@hide |
| 50 | */ |
Jason Monk | 602b232 | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 51 | public static final String LOCAL_EXCL_LIST = ""; |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 52 | /** |
| 53 | *@hide |
| 54 | */ |
Jason Monk | 6f8a68f | 2013-08-23 19:21:25 -0400 | [diff] [blame] | 55 | public static final int LOCAL_PORT = -1; |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 56 | /** |
| 57 | *@hide |
| 58 | */ |
Jason Monk | 602b232 | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 59 | public static final String LOCAL_HOST = "localhost"; |
| 60 | |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 61 | /** |
| 62 | * Constructs a {@link ProxyInfo} object that points at a Direct proxy |
| 63 | * on the specified host and port. |
| 64 | */ |
| 65 | public static ProxyInfo buildDirectProxy(String host, int port) { |
| 66 | return new ProxyInfo(host, port, null); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Constructs a {@link ProxyInfo} object that points at a Direct proxy |
| 71 | * on the specified host and port. |
| 72 | * |
| 73 | * The proxy will not be used to access any host in exclusion list, exclList. |
| 74 | * |
| 75 | * @param exclList Hosts to exclude using the proxy on connections for. These |
| 76 | * hosts can use wildcards such as *.example.com. |
| 77 | */ |
| 78 | public static ProxyInfo buildDirectProxy(String host, int port, List<String> exclList) { |
| 79 | String[] array = exclList.toArray(new String[exclList.size()]); |
| 80 | return new ProxyInfo(host, port, TextUtils.join(",", array), array); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Construct a {@link ProxyInfo} that will download and run the PAC script |
| 85 | * at the specified URL. |
| 86 | */ |
| 87 | public static ProxyInfo buildPacProxy(Uri pacUri) { |
Jason Monk | 83520b9 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 88 | return new ProxyInfo(pacUri); |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Create a ProxyProperties that points at a HTTP Proxy. |
| 93 | * @hide |
| 94 | */ |
Mathew Inwood | 53f089f | 2018-08-08 14:44:44 +0100 | [diff] [blame] | 95 | @UnsupportedAppUsage |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 96 | public ProxyInfo(String host, int port, String exclList) { |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 97 | mHost = host; |
| 98 | mPort = port; |
Irina Dumitrescu | 18622d3 | 2018-12-05 16:19:47 +0000 | [diff] [blame] | 99 | mExclusionList = exclList; |
| 100 | mParsedExclusionList = parseExclusionList(mExclusionList); |
Jason Monk | 83520b9 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 101 | mPacFileUrl = Uri.EMPTY; |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Create a ProxyProperties that points at a PAC URL. |
| 106 | * @hide |
| 107 | */ |
| 108 | public ProxyInfo(Uri pacFileUrl) { |
| 109 | mHost = LOCAL_HOST; |
| 110 | mPort = LOCAL_PORT; |
Irina Dumitrescu | 18622d3 | 2018-12-05 16:19:47 +0000 | [diff] [blame] | 111 | mExclusionList = LOCAL_EXCL_LIST; |
| 112 | mParsedExclusionList = parseExclusionList(mExclusionList); |
Jason Monk | 83520b9 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 113 | if (pacFileUrl == null) { |
| 114 | throw new NullPointerException(); |
| 115 | } |
| 116 | mPacFileUrl = pacFileUrl; |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 119 | /** |
| 120 | * Create a ProxyProperties that points at a PAC URL. |
| 121 | * @hide |
| 122 | */ |
| 123 | public ProxyInfo(String pacFileUrl) { |
Jason Monk | 602b232 | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 124 | mHost = LOCAL_HOST; |
| 125 | mPort = LOCAL_PORT; |
Irina Dumitrescu | 18622d3 | 2018-12-05 16:19:47 +0000 | [diff] [blame] | 126 | mExclusionList = LOCAL_EXCL_LIST; |
| 127 | mParsedExclusionList = parseExclusionList(mExclusionList); |
Jason Monk | 83520b9 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 128 | mPacFileUrl = Uri.parse(pacFileUrl); |
Jason Monk | 602b232 | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 129 | } |
| 130 | |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 131 | /** |
| 132 | * Only used in PacManager after Local Proxy is bound. |
| 133 | * @hide |
| 134 | */ |
Jason Monk | 83520b9 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 135 | public ProxyInfo(Uri pacFileUrl, int localProxyPort) { |
Jason Monk | 6f8a68f | 2013-08-23 19:21:25 -0400 | [diff] [blame] | 136 | mHost = LOCAL_HOST; |
| 137 | mPort = localProxyPort; |
Irina Dumitrescu | 18622d3 | 2018-12-05 16:19:47 +0000 | [diff] [blame] | 138 | mExclusionList = LOCAL_EXCL_LIST; |
| 139 | mParsedExclusionList = parseExclusionList(mExclusionList); |
Jason Monk | 83520b9 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 140 | if (pacFileUrl == null) { |
| 141 | throw new NullPointerException(); |
| 142 | } |
Jason Monk | 6f8a68f | 2013-08-23 19:21:25 -0400 | [diff] [blame] | 143 | mPacFileUrl = pacFileUrl; |
| 144 | } |
| 145 | |
Irina Dumitrescu | 18622d3 | 2018-12-05 16:19:47 +0000 | [diff] [blame] | 146 | private static String[] parseExclusionList(String exclusionList) { |
| 147 | if (exclusionList == null) { |
| 148 | return new String[0]; |
| 149 | } else { |
| 150 | return exclusionList.toLowerCase(Locale.ROOT).split(","); |
| 151 | } |
| 152 | } |
| 153 | |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 154 | private ProxyInfo(String host, int port, String exclList, String[] parsedExclList) { |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 155 | mHost = host; |
| 156 | mPort = port; |
| 157 | mExclusionList = exclList; |
| 158 | mParsedExclusionList = parsedExclList; |
Jason Monk | 83520b9 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 159 | mPacFileUrl = Uri.EMPTY; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 162 | // copy constructor instead of clone |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 163 | /** |
| 164 | * @hide |
| 165 | */ |
| 166 | public ProxyInfo(ProxyInfo source) { |
Irfan Sheriff | ef6c143 | 2010-08-30 20:37:17 -0700 | [diff] [blame] | 167 | if (source != null) { |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 168 | mHost = source.getHost(); |
| 169 | mPort = source.getPort(); |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 170 | mPacFileUrl = source.mPacFileUrl; |
| 171 | mExclusionList = source.getExclusionListAsString(); |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 172 | mParsedExclusionList = source.mParsedExclusionList; |
Sreeram Ramachandran | 4696ee4 | 2014-05-14 14:45:00 -0700 | [diff] [blame] | 173 | } else { |
Irina Dumitrescu | 18622d3 | 2018-12-05 16:19:47 +0000 | [diff] [blame] | 174 | mHost = null; |
| 175 | mPort = 0; |
| 176 | mExclusionList = null; |
| 177 | mParsedExclusionList = null; |
Sreeram Ramachandran | 4696ee4 | 2014-05-14 14:45:00 -0700 | [diff] [blame] | 178 | mPacFileUrl = Uri.EMPTY; |
Irfan Sheriff | ef6c143 | 2010-08-30 20:37:17 -0700 | [diff] [blame] | 179 | } |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 182 | /** |
| 183 | * @hide |
| 184 | */ |
Robert Greenwalt | 70af574 | 2010-09-03 13:02:05 -0700 | [diff] [blame] | 185 | public InetSocketAddress getSocketAddress() { |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 186 | InetSocketAddress inetSocketAddress = null; |
| 187 | try { |
| 188 | inetSocketAddress = new InetSocketAddress(mHost, mPort); |
| 189 | } catch (IllegalArgumentException e) { } |
| 190 | return inetSocketAddress; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 191 | } |
Andrew Stadler | ac19f24 | 2010-08-31 14:28:58 -0700 | [diff] [blame] | 192 | |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 193 | /** |
| 194 | * Returns the URL of the current PAC script or null if there is |
| 195 | * no PAC script. |
| 196 | */ |
| 197 | public Uri getPacFileUrl() { |
Jason Monk | 83520b9 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 198 | return mPacFileUrl; |
Jason Monk | 602b232 | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 199 | } |
| 200 | |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 201 | /** |
| 202 | * When configured to use a Direct Proxy this returns the host |
| 203 | * of the proxy. |
| 204 | */ |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 205 | public String getHost() { |
| 206 | return mHost; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 209 | /** |
| 210 | * When configured to use a Direct Proxy this returns the port |
| 211 | * of the proxy |
| 212 | */ |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 213 | public int getPort() { |
| 214 | return mPort; |
| 215 | } |
| 216 | |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 217 | /** |
| 218 | * When configured to use a Direct Proxy this returns the list |
| 219 | * of hosts for which the proxy is ignored. |
| 220 | */ |
| 221 | public String[] getExclusionList() { |
| 222 | return mParsedExclusionList; |
| 223 | } |
| 224 | |
| 225 | /** |
| 226 | * comma separated |
| 227 | * @hide |
| 228 | */ |
| 229 | public String getExclusionListAsString() { |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 230 | return mExclusionList; |
| 231 | } |
Andrew Stadler | ac19f24 | 2010-08-31 14:28:58 -0700 | [diff] [blame] | 232 | |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 233 | /** |
| 234 | * @hide |
| 235 | */ |
Raj Mamadgi | 92d02491 | 2013-11-11 13:52:58 -0800 | [diff] [blame] | 236 | public boolean isValid() { |
Jason Monk | 83520b9 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 237 | if (!Uri.EMPTY.equals(mPacFileUrl)) return true; |
Yuhao Zheng | 9070484 | 2014-02-28 17:22:45 -0800 | [diff] [blame] | 238 | return Proxy.PROXY_VALID == Proxy.validate(mHost == null ? "" : mHost, |
Irina Dumitrescu | 18622d3 | 2018-12-05 16:19:47 +0000 | [diff] [blame] | 239 | mPort == 0 ? "" : Integer.toString(mPort), |
| 240 | mExclusionList == null ? "" : mExclusionList); |
Raj Mamadgi | 92d02491 | 2013-11-11 13:52:58 -0800 | [diff] [blame] | 241 | } |
| 242 | |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 243 | /** |
| 244 | * @hide |
| 245 | */ |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 246 | public java.net.Proxy makeProxy() { |
| 247 | java.net.Proxy proxy = java.net.Proxy.NO_PROXY; |
| 248 | if (mHost != null) { |
| 249 | try { |
| 250 | InetSocketAddress inetSocketAddress = new InetSocketAddress(mHost, mPort); |
| 251 | proxy = new java.net.Proxy(java.net.Proxy.Type.HTTP, inetSocketAddress); |
| 252 | } catch (IllegalArgumentException e) { |
| 253 | } |
| 254 | } |
| 255 | return proxy; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Wink Saville | 1f6408a | 2010-08-27 11:15:18 -0700 | [diff] [blame] | 258 | @Override |
| 259 | public String toString() { |
| 260 | StringBuilder sb = new StringBuilder(); |
Jason Monk | 83520b9 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 261 | if (!Uri.EMPTY.equals(mPacFileUrl)) { |
Jason Monk | 602b232 | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 262 | sb.append("PAC Script: "); |
| 263 | sb.append(mPacFileUrl); |
Paul Jensen | e0bef71 | 2014-12-10 15:12:18 -0500 | [diff] [blame] | 264 | } |
| 265 | if (mHost != null) { |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 266 | sb.append("["); |
| 267 | sb.append(mHost); |
| 268 | sb.append("] "); |
| 269 | sb.append(Integer.toString(mPort)); |
Robert Greenwalt | f6682b0 | 2010-09-01 09:12:38 -0700 | [diff] [blame] | 270 | if (mExclusionList != null) { |
Irina Dumitrescu | 18622d3 | 2018-12-05 16:19:47 +0000 | [diff] [blame] | 271 | sb.append(" xl=").append(mExclusionList); |
Robert Greenwalt | f6682b0 | 2010-09-01 09:12:38 -0700 | [diff] [blame] | 272 | } |
Wink Saville | c9acde9 | 2011-09-21 11:05:43 -0700 | [diff] [blame] | 273 | } else { |
| 274 | sb.append("[ProxyProperties.mHost == null]"); |
Robert Greenwalt | f6682b0 | 2010-09-01 09:12:38 -0700 | [diff] [blame] | 275 | } |
Wink Saville | 1f6408a | 2010-08-27 11:15:18 -0700 | [diff] [blame] | 276 | return sb.toString(); |
| 277 | } |
| 278 | |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 279 | @Override |
| 280 | public boolean equals(Object o) { |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 281 | if (!(o instanceof ProxyInfo)) return false; |
| 282 | ProxyInfo p = (ProxyInfo)o; |
Jason Monk | 602b232 | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 283 | // If PAC URL is present in either then they must be equal. |
| 284 | // Other parameters will only be for fall back. |
Jason Monk | 83520b9 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 285 | if (!Uri.EMPTY.equals(mPacFileUrl)) { |
Jason Monk | decd295 | 2013-10-10 14:02:51 -0400 | [diff] [blame] | 286 | return mPacFileUrl.equals(p.getPacFileUrl()) && mPort == p.mPort; |
Jason Monk | 602b232 | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 287 | } |
Jason Monk | 83520b9 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 288 | if (!Uri.EMPTY.equals(p.mPacFileUrl)) { |
Jason Monk | 602b232 | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 289 | return false; |
| 290 | } |
Jason Monk | 83520b9 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 291 | if (mExclusionList != null && !mExclusionList.equals(p.getExclusionListAsString())) { |
| 292 | return false; |
| 293 | } |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 294 | if (mHost != null && p.getHost() != null && mHost.equals(p.getHost()) == false) { |
| 295 | return false; |
| 296 | } |
| 297 | if (mHost != null && p.mHost == null) return false; |
| 298 | if (mHost == null && p.mHost != null) return false; |
| 299 | if (mPort != p.mPort) return false; |
| 300 | return true; |
| 301 | } |
| 302 | |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 303 | /** |
| 304 | * Implement the Parcelable interface |
| 305 | * @hide |
| 306 | */ |
| 307 | public int describeContents() { |
| 308 | return 0; |
| 309 | } |
| 310 | |
John Wang | 4e90009 | 2011-04-04 12:35:42 -0700 | [diff] [blame] | 311 | @Override |
| 312 | /* |
| 313 | * generate hashcode based on significant fields |
| 314 | */ |
| 315 | public int hashCode() { |
| 316 | return ((null == mHost) ? 0 : mHost.hashCode()) |
Irina Dumitrescu | 18622d3 | 2018-12-05 16:19:47 +0000 | [diff] [blame] | 317 | + ((null == mExclusionList) ? 0 : mExclusionList.hashCode()) |
| 318 | + mPort; |
John Wang | 4e90009 | 2011-04-04 12:35:42 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 321 | /** |
| 322 | * Implement the Parcelable interface. |
| 323 | * @hide |
| 324 | */ |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 325 | public void writeToParcel(Parcel dest, int flags) { |
Jason Monk | 83520b9 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 326 | if (!Uri.EMPTY.equals(mPacFileUrl)) { |
Jason Monk | 602b232 | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 327 | dest.writeByte((byte)1); |
Jason Monk | 83520b9 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 328 | mPacFileUrl.writeToParcel(dest, 0); |
Jason Monk | decd295 | 2013-10-10 14:02:51 -0400 | [diff] [blame] | 329 | dest.writeInt(mPort); |
Jason Monk | 602b232 | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 330 | return; |
| 331 | } else { |
| 332 | dest.writeByte((byte)0); |
| 333 | } |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 334 | if (mHost != null) { |
Irfan Sheriff | 798ffa1 | 2010-09-26 14:54:54 -0700 | [diff] [blame] | 335 | dest.writeByte((byte)1); |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 336 | dest.writeString(mHost); |
| 337 | dest.writeInt(mPort); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 338 | } else { |
| 339 | dest.writeByte((byte)0); |
| 340 | } |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 341 | dest.writeString(mExclusionList); |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 342 | dest.writeStringArray(mParsedExclusionList); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 343 | } |
| 344 | |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 345 | public static final Creator<ProxyInfo> CREATOR = |
| 346 | new Creator<ProxyInfo>() { |
| 347 | public ProxyInfo createFromParcel(Parcel in) { |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 348 | String host = null; |
| 349 | int port = 0; |
Jason Monk | 602b232 | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 350 | if (in.readByte() != 0) { |
Jason Monk | 83520b9 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 351 | Uri url = Uri.CREATOR.createFromParcel(in); |
Jason Monk | decd295 | 2013-10-10 14:02:51 -0400 | [diff] [blame] | 352 | int localPort = in.readInt(); |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 353 | return new ProxyInfo(url, localPort); |
Jason Monk | 602b232 | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 354 | } |
| 355 | if (in.readByte() != 0) { |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 356 | host = in.readString(); |
| 357 | port = in.readInt(); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 358 | } |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 359 | String exclList = in.readString(); |
| 360 | String[] parsedExclList = in.readStringArray(); |
Irina Dumitrescu | 18622d3 | 2018-12-05 16:19:47 +0000 | [diff] [blame] | 361 | ProxyInfo proxyProperties = new ProxyInfo(host, port, exclList, parsedExclList); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 362 | return proxyProperties; |
| 363 | } |
| 364 | |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 365 | public ProxyInfo[] newArray(int size) { |
| 366 | return new ProxyInfo[size]; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 367 | } |
| 368 | }; |
Andrew Stadler | ac19f24 | 2010-08-31 14:28:58 -0700 | [diff] [blame] | 369 | } |