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 | a523b44 | 2019-10-02 23:37:02 +0800 | [diff] [blame] | 19 | import android.annotation.NonNull; |
| 20 | import android.annotation.Nullable; |
Artur Satayev | 0e45d78 | 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 | 0fcb987 | 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 | 1e3df5d | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 29 | import java.net.URLConnection; |
| 30 | import java.util.List; |
Elliott Hughes | 5547882 | 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 | 1e3df5d | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 34 | * Describes a proxy configuration. |
| 35 | * |
Narayan Kamath | 439fe7b | 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 | 1e3df5d | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 39 | * |
Lorenzo Colitti | b612fb4 | 2021-03-18 13:07:37 +0900 | [diff] [blame^] | 40 | * Other HTTP stacks will need to obtain the proxy info by watching for the |
| 41 | * {@link Proxy#PROXY_CHANGE_ACTION} broadcast and calling methods such as |
| 42 | * {@link android.net.ConnectivityManager#getDefaultProxy}. |
Robert Greenwalt | a7dfbd3 | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 43 | */ |
Jason Monk | 1e3df5d | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 44 | public class ProxyInfo implements Parcelable { |
Robert Greenwalt | a7dfbd3 | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 45 | |
Irina Dumitrescu | 3a83884 | 2018-12-05 16:19:47 +0000 | [diff] [blame] | 46 | private final String mHost; |
| 47 | private final int mPort; |
| 48 | private final String mExclusionList; |
| 49 | private final String[] mParsedExclusionList; |
| 50 | private final Uri mPacFileUrl; |
Robert Greenwalt | a7dfbd3 | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 51 | |
Jason Monk | 1e3df5d | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 52 | /** |
| 53 | *@hide |
| 54 | */ |
Jason Monk | 43324ee | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 55 | public static final String LOCAL_EXCL_LIST = ""; |
Jason Monk | 1e3df5d | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 56 | /** |
| 57 | *@hide |
| 58 | */ |
Jason Monk | af9ded0 | 2013-08-23 19:21:25 -0400 | [diff] [blame] | 59 | public static final int LOCAL_PORT = -1; |
Jason Monk | 1e3df5d | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 60 | /** |
| 61 | *@hide |
| 62 | */ |
Jason Monk | 43324ee | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 63 | public static final String LOCAL_HOST = "localhost"; |
| 64 | |
Jason Monk | 1e3df5d | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 65 | /** |
| 66 | * Constructs a {@link ProxyInfo} object that points at a Direct proxy |
| 67 | * on the specified host and port. |
| 68 | */ |
| 69 | public static ProxyInfo buildDirectProxy(String host, int port) { |
| 70 | return new ProxyInfo(host, port, null); |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Constructs a {@link ProxyInfo} object that points at a Direct proxy |
| 75 | * on the specified host and port. |
| 76 | * |
| 77 | * The proxy will not be used to access any host in exclusion list, exclList. |
| 78 | * |
| 79 | * @param exclList Hosts to exclude using the proxy on connections for. These |
| 80 | * hosts can use wildcards such as *.example.com. |
| 81 | */ |
| 82 | public static ProxyInfo buildDirectProxy(String host, int port, List<String> exclList) { |
| 83 | String[] array = exclList.toArray(new String[exclList.size()]); |
| 84 | return new ProxyInfo(host, port, TextUtils.join(",", array), array); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Construct a {@link ProxyInfo} that will download and run the PAC script |
| 89 | * at the specified URL. |
| 90 | */ |
| 91 | public static ProxyInfo buildPacProxy(Uri pacUri) { |
Jason Monk | 60a0e16 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 92 | return new ProxyInfo(pacUri); |
Jason Monk | 1e3df5d | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | /** |
Aaron Huang | a523b44 | 2019-10-02 23:37:02 +0800 | [diff] [blame] | 96 | * Construct a {@link ProxyInfo} object that will download and run the PAC script at the |
| 97 | * specified URL and port. |
| 98 | */ |
| 99 | @NonNull |
| 100 | public static ProxyInfo buildPacProxy(@NonNull Uri pacUrl, int port) { |
| 101 | return new ProxyInfo(pacUrl, port); |
| 102 | } |
| 103 | |
| 104 | /** |
Jason Monk | 1e3df5d | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 105 | * Create a ProxyProperties that points at a HTTP Proxy. |
| 106 | * @hide |
| 107 | */ |
Mathew Inwood | f34f05c | 2018-08-08 14:44:44 +0100 | [diff] [blame] | 108 | @UnsupportedAppUsage |
Jason Monk | 1e3df5d | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 109 | public ProxyInfo(String host, int port, String exclList) { |
Robert Greenwalt | c3c5f86 | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 110 | mHost = host; |
| 111 | mPort = port; |
Irina Dumitrescu | 3a83884 | 2018-12-05 16:19:47 +0000 | [diff] [blame] | 112 | mExclusionList = exclList; |
| 113 | mParsedExclusionList = parseExclusionList(mExclusionList); |
Jason Monk | 60a0e16 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 114 | mPacFileUrl = Uri.EMPTY; |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Create a ProxyProperties that points at a PAC URL. |
| 119 | * @hide |
| 120 | */ |
Aaron Huang | a523b44 | 2019-10-02 23:37:02 +0800 | [diff] [blame] | 121 | public ProxyInfo(@NonNull Uri pacFileUrl) { |
Jason Monk | 60a0e16 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 122 | mHost = LOCAL_HOST; |
| 123 | mPort = LOCAL_PORT; |
Irina Dumitrescu | 3a83884 | 2018-12-05 16:19:47 +0000 | [diff] [blame] | 124 | mExclusionList = LOCAL_EXCL_LIST; |
| 125 | mParsedExclusionList = parseExclusionList(mExclusionList); |
Jason Monk | 60a0e16 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 126 | if (pacFileUrl == null) { |
| 127 | throw new NullPointerException(); |
| 128 | } |
| 129 | mPacFileUrl = pacFileUrl; |
Robert Greenwalt | c3c5f86 | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 130 | } |
| 131 | |
Jason Monk | 1e3df5d | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 132 | /** |
Aaron Huang | b2ad4a9 | 2021-01-18 15:28:01 +0800 | [diff] [blame] | 133 | * Only used in PacProxyService after Local Proxy is bound. |
Jason Monk | 1e3df5d | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 134 | * @hide |
| 135 | */ |
Aaron Huang | a523b44 | 2019-10-02 23:37:02 +0800 | [diff] [blame] | 136 | public ProxyInfo(@NonNull Uri pacFileUrl, int localProxyPort) { |
Jason Monk | af9ded0 | 2013-08-23 19:21:25 -0400 | [diff] [blame] | 137 | mHost = LOCAL_HOST; |
| 138 | mPort = localProxyPort; |
Irina Dumitrescu | 3a83884 | 2018-12-05 16:19:47 +0000 | [diff] [blame] | 139 | mExclusionList = LOCAL_EXCL_LIST; |
| 140 | mParsedExclusionList = parseExclusionList(mExclusionList); |
Jason Monk | 60a0e16 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 141 | if (pacFileUrl == null) { |
| 142 | throw new NullPointerException(); |
| 143 | } |
Jason Monk | af9ded0 | 2013-08-23 19:21:25 -0400 | [diff] [blame] | 144 | mPacFileUrl = pacFileUrl; |
| 145 | } |
| 146 | |
Irina Dumitrescu | 3a83884 | 2018-12-05 16:19:47 +0000 | [diff] [blame] | 147 | private static String[] parseExclusionList(String exclusionList) { |
| 148 | if (exclusionList == null) { |
| 149 | return new String[0]; |
| 150 | } else { |
| 151 | return exclusionList.toLowerCase(Locale.ROOT).split(","); |
| 152 | } |
| 153 | } |
| 154 | |
Jason Monk | 1e3df5d | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 155 | private ProxyInfo(String host, int port, String exclList, String[] parsedExclList) { |
Robert Greenwalt | c3c5f86 | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 156 | mHost = host; |
| 157 | mPort = port; |
| 158 | mExclusionList = exclList; |
| 159 | mParsedExclusionList = parsedExclList; |
Jason Monk | 60a0e16 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 160 | mPacFileUrl = Uri.EMPTY; |
Robert Greenwalt | a7dfbd3 | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Jason Monk | 1e3df5d | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 163 | /** |
Aaron Huang | a523b44 | 2019-10-02 23:37:02 +0800 | [diff] [blame] | 164 | * A copy constructor to hold proxy properties. |
Jason Monk | 1e3df5d | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 165 | */ |
Aaron Huang | a523b44 | 2019-10-02 23:37:02 +0800 | [diff] [blame] | 166 | public ProxyInfo(@Nullable ProxyInfo source) { |
Irfan Sheriff | fd151ec | 2010-08-30 20:37:17 -0700 | [diff] [blame] | 167 | if (source != null) { |
Robert Greenwalt | c3c5f86 | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 168 | mHost = source.getHost(); |
| 169 | mPort = source.getPort(); |
Jason Monk | 1e3df5d | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 170 | mPacFileUrl = source.mPacFileUrl; |
| 171 | mExclusionList = source.getExclusionListAsString(); |
Robert Greenwalt | c3c5f86 | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 172 | mParsedExclusionList = source.mParsedExclusionList; |
Sreeram Ramachandran | 6e24ec7 | 2014-05-14 14:45:00 -0700 | [diff] [blame] | 173 | } else { |
Irina Dumitrescu | 3a83884 | 2018-12-05 16:19:47 +0000 | [diff] [blame] | 174 | mHost = null; |
| 175 | mPort = 0; |
| 176 | mExclusionList = null; |
| 177 | mParsedExclusionList = null; |
Sreeram Ramachandran | 6e24ec7 | 2014-05-14 14:45:00 -0700 | [diff] [blame] | 178 | mPacFileUrl = Uri.EMPTY; |
Irfan Sheriff | fd151ec | 2010-08-30 20:37:17 -0700 | [diff] [blame] | 179 | } |
Robert Greenwalt | 1f1bcfe | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Jason Monk | 1e3df5d | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 182 | /** |
| 183 | * @hide |
| 184 | */ |
Robert Greenwalt | 98f4583 | 2010-09-03 13:02:05 -0700 | [diff] [blame] | 185 | public InetSocketAddress getSocketAddress() { |
Robert Greenwalt | c3c5f86 | 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 | a7dfbd3 | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 191 | } |
Andrew Stadler | e55ada7 | 2010-08-31 14:28:58 -0700 | [diff] [blame] | 192 | |
Jason Monk | 1e3df5d | 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 | 60a0e16 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 198 | return mPacFileUrl; |
Jason Monk | 43324ee | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 199 | } |
| 200 | |
Jason Monk | 1e3df5d | 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 | c3c5f86 | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 205 | public String getHost() { |
| 206 | return mHost; |
Robert Greenwalt | a7dfbd3 | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Jason Monk | 1e3df5d | 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 | c3c5f86 | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 213 | public int getPort() { |
| 214 | return mPort; |
| 215 | } |
| 216 | |
Jason Monk | 1e3df5d | 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 | */ |
Aaron Huang | a523b44 | 2019-10-02 23:37:02 +0800 | [diff] [blame] | 229 | @Nullable |
Jason Monk | 1e3df5d | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 230 | public String getExclusionListAsString() { |
Robert Greenwalt | a7dfbd3 | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 231 | return mExclusionList; |
| 232 | } |
Andrew Stadler | e55ada7 | 2010-08-31 14:28:58 -0700 | [diff] [blame] | 233 | |
Jason Monk | 1e3df5d | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 234 | /** |
Aaron Huang | a523b44 | 2019-10-02 23:37:02 +0800 | [diff] [blame] | 235 | * Return true if the pattern of proxy is valid, otherwise return false. |
Jason Monk | 1e3df5d | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 236 | */ |
Raj Mamadgi | 08e512b | 2013-11-11 13:52:58 -0800 | [diff] [blame] | 237 | public boolean isValid() { |
Jason Monk | 60a0e16 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 238 | if (!Uri.EMPTY.equals(mPacFileUrl)) return true; |
Chiachang Wang | 0fcb987 | 2021-02-05 17:33:53 +0800 | [diff] [blame] | 239 | return ProxyUtils.PROXY_VALID == ProxyUtils.validate(mHost == null ? "" : mHost, |
Irina Dumitrescu | 3a83884 | 2018-12-05 16:19:47 +0000 | [diff] [blame] | 240 | mPort == 0 ? "" : Integer.toString(mPort), |
| 241 | mExclusionList == null ? "" : mExclusionList); |
Raj Mamadgi | 08e512b | 2013-11-11 13:52:58 -0800 | [diff] [blame] | 242 | } |
| 243 | |
Jason Monk | 1e3df5d | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 244 | /** |
| 245 | * @hide |
| 246 | */ |
Robert Greenwalt | c3c5f86 | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 247 | public java.net.Proxy makeProxy() { |
| 248 | java.net.Proxy proxy = java.net.Proxy.NO_PROXY; |
| 249 | if (mHost != null) { |
| 250 | try { |
| 251 | InetSocketAddress inetSocketAddress = new InetSocketAddress(mHost, mPort); |
| 252 | proxy = new java.net.Proxy(java.net.Proxy.Type.HTTP, inetSocketAddress); |
| 253 | } catch (IllegalArgumentException e) { |
| 254 | } |
| 255 | } |
| 256 | return proxy; |
Robert Greenwalt | a7dfbd3 | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Wink Saville | 7d85790 | 2010-08-27 11:15:18 -0700 | [diff] [blame] | 259 | @Override |
| 260 | public String toString() { |
| 261 | StringBuilder sb = new StringBuilder(); |
Jason Monk | 60a0e16 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 262 | if (!Uri.EMPTY.equals(mPacFileUrl)) { |
Jason Monk | 43324ee | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 263 | sb.append("PAC Script: "); |
| 264 | sb.append(mPacFileUrl); |
Paul Jensen | 1213135 | 2014-12-10 15:12:18 -0500 | [diff] [blame] | 265 | } |
| 266 | if (mHost != null) { |
Robert Greenwalt | c3c5f86 | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 267 | sb.append("["); |
| 268 | sb.append(mHost); |
| 269 | sb.append("] "); |
| 270 | sb.append(Integer.toString(mPort)); |
Robert Greenwalt | e422ad9 | 2010-09-01 09:12:38 -0700 | [diff] [blame] | 271 | if (mExclusionList != null) { |
Irina Dumitrescu | 3a83884 | 2018-12-05 16:19:47 +0000 | [diff] [blame] | 272 | sb.append(" xl=").append(mExclusionList); |
Robert Greenwalt | e422ad9 | 2010-09-01 09:12:38 -0700 | [diff] [blame] | 273 | } |
Wink Saville | a7d5657 | 2011-09-21 11:05:43 -0700 | [diff] [blame] | 274 | } else { |
| 275 | sb.append("[ProxyProperties.mHost == null]"); |
Robert Greenwalt | e422ad9 | 2010-09-01 09:12:38 -0700 | [diff] [blame] | 276 | } |
Wink Saville | 7d85790 | 2010-08-27 11:15:18 -0700 | [diff] [blame] | 277 | return sb.toString(); |
| 278 | } |
| 279 | |
Robert Greenwalt | c3c5f86 | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 280 | @Override |
Roman Kalukiewicz | 1f69a5e | 2020-10-14 15:59:06 -0700 | [diff] [blame] | 281 | public boolean equals(@Nullable Object o) { |
Jason Monk | 1e3df5d | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 282 | if (!(o instanceof ProxyInfo)) return false; |
| 283 | ProxyInfo p = (ProxyInfo)o; |
Jason Monk | 43324ee | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 284 | // If PAC URL is present in either then they must be equal. |
| 285 | // Other parameters will only be for fall back. |
Jason Monk | 60a0e16 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 286 | if (!Uri.EMPTY.equals(mPacFileUrl)) { |
Jason Monk | 445cea8 | 2013-10-10 14:02:51 -0400 | [diff] [blame] | 287 | return mPacFileUrl.equals(p.getPacFileUrl()) && mPort == p.mPort; |
Jason Monk | 43324ee | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 288 | } |
Jason Monk | 60a0e16 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 289 | if (!Uri.EMPTY.equals(p.mPacFileUrl)) { |
Jason Monk | 43324ee | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 290 | return false; |
| 291 | } |
Jason Monk | 60a0e16 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 292 | if (mExclusionList != null && !mExclusionList.equals(p.getExclusionListAsString())) { |
| 293 | return false; |
| 294 | } |
Robert Greenwalt | c3c5f86 | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 295 | if (mHost != null && p.getHost() != null && mHost.equals(p.getHost()) == false) { |
| 296 | return false; |
| 297 | } |
| 298 | if (mHost != null && p.mHost == null) return false; |
| 299 | if (mHost == null && p.mHost != null) return false; |
| 300 | if (mPort != p.mPort) return false; |
| 301 | return true; |
| 302 | } |
| 303 | |
Robert Greenwalt | a7dfbd3 | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 304 | /** |
| 305 | * Implement the Parcelable interface |
| 306 | * @hide |
| 307 | */ |
| 308 | public int describeContents() { |
| 309 | return 0; |
| 310 | } |
| 311 | |
John Wang | 3e567d5 | 2011-04-04 12:35:42 -0700 | [diff] [blame] | 312 | @Override |
| 313 | /* |
| 314 | * generate hashcode based on significant fields |
| 315 | */ |
| 316 | public int hashCode() { |
| 317 | return ((null == mHost) ? 0 : mHost.hashCode()) |
Irina Dumitrescu | 3a83884 | 2018-12-05 16:19:47 +0000 | [diff] [blame] | 318 | + ((null == mExclusionList) ? 0 : mExclusionList.hashCode()) |
| 319 | + mPort; |
John Wang | 3e567d5 | 2011-04-04 12:35:42 -0700 | [diff] [blame] | 320 | } |
| 321 | |
Robert Greenwalt | a7dfbd3 | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 322 | /** |
| 323 | * Implement the Parcelable interface. |
| 324 | * @hide |
| 325 | */ |
Robert Greenwalt | 1f1bcfe | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 326 | public void writeToParcel(Parcel dest, int flags) { |
Jason Monk | 60a0e16 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 327 | if (!Uri.EMPTY.equals(mPacFileUrl)) { |
Jason Monk | 43324ee | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 328 | dest.writeByte((byte)1); |
Jason Monk | 60a0e16 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 329 | mPacFileUrl.writeToParcel(dest, 0); |
Jason Monk | 445cea8 | 2013-10-10 14:02:51 -0400 | [diff] [blame] | 330 | dest.writeInt(mPort); |
Jason Monk | 43324ee | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 331 | return; |
| 332 | } else { |
| 333 | dest.writeByte((byte)0); |
| 334 | } |
Robert Greenwalt | c3c5f86 | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 335 | if (mHost != null) { |
Irfan Sheriff | 30bdeb3 | 2010-09-26 14:54:54 -0700 | [diff] [blame] | 336 | dest.writeByte((byte)1); |
Robert Greenwalt | c3c5f86 | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 337 | dest.writeString(mHost); |
| 338 | dest.writeInt(mPort); |
Robert Greenwalt | a7dfbd3 | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 339 | } else { |
| 340 | dest.writeByte((byte)0); |
| 341 | } |
Robert Greenwalt | a7dfbd3 | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 342 | dest.writeString(mExclusionList); |
Robert Greenwalt | c3c5f86 | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 343 | dest.writeStringArray(mParsedExclusionList); |
Robert Greenwalt | a7dfbd3 | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 344 | } |
| 345 | |
Jeff Sharkey | 9286f91 | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 346 | public static final @android.annotation.NonNull Creator<ProxyInfo> CREATOR = |
Jason Monk | 1e3df5d | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 347 | new Creator<ProxyInfo>() { |
| 348 | public ProxyInfo createFromParcel(Parcel in) { |
Robert Greenwalt | c3c5f86 | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 349 | String host = null; |
| 350 | int port = 0; |
Jason Monk | 43324ee | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 351 | if (in.readByte() != 0) { |
Jason Monk | 60a0e16 | 2014-05-09 15:16:06 -0400 | [diff] [blame] | 352 | Uri url = Uri.CREATOR.createFromParcel(in); |
Jason Monk | 445cea8 | 2013-10-10 14:02:51 -0400 | [diff] [blame] | 353 | int localPort = in.readInt(); |
Jason Monk | 1e3df5d | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 354 | return new ProxyInfo(url, localPort); |
Jason Monk | 43324ee | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 355 | } |
| 356 | if (in.readByte() != 0) { |
Robert Greenwalt | c3c5f86 | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 357 | host = in.readString(); |
| 358 | port = in.readInt(); |
Robert Greenwalt | a7dfbd3 | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 359 | } |
Robert Greenwalt | c3c5f86 | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 360 | String exclList = in.readString(); |
lucaslin | cee4354 | 2021-01-25 11:01:57 +0800 | [diff] [blame] | 361 | String[] parsedExclList = in.createStringArray(); |
Irina Dumitrescu | 3a83884 | 2018-12-05 16:19:47 +0000 | [diff] [blame] | 362 | ProxyInfo proxyProperties = new ProxyInfo(host, port, exclList, parsedExclList); |
Robert Greenwalt | a7dfbd3 | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 363 | return proxyProperties; |
| 364 | } |
| 365 | |
Jason Monk | 1e3df5d | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 366 | public ProxyInfo[] newArray(int size) { |
| 367 | return new ProxyInfo[size]; |
Robert Greenwalt | a7dfbd3 | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 368 | } |
| 369 | }; |
Andrew Stadler | e55ada7 | 2010-08-31 14:28:58 -0700 | [diff] [blame] | 370 | } |