summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIrfan Sheriff <isheriff@google.com>2011-09-16 22:03:09 -0700
committerIrfan Sheriff <isheriff@google.com>2011-09-16 22:03:09 -0700
commit2c08ede34ceb0f847cc9f996db9832f5358f8726 (patch)
tree739977e6a3a3cbd77f14aacd2ed38b6acf64a6cc
parent651cdfcbac6245f570475991588ddc2d30265e8d (diff)
downloadframeworks_base-2c08ede34ceb0f847cc9f996db9832f5358f8726.zip
frameworks_base-2c08ede34ceb0f847cc9f996db9832f5358f8726.tar.gz
frameworks_base-2c08ede34ceb0f847cc9f996db9832f5358f8726.tar.bz2
Retain DNS information from DHCP request
DHCP renewal can fail to fill DNS information. In such a case retain info from DHCP request Bug: 5314392 Change-Id: I2413f738be7c8c965ef9e7ffbc348e2738aa68b5
-rw-r--r--core/java/android/net/DhcpInfoInternal.java45
-rw-r--r--core/java/android/net/DhcpStateMachine.java5
2 files changed, 41 insertions, 9 deletions
diff --git a/core/java/android/net/DhcpInfoInternal.java b/core/java/android/net/DhcpInfoInternal.java
index 9b0a2d7..fa77bc5 100644
--- a/core/java/android/net/DhcpInfoInternal.java
+++ b/core/java/android/net/DhcpInfoInternal.java
@@ -24,6 +24,7 @@ import java.net.Inet4Address;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
/**
* A simple object for retrieving the results of a DHCP request.
@@ -41,14 +42,18 @@ public class DhcpInfoInternal {
public String serverAddress;
public int leaseDuration;
- private Collection<RouteInfo> routes;
+ private Collection<RouteInfo> mRoutes;
public DhcpInfoInternal() {
- routes = new ArrayList<RouteInfo>();
+ mRoutes = new ArrayList<RouteInfo>();
}
public void addRoute(RouteInfo routeInfo) {
- routes.add(routeInfo);
+ mRoutes.add(routeInfo);
+ }
+
+ public Collection<RouteInfo> getRoutes() {
+ return Collections.unmodifiableCollection(mRoutes);
}
private int convertToInt(String addr) {
@@ -66,7 +71,7 @@ public class DhcpInfoInternal {
public DhcpInfo makeDhcpInfo() {
DhcpInfo info = new DhcpInfo();
info.ipAddress = convertToInt(ipAddress);
- for (RouteInfo route : routes) {
+ for (RouteInfo route : mRoutes) {
if (route.isDefaultRoute()) {
info.gateway = convertToInt(route.getGateway().getHostAddress());
break;
@@ -94,14 +99,14 @@ public class DhcpInfoInternal {
public LinkProperties makeLinkProperties() {
LinkProperties p = new LinkProperties();
p.addLinkAddress(makeLinkAddress());
- for (RouteInfo route : routes) {
+ for (RouteInfo route : mRoutes) {
p.addRoute(route);
}
+ //if empty, connectivity configures default DNS
if (TextUtils.isEmpty(dns1) == false) {
p.addDns(NetworkUtils.numericToInetAddress(dns1));
} else {
- p.addDns(NetworkUtils.numericToInetAddress(serverAddress));
- Log.d(TAG, "empty dns1, use dhcp server as dns1!");
+ Log.d(TAG, "makeLinkProperties with empty dns1!");
}
if (TextUtils.isEmpty(dns2) == false) {
p.addDns(NetworkUtils.numericToInetAddress(dns2));
@@ -111,11 +116,33 @@ public class DhcpInfoInternal {
return p;
}
+ /* Updates the DHCP fields that need to be retained from
+ * original DHCP request if the DHCP renewal shows them as
+ * being empty
+ */
+ public void updateFromDhcpRequest(DhcpInfoInternal orig) {
+ if (orig == null) return;
+
+ if (TextUtils.isEmpty(dns1)) {
+ dns1 = orig.dns1;
+ }
+
+ if (TextUtils.isEmpty(dns2)) {
+ dns2 = orig.dns2;
+ }
+
+ if (mRoutes.size() == 0) {
+ for (RouteInfo route : orig.getRoutes()) {
+ addRoute(route);
+ }
+ }
+ }
+
public String toString() {
String routeString = "";
- for (RouteInfo route : routes) routeString += route.toString() + " | ";
+ for (RouteInfo route : mRoutes) routeString += route.toString() + " | ";
return "addr: " + ipAddress + "/" + prefixLength +
- " routes: " + routeString +
+ " mRoutes: " + routeString +
" dns: " + dns1 + "," + dns2 +
" dhcpServer: " + serverAddress +
" leaseDuration: " + leaseDuration;
diff --git a/core/java/android/net/DhcpStateMachine.java b/core/java/android/net/DhcpStateMachine.java
index 445b2f7..79c9395 100644
--- a/core/java/android/net/DhcpStateMachine.java
+++ b/core/java/android/net/DhcpStateMachine.java
@@ -63,6 +63,9 @@ public class DhcpStateMachine extends StateMachine {
private PowerManager.WakeLock mDhcpRenewWakeLock;
private static final String WAKELOCK_TAG = "DHCP";
+ //Remember DHCP configuration from first request
+ private DhcpInfoInternal mDhcpInfo;
+
private static final int DHCP_RENEW = 0;
private static final String ACTION_DHCP_RENEW = "android.net.wifi.DHCP_RENEW";
@@ -335,9 +338,11 @@ public class DhcpStateMachine extends StateMachine {
if (dhcpAction == DhcpAction.START) {
Log.d(TAG, "DHCP request on " + mInterfaceName);
success = NetworkUtils.runDhcp(mInterfaceName, dhcpInfoInternal);
+ mDhcpInfo = dhcpInfoInternal;
} else if (dhcpAction == DhcpAction.RENEW) {
Log.d(TAG, "DHCP renewal on " + mInterfaceName);
success = NetworkUtils.runDhcpRenew(mInterfaceName, dhcpInfoInternal);
+ dhcpInfoInternal.updateFromDhcpRequest(mDhcpInfo);
}
if (success) {