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