Merge "Add API for proxy configuration over VPN."
This commit is contained in:
committed by
Android (Google) Code Review
commit
f2cef662ec
@@ -39,12 +39,12 @@ import java.util.Locale;
|
||||
*/
|
||||
public class ProxyInfo implements Parcelable {
|
||||
|
||||
private String mHost;
|
||||
private int mPort;
|
||||
private String mExclusionList;
|
||||
private String[] mParsedExclusionList;
|
||||
private final String mHost;
|
||||
private final int mPort;
|
||||
private final String mExclusionList;
|
||||
private final String[] mParsedExclusionList;
|
||||
private final Uri mPacFileUrl;
|
||||
|
||||
private Uri mPacFileUrl;
|
||||
/**
|
||||
*@hide
|
||||
*/
|
||||
@@ -96,7 +96,8 @@ public class ProxyInfo implements Parcelable {
|
||||
public ProxyInfo(String host, int port, String exclList) {
|
||||
mHost = host;
|
||||
mPort = port;
|
||||
setExclusionList(exclList);
|
||||
mExclusionList = exclList;
|
||||
mParsedExclusionList = parseExclusionList(mExclusionList);
|
||||
mPacFileUrl = Uri.EMPTY;
|
||||
}
|
||||
|
||||
@@ -107,7 +108,8 @@ public class ProxyInfo implements Parcelable {
|
||||
public ProxyInfo(Uri pacFileUrl) {
|
||||
mHost = LOCAL_HOST;
|
||||
mPort = LOCAL_PORT;
|
||||
setExclusionList(LOCAL_EXCL_LIST);
|
||||
mExclusionList = LOCAL_EXCL_LIST;
|
||||
mParsedExclusionList = parseExclusionList(mExclusionList);
|
||||
if (pacFileUrl == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
@@ -121,7 +123,8 @@ public class ProxyInfo implements Parcelable {
|
||||
public ProxyInfo(String pacFileUrl) {
|
||||
mHost = LOCAL_HOST;
|
||||
mPort = LOCAL_PORT;
|
||||
setExclusionList(LOCAL_EXCL_LIST);
|
||||
mExclusionList = LOCAL_EXCL_LIST;
|
||||
mParsedExclusionList = parseExclusionList(mExclusionList);
|
||||
mPacFileUrl = Uri.parse(pacFileUrl);
|
||||
}
|
||||
|
||||
@@ -132,13 +135,22 @@ public class ProxyInfo implements Parcelable {
|
||||
public ProxyInfo(Uri pacFileUrl, int localProxyPort) {
|
||||
mHost = LOCAL_HOST;
|
||||
mPort = localProxyPort;
|
||||
setExclusionList(LOCAL_EXCL_LIST);
|
||||
mExclusionList = LOCAL_EXCL_LIST;
|
||||
mParsedExclusionList = parseExclusionList(mExclusionList);
|
||||
if (pacFileUrl == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
mPacFileUrl = pacFileUrl;
|
||||
}
|
||||
|
||||
private static String[] parseExclusionList(String exclusionList) {
|
||||
if (exclusionList == null) {
|
||||
return new String[0];
|
||||
} else {
|
||||
return exclusionList.toLowerCase(Locale.ROOT).split(",");
|
||||
}
|
||||
}
|
||||
|
||||
private ProxyInfo(String host, int port, String exclList, String[] parsedExclList) {
|
||||
mHost = host;
|
||||
mPort = port;
|
||||
@@ -159,6 +171,10 @@ public class ProxyInfo implements Parcelable {
|
||||
mExclusionList = source.getExclusionListAsString();
|
||||
mParsedExclusionList = source.mParsedExclusionList;
|
||||
} else {
|
||||
mHost = null;
|
||||
mPort = 0;
|
||||
mExclusionList = null;
|
||||
mParsedExclusionList = null;
|
||||
mPacFileUrl = Uri.EMPTY;
|
||||
}
|
||||
}
|
||||
@@ -214,24 +230,14 @@ public class ProxyInfo implements Parcelable {
|
||||
return mExclusionList;
|
||||
}
|
||||
|
||||
// comma separated
|
||||
private void setExclusionList(String exclusionList) {
|
||||
mExclusionList = exclusionList;
|
||||
if (mExclusionList == null) {
|
||||
mParsedExclusionList = new String[0];
|
||||
} else {
|
||||
mParsedExclusionList = exclusionList.toLowerCase(Locale.ROOT).split(",");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public boolean isValid() {
|
||||
if (!Uri.EMPTY.equals(mPacFileUrl)) return true;
|
||||
return Proxy.PROXY_VALID == Proxy.validate(mHost == null ? "" : mHost,
|
||||
mPort == 0 ? "" : Integer.toString(mPort),
|
||||
mExclusionList == null ? "" : mExclusionList);
|
||||
mPort == 0 ? "" : Integer.toString(mPort),
|
||||
mExclusionList == null ? "" : mExclusionList);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -262,7 +268,7 @@ public class ProxyInfo implements Parcelable {
|
||||
sb.append("] ");
|
||||
sb.append(Integer.toString(mPort));
|
||||
if (mExclusionList != null) {
|
||||
sb.append(" xl=").append(mExclusionList);
|
||||
sb.append(" xl=").append(mExclusionList);
|
||||
}
|
||||
} else {
|
||||
sb.append("[ProxyProperties.mHost == null]");
|
||||
@@ -308,8 +314,8 @@ public class ProxyInfo implements Parcelable {
|
||||
*/
|
||||
public int hashCode() {
|
||||
return ((null == mHost) ? 0 : mHost.hashCode())
|
||||
+ ((null == mExclusionList) ? 0 : mExclusionList.hashCode())
|
||||
+ mPort;
|
||||
+ ((null == mExclusionList) ? 0 : mExclusionList.hashCode())
|
||||
+ mPort;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -352,8 +358,7 @@ public class ProxyInfo implements Parcelable {
|
||||
}
|
||||
String exclList = in.readString();
|
||||
String[] parsedExclList = in.readStringArray();
|
||||
ProxyInfo proxyProperties =
|
||||
new ProxyInfo(host, port, exclList, parsedExclList);
|
||||
ProxyInfo proxyProperties = new ProxyInfo(host, port, exclList, parsedExclList);
|
||||
return proxyProperties;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user