diff options
author | Robert Greenwalt <robdroid@android.com> | 2010-08-30 10:56:47 -0700 |
---|---|---|
committer | Robert Greenwalt <rgreenwalt@google.com> | 2010-08-30 15:54:37 -0700 |
commit | 37e65ebb7eb932e1a144b1cab262e11ca5fd109b (patch) | |
tree | 8778822097d0ab67bc0a4c222cd7e01d2ade9082 /core/java | |
parent | e82235ae7049badf6758ffef3c13080b135986f4 (diff) | |
download | frameworks_base-37e65ebb7eb932e1a144b1cab262e11ca5fd109b.zip frameworks_base-37e65ebb7eb932e1a144b1cab262e11ca5fd109b.tar.gz frameworks_base-37e65ebb7eb932e1a144b1cab262e11ca5fd109b.tar.bz2 |
Rename NetworkProperties to LinkProperties
Also add copy constructors and use them when giving out data.
Change-Id: Id320eb8fb91d0bd250305ce7bb4f628570215615
Diffstat (limited to 'core/java')
-rw-r--r-- | core/java/android/net/LinkProperties.aidl (renamed from core/java/android/net/NetworkProperties.aidl) | 2 | ||||
-rw-r--r-- | core/java/android/net/LinkProperties.java (renamed from core/java/android/net/NetworkProperties.java) | 62 | ||||
-rw-r--r-- | core/java/android/net/MobileDataStateTracker.java | 22 | ||||
-rw-r--r-- | core/java/android/net/NetworkStateTracker.java | 4 | ||||
-rw-r--r-- | core/java/android/net/ProxyProperties.java | 21 |
5 files changed, 63 insertions, 48 deletions
diff --git a/core/java/android/net/NetworkProperties.aidl b/core/java/android/net/LinkProperties.aidl index 07aac6e..73c7988 100644 --- a/core/java/android/net/NetworkProperties.aidl +++ b/core/java/android/net/LinkProperties.aidl @@ -18,5 +18,5 @@ package android.net; -parcelable NetworkProperties; +parcelable LinkProperties; diff --git a/core/java/android/net/NetworkProperties.java b/core/java/android/net/LinkProperties.java index 03c0a2e..9cb38e3 100644 --- a/core/java/android/net/NetworkProperties.java +++ b/core/java/android/net/LinkProperties.java @@ -16,6 +16,7 @@ package android.net; +import android.net.ProxyProperties; import android.os.Parcelable; import android.os.Parcel; import android.util.Log; @@ -26,14 +27,14 @@ import java.net.SocketException; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; /** - * Describes the properties of a network interface or single address - * of an interface. + * Describes the properties of a network link. * TODO - consider adding optional fields like Apn and ApnType * @hide */ -public class NetworkProperties implements Parcelable { +public class LinkProperties implements Parcelable { private NetworkInterface mIface; private Collection<InetAddress> mAddresses; @@ -41,49 +42,58 @@ public class NetworkProperties implements Parcelable { private InetAddress mGateway; private ProxyProperties mHttpProxy; - public NetworkProperties() { + public LinkProperties() { clear(); } - public synchronized void setInterface(NetworkInterface iface) { + // copy constructor instead of clone + public LinkProperties(LinkProperties source) { + mIface = source.getInterface(); + mAddresses = source.getAddresses(); + mDnses = source.getDnses(); + mGateway = source.getGateway(); + mHttpProxy = new ProxyProperties(source.getHttpProxy()); + } + + public void setInterface(NetworkInterface iface) { mIface = iface; } - public synchronized NetworkInterface getInterface() { + public NetworkInterface getInterface() { return mIface; } - public synchronized String getInterfaceName() { + public String getInterfaceName() { return (mIface == null ? null : mIface.getName()); } - public synchronized void addAddress(InetAddress address) { + public void addAddress(InetAddress address) { mAddresses.add(address); } - public synchronized Collection<InetAddress> getAddresses() { - return mAddresses; + public Collection<InetAddress> getAddresses() { + return Collections.unmodifiableCollection(mAddresses); } - public synchronized void addDns(InetAddress dns) { + public void addDns(InetAddress dns) { mDnses.add(dns); } - public synchronized Collection<InetAddress> getDnses() { - return mDnses; + public Collection<InetAddress> getDnses() { + return Collections.unmodifiableCollection(mDnses); } - public synchronized void setGateway(InetAddress gateway) { + public void setGateway(InetAddress gateway) { mGateway = gateway; } - public synchronized InetAddress getGateway() { + public InetAddress getGateway() { return mGateway; } - public synchronized void setHttpProxy(ProxyProperties proxy) { + public void setHttpProxy(ProxyProperties proxy) { mHttpProxy = proxy; } - public synchronized ProxyProperties getHttpProxy() { + public ProxyProperties getHttpProxy() { return mHttpProxy; } - public synchronized void clear() { + public void clear() { mIface = null; mAddresses = new ArrayList<InetAddress>(); mDnses = new ArrayList<InetAddress>(); @@ -100,7 +110,7 @@ public class NetworkProperties implements Parcelable { } @Override - public synchronized String toString() { + public String toString() { String ifaceName = (mIface == null ? "" : "InterfaceName: " + mIface.getName() + " "); String ip = "IpAddresses: ["; @@ -121,7 +131,7 @@ public class NetworkProperties implements Parcelable { * Implement the Parcelable interface. * @hide */ - public synchronized void writeToParcel(Parcel dest, int flags) { + public void writeToParcel(Parcel dest, int flags) { dest.writeString(getInterfaceName()); dest.writeInt(mAddresses.size()); //TODO: explore an easy alternative to preserve hostname @@ -151,10 +161,10 @@ public class NetworkProperties implements Parcelable { * Implement the Parcelable interface. * @hide */ - public static final Creator<NetworkProperties> CREATOR = - new Creator<NetworkProperties>() { - public NetworkProperties createFromParcel(Parcel in) { - NetworkProperties netProp = new NetworkProperties(); + public static final Creator<LinkProperties> CREATOR = + new Creator<LinkProperties>() { + public LinkProperties createFromParcel(Parcel in) { + LinkProperties netProp = new LinkProperties(); String iface = in.readString(); if (iface != null) { try { @@ -186,8 +196,8 @@ public class NetworkProperties implements Parcelable { return netProp; } - public NetworkProperties[] newArray(int size) { - return new NetworkProperties[size]; + public LinkProperties[] newArray(int size) { + return new LinkProperties[size]; } }; } diff --git a/core/java/android/net/MobileDataStateTracker.java b/core/java/android/net/MobileDataStateTracker.java index 6dfd3bc..0498fff 100644 --- a/core/java/android/net/MobileDataStateTracker.java +++ b/core/java/android/net/MobileDataStateTracker.java @@ -16,8 +16,6 @@ package android.net; -import java.net.InetAddress; - import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -32,7 +30,7 @@ import com.android.internal.telephony.Phone; import com.android.internal.telephony.TelephonyIntents; import android.net.NetworkInfo.DetailedState; import android.net.NetworkInfo; -import android.net.NetworkProperties; +import android.net.LinkProperties; import android.telephony.TelephonyManager; import android.util.Log; import android.text.TextUtils; @@ -58,7 +56,7 @@ public class MobileDataStateTracker implements NetworkStateTracker { private boolean mTeardownRequested = false; private Handler mTarget; private Context mContext; - private NetworkProperties mNetworkProperties; + private LinkProperties mLinkProperties; private boolean mPrivateDnsRouteSet = false; private int mDefaultGatewayAddr = 0; private boolean mDefaultRouteSet = false; @@ -213,8 +211,8 @@ public class MobileDataStateTracker implements NetworkStateTracker { + e); } } - if (doReset && mNetworkProperties != null) { - String iface = mNetworkProperties.getInterfaceName(); + if (doReset && mLinkProperties != null) { + String iface = mLinkProperties.getInterfaceName(); if (iface != null) NetworkUtils.resetConnections(iface); } // TODO - check this @@ -233,11 +231,11 @@ public class MobileDataStateTracker implements NetworkStateTracker { setDetailedState(DetailedState.SUSPENDED, reason, apnName); break; case CONNECTED: - mNetworkProperties = intent.getParcelableExtra( - Phone.DATA_NETWORK_PROPERTIES_KEY); - if (mNetworkProperties == null) { + mLinkProperties = intent.getParcelableExtra( + Phone.DATA_LINK_PROPERTIES_KEY); + if (mLinkProperties == null) { Log.d(TAG, - "CONNECTED event did not supply network properties."); + "CONNECTED event did not supply link properties."); } setDetailedState(DetailedState.CONNECTED, reason, apnName); break; @@ -563,7 +561,7 @@ public class MobileDataStateTracker implements NetworkStateTracker { } } - public NetworkProperties getNetworkProperties() { - return mNetworkProperties; + public LinkProperties getLinkProperties() { + return new LinkProperties(mLinkProperties); } } diff --git a/core/java/android/net/NetworkStateTracker.java b/core/java/android/net/NetworkStateTracker.java index 0048a2e..420992b 100644 --- a/core/java/android/net/NetworkStateTracker.java +++ b/core/java/android/net/NetworkStateTracker.java @@ -91,9 +91,9 @@ public interface NetworkStateTracker { public NetworkInfo getNetworkInfo(); /** - * Fetch NetworkProperties for the network + * Fetch LinkProperties for the network */ - public NetworkProperties getNetworkProperties(); + public LinkProperties getLinkProperties(); /** * Return the system properties name associated with the tcp buffer sizes diff --git a/core/java/android/net/ProxyProperties.java b/core/java/android/net/ProxyProperties.java index 207fb51..24f6766 100644 --- a/core/java/android/net/ProxyProperties.java +++ b/core/java/android/net/ProxyProperties.java @@ -36,24 +36,31 @@ public class ProxyProperties implements Parcelable { public ProxyProperties() { } - public synchronized InetAddress getAddress() { + // copy constructor instead of clone + public ProxyProperties(ProxyProperties source) { + mProxy = source.getAddress(); + mPort = source.getPort(); + mExclusionList = new String(source.getExclusionList()); + } + + public InetAddress getAddress() { return mProxy; } - public synchronized void setAddress(InetAddress proxy) { + public void setAddress(InetAddress proxy) { mProxy = proxy; } - public synchronized int getPort() { + public int getPort() { return mPort; } - public synchronized void setPort(int port) { + public void setPort(int port) { mPort = port; } - public synchronized String getExclusionList() { + public String getExclusionList() { return mExclusionList; } - public synchronized void setExclusionList(String exclusionList) { + public void setExclusionList(String exclusionList) { mExclusionList = exclusionList; } @@ -77,7 +84,7 @@ public class ProxyProperties implements Parcelable { * Implement the Parcelable interface. * @hide */ - public synchronized void writeToParcel(Parcel dest, int flags) { + public void writeToParcel(Parcel dest, int flags) { if (mProxy != null) { dest.writeByte((byte)1); dest.writeString(mProxy.getHostName()); |