am e288b3af: Merge changes I5c994de5,I6cb0dd84 into mnc-dev
* commit 'e288b3af14421731d8f477b97e8d77588f20498b': Add a test for public bugs 2111 and 2136. Always check off-link connectivity in NetworkDiagnostics.
This commit is contained in:
@@ -661,6 +661,17 @@ public final class LinkProperties implements Parcelable {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if this link or any of its stacked interfaces has an IPv4 address.
|
||||||
|
*
|
||||||
|
* @return {@code true} if there is an IPv4 address, {@code false} otherwise.
|
||||||
|
*/
|
||||||
|
private boolean hasIPv4AddressOnInterface(String iface) {
|
||||||
|
return (mIfaceName.equals(iface) && hasIPv4Address()) ||
|
||||||
|
(iface != null && mStackedLinks.containsKey(iface) &&
|
||||||
|
mStackedLinks.get(iface).hasIPv4Address());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if this link has a global preferred IPv6 address.
|
* Returns true if this link has a global preferred IPv6 address.
|
||||||
*
|
*
|
||||||
@@ -792,7 +803,7 @@ public final class LinkProperties implements Parcelable {
|
|||||||
|
|
||||||
if (ip instanceof Inet4Address) {
|
if (ip instanceof Inet4Address) {
|
||||||
// For IPv4, it suffices for now to simply have any address.
|
// For IPv4, it suffices for now to simply have any address.
|
||||||
return hasIPv4Address();
|
return hasIPv4AddressOnInterface(bestRoute.getInterface());
|
||||||
} else if (ip instanceof Inet6Address) {
|
} else if (ip instanceof Inet6Address) {
|
||||||
if (ip.isLinkLocalAddress()) {
|
if (ip.isLinkLocalAddress()) {
|
||||||
// For now, just make sure link-local destinations have
|
// For now, just make sure link-local destinations have
|
||||||
|
|||||||
@@ -1784,7 +1784,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
// Start gathering diagnostic information.
|
// Start gathering diagnostic information.
|
||||||
netDiags.add(new NetworkDiagnostics(
|
netDiags.add(new NetworkDiagnostics(
|
||||||
nai.network,
|
nai.network,
|
||||||
new LinkProperties(nai.linkProperties),
|
new LinkProperties(nai.linkProperties), // Must be a copy.
|
||||||
DIAG_TIME_MS));
|
DIAG_TIME_MS));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import static android.system.OsConstants.*;
|
|||||||
|
|
||||||
import android.net.LinkProperties;
|
import android.net.LinkProperties;
|
||||||
import android.net.Network;
|
import android.net.Network;
|
||||||
|
import android.net.NetworkUtils;
|
||||||
import android.net.RouteInfo;
|
import android.net.RouteInfo;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.system.ErrnoException;
|
import android.system.ErrnoException;
|
||||||
@@ -79,6 +80,10 @@ import libcore.io.IoUtils;
|
|||||||
public class NetworkDiagnostics {
|
public class NetworkDiagnostics {
|
||||||
private static final String TAG = "NetworkDiagnostics";
|
private static final String TAG = "NetworkDiagnostics";
|
||||||
|
|
||||||
|
private static final InetAddress TEST_DNS4 = NetworkUtils.numericToInetAddress("8.8.8.8");
|
||||||
|
private static final InetAddress TEST_DNS6 = NetworkUtils.numericToInetAddress(
|
||||||
|
"2001:4860:4860::8888");
|
||||||
|
|
||||||
// For brevity elsewhere.
|
// For brevity elsewhere.
|
||||||
private static final long now() {
|
private static final long now() {
|
||||||
return SystemClock.elapsedRealtime();
|
return SystemClock.elapsedRealtime();
|
||||||
@@ -156,6 +161,21 @@ public class NetworkDiagnostics {
|
|||||||
mStartTime = now();
|
mStartTime = now();
|
||||||
mDeadlineTime = mStartTime + mTimeoutMs;
|
mDeadlineTime = mStartTime + mTimeoutMs;
|
||||||
|
|
||||||
|
// Hardcode measurements to TEST_DNS4 and TEST_DNS6 in order to test off-link connectivity.
|
||||||
|
// We are free to modify mLinkProperties with impunity because ConnectivityService passes us
|
||||||
|
// a copy and not the original object. It's easier to do it this way because we don't need
|
||||||
|
// to check whether the LinkProperties already contains these DNS servers because
|
||||||
|
// LinkProperties#addDnsServer checks for duplicates.
|
||||||
|
if (mLinkProperties.isReachable(TEST_DNS4)) {
|
||||||
|
mLinkProperties.addDnsServer(TEST_DNS4);
|
||||||
|
}
|
||||||
|
// TODO: we could use mLinkProperties.isReachable(TEST_DNS6) here, because we won't set any
|
||||||
|
// DNS servers for which isReachable() is false, but since this is diagnostic code, be extra
|
||||||
|
// careful.
|
||||||
|
if (mLinkProperties.hasGlobalIPv6Address() || mLinkProperties.hasIPv6DefaultRoute()) {
|
||||||
|
mLinkProperties.addDnsServer(TEST_DNS6);
|
||||||
|
}
|
||||||
|
|
||||||
for (RouteInfo route : mLinkProperties.getRoutes()) {
|
for (RouteInfo route : mLinkProperties.getRoutes()) {
|
||||||
if (route.hasGateway()) {
|
if (route.hasGateway()) {
|
||||||
prepareIcmpMeasurement(route.getGateway());
|
prepareIcmpMeasurement(route.getGateway());
|
||||||
|
|||||||
Reference in New Issue
Block a user