summaryrefslogtreecommitdiffstats
path: root/core/java/android/net/ProxyProperties.java
diff options
context:
space:
mode:
authorJason Monk <jmonk@google.com>2013-07-03 17:04:33 -0400
committerJason Monk <jmonk@google.com>2013-08-07 21:01:39 -0400
commit602b232a06ede86999aa362a12eb28cbc782dc1d (patch)
tree07a2168ba91425f81bd7ac9c9311adb78114cc13 /core/java/android/net/ProxyProperties.java
parent55db1e1218971105e68ba9d451b2e0b1e9e5f9fb (diff)
downloadframeworks_base-602b232a06ede86999aa362a12eb28cbc782dc1d.zip
frameworks_base-602b232a06ede86999aa362a12eb28cbc782dc1d.tar.gz
frameworks_base-602b232a06ede86999aa362a12eb28cbc782dc1d.tar.bz2
Add PAC File support for proxy configuration
PAC (Proxy auto-config) files contain a single javascript function, FindProxyForURL(url, host). It gets called to determine what proxy should be used for a specific request. This adds PAC support to the system. The ProxyProperties has been modified to hold the PAC file when one is present. The Proxy method setHttpProxySystemProperty has been modified to insert a PacProxySelector as the default ProxySelector when it is required. This new ProxySelector makes calls to the ConnectivityService to parse the PAC file. The ConnectivityService and the WifiConfigStore have been modified to support saving the extra PAC file data. The ConnectivityService now has a class attached (PacProxyNative) that interfaces to the native calls for PAC files. The parsing of the PAC file is handled by libpac (which is being added to external/) which utilizes libv8 to parse the javascript. As a fallback to applications that don't use the java ProxySelector, the proxy is setup to point to a local proxy server that will handle the pac parsing. bug:10182711 Change-Id: I5eb8df893c632fd3e1b732385cb7720ad646f401
Diffstat (limited to 'core/java/android/net/ProxyProperties.java')
-rw-r--r--core/java/android/net/ProxyProperties.java45
1 files changed, 41 insertions, 4 deletions
diff --git a/core/java/android/net/ProxyProperties.java b/core/java/android/net/ProxyProperties.java
index 9c4772b..76aea9f 100644
--- a/core/java/android/net/ProxyProperties.java
+++ b/core/java/android/net/ProxyProperties.java
@@ -20,9 +20,7 @@ package android.net;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
-import android.util.Log;
-import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.Locale;
@@ -38,17 +36,30 @@ public class ProxyProperties implements Parcelable {
private String mExclusionList;
private String[] mParsedExclusionList;
+ private String mPacFileUrl;
+ public static final String LOCAL_EXCL_LIST = "";
+ public static final int LOCAL_PORT = 8182;
+ public static final String LOCAL_HOST = "localhost";
+
public ProxyProperties(String host, int port, String exclList) {
mHost = host;
mPort = port;
setExclusionList(exclList);
}
+ public ProxyProperties(String pacFileUrl) {
+ mHost = LOCAL_HOST;
+ mPort = LOCAL_PORT;
+ setExclusionList(LOCAL_EXCL_LIST);
+ mPacFileUrl = pacFileUrl;
+ }
+
private ProxyProperties(String host, int port, String exclList, String[] parsedExclList) {
mHost = host;
mPort = port;
mExclusionList = exclList;
mParsedExclusionList = parsedExclList;
+ mPacFileUrl = null;
}
// copy constructor instead of clone
@@ -56,6 +67,7 @@ public class ProxyProperties implements Parcelable {
if (source != null) {
mHost = source.getHost();
mPort = source.getPort();
+ mPacFileUrl = source.getPacFileUrl();
mExclusionList = source.getExclusionList();
mParsedExclusionList = source.mParsedExclusionList;
}
@@ -69,6 +81,10 @@ public class ProxyProperties implements Parcelable {
return inetSocketAddress;
}
+ public String getPacFileUrl() {
+ return mPacFileUrl;
+ }
+
public String getHost() {
return mHost;
}
@@ -130,7 +146,10 @@ public class ProxyProperties implements Parcelable {
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
- if (mHost != null) {
+ if (mPacFileUrl != null) {
+ sb.append("PAC Script: ");
+ sb.append(mPacFileUrl);
+ } else if (mHost != null) {
sb.append("[");
sb.append(mHost);
sb.append("] ");
@@ -148,6 +167,14 @@ public class ProxyProperties implements Parcelable {
public boolean equals(Object o) {
if (!(o instanceof ProxyProperties)) return false;
ProxyProperties p = (ProxyProperties)o;
+ // If PAC URL is present in either then they must be equal.
+ // Other parameters will only be for fall back.
+ if (!TextUtils.isEmpty(mPacFileUrl)) {
+ return mPacFileUrl.equals(p.getPacFileUrl());
+ }
+ if (!TextUtils.isEmpty(p.getPacFileUrl())) {
+ return false;
+ }
if (mExclusionList != null && !mExclusionList.equals(p.getExclusionList())) return false;
if (mHost != null && p.getHost() != null && mHost.equals(p.getHost()) == false) {
return false;
@@ -181,6 +208,13 @@ public class ProxyProperties implements Parcelable {
* @hide
*/
public void writeToParcel(Parcel dest, int flags) {
+ if (mPacFileUrl != null) {
+ dest.writeByte((byte)1);
+ dest.writeString(mPacFileUrl);
+ return;
+ } else {
+ dest.writeByte((byte)0);
+ }
if (mHost != null) {
dest.writeByte((byte)1);
dest.writeString(mHost);
@@ -201,7 +235,10 @@ public class ProxyProperties implements Parcelable {
public ProxyProperties createFromParcel(Parcel in) {
String host = null;
int port = 0;
- if (in.readByte() == 1) {
+ if (in.readByte() != 0) {
+ return new ProxyProperties(in.readString());
+ }
+ if (in.readByte() != 0) {
host = in.readString();
port = in.readInt();
}