147f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt/* 26e80997a9a7b6a15370544edde322cd8833e9524Wink Saville * Copyright (C) 2010 The Android Open Source Project 347f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt * 447f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt * Licensed under the Apache License, Version 2.0 (the "License"); 547f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt * you may not use this file except in compliance with the License. 647f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt * You may obtain a copy of the License at 747f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt * 847f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt * http://www.apache.org/licenses/LICENSE-2.0 947f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt * 1047f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt * Unless required by applicable law or agreed to in writing, software 1147f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt * distributed under the License is distributed on an "AS IS" BASIS, 1247f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1347f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt * See the License for the specific language governing permissions and 1447f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt * limitations under the License. 1547f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt */ 1647f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt 1747f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwaltpackage android.net; 1847f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt 1947f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt 2047f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwaltimport android.os.Parcel; 2147f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwaltimport android.os.Parcelable; 22434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwaltimport android.text.TextUtils; 2347f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt 2470af574b3d61605e311a7b3b5cb1531d5201dc5bRobert Greenwaltimport java.net.InetSocketAddress; 25207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monkimport java.net.URLConnection; 26207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monkimport java.util.List; 27cb64d430627b71221c588ef5f23599dd34a89ee9Elliott Hughesimport java.util.Locale; 2847f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt 2947f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt/** 30207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk * Describes a proxy configuration. 31207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk * 323bdd327f8532a79b83f575cc62e8eb09a1f93f3dNarayan Kamath * Proxy configurations are already integrated within the {@code java.net} and 333bdd327f8532a79b83f575cc62e8eb09a1f93f3dNarayan Kamath * Apache HTTP stack. So {@link URLConnection} and Apache's {@code HttpClient} will use 343bdd327f8532a79b83f575cc62e8eb09a1f93f3dNarayan Kamath * them automatically. 35207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk * 36207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk * Other HTTP stacks will need to obtain the proxy info from 37207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk * {@link Proxy#PROXY_CHANGE_ACTION} broadcast as the extra {@link Proxy#EXTRA_PROXY_INFO}. 3847f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt */ 39207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monkpublic class ProxyInfo implements Parcelable { 4047f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt 41434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt private String mHost; 42434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt private int mPort; 4347f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt private String mExclusionList; 44434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt private String[] mParsedExclusionList; 4547f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt 4683520b95124e0fcaaf3154a7a267f6be0205bc74Jason Monk private Uri mPacFileUrl; 47207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk /** 48207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk *@hide 49207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk */ 50602b232a06ede86999aa362a12eb28cbc782dc1dJason Monk public static final String LOCAL_EXCL_LIST = ""; 51207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk /** 52207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk *@hide 53207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk */ 546f8a68f49a7e8cf86104e721a1e8be7568b5f730Jason Monk public static final int LOCAL_PORT = -1; 55207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk /** 56207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk *@hide 57207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk */ 58602b232a06ede86999aa362a12eb28cbc782dc1dJason Monk public static final String LOCAL_HOST = "localhost"; 59602b232a06ede86999aa362a12eb28cbc782dc1dJason Monk 60207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk /** 61207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk * Constructs a {@link ProxyInfo} object that points at a Direct proxy 62207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk * on the specified host and port. 63207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk */ 64207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk public static ProxyInfo buildDirectProxy(String host, int port) { 65207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk return new ProxyInfo(host, port, null); 66207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk } 67207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk 68207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk /** 69207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk * Constructs a {@link ProxyInfo} object that points at a Direct proxy 70207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk * on the specified host and port. 71207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk * 72207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk * The proxy will not be used to access any host in exclusion list, exclList. 73207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk * 74207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk * @param exclList Hosts to exclude using the proxy on connections for. These 75207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk * hosts can use wildcards such as *.example.com. 76207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk */ 77207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk public static ProxyInfo buildDirectProxy(String host, int port, List<String> exclList) { 78207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk String[] array = exclList.toArray(new String[exclList.size()]); 79207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk return new ProxyInfo(host, port, TextUtils.join(",", array), array); 80207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk } 81207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk 82207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk /** 83207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk * Construct a {@link ProxyInfo} that will download and run the PAC script 84207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk * at the specified URL. 85207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk */ 86207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk public static ProxyInfo buildPacProxy(Uri pacUri) { 8783520b95124e0fcaaf3154a7a267f6be0205bc74Jason Monk return new ProxyInfo(pacUri); 88207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk } 89207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk 90207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk /** 91207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk * Create a ProxyProperties that points at a HTTP Proxy. 92207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk * @hide 93207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk */ 94207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk public ProxyInfo(String host, int port, String exclList) { 95434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt mHost = host; 96434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt mPort = port; 97434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt setExclusionList(exclList); 9883520b95124e0fcaaf3154a7a267f6be0205bc74Jason Monk mPacFileUrl = Uri.EMPTY; 99434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt } 100434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt 101207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk /** 102207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk * Create a ProxyProperties that points at a PAC URL. 103207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk * @hide 104207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk */ 10583520b95124e0fcaaf3154a7a267f6be0205bc74Jason Monk public ProxyInfo(Uri pacFileUrl) { 106602b232a06ede86999aa362a12eb28cbc782dc1dJason Monk mHost = LOCAL_HOST; 107602b232a06ede86999aa362a12eb28cbc782dc1dJason Monk mPort = LOCAL_PORT; 108602b232a06ede86999aa362a12eb28cbc782dc1dJason Monk setExclusionList(LOCAL_EXCL_LIST); 10983520b95124e0fcaaf3154a7a267f6be0205bc74Jason Monk if (pacFileUrl == null) { 11083520b95124e0fcaaf3154a7a267f6be0205bc74Jason Monk throw new NullPointerException(); 11183520b95124e0fcaaf3154a7a267f6be0205bc74Jason Monk } 112602b232a06ede86999aa362a12eb28cbc782dc1dJason Monk mPacFileUrl = pacFileUrl; 113602b232a06ede86999aa362a12eb28cbc782dc1dJason Monk } 114602b232a06ede86999aa362a12eb28cbc782dc1dJason Monk 115207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk /** 11683520b95124e0fcaaf3154a7a267f6be0205bc74Jason Monk * Create a ProxyProperties that points at a PAC URL. 11783520b95124e0fcaaf3154a7a267f6be0205bc74Jason Monk * @hide 11883520b95124e0fcaaf3154a7a267f6be0205bc74Jason Monk */ 11983520b95124e0fcaaf3154a7a267f6be0205bc74Jason Monk public ProxyInfo(String pacFileUrl) { 12083520b95124e0fcaaf3154a7a267f6be0205bc74Jason Monk mHost = LOCAL_HOST; 12183520b95124e0fcaaf3154a7a267f6be0205bc74Jason Monk mPort = LOCAL_PORT; 12283520b95124e0fcaaf3154a7a267f6be0205bc74Jason Monk setExclusionList(LOCAL_EXCL_LIST); 12383520b95124e0fcaaf3154a7a267f6be0205bc74Jason Monk mPacFileUrl = Uri.parse(pacFileUrl); 12483520b95124e0fcaaf3154a7a267f6be0205bc74Jason Monk } 12583520b95124e0fcaaf3154a7a267f6be0205bc74Jason Monk 12683520b95124e0fcaaf3154a7a267f6be0205bc74Jason Monk /** 127207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk * Only used in PacManager after Local Proxy is bound. 128207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk * @hide 129207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk */ 13083520b95124e0fcaaf3154a7a267f6be0205bc74Jason Monk public ProxyInfo(Uri pacFileUrl, int localProxyPort) { 1316f8a68f49a7e8cf86104e721a1e8be7568b5f730Jason Monk mHost = LOCAL_HOST; 1326f8a68f49a7e8cf86104e721a1e8be7568b5f730Jason Monk mPort = localProxyPort; 1336f8a68f49a7e8cf86104e721a1e8be7568b5f730Jason Monk setExclusionList(LOCAL_EXCL_LIST); 13483520b95124e0fcaaf3154a7a267f6be0205bc74Jason Monk if (pacFileUrl == null) { 13583520b95124e0fcaaf3154a7a267f6be0205bc74Jason Monk throw new NullPointerException(); 13683520b95124e0fcaaf3154a7a267f6be0205bc74Jason Monk } 1376f8a68f49a7e8cf86104e721a1e8be7568b5f730Jason Monk mPacFileUrl = pacFileUrl; 1386f8a68f49a7e8cf86104e721a1e8be7568b5f730Jason Monk } 1396f8a68f49a7e8cf86104e721a1e8be7568b5f730Jason Monk 140207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk private ProxyInfo(String host, int port, String exclList, String[] parsedExclList) { 141434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt mHost = host; 142434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt mPort = port; 143434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt mExclusionList = exclList; 144434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt mParsedExclusionList = parsedExclList; 14583520b95124e0fcaaf3154a7a267f6be0205bc74Jason Monk mPacFileUrl = Uri.EMPTY; 14647f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt } 14747f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt 14837e65ebb7eb932e1a144b1cab262e11ca5fd109bRobert Greenwalt // copy constructor instead of clone 149207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk /** 150207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk * @hide 151207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk */ 152207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk public ProxyInfo(ProxyInfo source) { 153ef6c1431fa2039a4b8c604d651bb8f4dc0806581Irfan Sheriff if (source != null) { 154434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt mHost = source.getHost(); 155434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt mPort = source.getPort(); 156207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk mPacFileUrl = source.mPacFileUrl; 157207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk mExclusionList = source.getExclusionListAsString(); 158434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt mParsedExclusionList = source.mParsedExclusionList; 1594696ee488b07785e723d13f78a2ea90b50669e02Sreeram Ramachandran } else { 1604696ee488b07785e723d13f78a2ea90b50669e02Sreeram Ramachandran mPacFileUrl = Uri.EMPTY; 161ef6c1431fa2039a4b8c604d651bb8f4dc0806581Irfan Sheriff } 16237e65ebb7eb932e1a144b1cab262e11ca5fd109bRobert Greenwalt } 16337e65ebb7eb932e1a144b1cab262e11ca5fd109bRobert Greenwalt 164207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk /** 165207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk * @hide 166207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk */ 16770af574b3d61605e311a7b3b5cb1531d5201dc5bRobert Greenwalt public InetSocketAddress getSocketAddress() { 168434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt InetSocketAddress inetSocketAddress = null; 169434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt try { 170434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt inetSocketAddress = new InetSocketAddress(mHost, mPort); 171434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt } catch (IllegalArgumentException e) { } 172434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt return inetSocketAddress; 17347f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt } 174ac19f24cc10d380b4065778e8ff5492c10a75cddAndrew Stadler 175207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk /** 176207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk * Returns the URL of the current PAC script or null if there is 177207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk * no PAC script. 178207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk */ 179207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk public Uri getPacFileUrl() { 18083520b95124e0fcaaf3154a7a267f6be0205bc74Jason Monk return mPacFileUrl; 181602b232a06ede86999aa362a12eb28cbc782dc1dJason Monk } 182602b232a06ede86999aa362a12eb28cbc782dc1dJason Monk 183207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk /** 184207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk * When configured to use a Direct Proxy this returns the host 185207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk * of the proxy. 186207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk */ 187434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt public String getHost() { 188434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt return mHost; 18947f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt } 19047f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt 191207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk /** 192207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk * When configured to use a Direct Proxy this returns the port 193207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk * of the proxy 194207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk */ 195434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt public int getPort() { 196434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt return mPort; 197434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt } 198434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt 199207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk /** 200207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk * When configured to use a Direct Proxy this returns the list 201207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk * of hosts for which the proxy is ignored. 202207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk */ 203207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk public String[] getExclusionList() { 204207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk return mParsedExclusionList; 205207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk } 206207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk 207207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk /** 208207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk * comma separated 209207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk * @hide 210207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk */ 211207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk public String getExclusionListAsString() { 21247f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt return mExclusionList; 21347f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt } 214ac19f24cc10d380b4065778e8ff5492c10a75cddAndrew Stadler 215434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt // comma separated 216434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt private void setExclusionList(String exclusionList) { 21747f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt mExclusionList = exclusionList; 218434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt if (mExclusionList == null) { 219434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt mParsedExclusionList = new String[0]; 220434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt } else { 221207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk mParsedExclusionList = exclusionList.toLowerCase(Locale.ROOT).split(","); 222434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt } 223434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt } 224434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt 225207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk /** 226207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk * @hide 227207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk */ 22892d02491aded7ca233fd52d586cc0b0bda4521cfRaj Mamadgi public boolean isValid() { 22983520b95124e0fcaaf3154a7a267f6be0205bc74Jason Monk if (!Uri.EMPTY.equals(mPacFileUrl)) return true; 2309070484e179b2215ea595c8f3f1f69dbc0dc149dYuhao Zheng return Proxy.PROXY_VALID == Proxy.validate(mHost == null ? "" : mHost, 2319070484e179b2215ea595c8f3f1f69dbc0dc149dYuhao Zheng mPort == 0 ? "" : Integer.toString(mPort), 2329070484e179b2215ea595c8f3f1f69dbc0dc149dYuhao Zheng mExclusionList == null ? "" : mExclusionList); 23392d02491aded7ca233fd52d586cc0b0bda4521cfRaj Mamadgi } 23492d02491aded7ca233fd52d586cc0b0bda4521cfRaj Mamadgi 235207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk /** 236207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk * @hide 237207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk */ 238434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt public java.net.Proxy makeProxy() { 239434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt java.net.Proxy proxy = java.net.Proxy.NO_PROXY; 240434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt if (mHost != null) { 241434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt try { 242434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt InetSocketAddress inetSocketAddress = new InetSocketAddress(mHost, mPort); 243434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt proxy = new java.net.Proxy(java.net.Proxy.Type.HTTP, inetSocketAddress); 244434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt } catch (IllegalArgumentException e) { 245434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt } 246434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt } 247434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt return proxy; 24847f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt } 24947f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt 2501f6408a96c757b3001c553f8f34ef0bda00a224dWink Saville @Override 2511f6408a96c757b3001c553f8f34ef0bda00a224dWink Saville public String toString() { 2521f6408a96c757b3001c553f8f34ef0bda00a224dWink Saville StringBuilder sb = new StringBuilder(); 25383520b95124e0fcaaf3154a7a267f6be0205bc74Jason Monk if (!Uri.EMPTY.equals(mPacFileUrl)) { 254602b232a06ede86999aa362a12eb28cbc782dc1dJason Monk sb.append("PAC Script: "); 255602b232a06ede86999aa362a12eb28cbc782dc1dJason Monk sb.append(mPacFileUrl); 256e0bef71662d81caaaa0d7214fb0bef5d39996a69Paul Jensen } 257e0bef71662d81caaaa0d7214fb0bef5d39996a69Paul Jensen if (mHost != null) { 258434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt sb.append("["); 259434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt sb.append(mHost); 260434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt sb.append("] "); 261434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt sb.append(Integer.toString(mPort)); 262f6682b031742df794f95a3955db60595cb459b2aRobert Greenwalt if (mExclusionList != null) { 263f6682b031742df794f95a3955db60595cb459b2aRobert Greenwalt sb.append(" xl=").append(mExclusionList); 264f6682b031742df794f95a3955db60595cb459b2aRobert Greenwalt } 265c9acde9aa6cf21598640aeebb7d908f1926a48ddWink Saville } else { 266c9acde9aa6cf21598640aeebb7d908f1926a48ddWink Saville sb.append("[ProxyProperties.mHost == null]"); 267f6682b031742df794f95a3955db60595cb459b2aRobert Greenwalt } 2681f6408a96c757b3001c553f8f34ef0bda00a224dWink Saville return sb.toString(); 2691f6408a96c757b3001c553f8f34ef0bda00a224dWink Saville } 2701f6408a96c757b3001c553f8f34ef0bda00a224dWink Saville 271434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt @Override 272434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt public boolean equals(Object o) { 273207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk if (!(o instanceof ProxyInfo)) return false; 274207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk ProxyInfo p = (ProxyInfo)o; 275602b232a06ede86999aa362a12eb28cbc782dc1dJason Monk // If PAC URL is present in either then they must be equal. 276602b232a06ede86999aa362a12eb28cbc782dc1dJason Monk // Other parameters will only be for fall back. 27783520b95124e0fcaaf3154a7a267f6be0205bc74Jason Monk if (!Uri.EMPTY.equals(mPacFileUrl)) { 278decd295b1371238c97c170226c6145948492eda1Jason Monk return mPacFileUrl.equals(p.getPacFileUrl()) && mPort == p.mPort; 279602b232a06ede86999aa362a12eb28cbc782dc1dJason Monk } 28083520b95124e0fcaaf3154a7a267f6be0205bc74Jason Monk if (!Uri.EMPTY.equals(p.mPacFileUrl)) { 28183520b95124e0fcaaf3154a7a267f6be0205bc74Jason Monk return false; 28283520b95124e0fcaaf3154a7a267f6be0205bc74Jason Monk } 28383520b95124e0fcaaf3154a7a267f6be0205bc74Jason Monk if (mExclusionList != null && !mExclusionList.equals(p.getExclusionListAsString())) { 284602b232a06ede86999aa362a12eb28cbc782dc1dJason Monk return false; 285602b232a06ede86999aa362a12eb28cbc782dc1dJason Monk } 286434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt if (mHost != null && p.getHost() != null && mHost.equals(p.getHost()) == false) { 287434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt return false; 288434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt } 289434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt if (mHost != null && p.mHost == null) return false; 290434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt if (mHost == null && p.mHost != null) return false; 291434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt if (mPort != p.mPort) return false; 292434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt return true; 293434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt } 294434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt 29547f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt /** 29647f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt * Implement the Parcelable interface 29747f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt * @hide 29847f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt */ 29947f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt public int describeContents() { 30047f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt return 0; 30147f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt } 30247f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt 3034e900091c4da26eb1c9f0d232ee0e50f4522cc69John Wang @Override 3044e900091c4da26eb1c9f0d232ee0e50f4522cc69John Wang /* 3054e900091c4da26eb1c9f0d232ee0e50f4522cc69John Wang * generate hashcode based on significant fields 3064e900091c4da26eb1c9f0d232ee0e50f4522cc69John Wang */ 3074e900091c4da26eb1c9f0d232ee0e50f4522cc69John Wang public int hashCode() { 3084e900091c4da26eb1c9f0d232ee0e50f4522cc69John Wang return ((null == mHost) ? 0 : mHost.hashCode()) 3094e900091c4da26eb1c9f0d232ee0e50f4522cc69John Wang + ((null == mExclusionList) ? 0 : mExclusionList.hashCode()) 3104e900091c4da26eb1c9f0d232ee0e50f4522cc69John Wang + mPort; 3114e900091c4da26eb1c9f0d232ee0e50f4522cc69John Wang } 3124e900091c4da26eb1c9f0d232ee0e50f4522cc69John Wang 31347f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt /** 31447f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt * Implement the Parcelable interface. 31547f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt * @hide 31647f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt */ 31737e65ebb7eb932e1a144b1cab262e11ca5fd109bRobert Greenwalt public void writeToParcel(Parcel dest, int flags) { 31883520b95124e0fcaaf3154a7a267f6be0205bc74Jason Monk if (!Uri.EMPTY.equals(mPacFileUrl)) { 319602b232a06ede86999aa362a12eb28cbc782dc1dJason Monk dest.writeByte((byte)1); 32083520b95124e0fcaaf3154a7a267f6be0205bc74Jason Monk mPacFileUrl.writeToParcel(dest, 0); 321decd295b1371238c97c170226c6145948492eda1Jason Monk dest.writeInt(mPort); 322602b232a06ede86999aa362a12eb28cbc782dc1dJason Monk return; 323602b232a06ede86999aa362a12eb28cbc782dc1dJason Monk } else { 324602b232a06ede86999aa362a12eb28cbc782dc1dJason Monk dest.writeByte((byte)0); 325602b232a06ede86999aa362a12eb28cbc782dc1dJason Monk } 326434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt if (mHost != null) { 327798ffa12379d26d698f97b104e97a8309b059a62Irfan Sheriff dest.writeByte((byte)1); 328434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt dest.writeString(mHost); 329434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt dest.writeInt(mPort); 33047f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt } else { 33147f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt dest.writeByte((byte)0); 33247f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt } 33347f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt dest.writeString(mExclusionList); 334434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt dest.writeStringArray(mParsedExclusionList); 33547f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt } 33647f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt 337207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk public static final Creator<ProxyInfo> CREATOR = 338207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk new Creator<ProxyInfo>() { 339207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk public ProxyInfo createFromParcel(Parcel in) { 340434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt String host = null; 341434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt int port = 0; 342602b232a06ede86999aa362a12eb28cbc782dc1dJason Monk if (in.readByte() != 0) { 34383520b95124e0fcaaf3154a7a267f6be0205bc74Jason Monk Uri url = Uri.CREATOR.createFromParcel(in); 344decd295b1371238c97c170226c6145948492eda1Jason Monk int localPort = in.readInt(); 345207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk return new ProxyInfo(url, localPort); 346602b232a06ede86999aa362a12eb28cbc782dc1dJason Monk } 347602b232a06ede86999aa362a12eb28cbc782dc1dJason Monk if (in.readByte() != 0) { 348434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt host = in.readString(); 349434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt port = in.readInt(); 35047f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt } 351434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt String exclList = in.readString(); 352434203a277cd2f237a71508a3d5a7d1602126cd5Robert Greenwalt String[] parsedExclList = in.readStringArray(); 353207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk ProxyInfo proxyProperties = 354207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk new ProxyInfo(host, port, exclList, parsedExclList); 35547f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt return proxyProperties; 35647f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt } 35747f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt 358207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk public ProxyInfo[] newArray(int size) { 359207900c23b26d0df9ab28c709db4a1007d7d7904Jason Monk return new ProxyInfo[size]; 36047f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt } 36147f69fe2999e46004f2f2463b70d38de9ff7079aRobert Greenwalt }; 362ac19f24cc10d380b4065778e8ff5492c10a75cddAndrew Stadler} 363