Merge commit 'b873a17ce7be0a9771c24999adca6964431728f6' into HEAD
Change-Id: I938755073e70602cc8f51ce9bd420fdcf870cecd
This commit is contained in:
@@ -355,11 +355,17 @@ public class ConnectivityManager {
|
||||
*/
|
||||
public static final int TYPE_WIFI_P2P = 13;
|
||||
|
||||
/** {@hide} */
|
||||
public static final int MAX_RADIO_TYPE = TYPE_WIFI_P2P;
|
||||
/**
|
||||
* The network to use for initially attaching to the network
|
||||
* {@hide}
|
||||
*/
|
||||
public static final int TYPE_MOBILE_IA = 14;
|
||||
|
||||
/** {@hide} */
|
||||
public static final int MAX_NETWORK_TYPE = TYPE_WIFI_P2P;
|
||||
public static final int MAX_RADIO_TYPE = TYPE_MOBILE_IA;
|
||||
|
||||
/** {@hide} */
|
||||
public static final int MAX_NETWORK_TYPE = TYPE_MOBILE_IA;
|
||||
|
||||
/**
|
||||
* If you want to set the default network preference,you can directly
|
||||
@@ -436,6 +442,8 @@ public class ConnectivityManager {
|
||||
return "MOBILE_CBS";
|
||||
case TYPE_WIFI_P2P:
|
||||
return "WIFI_P2P";
|
||||
case TYPE_MOBILE_IA:
|
||||
return "MOBILE_IA";
|
||||
default:
|
||||
return Integer.toString(type);
|
||||
}
|
||||
@@ -458,6 +466,39 @@ public class ConnectivityManager {
|
||||
case TYPE_MOBILE_FOTA:
|
||||
case TYPE_MOBILE_IMS:
|
||||
case TYPE_MOBILE_CBS:
|
||||
case TYPE_MOBILE_IA:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given network type is backed by a Wi-Fi radio.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public static boolean isNetworkTypeWifi(int networkType) {
|
||||
switch (networkType) {
|
||||
case TYPE_WIFI:
|
||||
case TYPE_WIFI_P2P:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given network type should be exempt from VPN routing rules
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public static boolean isNetworkTypeExempt(int networkType) {
|
||||
switch (networkType) {
|
||||
case TYPE_MOBILE_MMS:
|
||||
case TYPE_MOBILE_SUPL:
|
||||
case TYPE_MOBILE_HIPRI:
|
||||
case TYPE_MOBILE_IA:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
@@ -582,6 +623,29 @@ public class ConnectivityManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns details about the Provisioning or currently active default data network. When
|
||||
* connected, this network is the default route for outgoing connections.
|
||||
* You should always check {@link NetworkInfo#isConnected()} before initiating
|
||||
* network traffic. This may return {@code null} when there is no default
|
||||
* network.
|
||||
*
|
||||
* @return a {@link NetworkInfo} object for the current default network
|
||||
* or {@code null} if no network default network is currently active
|
||||
*
|
||||
* <p>This method requires the call to hold the permission
|
||||
* {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
|
||||
*
|
||||
* {@hide}
|
||||
*/
|
||||
public NetworkInfo getProvisioningOrActiveNetworkInfo() {
|
||||
try {
|
||||
return mService.getProvisioningOrActiveNetworkInfo();
|
||||
} catch (RemoteException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the IP information for the current default network.
|
||||
*
|
||||
@@ -1282,6 +1346,25 @@ public class ConnectivityManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Signal that the captive portal check on the indicated network
|
||||
* is complete and whether its a captive portal or not.
|
||||
*
|
||||
* @param info the {@link NetworkInfo} object for the networkType
|
||||
* in question.
|
||||
* @param isCaptivePortal true/false.
|
||||
*
|
||||
* <p>This method requires the call to hold the permission
|
||||
* {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}.
|
||||
* {@hide}
|
||||
*/
|
||||
public void captivePortalCheckCompleted(NetworkInfo info, boolean isCaptivePortal) {
|
||||
try {
|
||||
mService.captivePortalCheckCompleted(info, isCaptivePortal);
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Supply the backend messenger for a network tracker
|
||||
*
|
||||
@@ -1297,70 +1380,26 @@ public class ConnectivityManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* The ResultReceiver resultCode for checkMobileProvisioning (CMP_RESULT_CODE)
|
||||
*/
|
||||
|
||||
/**
|
||||
* No connection was possible to the network.
|
||||
* {@hide}
|
||||
*/
|
||||
public static final int CMP_RESULT_CODE_NO_CONNECTION = 0;
|
||||
|
||||
/**
|
||||
* A connection was made to the internet, all is well.
|
||||
* {@hide}
|
||||
*/
|
||||
public static final int CMP_RESULT_CODE_CONNECTABLE = 1;
|
||||
|
||||
/**
|
||||
* A connection was made but there was a redirection, we appear to be in walled garden.
|
||||
* This is an indication of a warm sim on a mobile network.
|
||||
* {@hide}
|
||||
*/
|
||||
public static final int CMP_RESULT_CODE_REDIRECTED = 2;
|
||||
|
||||
/**
|
||||
* A connection was made but no dns server was available to resolve a name to address.
|
||||
* This is an indication of a warm sim on a mobile network.
|
||||
* Check mobile provisioning.
|
||||
*
|
||||
* {@hide}
|
||||
*/
|
||||
public static final int CMP_RESULT_CODE_NO_DNS = 3;
|
||||
|
||||
/**
|
||||
* A connection was made but could not open a TCP connection.
|
||||
* This is an indication of a warm sim on a mobile network.
|
||||
* {@hide}
|
||||
*/
|
||||
public static final int CMP_RESULT_CODE_NO_TCP_CONNECTION = 4;
|
||||
|
||||
/**
|
||||
* Check mobile provisioning. The resultCode passed to
|
||||
* onReceiveResult will be one of the CMP_RESULT_CODE_xxxx values above.
|
||||
* This may take a minute or more to complete.
|
||||
*
|
||||
* @param sendNotificaiton, when true a notification will be sent to user.
|
||||
* @param suggestedTimeOutMs, timeout in milliseconds
|
||||
* @param resultReceiver needs to be supplied to receive the result
|
||||
*
|
||||
* @return time out that will be used, maybe less that suggestedTimeOutMs
|
||||
* -1 if an error.
|
||||
*
|
||||
* {@hide}
|
||||
*/
|
||||
public int checkMobileProvisioning(boolean sendNotification, int suggestedTimeOutMs,
|
||||
ResultReceiver resultReceiver) {
|
||||
public int checkMobileProvisioning(int suggestedTimeOutMs) {
|
||||
int timeOutMs = -1;
|
||||
try {
|
||||
timeOutMs = mService.checkMobileProvisioning(sendNotification, suggestedTimeOutMs,
|
||||
resultReceiver);
|
||||
timeOutMs = mService.checkMobileProvisioning(suggestedTimeOutMs);
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
return timeOutMs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the carrier provisioning url.
|
||||
* Get the mobile provisioning url.
|
||||
* {@hide}
|
||||
*/
|
||||
public String getMobileProvisioningUrl() {
|
||||
@@ -1370,4 +1409,87 @@ public class ConnectivityManager {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mobile redirected provisioning url.
|
||||
* {@hide}
|
||||
*/
|
||||
public String getMobileRedirectedProvisioningUrl() {
|
||||
try {
|
||||
return mService.getMobileRedirectedProvisioningUrl();
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the information about a specific network link
|
||||
* @hide
|
||||
*/
|
||||
public LinkQualityInfo getLinkQualityInfo(int networkType) {
|
||||
try {
|
||||
LinkQualityInfo li = mService.getLinkQualityInfo(networkType);
|
||||
return li;
|
||||
} catch (RemoteException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get the information of currently active network link
|
||||
* @hide
|
||||
*/
|
||||
public LinkQualityInfo getActiveLinkQualityInfo() {
|
||||
try {
|
||||
LinkQualityInfo li = mService.getActiveLinkQualityInfo();
|
||||
return li;
|
||||
} catch (RemoteException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get the information of all network links
|
||||
* @hide
|
||||
*/
|
||||
public LinkQualityInfo[] getAllLinkQualityInfo() {
|
||||
try {
|
||||
LinkQualityInfo[] li = mService.getAllLinkQualityInfo();
|
||||
return li;
|
||||
} catch (RemoteException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set sign in error notification to visible or in visible
|
||||
*
|
||||
* @param visible
|
||||
* @param networkType
|
||||
*
|
||||
* {@hide}
|
||||
*/
|
||||
public void setProvisioningNotificationVisible(boolean visible, int networkType,
|
||||
String extraInfo, String url) {
|
||||
try {
|
||||
mService.setProvisioningNotificationVisible(visible, networkType, extraInfo, url);
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value for enabling/disabling airplane mode
|
||||
*
|
||||
* @param enable whether to enable airplane mode or not
|
||||
*
|
||||
* <p>This method requires the call to hold the permission
|
||||
* {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}.
|
||||
* @hide
|
||||
*/
|
||||
public void setAirplaneMode(boolean enable) {
|
||||
try {
|
||||
mService.setAirplaneMode(enable);
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import java.net.InetAddress;
|
||||
|
||||
/**
|
||||
* A simple object for retrieving the results of a DHCP request.
|
||||
* @deprecated - use LinkProperties - To be removed 11/2014
|
||||
*/
|
||||
public class DhcpInfo implements Parcelable {
|
||||
public int ipAddress;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package android.net;
|
||||
|
||||
import android.net.LinkQualityInfo;
|
||||
import android.net.LinkProperties;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.NetworkQuotaInfo;
|
||||
@@ -37,6 +38,9 @@ import com.android.internal.net.VpnProfile;
|
||||
/** {@hide} */
|
||||
interface IConnectivityManager
|
||||
{
|
||||
// Keep this in sync with framework/native/services/connectivitymanager/ConnectivityManager.h
|
||||
void markSocketAsUser(in ParcelFileDescriptor socket, int uid);
|
||||
|
||||
void setNetworkPreference(int pref);
|
||||
|
||||
int getNetworkPreference();
|
||||
@@ -46,6 +50,8 @@ interface IConnectivityManager
|
||||
NetworkInfo getNetworkInfo(int networkType);
|
||||
NetworkInfo[] getAllNetworkInfo();
|
||||
|
||||
NetworkInfo getProvisioningOrActiveNetworkInfo();
|
||||
|
||||
boolean isNetworkSupported(int networkType);
|
||||
|
||||
LinkProperties getActiveLinkProperties();
|
||||
@@ -87,12 +93,6 @@ interface IConnectivityManager
|
||||
|
||||
String[] getTetheredIfaces();
|
||||
|
||||
/**
|
||||
* Return list of interface pairs that are actively tethered. Even indexes are
|
||||
* remote interface, and odd indexes are corresponding local interfaces.
|
||||
*/
|
||||
String[] getTetheredIfacePairs();
|
||||
|
||||
String[] getTetheringErroredIfaces();
|
||||
|
||||
String[] getTetherableUsbRegexs();
|
||||
@@ -121,6 +121,8 @@ interface IConnectivityManager
|
||||
|
||||
ParcelFileDescriptor establishVpn(in VpnConfig config);
|
||||
|
||||
VpnConfig getVpnConfig();
|
||||
|
||||
void startLegacyVpn(in VpnProfile profile);
|
||||
|
||||
LegacyVpnInfo getLegacyVpnInfo();
|
||||
@@ -129,11 +131,25 @@ interface IConnectivityManager
|
||||
|
||||
void captivePortalCheckComplete(in NetworkInfo info);
|
||||
|
||||
void captivePortalCheckCompleted(in NetworkInfo info, boolean isCaptivePortal);
|
||||
|
||||
void supplyMessenger(int networkType, in Messenger messenger);
|
||||
|
||||
int findConnectionTypeForIface(in String iface);
|
||||
|
||||
int checkMobileProvisioning(boolean sendNotification, int suggestedTimeOutMs, in ResultReceiver resultReceiver);
|
||||
int checkMobileProvisioning(int suggestedTimeOutMs);
|
||||
|
||||
String getMobileProvisioningUrl();
|
||||
|
||||
String getMobileRedirectedProvisioningUrl();
|
||||
|
||||
LinkQualityInfo getLinkQualityInfo(int networkType);
|
||||
|
||||
LinkQualityInfo getActiveLinkQualityInfo();
|
||||
|
||||
LinkQualityInfo[] getAllLinkQualityInfo();
|
||||
|
||||
void setProvisioningNotificationVisible(boolean visible, int networkType, in String extraInfo, in String url);
|
||||
|
||||
void setAirplaneMode(boolean enable);
|
||||
}
|
||||
|
||||
@@ -32,27 +32,56 @@ public class LinkAddress implements Parcelable {
|
||||
/**
|
||||
* IPv4 or IPv6 address.
|
||||
*/
|
||||
private final InetAddress address;
|
||||
private InetAddress address;
|
||||
|
||||
/**
|
||||
* Network prefix length
|
||||
*/
|
||||
private final int prefixLength;
|
||||
private int prefixLength;
|
||||
|
||||
public LinkAddress(InetAddress address, int prefixLength) {
|
||||
private void init(InetAddress address, int prefixLength) {
|
||||
if (address == null || prefixLength < 0 ||
|
||||
((address instanceof Inet4Address) && prefixLength > 32) ||
|
||||
(prefixLength > 128)) {
|
||||
throw new IllegalArgumentException("Bad LinkAddress params " + address +
|
||||
prefixLength);
|
||||
"/" + prefixLength);
|
||||
}
|
||||
this.address = address;
|
||||
this.prefixLength = prefixLength;
|
||||
}
|
||||
|
||||
public LinkAddress(InetAddress address, int prefixLength) {
|
||||
init(address, prefixLength);
|
||||
}
|
||||
|
||||
public LinkAddress(InterfaceAddress interfaceAddress) {
|
||||
this.address = interfaceAddress.getAddress();
|
||||
this.prefixLength = interfaceAddress.getNetworkPrefixLength();
|
||||
init(interfaceAddress.getAddress(),
|
||||
interfaceAddress.getNetworkPrefixLength());
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new {@code LinkAddress} from a string such as "192.0.2.5/24" or
|
||||
* "2001:db8::1/64".
|
||||
* @param string The string to parse.
|
||||
*/
|
||||
public LinkAddress(String address) {
|
||||
InetAddress inetAddress = null;
|
||||
int prefixLength = -1;
|
||||
try {
|
||||
String [] pieces = address.split("/", 2);
|
||||
prefixLength = Integer.parseInt(pieces[1]);
|
||||
inetAddress = InetAddress.parseNumericAddress(pieces[0]);
|
||||
} catch (NullPointerException e) { // Null string.
|
||||
} catch (ArrayIndexOutOfBoundsException e) { // No prefix length.
|
||||
} catch (NumberFormatException e) { // Non-numeric prefix.
|
||||
} catch (IllegalArgumentException e) { // Invalid IP address.
|
||||
}
|
||||
|
||||
if (inetAddress == null || prefixLength == -1) {
|
||||
throw new IllegalArgumentException("Bad LinkAddress params " + address);
|
||||
}
|
||||
|
||||
init(inetAddress, prefixLength);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,6 +23,7 @@ import android.text.TextUtils;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.Inet6Address;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
@@ -65,6 +66,7 @@ public class LinkProperties implements Parcelable {
|
||||
private String mDomains;
|
||||
private Collection<RouteInfo> mRoutes = new ArrayList<RouteInfo>();
|
||||
private ProxyProperties mHttpProxy;
|
||||
private int mMtu;
|
||||
|
||||
// Stores the properties of links that are "stacked" above this link.
|
||||
// Indexed by interface name to allow modification and to prevent duplicates being added.
|
||||
@@ -103,6 +105,7 @@ public class LinkProperties implements Parcelable {
|
||||
for (LinkProperties l: source.mStackedLinks.values()) {
|
||||
addStackedLink(l);
|
||||
}
|
||||
setMtu(source.getMtu());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,6 +131,9 @@ public class LinkProperties implements Parcelable {
|
||||
return interfaceNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all the addresses on this link.
|
||||
*/
|
||||
public Collection<InetAddress> getAddresses() {
|
||||
Collection<InetAddress> addresses = new ArrayList<InetAddress>();
|
||||
for (LinkAddress linkAddress : mLinkAddresses) {
|
||||
@@ -136,14 +142,73 @@ public class LinkProperties implements Parcelable {
|
||||
return Collections.unmodifiableCollection(addresses);
|
||||
}
|
||||
|
||||
public void addLinkAddress(LinkAddress address) {
|
||||
if (address != null) mLinkAddresses.add(address);
|
||||
/**
|
||||
* Returns all the addresses on this link and all the links stacked above it.
|
||||
*/
|
||||
public Collection<InetAddress> getAllAddresses() {
|
||||
Collection<InetAddress> addresses = new ArrayList<InetAddress>();
|
||||
for (LinkAddress linkAddress : mLinkAddresses) {
|
||||
addresses.add(linkAddress.getAddress());
|
||||
}
|
||||
for (LinkProperties stacked: mStackedLinks.values()) {
|
||||
addresses.addAll(stacked.getAllAddresses());
|
||||
}
|
||||
return addresses;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a link address if it does not exist, or update it if it does.
|
||||
* @param address The {@code LinkAddress} to add.
|
||||
* @return true if the address was added, false if it already existed.
|
||||
*/
|
||||
public boolean addLinkAddress(LinkAddress address) {
|
||||
// TODO: when the LinkAddress has other attributes beyond the
|
||||
// address and the prefix length, update them here.
|
||||
if (address != null && !mLinkAddresses.contains(address)) {
|
||||
mLinkAddresses.add(address);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a link address.
|
||||
* @param address The {@code LinkAddress} to remove.
|
||||
* @return true if the address was removed, false if it did not exist.
|
||||
*/
|
||||
public boolean removeLinkAddress(LinkAddress toRemove) {
|
||||
return mLinkAddresses.remove(toRemove);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all the addresses on this link.
|
||||
*/
|
||||
public Collection<LinkAddress> getLinkAddresses() {
|
||||
return Collections.unmodifiableCollection(mLinkAddresses);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all the addresses on this link and all the links stacked above it.
|
||||
*/
|
||||
public Collection<LinkAddress> getAllLinkAddresses() {
|
||||
Collection<LinkAddress> addresses = new ArrayList<LinkAddress>();
|
||||
addresses.addAll(mLinkAddresses);
|
||||
for (LinkProperties stacked: mStackedLinks.values()) {
|
||||
addresses.addAll(stacked.getAllLinkAddresses());
|
||||
}
|
||||
return addresses;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the LinkAddresses on this link with the given collection of addresses.
|
||||
*/
|
||||
public void setLinkAddresses(Collection<LinkAddress> addresses) {
|
||||
mLinkAddresses.clear();
|
||||
for (LinkAddress address: addresses) {
|
||||
addLinkAddress(address);
|
||||
}
|
||||
}
|
||||
|
||||
public void addDns(InetAddress dns) {
|
||||
if (dns != null) mDnses.add(dns);
|
||||
}
|
||||
@@ -160,6 +225,14 @@ public class LinkProperties implements Parcelable {
|
||||
mDomains = domains;
|
||||
}
|
||||
|
||||
public void setMtu(int mtu) {
|
||||
mMtu = mtu;
|
||||
}
|
||||
|
||||
public int getMtu() {
|
||||
return mMtu;
|
||||
}
|
||||
|
||||
private RouteInfo routeWithInterface(RouteInfo route) {
|
||||
return new RouteInfo(
|
||||
route.getDestination(),
|
||||
@@ -213,11 +286,14 @@ public class LinkProperties implements Parcelable {
|
||||
* of stacked links. If link is null, nothing changes.
|
||||
*
|
||||
* @param link The link to add.
|
||||
* @return true if the link was stacked, false otherwise.
|
||||
*/
|
||||
public void addStackedLink(LinkProperties link) {
|
||||
public boolean addStackedLink(LinkProperties link) {
|
||||
if (link != null && link.getInterfaceName() != null) {
|
||||
mStackedLinks.put(link.getInterfaceName(), link);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -226,12 +302,15 @@ public class LinkProperties implements Parcelable {
|
||||
* If there a stacked link with the same interfacename as link, it is
|
||||
* removed. Otherwise, nothing changes.
|
||||
*
|
||||
* @param link The link to add.
|
||||
* @param link The link to remove.
|
||||
* @return true if the link was removed, false otherwise.
|
||||
*/
|
||||
public void removeStackedLink(LinkProperties link) {
|
||||
public boolean removeStackedLink(LinkProperties link) {
|
||||
if (link != null && link.getInterfaceName() != null) {
|
||||
mStackedLinks.remove(link.getInterfaceName());
|
||||
LinkProperties removed = mStackedLinks.remove(link.getInterfaceName());
|
||||
return removed != null;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -253,6 +332,7 @@ public class LinkProperties implements Parcelable {
|
||||
mRoutes.clear();
|
||||
mHttpProxy = null;
|
||||
mStackedLinks.clear();
|
||||
mMtu = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -277,6 +357,8 @@ public class LinkProperties implements Parcelable {
|
||||
|
||||
String domainName = "Domains: " + mDomains;
|
||||
|
||||
String mtu = "MTU: " + mMtu;
|
||||
|
||||
String routes = " Routes: [";
|
||||
for (RouteInfo route : mRoutes) routes += route.toString() + ",";
|
||||
routes += "] ";
|
||||
@@ -290,7 +372,8 @@ public class LinkProperties implements Parcelable {
|
||||
}
|
||||
stacked += "] ";
|
||||
}
|
||||
return "{" + ifaceName + linkAddresses + routes + dns + domainName + proxy + stacked + "}";
|
||||
return "{" + ifaceName + linkAddresses + routes + dns + domainName + mtu
|
||||
+ proxy + stacked + "}";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -307,6 +390,20 @@ public class LinkProperties implements Parcelable {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this link has an IPv6 address.
|
||||
*
|
||||
* @return {@code true} if there is an IPv6 address, {@code false} otherwise.
|
||||
*/
|
||||
public boolean hasIPv6Address() {
|
||||
for (LinkAddress address : mLinkAddresses) {
|
||||
if (address.getAddress() instanceof Inet6Address) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares this {@code LinkProperties} interface name against the target
|
||||
*
|
||||
@@ -391,6 +488,16 @@ public class LinkProperties implements Parcelable {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares this {@code LinkProperties} MTU against the target
|
||||
*
|
||||
* @param target LinkProperties to compare.
|
||||
* @return {@code true} if both are identical, {@code false} otherwise.
|
||||
*/
|
||||
public boolean isIdenticalMtu(LinkProperties target) {
|
||||
return getMtu() == target.getMtu();
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Compares this {@code LinkProperties} instance against the target
|
||||
@@ -422,17 +529,16 @@ public class LinkProperties implements Parcelable {
|
||||
isIdenticalDnses(target) &&
|
||||
isIdenticalRoutes(target) &&
|
||||
isIdenticalHttpProxy(target) &&
|
||||
isIdenticalStackedLinks(target);
|
||||
isIdenticalStackedLinks(target) &&
|
||||
isIdenticalMtu(target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return two lists, a list of addresses that would be removed from
|
||||
* mLinkAddresses and a list of addresses that would be added to
|
||||
* mLinkAddress which would then result in target and mLinkAddresses
|
||||
* being the same list.
|
||||
* Compares the addresses in this LinkProperties with another
|
||||
* LinkProperties, examining only addresses on the base link.
|
||||
*
|
||||
* @param target is a LinkProperties with the new list of addresses
|
||||
* @return the removed and added lists.
|
||||
* @param target a LinkProperties with the new list of addresses
|
||||
* @return the differences between the addresses.
|
||||
*/
|
||||
public CompareResult<LinkAddress> compareAddresses(LinkProperties target) {
|
||||
/*
|
||||
@@ -456,13 +562,11 @@ public class LinkProperties implements Parcelable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return two lists, a list of dns addresses that would be removed from
|
||||
* mDnses and a list of addresses that would be added to
|
||||
* mDnses which would then result in target and mDnses
|
||||
* being the same list.
|
||||
* Compares the DNS addresses in this LinkProperties with another
|
||||
* LinkProperties, examining only DNS addresses on the base link.
|
||||
*
|
||||
* @param target is a LinkProperties with the new list of dns addresses
|
||||
* @return the removed and added lists.
|
||||
* @param target a LinkProperties with the new list of dns addresses
|
||||
* @return the differences between the DNS addresses.
|
||||
*/
|
||||
public CompareResult<InetAddress> compareDnses(LinkProperties target) {
|
||||
/*
|
||||
@@ -487,15 +591,13 @@ public class LinkProperties implements Parcelable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return two lists, a list of routes that would be removed from
|
||||
* mRoutes and a list of routes that would be added to
|
||||
* mRoutes which would then result in target and mRoutes
|
||||
* being the same list.
|
||||
* Compares all routes in this LinkProperties with another LinkProperties,
|
||||
* examining both the the base link and all stacked links.
|
||||
*
|
||||
* @param target is a LinkProperties with the new list of routes
|
||||
* @return the removed and added lists.
|
||||
* @param target a LinkProperties with the new list of routes
|
||||
* @return the differences between the routes.
|
||||
*/
|
||||
public CompareResult<RouteInfo> compareRoutes(LinkProperties target) {
|
||||
public CompareResult<RouteInfo> compareAllRoutes(LinkProperties target) {
|
||||
/*
|
||||
* Duplicate the RouteInfos into removed, we will be removing
|
||||
* routes which are common between mRoutes and target
|
||||
@@ -530,7 +632,8 @@ public class LinkProperties implements Parcelable {
|
||||
+ ((null == mDomains) ? 0 : mDomains.hashCode())
|
||||
+ mRoutes.size() * 41
|
||||
+ ((null == mHttpProxy) ? 0 : mHttpProxy.hashCode())
|
||||
+ mStackedLinks.hashCode() * 47);
|
||||
+ mStackedLinks.hashCode() * 47)
|
||||
+ mMtu * 51;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -548,7 +651,7 @@ public class LinkProperties implements Parcelable {
|
||||
dest.writeByteArray(d.getAddress());
|
||||
}
|
||||
dest.writeString(mDomains);
|
||||
|
||||
dest.writeInt(mMtu);
|
||||
dest.writeInt(mRoutes.size());
|
||||
for(RouteInfo route : mRoutes) {
|
||||
dest.writeParcelable(route, flags);
|
||||
@@ -587,6 +690,7 @@ public class LinkProperties implements Parcelable {
|
||||
} catch (UnknownHostException e) { }
|
||||
}
|
||||
netProp.setDomains(in.readString());
|
||||
netProp.setMtu(in.readInt());
|
||||
addressCount = in.readInt();
|
||||
for (int i=0; i<addressCount; i++) {
|
||||
netProp.addRoute((RouteInfo)in.readParcelable(null));
|
||||
|
||||
@@ -83,7 +83,7 @@ public class NetworkInfo implements Parcelable {
|
||||
/** Link has poor connectivity. */
|
||||
VERIFYING_POOR_LINK,
|
||||
/** Checking if network is a captive portal */
|
||||
CAPTIVE_PORTAL_CHECK,
|
||||
CAPTIVE_PORTAL_CHECK
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,6 +120,8 @@ public class NetworkInfo implements Parcelable {
|
||||
private String mExtraInfo;
|
||||
private boolean mIsFailover;
|
||||
private boolean mIsRoaming;
|
||||
private boolean mIsConnectedToProvisioningNetwork;
|
||||
|
||||
/**
|
||||
* Indicates whether network connectivity is possible:
|
||||
*/
|
||||
@@ -148,6 +150,7 @@ public class NetworkInfo implements Parcelable {
|
||||
mState = State.UNKNOWN;
|
||||
mIsAvailable = false; // until we're told otherwise, assume unavailable
|
||||
mIsRoaming = false;
|
||||
mIsConnectedToProvisioningNetwork = false;
|
||||
}
|
||||
|
||||
/** {@hide} */
|
||||
@@ -164,6 +167,7 @@ public class NetworkInfo implements Parcelable {
|
||||
mIsFailover = source.mIsFailover;
|
||||
mIsRoaming = source.mIsRoaming;
|
||||
mIsAvailable = source.mIsAvailable;
|
||||
mIsConnectedToProvisioningNetwork = source.mIsConnectedToProvisioningNetwork;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,6 +326,22 @@ public class NetworkInfo implements Parcelable {
|
||||
}
|
||||
}
|
||||
|
||||
/** {@hide} */
|
||||
@VisibleForTesting
|
||||
public boolean isConnectedToProvisioningNetwork() {
|
||||
synchronized (this) {
|
||||
return mIsConnectedToProvisioningNetwork;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@hide} */
|
||||
@VisibleForTesting
|
||||
public void setIsConnectedToProvisioningNetwork(boolean val) {
|
||||
synchronized (this) {
|
||||
mIsConnectedToProvisioningNetwork = val;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports the current coarse-grained state of the network.
|
||||
* @return the coarse-grained state
|
||||
@@ -405,7 +425,9 @@ public class NetworkInfo implements Parcelable {
|
||||
append(", extra: ").append(mExtraInfo == null ? "(none)" : mExtraInfo).
|
||||
append(", roaming: ").append(mIsRoaming).
|
||||
append(", failover: ").append(mIsFailover).
|
||||
append(", isAvailable: ").append(mIsAvailable);
|
||||
append(", isAvailable: ").append(mIsAvailable).
|
||||
append(", isConnectedToProvisioningNetwork: ").
|
||||
append(mIsConnectedToProvisioningNetwork);
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
@@ -433,6 +455,7 @@ public class NetworkInfo implements Parcelable {
|
||||
dest.writeInt(mIsFailover ? 1 : 0);
|
||||
dest.writeInt(mIsAvailable ? 1 : 0);
|
||||
dest.writeInt(mIsRoaming ? 1 : 0);
|
||||
dest.writeInt(mIsConnectedToProvisioningNetwork ? 1 : 0);
|
||||
dest.writeString(mReason);
|
||||
dest.writeString(mExtraInfo);
|
||||
}
|
||||
@@ -455,6 +478,7 @@ public class NetworkInfo implements Parcelable {
|
||||
netInfo.mIsFailover = in.readInt() != 0;
|
||||
netInfo.mIsAvailable = in.readInt() != 0;
|
||||
netInfo.mIsRoaming = in.readInt() != 0;
|
||||
netInfo.mIsConnectedToProvisioningNetwork = in.readInt() != 0;
|
||||
netInfo.mReason = in.readString();
|
||||
netInfo.mExtraInfo = in.readString();
|
||||
return netInfo;
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.net.Inet4Address;
|
||||
import java.net.Inet6Address;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Collection;
|
||||
import java.util.Locale;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
@@ -102,6 +103,11 @@ public class NetworkUtils {
|
||||
*/
|
||||
public native static String getDhcpError();
|
||||
|
||||
/**
|
||||
* Set the SO_MARK of {@code socketfd} to {@code mark}
|
||||
*/
|
||||
public native static void markSocket(int socketfd, int mark);
|
||||
|
||||
/**
|
||||
* Convert a IPv4 address from an integer to an InetAddress.
|
||||
* @param hostAddress an int corresponding to the IPv4 address in network byte order
|
||||
@@ -223,7 +229,7 @@ public class NetworkUtils {
|
||||
public static InetAddress hexToInet6Address(String addrHexString)
|
||||
throws IllegalArgumentException {
|
||||
try {
|
||||
return numericToInetAddress(String.format("%s:%s:%s:%s:%s:%s:%s:%s",
|
||||
return numericToInetAddress(String.format(Locale.US, "%s:%s:%s:%s:%s:%s:%s:%s",
|
||||
addrHexString.substring(0,4), addrHexString.substring(4,8),
|
||||
addrHexString.substring(8,12), addrHexString.substring(12,16),
|
||||
addrHexString.substring(16,20), addrHexString.substring(20,24),
|
||||
|
||||
@@ -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,38 @@ 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 = -1;
|
||||
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;
|
||||
}
|
||||
|
||||
// Only used in PacManager after Local Proxy is bound.
|
||||
public ProxyProperties(String pacFileUrl, int localProxyPort) {
|
||||
mHost = LOCAL_HOST;
|
||||
mPort = localProxyPort;
|
||||
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 +75,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 +89,10 @@ public class ProxyProperties implements Parcelable {
|
||||
return inetSocketAddress;
|
||||
}
|
||||
|
||||
public String getPacFileUrl() {
|
||||
return mPacFileUrl;
|
||||
}
|
||||
|
||||
public String getHost() {
|
||||
return mHost;
|
||||
}
|
||||
@@ -140,7 +164,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("] ");
|
||||
@@ -158,6 +185,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()) && mPort == p.mPort;
|
||||
}
|
||||
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;
|
||||
@@ -191,6 +226,14 @@ public class ProxyProperties implements Parcelable {
|
||||
* @hide
|
||||
*/
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
if (mPacFileUrl != null) {
|
||||
dest.writeByte((byte)1);
|
||||
dest.writeString(mPacFileUrl);
|
||||
dest.writeInt(mPort);
|
||||
return;
|
||||
} else {
|
||||
dest.writeByte((byte)0);
|
||||
}
|
||||
if (mHost != null) {
|
||||
dest.writeByte((byte)1);
|
||||
dest.writeString(mHost);
|
||||
@@ -211,7 +254,12 @@ public class ProxyProperties implements Parcelable {
|
||||
public ProxyProperties createFromParcel(Parcel in) {
|
||||
String host = null;
|
||||
int port = 0;
|
||||
if (in.readByte() == 1) {
|
||||
if (in.readByte() != 0) {
|
||||
String url = in.readString();
|
||||
int localPort = in.readInt();
|
||||
return new ProxyProperties(url, localPort);
|
||||
}
|
||||
if (in.readByte() != 0) {
|
||||
host = in.readString();
|
||||
port = in.readInt();
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#define LOG_TAG "NetUtils"
|
||||
|
||||
#include "jni.h"
|
||||
#include "JNIHelp.h"
|
||||
#include <utils/misc.h>
|
||||
#include <android_runtime/AndroidRuntime.h>
|
||||
#include <utils/Log.h>
|
||||
@@ -36,7 +37,8 @@ int dhcp_do_request(const char * const ifname,
|
||||
const char *server,
|
||||
uint32_t *lease,
|
||||
const char *vendorInfo,
|
||||
const char *domains);
|
||||
const char *domains,
|
||||
const char *mtu);
|
||||
|
||||
int dhcp_do_request_renew(const char * const ifname,
|
||||
const char *ipaddr,
|
||||
@@ -46,7 +48,8 @@ int dhcp_do_request_renew(const char * const ifname,
|
||||
const char *server,
|
||||
uint32_t *lease,
|
||||
const char *vendorInfo,
|
||||
const char *domains);
|
||||
const char *domains,
|
||||
const char *mtu);
|
||||
|
||||
int dhcp_stop(const char *ifname);
|
||||
int dhcp_release_lease(const char *ifname);
|
||||
@@ -125,19 +128,20 @@ static jboolean android_net_utils_runDhcpCommon(JNIEnv* env, jobject clazz, jstr
|
||||
uint32_t lease;
|
||||
char vendorInfo[PROPERTY_VALUE_MAX];
|
||||
char domains[PROPERTY_VALUE_MAX];
|
||||
char mtu[PROPERTY_VALUE_MAX];
|
||||
|
||||
const char *nameStr = env->GetStringUTFChars(ifname, NULL);
|
||||
if (nameStr == NULL) return (jboolean)false;
|
||||
|
||||
if (renew) {
|
||||
result = ::dhcp_do_request_renew(nameStr, ipaddr, gateway, &prefixLength,
|
||||
dns, server, &lease, vendorInfo, domains);
|
||||
dns, server, &lease, vendorInfo, domains, mtu);
|
||||
} else {
|
||||
result = ::dhcp_do_request(nameStr, ipaddr, gateway, &prefixLength,
|
||||
dns, server, &lease, vendorInfo, domains);
|
||||
dns, server, &lease, vendorInfo, domains, mtu);
|
||||
}
|
||||
if (result != 0) {
|
||||
ALOGD("dhcp_do_request failed");
|
||||
ALOGD("dhcp_do_request failed : %s (%s)", nameStr, renew ? "renew" : "new");
|
||||
}
|
||||
|
||||
env->ReleaseStringUTFChars(ifname, nameStr);
|
||||
@@ -239,6 +243,13 @@ static jstring android_net_utils_getDhcpError(JNIEnv* env, jobject clazz)
|
||||
return env->NewStringUTF(::dhcp_get_errmsg());
|
||||
}
|
||||
|
||||
static void android_net_utils_markSocket(JNIEnv *env, jobject thiz, jint socket, jint mark)
|
||||
{
|
||||
if (setsockopt(socket, SOL_SOCKET, SO_MARK, &mark, sizeof(mark)) < 0) {
|
||||
jniThrowException(env, "java/lang/IllegalStateException", "Error marking socket");
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
@@ -255,6 +266,7 @@ static JNINativeMethod gNetworkUtilMethods[] = {
|
||||
{ "stopDhcp", "(Ljava/lang/String;)Z", (void *)android_net_utils_stopDhcp },
|
||||
{ "releaseDhcpLease", "(Ljava/lang/String;)Z", (void *)android_net_utils_releaseDhcpLease },
|
||||
{ "getDhcpError", "()Ljava/lang/String;", (void*) android_net_utils_getDhcpError },
|
||||
{ "markSocket", "(II)V", (void*) android_net_utils_markSocket },
|
||||
};
|
||||
|
||||
int register_android_net_NetworkUtils(JNIEnv* env)
|
||||
|
||||
@@ -25,13 +25,18 @@ import java.net.InetAddress;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class LinkPropertiesTest extends TestCase {
|
||||
private static String ADDRV4 = "75.208.6.1";
|
||||
private static String ADDRV6 = "2001:0db8:85a3:0000:0000:8a2e:0370:7334";
|
||||
private static String DNS1 = "75.208.7.1";
|
||||
private static String DNS2 = "69.78.7.1";
|
||||
private static String GATEWAY1 = "75.208.8.1";
|
||||
private static String GATEWAY2 = "69.78.8.1";
|
||||
private static InetAddress ADDRV4 = NetworkUtils.numericToInetAddress("75.208.6.1");
|
||||
private static InetAddress ADDRV6 = NetworkUtils.numericToInetAddress(
|
||||
"2001:0db8:85a3:0000:0000:8a2e:0370:7334");
|
||||
private static InetAddress DNS1 = NetworkUtils.numericToInetAddress("75.208.7.1");
|
||||
private static InetAddress DNS2 = NetworkUtils.numericToInetAddress("69.78.7.1");
|
||||
private static InetAddress GATEWAY1 = NetworkUtils.numericToInetAddress("75.208.8.1");
|
||||
private static InetAddress GATEWAY2 = NetworkUtils.numericToInetAddress("69.78.8.1");
|
||||
private static String NAME = "qmi0";
|
||||
private static int MTU = 1500;
|
||||
|
||||
private static LinkAddress LINKADDRV4 = new LinkAddress(ADDRV4, 32);
|
||||
private static LinkAddress LINKADDRV6 = new LinkAddress(ADDRV6, 128);
|
||||
|
||||
public void assertLinkPropertiesEqual(LinkProperties source, LinkProperties target) {
|
||||
// Check implementation of equals(), element by element.
|
||||
@@ -53,6 +58,9 @@ public class LinkPropertiesTest extends TestCase {
|
||||
assertTrue(source.isIdenticalStackedLinks(target));
|
||||
assertTrue(target.isIdenticalStackedLinks(source));
|
||||
|
||||
assertTrue(source.isIdenticalMtu(target));
|
||||
assertTrue(target.isIdenticalMtu(source));
|
||||
|
||||
// Check result of equals().
|
||||
assertTrue(source.equals(target));
|
||||
assertTrue(target.equals(source));
|
||||
@@ -76,43 +84,40 @@ public class LinkPropertiesTest extends TestCase {
|
||||
LinkProperties source = new LinkProperties();
|
||||
source.setInterfaceName(NAME);
|
||||
// set 2 link addresses
|
||||
source.addLinkAddress(new LinkAddress(
|
||||
NetworkUtils.numericToInetAddress(ADDRV4), 32));
|
||||
source.addLinkAddress(new LinkAddress(
|
||||
NetworkUtils.numericToInetAddress(ADDRV6), 128));
|
||||
source.addLinkAddress(LINKADDRV4);
|
||||
source.addLinkAddress(LINKADDRV6);
|
||||
// set 2 dnses
|
||||
source.addDns(NetworkUtils.numericToInetAddress(DNS1));
|
||||
source.addDns(NetworkUtils.numericToInetAddress(DNS2));
|
||||
source.addDns(DNS1);
|
||||
source.addDns(DNS2);
|
||||
// set 2 gateways
|
||||
source.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1)));
|
||||
source.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2)));
|
||||
source.addRoute(new RouteInfo(GATEWAY1));
|
||||
source.addRoute(new RouteInfo(GATEWAY2));
|
||||
source.setMtu(MTU);
|
||||
|
||||
LinkProperties target = new LinkProperties();
|
||||
|
||||
// All fields are same
|
||||
target.setInterfaceName(NAME);
|
||||
target.addLinkAddress(new LinkAddress(
|
||||
NetworkUtils.numericToInetAddress(ADDRV4), 32));
|
||||
target.addLinkAddress(new LinkAddress(
|
||||
NetworkUtils.numericToInetAddress(ADDRV6), 128));
|
||||
target.addDns(NetworkUtils.numericToInetAddress(DNS1));
|
||||
target.addDns(NetworkUtils.numericToInetAddress(DNS2));
|
||||
target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1)));
|
||||
target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2)));
|
||||
target.addLinkAddress(LINKADDRV4);
|
||||
target.addLinkAddress(LINKADDRV6);
|
||||
target.addDns(DNS1);
|
||||
target.addDns(DNS2);
|
||||
target.addRoute(new RouteInfo(GATEWAY1));
|
||||
target.addRoute(new RouteInfo(GATEWAY2));
|
||||
target.setMtu(MTU);
|
||||
|
||||
assertLinkPropertiesEqual(source, target);
|
||||
|
||||
target.clear();
|
||||
// change Interface Name
|
||||
target.setInterfaceName("qmi1");
|
||||
target.addLinkAddress(new LinkAddress(
|
||||
NetworkUtils.numericToInetAddress(ADDRV4), 32));
|
||||
target.addLinkAddress(new LinkAddress(
|
||||
NetworkUtils.numericToInetAddress(ADDRV6), 128));
|
||||
target.addDns(NetworkUtils.numericToInetAddress(DNS1));
|
||||
target.addDns(NetworkUtils.numericToInetAddress(DNS2));
|
||||
target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1)));
|
||||
target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2)));
|
||||
target.addLinkAddress(LINKADDRV4);
|
||||
target.addLinkAddress(LINKADDRV6);
|
||||
target.addDns(DNS1);
|
||||
target.addDns(DNS2);
|
||||
target.addRoute(new RouteInfo(GATEWAY1));
|
||||
target.addRoute(new RouteInfo(GATEWAY2));
|
||||
target.setMtu(MTU);
|
||||
assertFalse(source.equals(target));
|
||||
|
||||
target.clear();
|
||||
@@ -120,38 +125,48 @@ public class LinkPropertiesTest extends TestCase {
|
||||
// change link addresses
|
||||
target.addLinkAddress(new LinkAddress(
|
||||
NetworkUtils.numericToInetAddress("75.208.6.2"), 32));
|
||||
target.addLinkAddress(new LinkAddress(
|
||||
NetworkUtils.numericToInetAddress(ADDRV6), 128));
|
||||
target.addDns(NetworkUtils.numericToInetAddress(DNS1));
|
||||
target.addDns(NetworkUtils.numericToInetAddress(DNS2));
|
||||
target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1)));
|
||||
target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2)));
|
||||
target.addLinkAddress(LINKADDRV6);
|
||||
target.addDns(DNS1);
|
||||
target.addDns(DNS2);
|
||||
target.addRoute(new RouteInfo(GATEWAY1));
|
||||
target.addRoute(new RouteInfo(GATEWAY2));
|
||||
target.setMtu(MTU);
|
||||
assertFalse(source.equals(target));
|
||||
|
||||
target.clear();
|
||||
target.setInterfaceName(NAME);
|
||||
target.addLinkAddress(new LinkAddress(
|
||||
NetworkUtils.numericToInetAddress(ADDRV4), 32));
|
||||
target.addLinkAddress(new LinkAddress(
|
||||
NetworkUtils.numericToInetAddress(ADDRV6), 128));
|
||||
target.addLinkAddress(LINKADDRV4);
|
||||
target.addLinkAddress(LINKADDRV6);
|
||||
// change dnses
|
||||
target.addDns(NetworkUtils.numericToInetAddress("75.208.7.2"));
|
||||
target.addDns(NetworkUtils.numericToInetAddress(DNS2));
|
||||
target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1)));
|
||||
target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2)));
|
||||
target.addDns(DNS2);
|
||||
target.addRoute(new RouteInfo(GATEWAY1));
|
||||
target.addRoute(new RouteInfo(GATEWAY2));
|
||||
target.setMtu(MTU);
|
||||
assertFalse(source.equals(target));
|
||||
|
||||
target.clear();
|
||||
target.setInterfaceName(NAME);
|
||||
target.addLinkAddress(new LinkAddress(
|
||||
NetworkUtils.numericToInetAddress(ADDRV4), 32));
|
||||
target.addLinkAddress(new LinkAddress(
|
||||
NetworkUtils.numericToInetAddress(ADDRV6), 128));
|
||||
target.addDns(NetworkUtils.numericToInetAddress(DNS1));
|
||||
target.addDns(NetworkUtils.numericToInetAddress(DNS2));
|
||||
target.addLinkAddress(LINKADDRV4);
|
||||
target.addLinkAddress(LINKADDRV6);
|
||||
target.addDns(DNS1);
|
||||
target.addDns(DNS2);
|
||||
// change gateway
|
||||
target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress("75.208.8.2")));
|
||||
target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2)));
|
||||
target.addRoute(new RouteInfo(GATEWAY2));
|
||||
target.setMtu(MTU);
|
||||
assertFalse(source.equals(target));
|
||||
|
||||
target.clear();
|
||||
target.setInterfaceName(NAME);
|
||||
target.addLinkAddress(LINKADDRV4);
|
||||
target.addLinkAddress(LINKADDRV6);
|
||||
target.addDns(DNS1);
|
||||
target.addDns(DNS2);
|
||||
target.addRoute(new RouteInfo(GATEWAY1));
|
||||
target.addRoute(new RouteInfo(GATEWAY2));
|
||||
// change mtu
|
||||
target.setMtu(1440);
|
||||
assertFalse(source.equals(target));
|
||||
|
||||
} catch (Exception e) {
|
||||
@@ -166,28 +181,26 @@ public class LinkPropertiesTest extends TestCase {
|
||||
LinkProperties source = new LinkProperties();
|
||||
source.setInterfaceName(NAME);
|
||||
// set 2 link addresses
|
||||
source.addLinkAddress(new LinkAddress(
|
||||
NetworkUtils.numericToInetAddress(ADDRV4), 32));
|
||||
source.addLinkAddress(new LinkAddress(
|
||||
NetworkUtils.numericToInetAddress(ADDRV6), 128));
|
||||
source.addLinkAddress(LINKADDRV4);
|
||||
source.addLinkAddress(LINKADDRV6);
|
||||
// set 2 dnses
|
||||
source.addDns(NetworkUtils.numericToInetAddress(DNS1));
|
||||
source.addDns(NetworkUtils.numericToInetAddress(DNS2));
|
||||
source.addDns(DNS1);
|
||||
source.addDns(DNS2);
|
||||
// set 2 gateways
|
||||
source.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1)));
|
||||
source.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2)));
|
||||
source.addRoute(new RouteInfo(GATEWAY1));
|
||||
source.addRoute(new RouteInfo(GATEWAY2));
|
||||
source.setMtu(MTU);
|
||||
|
||||
LinkProperties target = new LinkProperties();
|
||||
// Exchange order
|
||||
target.setInterfaceName(NAME);
|
||||
target.addLinkAddress(new LinkAddress(
|
||||
NetworkUtils.numericToInetAddress(ADDRV6), 128));
|
||||
target.addLinkAddress(new LinkAddress(
|
||||
NetworkUtils.numericToInetAddress(ADDRV4), 32));
|
||||
target.addDns(NetworkUtils.numericToInetAddress(DNS2));
|
||||
target.addDns(NetworkUtils.numericToInetAddress(DNS1));
|
||||
target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2)));
|
||||
target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1)));
|
||||
target.addLinkAddress(LINKADDRV6);
|
||||
target.addLinkAddress(LINKADDRV4);
|
||||
target.addDns(DNS2);
|
||||
target.addDns(DNS1);
|
||||
target.addRoute(new RouteInfo(GATEWAY2));
|
||||
target.addRoute(new RouteInfo(GATEWAY1));
|
||||
target.setMtu(MTU);
|
||||
|
||||
assertLinkPropertiesEqual(source, target);
|
||||
} catch (Exception e) {
|
||||
@@ -200,21 +213,15 @@ public class LinkPropertiesTest extends TestCase {
|
||||
try {
|
||||
LinkProperties source = new LinkProperties();
|
||||
// set 3 link addresses, eg, [A, A, B]
|
||||
source.addLinkAddress(new LinkAddress(
|
||||
NetworkUtils.numericToInetAddress(ADDRV4), 32));
|
||||
source.addLinkAddress(new LinkAddress(
|
||||
NetworkUtils.numericToInetAddress(ADDRV4), 32));
|
||||
source.addLinkAddress(new LinkAddress(
|
||||
NetworkUtils.numericToInetAddress(ADDRV6), 128));
|
||||
source.addLinkAddress(LINKADDRV4);
|
||||
source.addLinkAddress(LINKADDRV4);
|
||||
source.addLinkAddress(LINKADDRV6);
|
||||
|
||||
LinkProperties target = new LinkProperties();
|
||||
// set 3 link addresses, eg, [A, B, B]
|
||||
target.addLinkAddress(new LinkAddress(
|
||||
NetworkUtils.numericToInetAddress(ADDRV4), 32));
|
||||
target.addLinkAddress(new LinkAddress(
|
||||
NetworkUtils.numericToInetAddress(ADDRV6), 128));
|
||||
target.addLinkAddress(new LinkAddress(
|
||||
NetworkUtils.numericToInetAddress(ADDRV6), 128));
|
||||
target.addLinkAddress(LINKADDRV4);
|
||||
target.addLinkAddress(LINKADDRV6);
|
||||
target.addLinkAddress(LINKADDRV6);
|
||||
|
||||
assertLinkPropertiesEqual(source, target);
|
||||
} catch (Exception e) {
|
||||
@@ -232,7 +239,7 @@ public class LinkPropertiesTest extends TestCase {
|
||||
public void testRouteInterfaces() {
|
||||
LinkAddress prefix = new LinkAddress(
|
||||
NetworkUtils.numericToInetAddress("2001:db8::"), 32);
|
||||
InetAddress address = NetworkUtils.numericToInetAddress(ADDRV6);
|
||||
InetAddress address = ADDRV6;
|
||||
|
||||
// Add a route with no interface to a LinkProperties with no interface. No errors.
|
||||
LinkProperties lp = new LinkProperties();
|
||||
@@ -265,7 +272,7 @@ public class LinkPropertiesTest extends TestCase {
|
||||
assertAllRoutesHaveInterface("wlan0", lp);
|
||||
|
||||
// Routes with null interfaces are converted to wlan0.
|
||||
r = RouteInfo.makeHostRoute(NetworkUtils.numericToInetAddress(ADDRV6), null);
|
||||
r = RouteInfo.makeHostRoute(ADDRV6, null);
|
||||
lp.addRoute(r);
|
||||
assertEquals(3, lp.getRoutes().size());
|
||||
assertAllRoutesHaveInterface("wlan0", lp);
|
||||
@@ -273,28 +280,45 @@ public class LinkPropertiesTest extends TestCase {
|
||||
// Check comparisons work.
|
||||
LinkProperties lp2 = new LinkProperties(lp);
|
||||
assertAllRoutesHaveInterface("wlan0", lp);
|
||||
assertEquals(0, lp.compareRoutes(lp2).added.size());
|
||||
assertEquals(0, lp.compareRoutes(lp2).removed.size());
|
||||
assertEquals(0, lp.compareAllRoutes(lp2).added.size());
|
||||
assertEquals(0, lp.compareAllRoutes(lp2).removed.size());
|
||||
|
||||
lp2.setInterfaceName("p2p0");
|
||||
assertAllRoutesHaveInterface("p2p0", lp2);
|
||||
assertEquals(3, lp.compareRoutes(lp2).added.size());
|
||||
assertEquals(3, lp.compareRoutes(lp2).removed.size());
|
||||
assertEquals(3, lp.compareAllRoutes(lp2).added.size());
|
||||
assertEquals(3, lp.compareAllRoutes(lp2).removed.size());
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testStackedInterfaces() {
|
||||
LinkProperties rmnet0 = new LinkProperties();
|
||||
rmnet0.setInterfaceName("rmnet0");
|
||||
rmnet0.addLinkAddress(LINKADDRV6);
|
||||
|
||||
LinkProperties clat4 = new LinkProperties();
|
||||
clat4.setInterfaceName("clat4");
|
||||
clat4.addLinkAddress(LINKADDRV4);
|
||||
|
||||
assertEquals(0, rmnet0.getStackedLinks().size());
|
||||
assertEquals(1, rmnet0.getAddresses().size());
|
||||
assertEquals(1, rmnet0.getLinkAddresses().size());
|
||||
assertEquals(1, rmnet0.getAllAddresses().size());
|
||||
assertEquals(1, rmnet0.getAllLinkAddresses().size());
|
||||
|
||||
rmnet0.addStackedLink(clat4);
|
||||
assertEquals(1, rmnet0.getStackedLinks().size());
|
||||
assertEquals(1, rmnet0.getAddresses().size());
|
||||
assertEquals(1, rmnet0.getLinkAddresses().size());
|
||||
assertEquals(2, rmnet0.getAllAddresses().size());
|
||||
assertEquals(2, rmnet0.getAllLinkAddresses().size());
|
||||
|
||||
rmnet0.addStackedLink(clat4);
|
||||
assertEquals(1, rmnet0.getStackedLinks().size());
|
||||
assertEquals(1, rmnet0.getAddresses().size());
|
||||
assertEquals(1, rmnet0.getLinkAddresses().size());
|
||||
assertEquals(2, rmnet0.getAllAddresses().size());
|
||||
assertEquals(2, rmnet0.getAllLinkAddresses().size());
|
||||
|
||||
assertEquals(0, clat4.getStackedLinks().size());
|
||||
|
||||
// Modify an item in the returned collection to see what happens.
|
||||
@@ -306,5 +330,76 @@ public class LinkPropertiesTest extends TestCase {
|
||||
for (LinkProperties link : rmnet0.getStackedLinks()) {
|
||||
assertFalse("newname".equals(link.getInterfaceName()));
|
||||
}
|
||||
|
||||
assertTrue(rmnet0.removeStackedLink(clat4));
|
||||
assertEquals(0, rmnet0.getStackedLinks().size());
|
||||
assertEquals(1, rmnet0.getAddresses().size());
|
||||
assertEquals(1, rmnet0.getLinkAddresses().size());
|
||||
assertEquals(1, rmnet0.getAllAddresses().size());
|
||||
assertEquals(1, rmnet0.getAllLinkAddresses().size());
|
||||
|
||||
assertFalse(rmnet0.removeStackedLink(clat4));
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testAddressMethods() {
|
||||
LinkProperties lp = new LinkProperties();
|
||||
|
||||
// No addresses.
|
||||
assertFalse(lp.hasIPv4Address());
|
||||
assertFalse(lp.hasIPv6Address());
|
||||
|
||||
// Addresses on stacked links don't count.
|
||||
LinkProperties stacked = new LinkProperties();
|
||||
stacked.setInterfaceName("stacked");
|
||||
lp.addStackedLink(stacked);
|
||||
stacked.addLinkAddress(LINKADDRV4);
|
||||
stacked.addLinkAddress(LINKADDRV6);
|
||||
assertTrue(stacked.hasIPv4Address());
|
||||
assertTrue(stacked.hasIPv6Address());
|
||||
assertFalse(lp.hasIPv4Address());
|
||||
assertFalse(lp.hasIPv6Address());
|
||||
lp.removeStackedLink(stacked);
|
||||
assertFalse(lp.hasIPv4Address());
|
||||
assertFalse(lp.hasIPv6Address());
|
||||
|
||||
// Addresses on the base link.
|
||||
// Check the return values of hasIPvXAddress and ensure the add/remove methods return true
|
||||
// iff something changes.
|
||||
assertTrue(lp.addLinkAddress(LINKADDRV6));
|
||||
assertFalse(lp.hasIPv4Address());
|
||||
assertTrue(lp.hasIPv6Address());
|
||||
|
||||
assertTrue(lp.removeLinkAddress(LINKADDRV6));
|
||||
assertTrue(lp.addLinkAddress(LINKADDRV4));
|
||||
assertTrue(lp.hasIPv4Address());
|
||||
assertFalse(lp.hasIPv6Address());
|
||||
|
||||
assertTrue(lp.addLinkAddress(LINKADDRV6));
|
||||
assertTrue(lp.hasIPv4Address());
|
||||
assertTrue(lp.hasIPv6Address());
|
||||
|
||||
// Adding an address twice has no effect.
|
||||
// Removing an address that's not present has no effect.
|
||||
assertFalse(lp.addLinkAddress(LINKADDRV4));
|
||||
assertTrue(lp.hasIPv4Address());
|
||||
assertTrue(lp.removeLinkAddress(LINKADDRV4));
|
||||
assertFalse(lp.hasIPv4Address());
|
||||
assertFalse(lp.removeLinkAddress(LINKADDRV4));
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testSetLinkAddresses() {
|
||||
LinkProperties lp = new LinkProperties();
|
||||
lp.addLinkAddress(LINKADDRV4);
|
||||
lp.addLinkAddress(LINKADDRV6);
|
||||
|
||||
LinkProperties lp2 = new LinkProperties();
|
||||
lp2.addLinkAddress(LINKADDRV6);
|
||||
|
||||
assertFalse(lp.equals(lp2));
|
||||
|
||||
lp2.setLinkAddresses(lp.getLinkAddresses());
|
||||
assertTrue(lp.equals(lp));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user