From 30bdeb33fea8d240d6b5cb4f9b1ff92284ff9bdd Mon Sep 17 00:00:00 2001 From: Irfan Sheriff Date: Sun, 26 Sep 2010 14:54:54 -0700 Subject: [PATCH] use hostname when address null ProxyProperties parcelling In ProxyProperties parcel, use toString so that hostname is used when address is null Change-Id: I4813dbdaf3c4a7bb404edf960d0f990c732ec0b8 --- core/java/android/net/ProxyProperties.java | 30 +++++++++++++++------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/core/java/android/net/ProxyProperties.java b/core/java/android/net/ProxyProperties.java index 140b71fd12..5fd0d89c72 100644 --- a/core/java/android/net/ProxyProperties.java +++ b/core/java/android/net/ProxyProperties.java @@ -88,13 +88,23 @@ public class ProxyProperties implements Parcelable { * @hide */ public void writeToParcel(Parcel dest, int flags) { + String host = null; if (mProxy != null) { - InetAddress addr = mProxy.getAddress(); - if (addr != null) { - dest.writeByte((byte)1); - dest.writeByteArray(addr.getAddress()); - dest.writeInt(mProxy.getPort()); - } + try { + InetAddress addr = mProxy.getAddress(); + if (addr != null) { + host = addr.getHostAddress(); + } else { + /* Does not resolve when addr is null */ + host = mProxy.getHostName(); + } + } catch (Exception e) { } + } + + if (host != null) { + dest.writeByte((byte)1); + dest.writeString(host); + dest.writeInt(mProxy.getPort()); } else { dest.writeByte((byte)0); } @@ -111,9 +121,11 @@ public class ProxyProperties implements Parcelable { ProxyProperties proxyProperties = new ProxyProperties(); if (in.readByte() == 1) { try { - InetAddress addr = InetAddress.getByAddress(in.createByteArray()); - proxyProperties.setSocketAddress(new InetSocketAddress(addr, in.readInt())); - } catch (UnknownHostException e) { } + String host = in.readString(); + int port = in.readInt(); + proxyProperties.setSocketAddress(InetSocketAddress.createUnresolved( + host, port)); + } catch (IllegalArgumentException e) { } } proxyProperties.setExclusionList(in.readString()); return proxyProperties;