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