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;
|
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} */
|
/** {@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
|
* If you want to set the default network preference,you can directly
|
||||||
@@ -436,6 +442,8 @@ public class ConnectivityManager {
|
|||||||
return "MOBILE_CBS";
|
return "MOBILE_CBS";
|
||||||
case TYPE_WIFI_P2P:
|
case TYPE_WIFI_P2P:
|
||||||
return "WIFI_P2P";
|
return "WIFI_P2P";
|
||||||
|
case TYPE_MOBILE_IA:
|
||||||
|
return "MOBILE_IA";
|
||||||
default:
|
default:
|
||||||
return Integer.toString(type);
|
return Integer.toString(type);
|
||||||
}
|
}
|
||||||
@@ -458,6 +466,39 @@ public class ConnectivityManager {
|
|||||||
case TYPE_MOBILE_FOTA:
|
case TYPE_MOBILE_FOTA:
|
||||||
case TYPE_MOBILE_IMS:
|
case TYPE_MOBILE_IMS:
|
||||||
case TYPE_MOBILE_CBS:
|
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;
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
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.
|
* 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
|
* Supply the backend messenger for a network tracker
|
||||||
*
|
*
|
||||||
@@ -1297,70 +1380,26 @@ public class ConnectivityManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The ResultReceiver resultCode for checkMobileProvisioning (CMP_RESULT_CODE)
|
* Check mobile provisioning.
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
|
||||||
*
|
*
|
||||||
* {@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 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
|
* @return time out that will be used, maybe less that suggestedTimeOutMs
|
||||||
* -1 if an error.
|
* -1 if an error.
|
||||||
*
|
*
|
||||||
* {@hide}
|
* {@hide}
|
||||||
*/
|
*/
|
||||||
public int checkMobileProvisioning(boolean sendNotification, int suggestedTimeOutMs,
|
public int checkMobileProvisioning(int suggestedTimeOutMs) {
|
||||||
ResultReceiver resultReceiver) {
|
|
||||||
int timeOutMs = -1;
|
int timeOutMs = -1;
|
||||||
try {
|
try {
|
||||||
timeOutMs = mService.checkMobileProvisioning(sendNotification, suggestedTimeOutMs,
|
timeOutMs = mService.checkMobileProvisioning(suggestedTimeOutMs);
|
||||||
resultReceiver);
|
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
}
|
}
|
||||||
return timeOutMs;
|
return timeOutMs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the carrier provisioning url.
|
* Get the mobile provisioning url.
|
||||||
* {@hide}
|
* {@hide}
|
||||||
*/
|
*/
|
||||||
public String getMobileProvisioningUrl() {
|
public String getMobileProvisioningUrl() {
|
||||||
@@ -1370,4 +1409,87 @@ public class ConnectivityManager {
|
|||||||
}
|
}
|
||||||
return null;
|
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.
|
* 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 class DhcpInfo implements Parcelable {
|
||||||
public int ipAddress;
|
public int ipAddress;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package android.net;
|
package android.net;
|
||||||
|
|
||||||
|
import android.net.LinkQualityInfo;
|
||||||
import android.net.LinkProperties;
|
import android.net.LinkProperties;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
import android.net.NetworkQuotaInfo;
|
import android.net.NetworkQuotaInfo;
|
||||||
@@ -37,6 +38,9 @@ import com.android.internal.net.VpnProfile;
|
|||||||
/** {@hide} */
|
/** {@hide} */
|
||||||
interface IConnectivityManager
|
interface IConnectivityManager
|
||||||
{
|
{
|
||||||
|
// Keep this in sync with framework/native/services/connectivitymanager/ConnectivityManager.h
|
||||||
|
void markSocketAsUser(in ParcelFileDescriptor socket, int uid);
|
||||||
|
|
||||||
void setNetworkPreference(int pref);
|
void setNetworkPreference(int pref);
|
||||||
|
|
||||||
int getNetworkPreference();
|
int getNetworkPreference();
|
||||||
@@ -46,6 +50,8 @@ interface IConnectivityManager
|
|||||||
NetworkInfo getNetworkInfo(int networkType);
|
NetworkInfo getNetworkInfo(int networkType);
|
||||||
NetworkInfo[] getAllNetworkInfo();
|
NetworkInfo[] getAllNetworkInfo();
|
||||||
|
|
||||||
|
NetworkInfo getProvisioningOrActiveNetworkInfo();
|
||||||
|
|
||||||
boolean isNetworkSupported(int networkType);
|
boolean isNetworkSupported(int networkType);
|
||||||
|
|
||||||
LinkProperties getActiveLinkProperties();
|
LinkProperties getActiveLinkProperties();
|
||||||
@@ -87,12 +93,6 @@ interface IConnectivityManager
|
|||||||
|
|
||||||
String[] getTetheredIfaces();
|
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[] getTetheringErroredIfaces();
|
||||||
|
|
||||||
String[] getTetherableUsbRegexs();
|
String[] getTetherableUsbRegexs();
|
||||||
@@ -121,6 +121,8 @@ interface IConnectivityManager
|
|||||||
|
|
||||||
ParcelFileDescriptor establishVpn(in VpnConfig config);
|
ParcelFileDescriptor establishVpn(in VpnConfig config);
|
||||||
|
|
||||||
|
VpnConfig getVpnConfig();
|
||||||
|
|
||||||
void startLegacyVpn(in VpnProfile profile);
|
void startLegacyVpn(in VpnProfile profile);
|
||||||
|
|
||||||
LegacyVpnInfo getLegacyVpnInfo();
|
LegacyVpnInfo getLegacyVpnInfo();
|
||||||
@@ -129,11 +131,25 @@ interface IConnectivityManager
|
|||||||
|
|
||||||
void captivePortalCheckComplete(in NetworkInfo info);
|
void captivePortalCheckComplete(in NetworkInfo info);
|
||||||
|
|
||||||
|
void captivePortalCheckCompleted(in NetworkInfo info, boolean isCaptivePortal);
|
||||||
|
|
||||||
void supplyMessenger(int networkType, in Messenger messenger);
|
void supplyMessenger(int networkType, in Messenger messenger);
|
||||||
|
|
||||||
int findConnectionTypeForIface(in String iface);
|
int findConnectionTypeForIface(in String iface);
|
||||||
|
|
||||||
int checkMobileProvisioning(boolean sendNotification, int suggestedTimeOutMs, in ResultReceiver resultReceiver);
|
int checkMobileProvisioning(int suggestedTimeOutMs);
|
||||||
|
|
||||||
String getMobileProvisioningUrl();
|
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.
|
* IPv4 or IPv6 address.
|
||||||
*/
|
*/
|
||||||
private final InetAddress address;
|
private InetAddress address;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Network prefix length
|
* 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 ||
|
if (address == null || prefixLength < 0 ||
|
||||||
((address instanceof Inet4Address) && prefixLength > 32) ||
|
((address instanceof Inet4Address) && prefixLength > 32) ||
|
||||||
(prefixLength > 128)) {
|
(prefixLength > 128)) {
|
||||||
throw new IllegalArgumentException("Bad LinkAddress params " + address +
|
throw new IllegalArgumentException("Bad LinkAddress params " + address +
|
||||||
prefixLength);
|
"/" + prefixLength);
|
||||||
}
|
}
|
||||||
this.address = address;
|
this.address = address;
|
||||||
this.prefixLength = prefixLength;
|
this.prefixLength = prefixLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LinkAddress(InetAddress address, int prefixLength) {
|
||||||
|
init(address, prefixLength);
|
||||||
|
}
|
||||||
|
|
||||||
public LinkAddress(InterfaceAddress interfaceAddress) {
|
public LinkAddress(InterfaceAddress interfaceAddress) {
|
||||||
this.address = interfaceAddress.getAddress();
|
init(interfaceAddress.getAddress(),
|
||||||
this.prefixLength = interfaceAddress.getNetworkPrefixLength();
|
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
|
@Override
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import android.text.TextUtils;
|
|||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.Inet4Address;
|
import java.net.Inet4Address;
|
||||||
|
import java.net.Inet6Address;
|
||||||
|
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -65,6 +66,7 @@ public class LinkProperties implements Parcelable {
|
|||||||
private String mDomains;
|
private String mDomains;
|
||||||
private Collection<RouteInfo> mRoutes = new ArrayList<RouteInfo>();
|
private Collection<RouteInfo> mRoutes = new ArrayList<RouteInfo>();
|
||||||
private ProxyProperties mHttpProxy;
|
private ProxyProperties mHttpProxy;
|
||||||
|
private int mMtu;
|
||||||
|
|
||||||
// Stores the properties of links that are "stacked" above this link.
|
// Stores the properties of links that are "stacked" above this link.
|
||||||
// Indexed by interface name to allow modification and to prevent duplicates being added.
|
// 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()) {
|
for (LinkProperties l: source.mStackedLinks.values()) {
|
||||||
addStackedLink(l);
|
addStackedLink(l);
|
||||||
}
|
}
|
||||||
|
setMtu(source.getMtu());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,6 +131,9 @@ public class LinkProperties implements Parcelable {
|
|||||||
return interfaceNames;
|
return interfaceNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all the addresses on this link.
|
||||||
|
*/
|
||||||
public Collection<InetAddress> getAddresses() {
|
public Collection<InetAddress> getAddresses() {
|
||||||
Collection<InetAddress> addresses = new ArrayList<InetAddress>();
|
Collection<InetAddress> addresses = new ArrayList<InetAddress>();
|
||||||
for (LinkAddress linkAddress : mLinkAddresses) {
|
for (LinkAddress linkAddress : mLinkAddresses) {
|
||||||
@@ -136,14 +142,73 @@ public class LinkProperties implements Parcelable {
|
|||||||
return Collections.unmodifiableCollection(addresses);
|
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() {
|
public Collection<LinkAddress> getLinkAddresses() {
|
||||||
return Collections.unmodifiableCollection(mLinkAddresses);
|
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) {
|
public void addDns(InetAddress dns) {
|
||||||
if (dns != null) mDnses.add(dns);
|
if (dns != null) mDnses.add(dns);
|
||||||
}
|
}
|
||||||
@@ -160,6 +225,14 @@ public class LinkProperties implements Parcelable {
|
|||||||
mDomains = domains;
|
mDomains = domains;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setMtu(int mtu) {
|
||||||
|
mMtu = mtu;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMtu() {
|
||||||
|
return mMtu;
|
||||||
|
}
|
||||||
|
|
||||||
private RouteInfo routeWithInterface(RouteInfo route) {
|
private RouteInfo routeWithInterface(RouteInfo route) {
|
||||||
return new RouteInfo(
|
return new RouteInfo(
|
||||||
route.getDestination(),
|
route.getDestination(),
|
||||||
@@ -213,11 +286,14 @@ public class LinkProperties implements Parcelable {
|
|||||||
* of stacked links. If link is null, nothing changes.
|
* of stacked links. If link is null, nothing changes.
|
||||||
*
|
*
|
||||||
* @param link The link to add.
|
* @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) {
|
if (link != null && link.getInterfaceName() != null) {
|
||||||
mStackedLinks.put(link.getInterfaceName(), link);
|
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
|
* If there a stacked link with the same interfacename as link, it is
|
||||||
* removed. Otherwise, nothing changes.
|
* 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) {
|
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();
|
mRoutes.clear();
|
||||||
mHttpProxy = null;
|
mHttpProxy = null;
|
||||||
mStackedLinks.clear();
|
mStackedLinks.clear();
|
||||||
|
mMtu = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -277,6 +357,8 @@ public class LinkProperties implements Parcelable {
|
|||||||
|
|
||||||
String domainName = "Domains: " + mDomains;
|
String domainName = "Domains: " + mDomains;
|
||||||
|
|
||||||
|
String mtu = "MTU: " + mMtu;
|
||||||
|
|
||||||
String routes = " Routes: [";
|
String routes = " Routes: [";
|
||||||
for (RouteInfo route : mRoutes) routes += route.toString() + ",";
|
for (RouteInfo route : mRoutes) routes += route.toString() + ",";
|
||||||
routes += "] ";
|
routes += "] ";
|
||||||
@@ -290,7 +372,8 @@ public class LinkProperties implements Parcelable {
|
|||||||
}
|
}
|
||||||
stacked += "] ";
|
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;
|
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
|
* Compares this {@code LinkProperties} interface name against the target
|
||||||
*
|
*
|
||||||
@@ -391,6 +488,16 @@ public class LinkProperties implements Parcelable {
|
|||||||
return true;
|
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
|
@Override
|
||||||
/**
|
/**
|
||||||
* Compares this {@code LinkProperties} instance against the target
|
* Compares this {@code LinkProperties} instance against the target
|
||||||
@@ -422,17 +529,16 @@ public class LinkProperties implements Parcelable {
|
|||||||
isIdenticalDnses(target) &&
|
isIdenticalDnses(target) &&
|
||||||
isIdenticalRoutes(target) &&
|
isIdenticalRoutes(target) &&
|
||||||
isIdenticalHttpProxy(target) &&
|
isIdenticalHttpProxy(target) &&
|
||||||
isIdenticalStackedLinks(target);
|
isIdenticalStackedLinks(target) &&
|
||||||
|
isIdenticalMtu(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return two lists, a list of addresses that would be removed from
|
* Compares the addresses in this LinkProperties with another
|
||||||
* mLinkAddresses and a list of addresses that would be added to
|
* LinkProperties, examining only addresses on the base link.
|
||||||
* mLinkAddress which would then result in target and mLinkAddresses
|
|
||||||
* being the same list.
|
|
||||||
*
|
*
|
||||||
* @param target is a LinkProperties with the new list of addresses
|
* @param target a LinkProperties with the new list of addresses
|
||||||
* @return the removed and added lists.
|
* @return the differences between the addresses.
|
||||||
*/
|
*/
|
||||||
public CompareResult<LinkAddress> compareAddresses(LinkProperties target) {
|
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
|
* Compares the DNS addresses in this LinkProperties with another
|
||||||
* mDnses and a list of addresses that would be added to
|
* LinkProperties, examining only DNS addresses on the base link.
|
||||||
* mDnses which would then result in target and mDnses
|
|
||||||
* being the same list.
|
|
||||||
*
|
*
|
||||||
* @param target is a LinkProperties with the new list of dns addresses
|
* @param target a LinkProperties with the new list of dns addresses
|
||||||
* @return the removed and added lists.
|
* @return the differences between the DNS addresses.
|
||||||
*/
|
*/
|
||||||
public CompareResult<InetAddress> compareDnses(LinkProperties target) {
|
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
|
* Compares all routes in this LinkProperties with another LinkProperties,
|
||||||
* mRoutes and a list of routes that would be added to
|
* examining both the the base link and all stacked links.
|
||||||
* mRoutes which would then result in target and mRoutes
|
|
||||||
* being the same list.
|
|
||||||
*
|
*
|
||||||
* @param target is a LinkProperties with the new list of routes
|
* @param target a LinkProperties with the new list of routes
|
||||||
* @return the removed and added lists.
|
* @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
|
* Duplicate the RouteInfos into removed, we will be removing
|
||||||
* routes which are common between mRoutes and target
|
* routes which are common between mRoutes and target
|
||||||
@@ -530,7 +632,8 @@ public class LinkProperties implements Parcelable {
|
|||||||
+ ((null == mDomains) ? 0 : mDomains.hashCode())
|
+ ((null == mDomains) ? 0 : mDomains.hashCode())
|
||||||
+ mRoutes.size() * 41
|
+ mRoutes.size() * 41
|
||||||
+ ((null == mHttpProxy) ? 0 : mHttpProxy.hashCode())
|
+ ((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.writeByteArray(d.getAddress());
|
||||||
}
|
}
|
||||||
dest.writeString(mDomains);
|
dest.writeString(mDomains);
|
||||||
|
dest.writeInt(mMtu);
|
||||||
dest.writeInt(mRoutes.size());
|
dest.writeInt(mRoutes.size());
|
||||||
for(RouteInfo route : mRoutes) {
|
for(RouteInfo route : mRoutes) {
|
||||||
dest.writeParcelable(route, flags);
|
dest.writeParcelable(route, flags);
|
||||||
@@ -587,6 +690,7 @@ public class LinkProperties implements Parcelable {
|
|||||||
} catch (UnknownHostException e) { }
|
} catch (UnknownHostException e) { }
|
||||||
}
|
}
|
||||||
netProp.setDomains(in.readString());
|
netProp.setDomains(in.readString());
|
||||||
|
netProp.setMtu(in.readInt());
|
||||||
addressCount = in.readInt();
|
addressCount = in.readInt();
|
||||||
for (int i=0; i<addressCount; i++) {
|
for (int i=0; i<addressCount; i++) {
|
||||||
netProp.addRoute((RouteInfo)in.readParcelable(null));
|
netProp.addRoute((RouteInfo)in.readParcelable(null));
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ public class NetworkInfo implements Parcelable {
|
|||||||
/** Link has poor connectivity. */
|
/** Link has poor connectivity. */
|
||||||
VERIFYING_POOR_LINK,
|
VERIFYING_POOR_LINK,
|
||||||
/** Checking if network is a captive portal */
|
/** 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 String mExtraInfo;
|
||||||
private boolean mIsFailover;
|
private boolean mIsFailover;
|
||||||
private boolean mIsRoaming;
|
private boolean mIsRoaming;
|
||||||
|
private boolean mIsConnectedToProvisioningNetwork;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates whether network connectivity is possible:
|
* Indicates whether network connectivity is possible:
|
||||||
*/
|
*/
|
||||||
@@ -148,6 +150,7 @@ public class NetworkInfo implements Parcelable {
|
|||||||
mState = State.UNKNOWN;
|
mState = State.UNKNOWN;
|
||||||
mIsAvailable = false; // until we're told otherwise, assume unavailable
|
mIsAvailable = false; // until we're told otherwise, assume unavailable
|
||||||
mIsRoaming = false;
|
mIsRoaming = false;
|
||||||
|
mIsConnectedToProvisioningNetwork = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@hide} */
|
/** {@hide} */
|
||||||
@@ -164,6 +167,7 @@ public class NetworkInfo implements Parcelable {
|
|||||||
mIsFailover = source.mIsFailover;
|
mIsFailover = source.mIsFailover;
|
||||||
mIsRoaming = source.mIsRoaming;
|
mIsRoaming = source.mIsRoaming;
|
||||||
mIsAvailable = source.mIsAvailable;
|
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.
|
* Reports the current coarse-grained state of the network.
|
||||||
* @return the coarse-grained state
|
* @return the coarse-grained state
|
||||||
@@ -405,7 +425,9 @@ public class NetworkInfo implements Parcelable {
|
|||||||
append(", extra: ").append(mExtraInfo == null ? "(none)" : mExtraInfo).
|
append(", extra: ").append(mExtraInfo == null ? "(none)" : mExtraInfo).
|
||||||
append(", roaming: ").append(mIsRoaming).
|
append(", roaming: ").append(mIsRoaming).
|
||||||
append(", failover: ").append(mIsFailover).
|
append(", failover: ").append(mIsFailover).
|
||||||
append(", isAvailable: ").append(mIsAvailable);
|
append(", isAvailable: ").append(mIsAvailable).
|
||||||
|
append(", isConnectedToProvisioningNetwork: ").
|
||||||
|
append(mIsConnectedToProvisioningNetwork);
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -433,6 +455,7 @@ public class NetworkInfo implements Parcelable {
|
|||||||
dest.writeInt(mIsFailover ? 1 : 0);
|
dest.writeInt(mIsFailover ? 1 : 0);
|
||||||
dest.writeInt(mIsAvailable ? 1 : 0);
|
dest.writeInt(mIsAvailable ? 1 : 0);
|
||||||
dest.writeInt(mIsRoaming ? 1 : 0);
|
dest.writeInt(mIsRoaming ? 1 : 0);
|
||||||
|
dest.writeInt(mIsConnectedToProvisioningNetwork ? 1 : 0);
|
||||||
dest.writeString(mReason);
|
dest.writeString(mReason);
|
||||||
dest.writeString(mExtraInfo);
|
dest.writeString(mExtraInfo);
|
||||||
}
|
}
|
||||||
@@ -455,6 +478,7 @@ public class NetworkInfo implements Parcelable {
|
|||||||
netInfo.mIsFailover = in.readInt() != 0;
|
netInfo.mIsFailover = in.readInt() != 0;
|
||||||
netInfo.mIsAvailable = in.readInt() != 0;
|
netInfo.mIsAvailable = in.readInt() != 0;
|
||||||
netInfo.mIsRoaming = in.readInt() != 0;
|
netInfo.mIsRoaming = in.readInt() != 0;
|
||||||
|
netInfo.mIsConnectedToProvisioningNetwork = in.readInt() != 0;
|
||||||
netInfo.mReason = in.readString();
|
netInfo.mReason = in.readString();
|
||||||
netInfo.mExtraInfo = in.readString();
|
netInfo.mExtraInfo = in.readString();
|
||||||
return netInfo;
|
return netInfo;
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import java.net.Inet4Address;
|
|||||||
import java.net.Inet6Address;
|
import java.net.Inet6Address;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@@ -102,6 +103,11 @@ public class NetworkUtils {
|
|||||||
*/
|
*/
|
||||||
public native static String getDhcpError();
|
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.
|
* Convert a IPv4 address from an integer to an InetAddress.
|
||||||
* @param hostAddress an int corresponding to the IPv4 address in network byte order
|
* @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)
|
public static InetAddress hexToInet6Address(String addrHexString)
|
||||||
throws IllegalArgumentException {
|
throws IllegalArgumentException {
|
||||||
try {
|
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(0,4), addrHexString.substring(4,8),
|
||||||
addrHexString.substring(8,12), addrHexString.substring(12,16),
|
addrHexString.substring(8,12), addrHexString.substring(12,16),
|
||||||
addrHexString.substring(16,20), addrHexString.substring(20,24),
|
addrHexString.substring(16,20), addrHexString.substring(20,24),
|
||||||
|
|||||||
@@ -20,9 +20,7 @@ package android.net;
|
|||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@@ -38,17 +36,38 @@ public class ProxyProperties implements Parcelable {
|
|||||||
private String mExclusionList;
|
private String mExclusionList;
|
||||||
private String[] mParsedExclusionList;
|
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) {
|
public ProxyProperties(String host, int port, String exclList) {
|
||||||
mHost = host;
|
mHost = host;
|
||||||
mPort = port;
|
mPort = port;
|
||||||
setExclusionList(exclList);
|
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) {
|
private ProxyProperties(String host, int port, String exclList, String[] parsedExclList) {
|
||||||
mHost = host;
|
mHost = host;
|
||||||
mPort = port;
|
mPort = port;
|
||||||
mExclusionList = exclList;
|
mExclusionList = exclList;
|
||||||
mParsedExclusionList = parsedExclList;
|
mParsedExclusionList = parsedExclList;
|
||||||
|
mPacFileUrl = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy constructor instead of clone
|
// copy constructor instead of clone
|
||||||
@@ -56,6 +75,7 @@ public class ProxyProperties implements Parcelable {
|
|||||||
if (source != null) {
|
if (source != null) {
|
||||||
mHost = source.getHost();
|
mHost = source.getHost();
|
||||||
mPort = source.getPort();
|
mPort = source.getPort();
|
||||||
|
mPacFileUrl = source.getPacFileUrl();
|
||||||
mExclusionList = source.getExclusionList();
|
mExclusionList = source.getExclusionList();
|
||||||
mParsedExclusionList = source.mParsedExclusionList;
|
mParsedExclusionList = source.mParsedExclusionList;
|
||||||
}
|
}
|
||||||
@@ -69,6 +89,10 @@ public class ProxyProperties implements Parcelable {
|
|||||||
return inetSocketAddress;
|
return inetSocketAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getPacFileUrl() {
|
||||||
|
return mPacFileUrl;
|
||||||
|
}
|
||||||
|
|
||||||
public String getHost() {
|
public String getHost() {
|
||||||
return mHost;
|
return mHost;
|
||||||
}
|
}
|
||||||
@@ -140,7 +164,10 @@ public class ProxyProperties implements Parcelable {
|
|||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder sb = new StringBuilder();
|
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("[");
|
||||||
sb.append(mHost);
|
sb.append(mHost);
|
||||||
sb.append("] ");
|
sb.append("] ");
|
||||||
@@ -158,6 +185,14 @@ public class ProxyProperties implements Parcelable {
|
|||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (!(o instanceof ProxyProperties)) return false;
|
if (!(o instanceof ProxyProperties)) return false;
|
||||||
ProxyProperties p = (ProxyProperties)o;
|
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 (mExclusionList != null && !mExclusionList.equals(p.getExclusionList())) return false;
|
||||||
if (mHost != null && p.getHost() != null && mHost.equals(p.getHost()) == false) {
|
if (mHost != null && p.getHost() != null && mHost.equals(p.getHost()) == false) {
|
||||||
return false;
|
return false;
|
||||||
@@ -191,6 +226,14 @@ public class ProxyProperties implements Parcelable {
|
|||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public void writeToParcel(Parcel dest, int flags) {
|
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) {
|
if (mHost != null) {
|
||||||
dest.writeByte((byte)1);
|
dest.writeByte((byte)1);
|
||||||
dest.writeString(mHost);
|
dest.writeString(mHost);
|
||||||
@@ -211,7 +254,12 @@ public class ProxyProperties implements Parcelable {
|
|||||||
public ProxyProperties createFromParcel(Parcel in) {
|
public ProxyProperties createFromParcel(Parcel in) {
|
||||||
String host = null;
|
String host = null;
|
||||||
int port = 0;
|
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();
|
host = in.readString();
|
||||||
port = in.readInt();
|
port = in.readInt();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#define LOG_TAG "NetUtils"
|
#define LOG_TAG "NetUtils"
|
||||||
|
|
||||||
#include "jni.h"
|
#include "jni.h"
|
||||||
|
#include "JNIHelp.h"
|
||||||
#include <utils/misc.h>
|
#include <utils/misc.h>
|
||||||
#include <android_runtime/AndroidRuntime.h>
|
#include <android_runtime/AndroidRuntime.h>
|
||||||
#include <utils/Log.h>
|
#include <utils/Log.h>
|
||||||
@@ -36,7 +37,8 @@ int dhcp_do_request(const char * const ifname,
|
|||||||
const char *server,
|
const char *server,
|
||||||
uint32_t *lease,
|
uint32_t *lease,
|
||||||
const char *vendorInfo,
|
const char *vendorInfo,
|
||||||
const char *domains);
|
const char *domains,
|
||||||
|
const char *mtu);
|
||||||
|
|
||||||
int dhcp_do_request_renew(const char * const ifname,
|
int dhcp_do_request_renew(const char * const ifname,
|
||||||
const char *ipaddr,
|
const char *ipaddr,
|
||||||
@@ -46,7 +48,8 @@ int dhcp_do_request_renew(const char * const ifname,
|
|||||||
const char *server,
|
const char *server,
|
||||||
uint32_t *lease,
|
uint32_t *lease,
|
||||||
const char *vendorInfo,
|
const char *vendorInfo,
|
||||||
const char *domains);
|
const char *domains,
|
||||||
|
const char *mtu);
|
||||||
|
|
||||||
int dhcp_stop(const char *ifname);
|
int dhcp_stop(const char *ifname);
|
||||||
int dhcp_release_lease(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;
|
uint32_t lease;
|
||||||
char vendorInfo[PROPERTY_VALUE_MAX];
|
char vendorInfo[PROPERTY_VALUE_MAX];
|
||||||
char domains[PROPERTY_VALUE_MAX];
|
char domains[PROPERTY_VALUE_MAX];
|
||||||
|
char mtu[PROPERTY_VALUE_MAX];
|
||||||
|
|
||||||
const char *nameStr = env->GetStringUTFChars(ifname, NULL);
|
const char *nameStr = env->GetStringUTFChars(ifname, NULL);
|
||||||
if (nameStr == NULL) return (jboolean)false;
|
if (nameStr == NULL) return (jboolean)false;
|
||||||
|
|
||||||
if (renew) {
|
if (renew) {
|
||||||
result = ::dhcp_do_request_renew(nameStr, ipaddr, gateway, &prefixLength,
|
result = ::dhcp_do_request_renew(nameStr, ipaddr, gateway, &prefixLength,
|
||||||
dns, server, &lease, vendorInfo, domains);
|
dns, server, &lease, vendorInfo, domains, mtu);
|
||||||
} else {
|
} else {
|
||||||
result = ::dhcp_do_request(nameStr, ipaddr, gateway, &prefixLength,
|
result = ::dhcp_do_request(nameStr, ipaddr, gateway, &prefixLength,
|
||||||
dns, server, &lease, vendorInfo, domains);
|
dns, server, &lease, vendorInfo, domains, mtu);
|
||||||
}
|
}
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
ALOGD("dhcp_do_request failed");
|
ALOGD("dhcp_do_request failed : %s (%s)", nameStr, renew ? "renew" : "new");
|
||||||
}
|
}
|
||||||
|
|
||||||
env->ReleaseStringUTFChars(ifname, nameStr);
|
env->ReleaseStringUTFChars(ifname, nameStr);
|
||||||
@@ -239,6 +243,13 @@ static jstring android_net_utils_getDhcpError(JNIEnv* env, jobject clazz)
|
|||||||
return env->NewStringUTF(::dhcp_get_errmsg());
|
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 },
|
{ "stopDhcp", "(Ljava/lang/String;)Z", (void *)android_net_utils_stopDhcp },
|
||||||
{ "releaseDhcpLease", "(Ljava/lang/String;)Z", (void *)android_net_utils_releaseDhcpLease },
|
{ "releaseDhcpLease", "(Ljava/lang/String;)Z", (void *)android_net_utils_releaseDhcpLease },
|
||||||
{ "getDhcpError", "()Ljava/lang/String;", (void*) android_net_utils_getDhcpError },
|
{ "getDhcpError", "()Ljava/lang/String;", (void*) android_net_utils_getDhcpError },
|
||||||
|
{ "markSocket", "(II)V", (void*) android_net_utils_markSocket },
|
||||||
};
|
};
|
||||||
|
|
||||||
int register_android_net_NetworkUtils(JNIEnv* env)
|
int register_android_net_NetworkUtils(JNIEnv* env)
|
||||||
|
|||||||
@@ -25,13 +25,18 @@ import java.net.InetAddress;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class LinkPropertiesTest extends TestCase {
|
public class LinkPropertiesTest extends TestCase {
|
||||||
private static String ADDRV4 = "75.208.6.1";
|
private static InetAddress ADDRV4 = NetworkUtils.numericToInetAddress("75.208.6.1");
|
||||||
private static String ADDRV6 = "2001:0db8:85a3:0000:0000:8a2e:0370:7334";
|
private static InetAddress ADDRV6 = NetworkUtils.numericToInetAddress(
|
||||||
private static String DNS1 = "75.208.7.1";
|
"2001:0db8:85a3:0000:0000:8a2e:0370:7334");
|
||||||
private static String DNS2 = "69.78.7.1";
|
private static InetAddress DNS1 = NetworkUtils.numericToInetAddress("75.208.7.1");
|
||||||
private static String GATEWAY1 = "75.208.8.1";
|
private static InetAddress DNS2 = NetworkUtils.numericToInetAddress("69.78.7.1");
|
||||||
private static String GATEWAY2 = "69.78.8.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 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) {
|
public void assertLinkPropertiesEqual(LinkProperties source, LinkProperties target) {
|
||||||
// Check implementation of equals(), element by element.
|
// Check implementation of equals(), element by element.
|
||||||
@@ -53,6 +58,9 @@ public class LinkPropertiesTest extends TestCase {
|
|||||||
assertTrue(source.isIdenticalStackedLinks(target));
|
assertTrue(source.isIdenticalStackedLinks(target));
|
||||||
assertTrue(target.isIdenticalStackedLinks(source));
|
assertTrue(target.isIdenticalStackedLinks(source));
|
||||||
|
|
||||||
|
assertTrue(source.isIdenticalMtu(target));
|
||||||
|
assertTrue(target.isIdenticalMtu(source));
|
||||||
|
|
||||||
// Check result of equals().
|
// Check result of equals().
|
||||||
assertTrue(source.equals(target));
|
assertTrue(source.equals(target));
|
||||||
assertTrue(target.equals(source));
|
assertTrue(target.equals(source));
|
||||||
@@ -76,43 +84,40 @@ public class LinkPropertiesTest extends TestCase {
|
|||||||
LinkProperties source = new LinkProperties();
|
LinkProperties source = new LinkProperties();
|
||||||
source.setInterfaceName(NAME);
|
source.setInterfaceName(NAME);
|
||||||
// set 2 link addresses
|
// set 2 link addresses
|
||||||
source.addLinkAddress(new LinkAddress(
|
source.addLinkAddress(LINKADDRV4);
|
||||||
NetworkUtils.numericToInetAddress(ADDRV4), 32));
|
source.addLinkAddress(LINKADDRV6);
|
||||||
source.addLinkAddress(new LinkAddress(
|
|
||||||
NetworkUtils.numericToInetAddress(ADDRV6), 128));
|
|
||||||
// set 2 dnses
|
// set 2 dnses
|
||||||
source.addDns(NetworkUtils.numericToInetAddress(DNS1));
|
source.addDns(DNS1);
|
||||||
source.addDns(NetworkUtils.numericToInetAddress(DNS2));
|
source.addDns(DNS2);
|
||||||
// set 2 gateways
|
// set 2 gateways
|
||||||
source.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1)));
|
source.addRoute(new RouteInfo(GATEWAY1));
|
||||||
source.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2)));
|
source.addRoute(new RouteInfo(GATEWAY2));
|
||||||
|
source.setMtu(MTU);
|
||||||
|
|
||||||
LinkProperties target = new LinkProperties();
|
LinkProperties target = new LinkProperties();
|
||||||
|
|
||||||
// All fields are same
|
// All fields are same
|
||||||
target.setInterfaceName(NAME);
|
target.setInterfaceName(NAME);
|
||||||
target.addLinkAddress(new LinkAddress(
|
target.addLinkAddress(LINKADDRV4);
|
||||||
NetworkUtils.numericToInetAddress(ADDRV4), 32));
|
target.addLinkAddress(LINKADDRV6);
|
||||||
target.addLinkAddress(new LinkAddress(
|
target.addDns(DNS1);
|
||||||
NetworkUtils.numericToInetAddress(ADDRV6), 128));
|
target.addDns(DNS2);
|
||||||
target.addDns(NetworkUtils.numericToInetAddress(DNS1));
|
target.addRoute(new RouteInfo(GATEWAY1));
|
||||||
target.addDns(NetworkUtils.numericToInetAddress(DNS2));
|
target.addRoute(new RouteInfo(GATEWAY2));
|
||||||
target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1)));
|
target.setMtu(MTU);
|
||||||
target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2)));
|
|
||||||
|
|
||||||
assertLinkPropertiesEqual(source, target);
|
assertLinkPropertiesEqual(source, target);
|
||||||
|
|
||||||
target.clear();
|
target.clear();
|
||||||
// change Interface Name
|
// change Interface Name
|
||||||
target.setInterfaceName("qmi1");
|
target.setInterfaceName("qmi1");
|
||||||
target.addLinkAddress(new LinkAddress(
|
target.addLinkAddress(LINKADDRV4);
|
||||||
NetworkUtils.numericToInetAddress(ADDRV4), 32));
|
target.addLinkAddress(LINKADDRV6);
|
||||||
target.addLinkAddress(new LinkAddress(
|
target.addDns(DNS1);
|
||||||
NetworkUtils.numericToInetAddress(ADDRV6), 128));
|
target.addDns(DNS2);
|
||||||
target.addDns(NetworkUtils.numericToInetAddress(DNS1));
|
target.addRoute(new RouteInfo(GATEWAY1));
|
||||||
target.addDns(NetworkUtils.numericToInetAddress(DNS2));
|
target.addRoute(new RouteInfo(GATEWAY2));
|
||||||
target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1)));
|
target.setMtu(MTU);
|
||||||
target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2)));
|
|
||||||
assertFalse(source.equals(target));
|
assertFalse(source.equals(target));
|
||||||
|
|
||||||
target.clear();
|
target.clear();
|
||||||
@@ -120,38 +125,48 @@ public class LinkPropertiesTest extends TestCase {
|
|||||||
// change link addresses
|
// change link addresses
|
||||||
target.addLinkAddress(new LinkAddress(
|
target.addLinkAddress(new LinkAddress(
|
||||||
NetworkUtils.numericToInetAddress("75.208.6.2"), 32));
|
NetworkUtils.numericToInetAddress("75.208.6.2"), 32));
|
||||||
target.addLinkAddress(new LinkAddress(
|
target.addLinkAddress(LINKADDRV6);
|
||||||
NetworkUtils.numericToInetAddress(ADDRV6), 128));
|
target.addDns(DNS1);
|
||||||
target.addDns(NetworkUtils.numericToInetAddress(DNS1));
|
target.addDns(DNS2);
|
||||||
target.addDns(NetworkUtils.numericToInetAddress(DNS2));
|
target.addRoute(new RouteInfo(GATEWAY1));
|
||||||
target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1)));
|
target.addRoute(new RouteInfo(GATEWAY2));
|
||||||
target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2)));
|
target.setMtu(MTU);
|
||||||
assertFalse(source.equals(target));
|
assertFalse(source.equals(target));
|
||||||
|
|
||||||
target.clear();
|
target.clear();
|
||||||
target.setInterfaceName(NAME);
|
target.setInterfaceName(NAME);
|
||||||
target.addLinkAddress(new LinkAddress(
|
target.addLinkAddress(LINKADDRV4);
|
||||||
NetworkUtils.numericToInetAddress(ADDRV4), 32));
|
target.addLinkAddress(LINKADDRV6);
|
||||||
target.addLinkAddress(new LinkAddress(
|
|
||||||
NetworkUtils.numericToInetAddress(ADDRV6), 128));
|
|
||||||
// change dnses
|
// change dnses
|
||||||
target.addDns(NetworkUtils.numericToInetAddress("75.208.7.2"));
|
target.addDns(NetworkUtils.numericToInetAddress("75.208.7.2"));
|
||||||
target.addDns(NetworkUtils.numericToInetAddress(DNS2));
|
target.addDns(DNS2);
|
||||||
target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1)));
|
target.addRoute(new RouteInfo(GATEWAY1));
|
||||||
target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2)));
|
target.addRoute(new RouteInfo(GATEWAY2));
|
||||||
|
target.setMtu(MTU);
|
||||||
assertFalse(source.equals(target));
|
assertFalse(source.equals(target));
|
||||||
|
|
||||||
target.clear();
|
target.clear();
|
||||||
target.setInterfaceName(NAME);
|
target.setInterfaceName(NAME);
|
||||||
target.addLinkAddress(new LinkAddress(
|
target.addLinkAddress(LINKADDRV4);
|
||||||
NetworkUtils.numericToInetAddress(ADDRV4), 32));
|
target.addLinkAddress(LINKADDRV6);
|
||||||
target.addLinkAddress(new LinkAddress(
|
target.addDns(DNS1);
|
||||||
NetworkUtils.numericToInetAddress(ADDRV6), 128));
|
target.addDns(DNS2);
|
||||||
target.addDns(NetworkUtils.numericToInetAddress(DNS1));
|
|
||||||
target.addDns(NetworkUtils.numericToInetAddress(DNS2));
|
|
||||||
// change gateway
|
// change gateway
|
||||||
target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress("75.208.8.2")));
|
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));
|
assertFalse(source.equals(target));
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -166,28 +181,26 @@ public class LinkPropertiesTest extends TestCase {
|
|||||||
LinkProperties source = new LinkProperties();
|
LinkProperties source = new LinkProperties();
|
||||||
source.setInterfaceName(NAME);
|
source.setInterfaceName(NAME);
|
||||||
// set 2 link addresses
|
// set 2 link addresses
|
||||||
source.addLinkAddress(new LinkAddress(
|
source.addLinkAddress(LINKADDRV4);
|
||||||
NetworkUtils.numericToInetAddress(ADDRV4), 32));
|
source.addLinkAddress(LINKADDRV6);
|
||||||
source.addLinkAddress(new LinkAddress(
|
|
||||||
NetworkUtils.numericToInetAddress(ADDRV6), 128));
|
|
||||||
// set 2 dnses
|
// set 2 dnses
|
||||||
source.addDns(NetworkUtils.numericToInetAddress(DNS1));
|
source.addDns(DNS1);
|
||||||
source.addDns(NetworkUtils.numericToInetAddress(DNS2));
|
source.addDns(DNS2);
|
||||||
// set 2 gateways
|
// set 2 gateways
|
||||||
source.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1)));
|
source.addRoute(new RouteInfo(GATEWAY1));
|
||||||
source.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2)));
|
source.addRoute(new RouteInfo(GATEWAY2));
|
||||||
|
source.setMtu(MTU);
|
||||||
|
|
||||||
LinkProperties target = new LinkProperties();
|
LinkProperties target = new LinkProperties();
|
||||||
// Exchange order
|
// Exchange order
|
||||||
target.setInterfaceName(NAME);
|
target.setInterfaceName(NAME);
|
||||||
target.addLinkAddress(new LinkAddress(
|
target.addLinkAddress(LINKADDRV6);
|
||||||
NetworkUtils.numericToInetAddress(ADDRV6), 128));
|
target.addLinkAddress(LINKADDRV4);
|
||||||
target.addLinkAddress(new LinkAddress(
|
target.addDns(DNS2);
|
||||||
NetworkUtils.numericToInetAddress(ADDRV4), 32));
|
target.addDns(DNS1);
|
||||||
target.addDns(NetworkUtils.numericToInetAddress(DNS2));
|
target.addRoute(new RouteInfo(GATEWAY2));
|
||||||
target.addDns(NetworkUtils.numericToInetAddress(DNS1));
|
target.addRoute(new RouteInfo(GATEWAY1));
|
||||||
target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2)));
|
target.setMtu(MTU);
|
||||||
target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1)));
|
|
||||||
|
|
||||||
assertLinkPropertiesEqual(source, target);
|
assertLinkPropertiesEqual(source, target);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -200,21 +213,15 @@ public class LinkPropertiesTest extends TestCase {
|
|||||||
try {
|
try {
|
||||||
LinkProperties source = new LinkProperties();
|
LinkProperties source = new LinkProperties();
|
||||||
// set 3 link addresses, eg, [A, A, B]
|
// set 3 link addresses, eg, [A, A, B]
|
||||||
source.addLinkAddress(new LinkAddress(
|
source.addLinkAddress(LINKADDRV4);
|
||||||
NetworkUtils.numericToInetAddress(ADDRV4), 32));
|
source.addLinkAddress(LINKADDRV4);
|
||||||
source.addLinkAddress(new LinkAddress(
|
source.addLinkAddress(LINKADDRV6);
|
||||||
NetworkUtils.numericToInetAddress(ADDRV4), 32));
|
|
||||||
source.addLinkAddress(new LinkAddress(
|
|
||||||
NetworkUtils.numericToInetAddress(ADDRV6), 128));
|
|
||||||
|
|
||||||
LinkProperties target = new LinkProperties();
|
LinkProperties target = new LinkProperties();
|
||||||
// set 3 link addresses, eg, [A, B, B]
|
// set 3 link addresses, eg, [A, B, B]
|
||||||
target.addLinkAddress(new LinkAddress(
|
target.addLinkAddress(LINKADDRV4);
|
||||||
NetworkUtils.numericToInetAddress(ADDRV4), 32));
|
target.addLinkAddress(LINKADDRV6);
|
||||||
target.addLinkAddress(new LinkAddress(
|
target.addLinkAddress(LINKADDRV6);
|
||||||
NetworkUtils.numericToInetAddress(ADDRV6), 128));
|
|
||||||
target.addLinkAddress(new LinkAddress(
|
|
||||||
NetworkUtils.numericToInetAddress(ADDRV6), 128));
|
|
||||||
|
|
||||||
assertLinkPropertiesEqual(source, target);
|
assertLinkPropertiesEqual(source, target);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -232,7 +239,7 @@ public class LinkPropertiesTest extends TestCase {
|
|||||||
public void testRouteInterfaces() {
|
public void testRouteInterfaces() {
|
||||||
LinkAddress prefix = new LinkAddress(
|
LinkAddress prefix = new LinkAddress(
|
||||||
NetworkUtils.numericToInetAddress("2001:db8::"), 32);
|
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.
|
// Add a route with no interface to a LinkProperties with no interface. No errors.
|
||||||
LinkProperties lp = new LinkProperties();
|
LinkProperties lp = new LinkProperties();
|
||||||
@@ -265,7 +272,7 @@ public class LinkPropertiesTest extends TestCase {
|
|||||||
assertAllRoutesHaveInterface("wlan0", lp);
|
assertAllRoutesHaveInterface("wlan0", lp);
|
||||||
|
|
||||||
// Routes with null interfaces are converted to wlan0.
|
// Routes with null interfaces are converted to wlan0.
|
||||||
r = RouteInfo.makeHostRoute(NetworkUtils.numericToInetAddress(ADDRV6), null);
|
r = RouteInfo.makeHostRoute(ADDRV6, null);
|
||||||
lp.addRoute(r);
|
lp.addRoute(r);
|
||||||
assertEquals(3, lp.getRoutes().size());
|
assertEquals(3, lp.getRoutes().size());
|
||||||
assertAllRoutesHaveInterface("wlan0", lp);
|
assertAllRoutesHaveInterface("wlan0", lp);
|
||||||
@@ -273,28 +280,45 @@ public class LinkPropertiesTest extends TestCase {
|
|||||||
// Check comparisons work.
|
// Check comparisons work.
|
||||||
LinkProperties lp2 = new LinkProperties(lp);
|
LinkProperties lp2 = new LinkProperties(lp);
|
||||||
assertAllRoutesHaveInterface("wlan0", lp);
|
assertAllRoutesHaveInterface("wlan0", lp);
|
||||||
assertEquals(0, lp.compareRoutes(lp2).added.size());
|
assertEquals(0, lp.compareAllRoutes(lp2).added.size());
|
||||||
assertEquals(0, lp.compareRoutes(lp2).removed.size());
|
assertEquals(0, lp.compareAllRoutes(lp2).removed.size());
|
||||||
|
|
||||||
lp2.setInterfaceName("p2p0");
|
lp2.setInterfaceName("p2p0");
|
||||||
assertAllRoutesHaveInterface("p2p0", lp2);
|
assertAllRoutesHaveInterface("p2p0", lp2);
|
||||||
assertEquals(3, lp.compareRoutes(lp2).added.size());
|
assertEquals(3, lp.compareAllRoutes(lp2).added.size());
|
||||||
assertEquals(3, lp.compareRoutes(lp2).removed.size());
|
assertEquals(3, lp.compareAllRoutes(lp2).removed.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SmallTest
|
@SmallTest
|
||||||
public void testStackedInterfaces() {
|
public void testStackedInterfaces() {
|
||||||
LinkProperties rmnet0 = new LinkProperties();
|
LinkProperties rmnet0 = new LinkProperties();
|
||||||
rmnet0.setInterfaceName("rmnet0");
|
rmnet0.setInterfaceName("rmnet0");
|
||||||
|
rmnet0.addLinkAddress(LINKADDRV6);
|
||||||
|
|
||||||
LinkProperties clat4 = new LinkProperties();
|
LinkProperties clat4 = new LinkProperties();
|
||||||
clat4.setInterfaceName("clat4");
|
clat4.setInterfaceName("clat4");
|
||||||
|
clat4.addLinkAddress(LINKADDRV4);
|
||||||
|
|
||||||
assertEquals(0, rmnet0.getStackedLinks().size());
|
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);
|
rmnet0.addStackedLink(clat4);
|
||||||
assertEquals(1, rmnet0.getStackedLinks().size());
|
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);
|
rmnet0.addStackedLink(clat4);
|
||||||
assertEquals(1, rmnet0.getStackedLinks().size());
|
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());
|
assertEquals(0, clat4.getStackedLinks().size());
|
||||||
|
|
||||||
// Modify an item in the returned collection to see what happens.
|
// 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()) {
|
for (LinkProperties link : rmnet0.getStackedLinks()) {
|
||||||
assertFalse("newname".equals(link.getInterfaceName()));
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,175 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.server;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.net.LocalSocket;
|
||||||
|
import android.net.LocalServerSocket;
|
||||||
|
import android.os.Binder;
|
||||||
|
import android.test.AndroidTestCase;
|
||||||
|
import android.test.suitebuilder.annotation.LargeTest;
|
||||||
|
import com.android.server.net.BaseNetworkObserver;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.reset;
|
||||||
|
import static org.mockito.Mockito.timeout;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for {@link NetworkManagementService}.
|
||||||
|
*/
|
||||||
|
@LargeTest
|
||||||
|
public class NetworkManagementServiceTest extends AndroidTestCase {
|
||||||
|
|
||||||
|
private static final String SOCKET_NAME = "__test__NetworkManagementServiceTest";
|
||||||
|
private NetworkManagementService mNMService;
|
||||||
|
private LocalServerSocket mServerSocket;
|
||||||
|
private LocalSocket mSocket;
|
||||||
|
private OutputStream mOutputStream;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
// TODO: make this unnecessary. runtest might already make it unnecessary.
|
||||||
|
System.setProperty("dexmaker.dexcache", getContext().getCacheDir().toString());
|
||||||
|
|
||||||
|
// Set up a sheltered test environment.
|
||||||
|
BroadcastInterceptingContext context = new BroadcastInterceptingContext(getContext());
|
||||||
|
mServerSocket = new LocalServerSocket(SOCKET_NAME);
|
||||||
|
|
||||||
|
// Start the service and wait until it connects to our socket.
|
||||||
|
mNMService = NetworkManagementService.create(context, SOCKET_NAME);
|
||||||
|
mSocket = mServerSocket.accept();
|
||||||
|
mOutputStream = mSocket.getOutputStream();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tearDown() throws Exception {
|
||||||
|
if (mSocket != null) mSocket.close();
|
||||||
|
if (mServerSocket != null) mServerSocket.close();
|
||||||
|
super.tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a message on the netd socket and gives the events some time to make it back.
|
||||||
|
*/
|
||||||
|
private void sendMessage(String message) throws IOException {
|
||||||
|
// Strings are null-terminated, so add "\0" at the end.
|
||||||
|
mOutputStream.write((message + "\0").getBytes());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <T> T expectSoon(T mock) {
|
||||||
|
return verify(mock, timeout(100));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests that network observers work properly.
|
||||||
|
*/
|
||||||
|
public void testNetworkObservers() throws Exception {
|
||||||
|
BaseNetworkObserver observer = mock(BaseNetworkObserver.class);
|
||||||
|
doReturn(new Binder()).when(observer).asBinder(); // Used by registerObserver.
|
||||||
|
mNMService.registerObserver(observer);
|
||||||
|
|
||||||
|
// Forget everything that happened to the mock so far, so we can explicitly verify
|
||||||
|
// everything that happens and does not happen to it from now on.
|
||||||
|
reset(observer);
|
||||||
|
|
||||||
|
// Now send NetworkManagementService messages and ensure that the observer methods are
|
||||||
|
// called. After every valid message we expect a callback soon after; to ensure that
|
||||||
|
// invalid messages don't cause any callbacks, we call verifyNoMoreInteractions at the end.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface changes.
|
||||||
|
*/
|
||||||
|
sendMessage("600 Iface added rmnet12");
|
||||||
|
expectSoon(observer).interfaceAdded("rmnet12");
|
||||||
|
|
||||||
|
sendMessage("600 Iface removed eth1");
|
||||||
|
expectSoon(observer).interfaceRemoved("eth1");
|
||||||
|
|
||||||
|
sendMessage("607 Iface removed eth1");
|
||||||
|
// Invalid code.
|
||||||
|
|
||||||
|
sendMessage("600 Iface borked lo down");
|
||||||
|
// Invalid event.
|
||||||
|
|
||||||
|
sendMessage("600 Iface changed clat4 up again");
|
||||||
|
// Extra tokens.
|
||||||
|
|
||||||
|
sendMessage("600 Iface changed clat4 up");
|
||||||
|
expectSoon(observer).interfaceStatusChanged("clat4", true);
|
||||||
|
|
||||||
|
sendMessage("600 Iface linkstate rmnet0 down");
|
||||||
|
expectSoon(observer).interfaceLinkStateChanged("rmnet0", false);
|
||||||
|
|
||||||
|
sendMessage("600 IFACE linkstate clat4 up");
|
||||||
|
// Invalid group.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bandwidth control events.
|
||||||
|
*/
|
||||||
|
sendMessage("601 limit alert data rmnet_usb0");
|
||||||
|
expectSoon(observer).limitReached("data", "rmnet_usb0");
|
||||||
|
|
||||||
|
sendMessage("601 invalid alert data rmnet0");
|
||||||
|
// Invalid group.
|
||||||
|
|
||||||
|
sendMessage("601 limit increased data rmnet0");
|
||||||
|
// Invalid event.
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface class activity.
|
||||||
|
*/
|
||||||
|
sendMessage("613 IfaceClass active rmnet0");
|
||||||
|
expectSoon(observer).interfaceClassDataActivityChanged("rmnet0", true);
|
||||||
|
|
||||||
|
sendMessage("613 IfaceClass idle eth0");
|
||||||
|
expectSoon(observer).interfaceClassDataActivityChanged("eth0", false);
|
||||||
|
|
||||||
|
sendMessage("613 IfaceClass reallyactive rmnet0");
|
||||||
|
expectSoon(observer).interfaceClassDataActivityChanged("rmnet0", false);
|
||||||
|
|
||||||
|
sendMessage("613 InterfaceClass reallyactive rmnet0");
|
||||||
|
// Invalid group.
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IP address changes.
|
||||||
|
*/
|
||||||
|
sendMessage("614 Address updated fe80::1/64 wlan0 128 253");
|
||||||
|
expectSoon(observer).addressUpdated("fe80::1/64", "wlan0", 128, 253);
|
||||||
|
|
||||||
|
// There is no "added".
|
||||||
|
sendMessage("614 Address added fe80::1/64 wlan0 128 253");
|
||||||
|
expectSoon(observer).addressRemoved("fe80::1/64", "wlan0", 128, 253);
|
||||||
|
|
||||||
|
sendMessage("614 Address removed 2001:db8::1/64 wlan0 1 0");
|
||||||
|
expectSoon(observer).addressRemoved("2001:db8::1/64", "wlan0", 1, 0);
|
||||||
|
|
||||||
|
sendMessage("666 Address added 2001:db8::1/64 wlan0 1 0");
|
||||||
|
// Invalid code.
|
||||||
|
|
||||||
|
// Make sure nothing else was called.
|
||||||
|
verifyNoMoreInteractions(observer);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -40,7 +40,6 @@ import static android.text.format.DateUtils.MINUTE_IN_MILLIS;
|
|||||||
import static android.text.format.DateUtils.WEEK_IN_MILLIS;
|
import static android.text.format.DateUtils.WEEK_IN_MILLIS;
|
||||||
import static com.android.server.net.NetworkStatsService.ACTION_NETWORK_STATS_POLL;
|
import static com.android.server.net.NetworkStatsService.ACTION_NETWORK_STATS_POLL;
|
||||||
import static org.easymock.EasyMock.anyLong;
|
import static org.easymock.EasyMock.anyLong;
|
||||||
import static org.easymock.EasyMock.aryEq;
|
|
||||||
import static org.easymock.EasyMock.capture;
|
import static org.easymock.EasyMock.capture;
|
||||||
import static org.easymock.EasyMock.createMock;
|
import static org.easymock.EasyMock.createMock;
|
||||||
import static org.easymock.EasyMock.eq;
|
import static org.easymock.EasyMock.eq;
|
||||||
@@ -63,6 +62,7 @@ import android.net.NetworkStats;
|
|||||||
import android.net.NetworkStatsHistory;
|
import android.net.NetworkStatsHistory;
|
||||||
import android.net.NetworkTemplate;
|
import android.net.NetworkTemplate;
|
||||||
import android.os.INetworkManagementService;
|
import android.os.INetworkManagementService;
|
||||||
|
import android.os.WorkSource;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.test.AndroidTestCase;
|
import android.test.AndroidTestCase;
|
||||||
import android.test.suitebuilder.annotation.LargeTest;
|
import android.test.suitebuilder.annotation.LargeTest;
|
||||||
@@ -73,13 +73,13 @@ import com.android.server.net.NetworkStatsService;
|
|||||||
import com.android.server.net.NetworkStatsService.NetworkStatsSettings;
|
import com.android.server.net.NetworkStatsService.NetworkStatsSettings;
|
||||||
import com.android.server.net.NetworkStatsService.NetworkStatsSettings.Config;
|
import com.android.server.net.NetworkStatsService.NetworkStatsSettings.Config;
|
||||||
|
|
||||||
|
import libcore.io.IoUtils;
|
||||||
|
|
||||||
import org.easymock.Capture;
|
import org.easymock.Capture;
|
||||||
import org.easymock.EasyMock;
|
import org.easymock.EasyMock;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import libcore.io.IoUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link NetworkStatsService}.
|
* Tests for {@link NetworkStatsService}.
|
||||||
*/
|
*/
|
||||||
@@ -878,8 +878,8 @@ public class NetworkStatsServiceTest extends AndroidTestCase {
|
|||||||
mAlarmManager.remove(isA(PendingIntent.class));
|
mAlarmManager.remove(isA(PendingIntent.class));
|
||||||
expectLastCall().anyTimes();
|
expectLastCall().anyTimes();
|
||||||
|
|
||||||
mAlarmManager.setInexactRepeating(
|
mAlarmManager.set(eq(AlarmManager.ELAPSED_REALTIME), anyLong(), anyLong(), anyLong(),
|
||||||
eq(AlarmManager.ELAPSED_REALTIME), anyLong(), anyLong(), isA(PendingIntent.class));
|
isA(PendingIntent.class), isA(WorkSource.class));
|
||||||
expectLastCall().atLeastOnce();
|
expectLastCall().atLeastOnce();
|
||||||
|
|
||||||
mNetManager.setGlobalAlert(anyLong());
|
mNetManager.setGlobalAlert(anyLong());
|
||||||
@@ -918,8 +918,7 @@ public class NetworkStatsServiceTest extends AndroidTestCase {
|
|||||||
expect(mNetManager.getNetworkStatsUidDetail(eq(UID_ALL))).andReturn(detail).atLeastOnce();
|
expect(mNetManager.getNetworkStatsUidDetail(eq(UID_ALL))).andReturn(detail).atLeastOnce();
|
||||||
|
|
||||||
// also include tethering details, since they are folded into UID
|
// also include tethering details, since they are folded into UID
|
||||||
expect(mConnManager.getTetheredIfacePairs()).andReturn(tetherIfacePairs).atLeastOnce();
|
expect(mNetManager.getNetworkStatsTethering())
|
||||||
expect(mNetManager.getNetworkStatsTethering(aryEq(tetherIfacePairs)))
|
|
||||||
.andReturn(tetherStats).atLeastOnce();
|
.andReturn(tetherStats).atLeastOnce();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user