summaryrefslogtreecommitdiff
path: root/core/java/android/net/LinkProperties.java
diff options
context:
space:
mode:
authorErik Kline <ek@google.com>2015-05-21 16:15:02 +0900
committerErik Kline <ek@google.com>2015-05-21 20:43:47 +0900
commitcd7ed16f00d243568e3b73b7fc7f0f94cfebe8ce (patch)
tree3ca318b9a160cc70bbe9f035d07ae122366b16d6 /core/java/android/net/LinkProperties.java
parent184016aac08c31eb9c3f8539fb362ed2dfb30a93 (diff)
LinkProperties function to compare provisioning and remove DNS servers
Adds: - enum ProvisioningChange - LinkProperties#compareProvisioning() return a ProvisioningChange value describing the delta in provisioning between two LinkProperties objects - LinkProperties#removeDnsServer() - make "@hide public" isIPv4Provisioned() and isIPv6Provisioned() Bug: 18581716 Change-Id: I3df90b2b89617f693346f2dbe72e77c88ce91ffd
Diffstat (limited to 'core/java/android/net/LinkProperties.java')
-rw-r--r--core/java/android/net/LinkProperties.java70
1 files changed, 67 insertions, 3 deletions
diff --git a/core/java/android/net/LinkProperties.java b/core/java/android/net/LinkProperties.java
index 8b0dfc95fef0..31aedad77116 100644
--- a/core/java/android/net/LinkProperties.java
+++ b/core/java/android/net/LinkProperties.java
@@ -88,6 +88,54 @@ public final class LinkProperties implements Parcelable {
/**
* @hide
*/
+ public enum ProvisioningChange {
+ STILL_NOT_PROVISIONED,
+ LOST_PROVISIONING,
+ GAINED_PROVISIONING,
+ STILL_PROVISIONED,
+ }
+
+ /**
+ * Compare the provisioning states of two LinkProperties instances.
+ *
+ * @hide
+ */
+ public static ProvisioningChange compareProvisioning(
+ LinkProperties before, LinkProperties after) {
+ if (before.isProvisioned() && after.isProvisioned()) {
+ // On dualstack networks, DHCPv4 renewals can occasionally fail.
+ // When this happens, IPv6-reachable services continue to function
+ // normally but IPv4-only services (naturally) fail.
+ //
+ // When an application using an IPv4-only service reports a bad
+ // network condition to the framework, attempts to re-validate
+ // the network succeed (since we support IPv6-only networks) and
+ // nothing is changed.
+ //
+ // For users, this is confusing and unexpected behaviour, and is
+ // not necessarily easy to diagnose. Therefore, we treat changing
+ // from a dualstack network to an IPv6-only network equivalent to
+ // a total loss of provisioning.
+ //
+ // For one such example of this, see b/18867306.
+ //
+ // TODO: Remove this special case altogether.
+ if (before.isIPv4Provisioned() && !after.isIPv4Provisioned()) {
+ return ProvisioningChange.LOST_PROVISIONING;
+ }
+ return ProvisioningChange.STILL_PROVISIONED;
+ } else if (before.isProvisioned() && !after.isProvisioned()) {
+ return ProvisioningChange.LOST_PROVISIONING;
+ } else if (!before.isProvisioned() && after.isProvisioned()) {
+ return ProvisioningChange.GAINED_PROVISIONING;
+ } else { // !before.isProvisioned() && !after.isProvisioned()
+ return ProvisioningChange.STILL_NOT_PROVISIONED;
+ }
+ }
+
+ /**
+ * @hide
+ */
public LinkProperties() {
}
@@ -287,6 +335,20 @@ public final class LinkProperties implements Parcelable {
}
/**
+ * Removes the given {@link InetAddress} from the list of DNS servers.
+ *
+ * @param dnsServer The {@link InetAddress} to remove from the list of DNS servers.
+ * @return true if the DNS server was removed, false if it did not exist.
+ * @hide
+ */
+ public boolean removeDnsServer(InetAddress dnsServer) {
+ if (dnsServer != null) {
+ return mDnses.remove(dnsServer);
+ }
+ return false;
+ }
+
+ /**
* Replaces the DNS servers in this {@code LinkProperties} with
* the given {@link Collection} of {@link InetAddress} objects.
*
@@ -679,8 +741,9 @@ public final class LinkProperties implements Parcelable {
* This requires an IP address, default route, and DNS server.
*
* @return {@code true} if the link is provisioned, {@code false} otherwise.
+ * @hide
*/
- private boolean hasIPv4() {
+ public boolean isIPv4Provisioned() {
return (hasIPv4Address() &&
hasIPv4DefaultRoute() &&
hasIPv4DnsServer());
@@ -691,8 +754,9 @@ public final class LinkProperties implements Parcelable {
* This requires an IP address, default route, and DNS server.
*
* @return {@code true} if the link is provisioned, {@code false} otherwise.
+ * @hide
*/
- private boolean hasIPv6() {
+ public boolean isIPv6Provisioned() {
return (hasGlobalIPv6Address() &&
hasIPv6DefaultRoute() &&
hasIPv6DnsServer());
@@ -706,7 +770,7 @@ public final class LinkProperties implements Parcelable {
* @hide
*/
public boolean isProvisioned() {
- return (hasIPv4() || hasIPv6());
+ return (isIPv4Provisioned() || isIPv6Provisioned());
}
/**