Rename NetworkProperties to LinkProperties
Also add copy constructors and use them when giving out data. Change-Id: Id320eb8fb91d0bd250305ce7bb4f628570215615
This commit is contained in:
committed by
Robert Greenwalt
parent
906eda5bac
commit
1f1bcfe6a2
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package android.net;
|
package android.net;
|
||||||
|
|
||||||
|
import android.net.ProxyProperties;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -26,14 +27,14 @@ import java.net.SocketException;
|
|||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Describes the properties of a network interface or single address
|
* Describes the properties of a network link.
|
||||||
* of an interface.
|
|
||||||
* TODO - consider adding optional fields like Apn and ApnType
|
* TODO - consider adding optional fields like Apn and ApnType
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public class NetworkProperties implements Parcelable {
|
public class LinkProperties implements Parcelable {
|
||||||
|
|
||||||
private NetworkInterface mIface;
|
private NetworkInterface mIface;
|
||||||
private Collection<InetAddress> mAddresses;
|
private Collection<InetAddress> mAddresses;
|
||||||
@@ -41,49 +42,58 @@ public class NetworkProperties implements Parcelable {
|
|||||||
private InetAddress mGateway;
|
private InetAddress mGateway;
|
||||||
private ProxyProperties mHttpProxy;
|
private ProxyProperties mHttpProxy;
|
||||||
|
|
||||||
public NetworkProperties() {
|
public LinkProperties() {
|
||||||
clear();
|
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;
|
mIface = iface;
|
||||||
}
|
}
|
||||||
public synchronized NetworkInterface getInterface() {
|
public NetworkInterface getInterface() {
|
||||||
return mIface;
|
return mIface;
|
||||||
}
|
}
|
||||||
public synchronized String getInterfaceName() {
|
public String getInterfaceName() {
|
||||||
return (mIface == null ? null : mIface.getName());
|
return (mIface == null ? null : mIface.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void addAddress(InetAddress address) {
|
public void addAddress(InetAddress address) {
|
||||||
mAddresses.add(address);
|
mAddresses.add(address);
|
||||||
}
|
}
|
||||||
public synchronized Collection<InetAddress> getAddresses() {
|
public Collection<InetAddress> getAddresses() {
|
||||||
return mAddresses;
|
return Collections.unmodifiableCollection(mAddresses);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void addDns(InetAddress dns) {
|
public void addDns(InetAddress dns) {
|
||||||
mDnses.add(dns);
|
mDnses.add(dns);
|
||||||
}
|
}
|
||||||
public synchronized Collection<InetAddress> getDnses() {
|
public Collection<InetAddress> getDnses() {
|
||||||
return mDnses;
|
return Collections.unmodifiableCollection(mDnses);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void setGateway(InetAddress gateway) {
|
public void setGateway(InetAddress gateway) {
|
||||||
mGateway = gateway;
|
mGateway = gateway;
|
||||||
}
|
}
|
||||||
public synchronized InetAddress getGateway() {
|
public InetAddress getGateway() {
|
||||||
return mGateway;
|
return mGateway;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void setHttpProxy(ProxyProperties proxy) {
|
public void setHttpProxy(ProxyProperties proxy) {
|
||||||
mHttpProxy = proxy;
|
mHttpProxy = proxy;
|
||||||
}
|
}
|
||||||
public synchronized ProxyProperties getHttpProxy() {
|
public ProxyProperties getHttpProxy() {
|
||||||
return mHttpProxy;
|
return mHttpProxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void clear() {
|
public void clear() {
|
||||||
mIface = null;
|
mIface = null;
|
||||||
mAddresses = new ArrayList<InetAddress>();
|
mAddresses = new ArrayList<InetAddress>();
|
||||||
mDnses = new ArrayList<InetAddress>();
|
mDnses = new ArrayList<InetAddress>();
|
||||||
@@ -100,7 +110,7 @@ public class NetworkProperties implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized String toString() {
|
public String toString() {
|
||||||
String ifaceName = (mIface == null ? "" : "InterfaceName: " + mIface.getName() + " ");
|
String ifaceName = (mIface == null ? "" : "InterfaceName: " + mIface.getName() + " ");
|
||||||
|
|
||||||
String ip = "IpAddresses: [";
|
String ip = "IpAddresses: [";
|
||||||
@@ -121,7 +131,7 @@ public class NetworkProperties implements Parcelable {
|
|||||||
* Implement the Parcelable interface.
|
* Implement the Parcelable interface.
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public synchronized void writeToParcel(Parcel dest, int flags) {
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
dest.writeString(getInterfaceName());
|
dest.writeString(getInterfaceName());
|
||||||
dest.writeInt(mAddresses.size());
|
dest.writeInt(mAddresses.size());
|
||||||
//TODO: explore an easy alternative to preserve hostname
|
//TODO: explore an easy alternative to preserve hostname
|
||||||
@@ -151,10 +161,10 @@ public class NetworkProperties implements Parcelable {
|
|||||||
* Implement the Parcelable interface.
|
* Implement the Parcelable interface.
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public static final Creator<NetworkProperties> CREATOR =
|
public static final Creator<LinkProperties> CREATOR =
|
||||||
new Creator<NetworkProperties>() {
|
new Creator<LinkProperties>() {
|
||||||
public NetworkProperties createFromParcel(Parcel in) {
|
public LinkProperties createFromParcel(Parcel in) {
|
||||||
NetworkProperties netProp = new NetworkProperties();
|
LinkProperties netProp = new LinkProperties();
|
||||||
String iface = in.readString();
|
String iface = in.readString();
|
||||||
if (iface != null) {
|
if (iface != null) {
|
||||||
try {
|
try {
|
||||||
@@ -186,8 +196,8 @@ public class NetworkProperties implements Parcelable {
|
|||||||
return netProp;
|
return netProp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NetworkProperties[] newArray(int size) {
|
public LinkProperties[] newArray(int size) {
|
||||||
return new NetworkProperties[size];
|
return new LinkProperties[size];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -36,24 +36,31 @@ public class ProxyProperties implements Parcelable {
|
|||||||
public ProxyProperties() {
|
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;
|
return mProxy;
|
||||||
}
|
}
|
||||||
public synchronized void setAddress(InetAddress proxy) {
|
public void setAddress(InetAddress proxy) {
|
||||||
mProxy = proxy;
|
mProxy = proxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized int getPort() {
|
public int getPort() {
|
||||||
return mPort;
|
return mPort;
|
||||||
}
|
}
|
||||||
public synchronized void setPort(int port) {
|
public void setPort(int port) {
|
||||||
mPort = port;
|
mPort = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized String getExclusionList() {
|
public String getExclusionList() {
|
||||||
return mExclusionList;
|
return mExclusionList;
|
||||||
}
|
}
|
||||||
public synchronized void setExclusionList(String exclusionList) {
|
public void setExclusionList(String exclusionList) {
|
||||||
mExclusionList = exclusionList;
|
mExclusionList = exclusionList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,7 +84,7 @@ public class ProxyProperties implements Parcelable {
|
|||||||
* Implement the Parcelable interface.
|
* Implement the Parcelable interface.
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public synchronized void writeToParcel(Parcel dest, int flags) {
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
if (mProxy != null) {
|
if (mProxy != null) {
|
||||||
dest.writeByte((byte)1);
|
dest.writeByte((byte)1);
|
||||||
dest.writeString(mProxy.getHostName());
|
dest.writeString(mProxy.getHostName());
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import android.net.ConnectivityManager;
|
|||||||
import android.net.IConnectivityManager;
|
import android.net.IConnectivityManager;
|
||||||
import android.net.MobileDataStateTracker;
|
import android.net.MobileDataStateTracker;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
import android.net.NetworkProperties;
|
import android.net.LinkProperties;
|
||||||
import android.net.NetworkStateTracker;
|
import android.net.NetworkStateTracker;
|
||||||
import android.net.NetworkUtils;
|
import android.net.NetworkUtils;
|
||||||
import android.net.wifi.WifiStateTracker;
|
import android.net.wifi.WifiStateTracker;
|
||||||
@@ -756,7 +756,6 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
* specified host is to be routed
|
* specified host is to be routed
|
||||||
* @param hostAddress the IP address of the host to which the route is
|
* @param hostAddress the IP address of the host to which the route is
|
||||||
* desired
|
* desired
|
||||||
* todo - deprecate (only v4!)
|
|
||||||
* @return {@code true} on success, {@code false} on failure
|
* @return {@code true} on success, {@code false} on failure
|
||||||
*/
|
*/
|
||||||
public boolean requestRouteToHost(int networkType, int hostAddress) {
|
public boolean requestRouteToHost(int networkType, int hostAddress) {
|
||||||
@@ -813,7 +812,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkProperties p = nt.getNetworkProperties();
|
LinkProperties p = nt.getLinkProperties();
|
||||||
if (p == null) return false;
|
if (p == null) return false;
|
||||||
String interfaceName = p.getInterfaceName();
|
String interfaceName = p.getInterfaceName();
|
||||||
|
|
||||||
@@ -1258,7 +1257,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
|
|
||||||
private void addPrivateDnsRoutes(NetworkStateTracker nt) {
|
private void addPrivateDnsRoutes(NetworkStateTracker nt) {
|
||||||
boolean privateDnsRouteSet = nt.isPrivateDnsRouteSet();
|
boolean privateDnsRouteSet = nt.isPrivateDnsRouteSet();
|
||||||
NetworkProperties p = nt.getNetworkProperties();
|
LinkProperties p = nt.getLinkProperties();
|
||||||
if (p == null) return;
|
if (p == null) return;
|
||||||
String interfaceName = p.getInterfaceName();
|
String interfaceName = p.getInterfaceName();
|
||||||
|
|
||||||
@@ -1279,7 +1278,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
private void removePrivateDnsRoutes(NetworkStateTracker nt) {
|
private void removePrivateDnsRoutes(NetworkStateTracker nt) {
|
||||||
// TODO - we should do this explicitly but the NetUtils api doesnt
|
// TODO - we should do this explicitly but the NetUtils api doesnt
|
||||||
// support this yet - must remove all. No worse than before
|
// support this yet - must remove all. No worse than before
|
||||||
NetworkProperties p = nt.getNetworkProperties();
|
LinkProperties p = nt.getLinkProperties();
|
||||||
if (p == null) return;
|
if (p == null) return;
|
||||||
String interfaceName = p.getInterfaceName();
|
String interfaceName = p.getInterfaceName();
|
||||||
boolean privateDnsRouteSet = nt.isPrivateDnsRouteSet();
|
boolean privateDnsRouteSet = nt.isPrivateDnsRouteSet();
|
||||||
@@ -1295,7 +1294,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
|
|
||||||
|
|
||||||
private void addDefaultRoute(NetworkStateTracker nt) {
|
private void addDefaultRoute(NetworkStateTracker nt) {
|
||||||
NetworkProperties p = nt.getNetworkProperties();
|
LinkProperties p = nt.getLinkProperties();
|
||||||
if (p == null) return;
|
if (p == null) return;
|
||||||
String interfaceName = p.getInterfaceName();
|
String interfaceName = p.getInterfaceName();
|
||||||
InetAddress defaultGatewayAddr = p.getGateway();
|
InetAddress defaultGatewayAddr = p.getGateway();
|
||||||
@@ -1311,7 +1310,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
|
|
||||||
|
|
||||||
public void removeDefaultRoute(NetworkStateTracker nt) {
|
public void removeDefaultRoute(NetworkStateTracker nt) {
|
||||||
NetworkProperties p = nt.getNetworkProperties();
|
LinkProperties p = nt.getLinkProperties();
|
||||||
if (p == null) return;
|
if (p == null) return;
|
||||||
String interfaceName = p.getInterfaceName();
|
String interfaceName = p.getInterfaceName();
|
||||||
|
|
||||||
@@ -1410,7 +1409,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
NetworkStateTracker nt = mNetTrackers[i];
|
NetworkStateTracker nt = mNetTrackers[i];
|
||||||
if (nt.getNetworkInfo().isConnected() &&
|
if (nt.getNetworkInfo().isConnected() &&
|
||||||
!nt.isTeardownRequested()) {
|
!nt.isTeardownRequested()) {
|
||||||
NetworkProperties p = nt.getNetworkProperties();
|
LinkProperties p = nt.getLinkProperties();
|
||||||
if (p == null) continue;
|
if (p == null) continue;
|
||||||
List pids = mNetRequestersPids[i];
|
List pids = mNetRequestersPids[i];
|
||||||
for (int j=0; j<pids.size(); j++) {
|
for (int j=0; j<pids.size(); j++) {
|
||||||
@@ -1465,7 +1464,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
// add default net's dns entries
|
// add default net's dns entries
|
||||||
NetworkStateTracker nt = mNetTrackers[netType];
|
NetworkStateTracker nt = mNetTrackers[netType];
|
||||||
if (nt != null && nt.getNetworkInfo().isConnected() && !nt.isTeardownRequested()) {
|
if (nt != null && nt.getNetworkInfo().isConnected() && !nt.isTeardownRequested()) {
|
||||||
NetworkProperties p = nt.getNetworkProperties();
|
LinkProperties p = nt.getLinkProperties();
|
||||||
if (p == null) return;
|
if (p == null) return;
|
||||||
Collection<InetAddress> dnses = p.getDnses();
|
Collection<InetAddress> dnses = p.getDnses();
|
||||||
if (mNetAttributes[netType].isDefault()) {
|
if (mNetAttributes[netType].isDefault()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user