diff options
author | Robert Greenwalt <rgreenwalt@google.com> | 2010-09-08 15:35:40 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2010-09-08 15:35:40 -0700 |
commit | fa018890643dfc2ccc3a74a223b21dc24b72fa05 (patch) | |
tree | 5e292c883b93f526a5642ec211ce15af0294fe9b /core | |
parent | 53e7ae9065e506da2f0337c7c77cf2749d9ee970 (diff) | |
parent | 70af574b3d61605e311a7b3b5cb1531d5201dc5b (diff) | |
download | frameworks_base-fa018890643dfc2ccc3a74a223b21dc24b72fa05.zip frameworks_base-fa018890643dfc2ccc3a74a223b21dc24b72fa05.tar.gz frameworks_base-fa018890643dfc2ccc3a74a223b21dc24b72fa05.tar.bz2 |
Merge "Some cleanup of Proxy class."
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/net/Proxy.java | 13 | ||||
-rw-r--r-- | core/java/android/net/ProxyProperties.java | 38 |
2 files changed, 23 insertions, 28 deletions
diff --git a/core/java/android/net/Proxy.java b/core/java/android/net/Proxy.java index e2e4d2c..9c63cd9 100644 --- a/core/java/android/net/Proxy.java +++ b/core/java/android/net/Proxy.java @@ -46,6 +46,8 @@ public final class Proxy { // Set to true to enable extra debugging. private static final boolean DEBUG = false; + // Used to notify an app that's caching the default connection proxy + // that either the default connection or its proxy has changed public static final String PROXY_CHANGE_ACTION = "android.intent.action.PROXY_CHANGE"; @@ -74,9 +76,10 @@ public final class Proxy { EXCLLIST_PATTERN = Pattern.compile(EXCLLIST_REGEXP); } + // useful because it holds the processed exclusion list - don't want to reparse it each time private static class ProxySpec { String[] exclusionList = null; - InetSocketAddress proxyAddress = null; + InetSocketAddress address = null; public ProxySpec() { }; } @@ -151,7 +154,7 @@ public final class Proxy { retval = java.net.Proxy.NO_PROXY; } else { retval = - new java.net.Proxy(java.net.Proxy.Type.HTTP, sGlobalProxySpec.proxyAddress); + new java.net.Proxy(java.net.Proxy.Type.HTTP, sGlobalProxySpec.address); } } else { // If network is WiFi, return no proxy. @@ -187,7 +190,7 @@ public final class Proxy { parseGlobalProxyInfoReadLocked(ctx); } if (sGlobalProxySpec != null) { - InetSocketAddress sa = sGlobalProxySpec.proxyAddress; + InetSocketAddress sa = sGlobalProxySpec.address; return sa.getHostName(); } return getDefaultHost(); @@ -210,7 +213,7 @@ public final class Proxy { parseGlobalProxyInfoReadLocked(ctx); } if (sGlobalProxySpec != null) { - InetSocketAddress sa = sGlobalProxySpec.proxyAddress; + InetSocketAddress sa = sGlobalProxySpec.address; return sa.getPort(); } return getDefaultPort(); @@ -389,7 +392,7 @@ public final class Proxy { int port = parsePort(proxyHost); if (proxyHost != null) { sGlobalProxySpec = new ProxySpec(); - sGlobalProxySpec.proxyAddress = new InetSocketAddress(host, port); + sGlobalProxySpec.address= new InetSocketAddress(host, port); if ((exclusionListSpec != null) && (exclusionListSpec.length() != 0)) { String[] exclusionListEntries = exclusionListSpec.toLowerCase().split(","); String[] processedEntries = new String[exclusionListEntries.length]; diff --git a/core/java/android/net/ProxyProperties.java b/core/java/android/net/ProxyProperties.java index bce7ec0..fb59fed 100644 --- a/core/java/android/net/ProxyProperties.java +++ b/core/java/android/net/ProxyProperties.java @@ -21,6 +21,7 @@ import android.os.Parcel; import android.os.Parcelable; import java.net.InetAddress; +import java.net.InetSocketAddress; import java.net.UnknownHostException; /** @@ -29,8 +30,7 @@ import java.net.UnknownHostException; */ public class ProxyProperties implements Parcelable { - private InetAddress mProxy; - private int mPort; + private InetSocketAddress mProxy; private String mExclusionList; public ProxyProperties() { @@ -39,8 +39,7 @@ public class ProxyProperties implements Parcelable { // copy constructor instead of clone public ProxyProperties(ProxyProperties source) { if (source != null) { - mProxy = source.getAddress(); - mPort = source.getPort(); + mProxy = source.getSocketAddress(); String exclusionList = source.getExclusionList(); if (exclusionList != null) { mExclusionList = new String(exclusionList); @@ -48,22 +47,14 @@ public class ProxyProperties implements Parcelable { } } - public InetAddress getAddress() { + public InetSocketAddress getSocketAddress() { return mProxy; } - public void setAddress(InetAddress proxy) { + public void setSocketAddress(InetSocketAddress proxy) { mProxy = proxy; } - public int getPort() { - return mPort; - } - - public void setPort(int port) { - mPort = port; - } - public String getExclusionList() { return mExclusionList; } @@ -76,7 +67,7 @@ public class ProxyProperties implements Parcelable { public String toString() { StringBuilder sb = new StringBuilder(); if (mProxy != null) { - sb.append(mProxy.getHostAddress()).append(":").append(mPort); + sb.append(mProxy.toString()); if (mExclusionList != null) { sb.append(" xl=").append(mExclusionList); } @@ -98,13 +89,15 @@ public class ProxyProperties implements Parcelable { */ public void writeToParcel(Parcel dest, int flags) { if (mProxy != null) { - dest.writeByte((byte)1); - dest.writeString(mProxy.getHostName()); - dest.writeByteArray(mProxy.getAddress()); + InetAddress addr = mProxy.getAddress(); + if (addr != null) { + dest.writeByte((byte)1); + dest.writeByteArray(addr.getAddress()); + dest.writeInt(mProxy.getPort()); + } } else { dest.writeByte((byte)0); } - dest.writeInt(mPort); dest.writeString(mExclusionList); } @@ -118,11 +111,10 @@ public class ProxyProperties implements Parcelable { ProxyProperties proxyProperties = new ProxyProperties(); if (in.readByte() == 1) { try { - proxyProperties.setAddress(InetAddress.getByAddress(in.readString(), - in.createByteArray())); - } catch (UnknownHostException e) {} + InetAddress addr = InetAddress.getByAddress(in.createByteArray()); + proxyProperties.setSocketAddress(new InetSocketAddress(addr, in.readInt())); + } catch (UnknownHostException e) { } } - proxyProperties.setPort(in.readInt()); proxyProperties.setExclusionList(in.readString()); return proxyProperties; } |