Robert Greenwalt | a7dfbd3 | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1 | /* |
Wink Saville | 1746543 | 2010-09-21 09:15:35 -0700 | [diff] [blame] | 2 | * Copyright (C) 2010 The Android Open Source Project |
Robert Greenwalt | a7dfbd3 | 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 | |
Aaron Huang | fb8581a | 2019-10-02 23:37:02 +0800 | [diff] [blame] | 19 | import android.annotation.NonNull; |
| 20 | import android.annotation.Nullable; |
Artur Satayev | 9c2add6 | 2019-12-10 17:47:52 +0000 | [diff] [blame] | 21 | import android.compat.annotation.UnsupportedAppUsage; |
Robert Greenwalt | a7dfbd3 | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 22 | import android.os.Parcel; |
| 23 | import android.os.Parcelable; |
Robert Greenwalt | c3c5f86 | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 24 | import android.text.TextUtils; |
Robert Greenwalt | a7dfbd3 | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 25 | |
Chiachang Wang | ab9f017 | 2021-02-05 17:33:53 +0800 | [diff] [blame] | 26 | import com.android.net.module.util.ProxyUtils; |
| 27 | |
Robert Greenwalt | 98f4583 | 2010-09-03 13:02:05 -0700 | [diff] [blame] | 28 | import java.net.InetSocketAddress; |
Jason Monk | 4d5e20f | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 29 | import java.net.URLConnection; |
| 30 | import java.util.List; |
Elliott Hughes | 4e34759 | 2013-08-02 10:00:44 -0700 | [diff] [blame] | 31 | import java.util.Locale; |
Robert Greenwalt | a7dfbd3 | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 32 | |
| 33 | /** |
Jason Monk | 4d5e20f | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 34 | * Describes a proxy configuration. |
| 35 | * |
Narayan Kamath | 9a87ca5 | 2014-11-27 18:17:35 +0000 | [diff] [blame] | 36 | * Proxy configurations are already integrated within the {@code java.net} and |
| 37 | * Apache HTTP stack. So {@link URLConnection} and Apache's {@code HttpClient} will use |
| 38 | * them automatically. |
Jason Monk | 4d5e20f | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 39 | * |
| 40 | * Other HTTP stacks will need to obtain the proxy info from |
| 41 | * {@link Proxy#PROXY_CHANGE_ACTION} broadcast as the extra {@link Proxy#EXTRA_PROXY_INFO}. |
Robert Greenwalt | a7dfbd3 | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 42 | */ |
Jason Monk | 4d5e20f | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 43 | public class ProxyInfo implements Parcelable { |
Robert Greenwalt | a7dfbd3 | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 44 | |
Irina Dumitrescu | 8767f41 | 2018-12-05 16:19:47 +0000 | [diff] [blame] | 45 | private final String mHost; |
| 46 | private final int mPort; |
| 47 | private final String mExclusionList; |
| 48 | private final String[] mParsedExclusionList; |
| 49 | private final Uri mPacFileUrl; |
Robert Greenwalt | a7dfbd3 | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 50 | |
Jason Monk | 4d5e20f | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 51 | /** |
| 52 | *@hide |
| 53 | */ |
Jason Monk | a5bf284 | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 54 | public static final String LOCAL_EXCL_LIST = ""; |
Jason Monk | 4d5e20f | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 55 | /** |
| 56 | *@hide |
| 57 | */ |
Jason Monk | 0a9cc50 | 2013-08-23 19:21:25 -0400 | [diff] [blame] | 58 | public static final int LOCAL_PORT = -1; |
Jason Monk | 4d5e20f | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 59 | /** |
| 60 | *@hide |
| 61 | */ |
Jason Monk | a5bf284 | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 62 | public static final String LOCAL_HOST = "localhost"; |
| 63 | |
Jason Monk | 4d5e20f | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 64 | /** |
| 65 | * Constructs a {@link ProxyInfo} object that points at a Direct proxy |
| 66 | * on the specified host and port. |
| 67 | */ |
| 68 | public static ProxyInfo buildDirectProxy(String host, int port) { |
| 69 | return new ProxyInfo(host, port, null); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Constructs a {@link ProxyInfo} object that points at a Direct proxy |
| 74 | * on the specified host and port. |
| 75 | * |
| 76 | * The proxy will not be used to access any host in exclusion list, exclList. |
| 77 | * |
| 78 | * @param exclList Hosts to exclude using the proxy on connections for. These |
| 79 | * hosts can use wildcards such as *.example.com. |
| 80 | */ |
| 81 | public static ProxyInfo buildDirectProxy(String host, int port, List<String> exclList) { |
| 82 | String[] array = exclList.toArray(new String[exclList.size()]); |
| 83 | return new ProxyInfo(host, port, TextUtils.join(",", array), array); |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Construct a {@link ProxyInfo} that will download and run the PAC script |
| 88 | * at the specified URL. |
| 89 | */ |
| 90 | public static ProxyInfo buildPacProxy(Uri pacUri) { |
Jason Monk | 19c6561 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 91 | return new ProxyInfo(pacUri); |
Jason Monk | 4d5e20f | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | /** |
Aaron Huang | fb8581a | 2019-10-02 23:37:02 +0800 | [diff] [blame] | 95 | * Construct a {@link ProxyInfo} object that will download and run the PAC script at the |
| 96 | * specified URL and port. |
| 97 | */ |
| 98 | @NonNull |
| 99 | public static ProxyInfo buildPacProxy(@NonNull Uri pacUrl, int port) { |
| 100 | return new ProxyInfo(pacUrl, port); |
| 101 | } |
| 102 | |
| 103 | /** |
Jason Monk | 4d5e20f | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 104 | * Create a ProxyProperties that points at a HTTP Proxy. |
| 105 | * @hide |
| 106 | */ |
Mathew Inwood | 5857479 | 2018-08-08 14:44:44 +0100 | [diff] [blame] | 107 | @UnsupportedAppUsage |
Jason Monk | 4d5e20f | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 108 | public ProxyInfo(String host, int port, String exclList) { |
Robert Greenwalt | c3c5f86 | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 109 | mHost = host; |
| 110 | mPort = port; |
Irina Dumitrescu | 8767f41 | 2018-12-05 16:19:47 +0000 | [diff] [blame] | 111 | mExclusionList = exclList; |
| 112 | mParsedExclusionList = parseExclusionList(mExclusionList); |
Jason Monk | 19c6561 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 113 | mPacFileUrl = Uri.EMPTY; |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Create a ProxyProperties that points at a PAC URL. |
| 118 | * @hide |
| 119 | */ |
Aaron Huang | fb8581a | 2019-10-02 23:37:02 +0800 | [diff] [blame] | 120 | public ProxyInfo(@NonNull Uri pacFileUrl) { |
Jason Monk | 19c6561 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 121 | mHost = LOCAL_HOST; |
| 122 | mPort = LOCAL_PORT; |
Irina Dumitrescu | 8767f41 | 2018-12-05 16:19:47 +0000 | [diff] [blame] | 123 | mExclusionList = LOCAL_EXCL_LIST; |
| 124 | mParsedExclusionList = parseExclusionList(mExclusionList); |
Jason Monk | 19c6561 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 125 | if (pacFileUrl == null) { |
| 126 | throw new NullPointerException(); |
| 127 | } |
| 128 | mPacFileUrl = pacFileUrl; |
Robert Greenwalt | c3c5f86 | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 129 | } |
| 130 | |
Jason Monk | 4d5e20f | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 131 | /** |
Aaron Huang | f9fa0b9 | 2021-01-18 15:28:01 +0800 | [diff] [blame] | 132 | * Only used in PacProxyService after Local Proxy is bound. |
Jason Monk | 4d5e20f | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 133 | * @hide |
| 134 | */ |
Aaron Huang | fb8581a | 2019-10-02 23:37:02 +0800 | [diff] [blame] | 135 | public ProxyInfo(@NonNull Uri pacFileUrl, int localProxyPort) { |
Jason Monk | 0a9cc50 | 2013-08-23 19:21:25 -0400 | [diff] [blame] | 136 | mHost = LOCAL_HOST; |
| 137 | mPort = localProxyPort; |
Irina Dumitrescu | 8767f41 | 2018-12-05 16:19:47 +0000 | [diff] [blame] | 138 | mExclusionList = LOCAL_EXCL_LIST; |
| 139 | mParsedExclusionList = parseExclusionList(mExclusionList); |
Jason Monk | 19c6561 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 140 | if (pacFileUrl == null) { |
| 141 | throw new NullPointerException(); |
| 142 | } |
Jason Monk | 0a9cc50 | 2013-08-23 19:21:25 -0400 | [diff] [blame] | 143 | mPacFileUrl = pacFileUrl; |
| 144 | } |
| 145 | |
Irina Dumitrescu | 8767f41 | 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 | 4d5e20f | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 154 | private ProxyInfo(String host, int port, String exclList, String[] parsedExclList) { |
Robert Greenwalt | c3c5f86 | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 155 | mHost = host; |
| 156 | mPort = port; |
| 157 | mExclusionList = exclList; |
| 158 | mParsedExclusionList = parsedExclList; |
Jason Monk | 19c6561 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 159 | mPacFileUrl = Uri.EMPTY; |
Robert Greenwalt | a7dfbd3 | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Jason Monk | 4d5e20f | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 162 | /** |
Aaron Huang | fb8581a | 2019-10-02 23:37:02 +0800 | [diff] [blame] | 163 | * A copy constructor to hold proxy properties. |
Jason Monk | 4d5e20f | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 164 | */ |
Aaron Huang | fb8581a | 2019-10-02 23:37:02 +0800 | [diff] [blame] | 165 | public ProxyInfo(@Nullable ProxyInfo source) { |
Irfan Sheriff | fd151ec | 2010-08-30 20:37:17 -0700 | [diff] [blame] | 166 | if (source != null) { |
Robert Greenwalt | c3c5f86 | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 167 | mHost = source.getHost(); |
| 168 | mPort = source.getPort(); |
Jason Monk | 4d5e20f | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 169 | mPacFileUrl = source.mPacFileUrl; |
| 170 | mExclusionList = source.getExclusionListAsString(); |
Robert Greenwalt | c3c5f86 | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 171 | mParsedExclusionList = source.mParsedExclusionList; |
Sreeram Ramachandran | 44a242a | 2014-05-14 14:45:00 -0700 | [diff] [blame] | 172 | } else { |
Irina Dumitrescu | 8767f41 | 2018-12-05 16:19:47 +0000 | [diff] [blame] | 173 | mHost = null; |
| 174 | mPort = 0; |
| 175 | mExclusionList = null; |
| 176 | mParsedExclusionList = null; |
Sreeram Ramachandran | 44a242a | 2014-05-14 14:45:00 -0700 | [diff] [blame] | 177 | mPacFileUrl = Uri.EMPTY; |
Irfan Sheriff | fd151ec | 2010-08-30 20:37:17 -0700 | [diff] [blame] | 178 | } |
Robert Greenwalt | 1f1bcfe | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Jason Monk | 4d5e20f | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 181 | /** |
| 182 | * @hide |
| 183 | */ |
Robert Greenwalt | 98f4583 | 2010-09-03 13:02:05 -0700 | [diff] [blame] | 184 | public InetSocketAddress getSocketAddress() { |
Robert Greenwalt | c3c5f86 | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 185 | InetSocketAddress inetSocketAddress = null; |
| 186 | try { |
| 187 | inetSocketAddress = new InetSocketAddress(mHost, mPort); |
| 188 | } catch (IllegalArgumentException e) { } |
| 189 | return inetSocketAddress; |
Robert Greenwalt | a7dfbd3 | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 190 | } |
Andrew Stadler | e55ada7 | 2010-08-31 14:28:58 -0700 | [diff] [blame] | 191 | |
Jason Monk | 4d5e20f | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 192 | /** |
| 193 | * Returns the URL of the current PAC script or null if there is |
| 194 | * no PAC script. |
| 195 | */ |
| 196 | public Uri getPacFileUrl() { |
Jason Monk | 19c6561 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 197 | return mPacFileUrl; |
Jason Monk | a5bf284 | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 198 | } |
| 199 | |
Jason Monk | 4d5e20f | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 200 | /** |
| 201 | * When configured to use a Direct Proxy this returns the host |
| 202 | * of the proxy. |
| 203 | */ |
Robert Greenwalt | c3c5f86 | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 204 | public String getHost() { |
| 205 | return mHost; |
Robert Greenwalt | a7dfbd3 | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Jason Monk | 4d5e20f | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 208 | /** |
| 209 | * When configured to use a Direct Proxy this returns the port |
| 210 | * of the proxy |
| 211 | */ |
Robert Greenwalt | c3c5f86 | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 212 | public int getPort() { |
| 213 | return mPort; |
| 214 | } |
| 215 | |
Jason Monk | 4d5e20f | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 216 | /** |
| 217 | * When configured to use a Direct Proxy this returns the list |
| 218 | * of hosts for which the proxy is ignored. |
| 219 | */ |
| 220 | public String[] getExclusionList() { |
| 221 | return mParsedExclusionList; |
| 222 | } |
| 223 | |
| 224 | /** |
| 225 | * comma separated |
| 226 | * @hide |
| 227 | */ |
Aaron Huang | fb8581a | 2019-10-02 23:37:02 +0800 | [diff] [blame] | 228 | @Nullable |
Jason Monk | 4d5e20f | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 229 | public String getExclusionListAsString() { |
Robert Greenwalt | a7dfbd3 | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 230 | return mExclusionList; |
| 231 | } |
Andrew Stadler | e55ada7 | 2010-08-31 14:28:58 -0700 | [diff] [blame] | 232 | |
Jason Monk | 4d5e20f | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 233 | /** |
Aaron Huang | fb8581a | 2019-10-02 23:37:02 +0800 | [diff] [blame] | 234 | * Return true if the pattern of proxy is valid, otherwise return false. |
Jason Monk | 4d5e20f | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 235 | */ |
Raj Mamadgi | f3df162 | 2013-11-11 13:52:58 -0800 | [diff] [blame] | 236 | public boolean isValid() { |
Jason Monk | 19c6561 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 237 | if (!Uri.EMPTY.equals(mPacFileUrl)) return true; |
Chiachang Wang | ab9f017 | 2021-02-05 17:33:53 +0800 | [diff] [blame] | 238 | return ProxyUtils.PROXY_VALID == ProxyUtils.validate(mHost == null ? "" : mHost, |
Irina Dumitrescu | 8767f41 | 2018-12-05 16:19:47 +0000 | [diff] [blame] | 239 | mPort == 0 ? "" : Integer.toString(mPort), |
| 240 | mExclusionList == null ? "" : mExclusionList); |
Raj Mamadgi | f3df162 | 2013-11-11 13:52:58 -0800 | [diff] [blame] | 241 | } |
| 242 | |
Jason Monk | 4d5e20f | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 243 | /** |
| 244 | * @hide |
| 245 | */ |
Robert Greenwalt | c3c5f86 | 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 | a7dfbd3 | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Wink Saville | 7d85790 | 2010-08-27 11:15:18 -0700 | [diff] [blame] | 258 | @Override |
| 259 | public String toString() { |
| 260 | StringBuilder sb = new StringBuilder(); |
Jason Monk | 19c6561 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 261 | if (!Uri.EMPTY.equals(mPacFileUrl)) { |
Jason Monk | a5bf284 | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 262 | sb.append("PAC Script: "); |
| 263 | sb.append(mPacFileUrl); |
Paul Jensen | c0618a6 | 2014-12-10 15:12:18 -0500 | [diff] [blame] | 264 | } |
| 265 | if (mHost != null) { |
Robert Greenwalt | c3c5f86 | 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 | e422ad9 | 2010-09-01 09:12:38 -0700 | [diff] [blame] | 270 | if (mExclusionList != null) { |
Irina Dumitrescu | 8767f41 | 2018-12-05 16:19:47 +0000 | [diff] [blame] | 271 | sb.append(" xl=").append(mExclusionList); |
Robert Greenwalt | e422ad9 | 2010-09-01 09:12:38 -0700 | [diff] [blame] | 272 | } |
Wink Saville | a7d5657 | 2011-09-21 11:05:43 -0700 | [diff] [blame] | 273 | } else { |
| 274 | sb.append("[ProxyProperties.mHost == null]"); |
Robert Greenwalt | e422ad9 | 2010-09-01 09:12:38 -0700 | [diff] [blame] | 275 | } |
Wink Saville | 7d85790 | 2010-08-27 11:15:18 -0700 | [diff] [blame] | 276 | return sb.toString(); |
| 277 | } |
| 278 | |
Robert Greenwalt | c3c5f86 | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 279 | @Override |
Roman Kalukiewicz | 384a8c6 | 2020-10-14 15:59:06 -0700 | [diff] [blame] | 280 | public boolean equals(@Nullable Object o) { |
Jason Monk | 4d5e20f | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 281 | if (!(o instanceof ProxyInfo)) return false; |
| 282 | ProxyInfo p = (ProxyInfo)o; |
Jason Monk | a5bf284 | 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 | 19c6561 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 285 | if (!Uri.EMPTY.equals(mPacFileUrl)) { |
Jason Monk | a69f1b0 | 2013-10-10 14:02:51 -0400 | [diff] [blame] | 286 | return mPacFileUrl.equals(p.getPacFileUrl()) && mPort == p.mPort; |
Jason Monk | a5bf284 | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 287 | } |
Jason Monk | 19c6561 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 288 | if (!Uri.EMPTY.equals(p.mPacFileUrl)) { |
Jason Monk | a5bf284 | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 289 | return false; |
| 290 | } |
Jason Monk | 19c6561 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 291 | if (mExclusionList != null && !mExclusionList.equals(p.getExclusionListAsString())) { |
| 292 | return false; |
| 293 | } |
Robert Greenwalt | c3c5f86 | 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 | a7dfbd3 | 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 | 3e567d5 | 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 | 8767f41 | 2018-12-05 16:19:47 +0000 | [diff] [blame] | 317 | + ((null == mExclusionList) ? 0 : mExclusionList.hashCode()) |
| 318 | + mPort; |
John Wang | 3e567d5 | 2011-04-04 12:35:42 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Robert Greenwalt | a7dfbd3 | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 321 | /** |
| 322 | * Implement the Parcelable interface. |
| 323 | * @hide |
| 324 | */ |
Robert Greenwalt | 1f1bcfe | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 325 | public void writeToParcel(Parcel dest, int flags) { |
Jason Monk | 19c6561 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 326 | if (!Uri.EMPTY.equals(mPacFileUrl)) { |
Jason Monk | a5bf284 | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 327 | dest.writeByte((byte)1); |
Jason Monk | 19c6561 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 328 | mPacFileUrl.writeToParcel(dest, 0); |
Jason Monk | a69f1b0 | 2013-10-10 14:02:51 -0400 | [diff] [blame] | 329 | dest.writeInt(mPort); |
Jason Monk | a5bf284 | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 330 | return; |
| 331 | } else { |
| 332 | dest.writeByte((byte)0); |
| 333 | } |
Robert Greenwalt | c3c5f86 | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 334 | if (mHost != null) { |
Irfan Sheriff | 30bdeb3 | 2010-09-26 14:54:54 -0700 | [diff] [blame] | 335 | dest.writeByte((byte)1); |
Robert Greenwalt | c3c5f86 | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 336 | dest.writeString(mHost); |
| 337 | dest.writeInt(mPort); |
Robert Greenwalt | a7dfbd3 | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 338 | } else { |
| 339 | dest.writeByte((byte)0); |
| 340 | } |
Robert Greenwalt | a7dfbd3 | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 341 | dest.writeString(mExclusionList); |
Robert Greenwalt | c3c5f86 | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 342 | dest.writeStringArray(mParsedExclusionList); |
Robert Greenwalt | a7dfbd3 | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 343 | } |
| 344 | |
Jeff Sharkey | f852528 | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 345 | public static final @android.annotation.NonNull Creator<ProxyInfo> CREATOR = |
Jason Monk | 4d5e20f | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 346 | new Creator<ProxyInfo>() { |
| 347 | public ProxyInfo createFromParcel(Parcel in) { |
Robert Greenwalt | c3c5f86 | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 348 | String host = null; |
| 349 | int port = 0; |
Jason Monk | a5bf284 | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 350 | if (in.readByte() != 0) { |
Jason Monk | 19c6561 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 351 | Uri url = Uri.CREATOR.createFromParcel(in); |
Jason Monk | a69f1b0 | 2013-10-10 14:02:51 -0400 | [diff] [blame] | 352 | int localPort = in.readInt(); |
Jason Monk | 4d5e20f | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 353 | return new ProxyInfo(url, localPort); |
Jason Monk | a5bf284 | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 354 | } |
| 355 | if (in.readByte() != 0) { |
Robert Greenwalt | c3c5f86 | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 356 | host = in.readString(); |
| 357 | port = in.readInt(); |
Robert Greenwalt | a7dfbd3 | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 358 | } |
Robert Greenwalt | c3c5f86 | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 359 | String exclList = in.readString(); |
lucaslin | 20f95d4 | 2021-01-25 11:01:57 +0800 | [diff] [blame] | 360 | String[] parsedExclList = in.createStringArray(); |
Irina Dumitrescu | 8767f41 | 2018-12-05 16:19:47 +0000 | [diff] [blame] | 361 | ProxyInfo proxyProperties = new ProxyInfo(host, port, exclList, parsedExclList); |
Robert Greenwalt | a7dfbd3 | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 362 | return proxyProperties; |
| 363 | } |
| 364 | |
Jason Monk | 4d5e20f | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 365 | public ProxyInfo[] newArray(int size) { |
| 366 | return new ProxyInfo[size]; |
Robert Greenwalt | a7dfbd3 | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 367 | } |
| 368 | }; |
Andrew Stadler | e55ada7 | 2010-08-31 14:28:58 -0700 | [diff] [blame] | 369 | } |