From 0ef6875b30117fb34cf6b6b7a27fdb049910459f Mon Sep 17 00:00:00 2001 From: Robert Greenwalt Date: Fri, 13 Aug 2010 14:16:12 -0700 Subject: [PATCH] DO NOT MERGE Always set/remove default routes. Must clean up default route if a default 3g connection is replaced by a non-default (ie, mms) connection on teh same interface. Also stop mucking with all connections dns and routes - do it only for the connection that has changed. bug:2865974 Change-Id: Ifdf49080fa0413a4d826813706c809975a562dfa --- .../android/server/ConnectivityService.java | 110 ++++++++---------- 1 file changed, 48 insertions(+), 62 deletions(-) diff --git a/services/java/com/android/server/ConnectivityService.java b/services/java/com/android/server/ConnectivityService.java index 81b8d40b0a..041c13b2bd 100644 --- a/services/java/com/android/server/ConnectivityService.java +++ b/services/java/com/android/server/ConnectivityService.java @@ -582,7 +582,7 @@ public class ConnectivityService extends IConnectivityManager.Stub { !network.isTeardownRequested()) { if (ni.isConnected() == true) { // add the pid-specific dns - handleDnsConfigurationChange(); + handleDnsConfigurationChange(networkType); if (DBG) Slog.d(TAG, "special network already active"); return Phone.APN_ALREADY_ACTIVE; } @@ -914,7 +914,7 @@ public class ConnectivityService extends IConnectivityManager.Stub { } } // do this before we broadcast the change - handleConnectivityChange(); + handleConnectivityChange(prevNetType); sendStickyBroadcast(intent); /* @@ -1070,9 +1070,6 @@ public class ConnectivityService extends IConnectivityManager.Stub { } } - // do this before we broadcast the change - handleConnectivityChange(); - sendStickyBroadcast(intent); /* * If the failover network is already connected, then immediately send @@ -1143,7 +1140,7 @@ public class ConnectivityService extends IConnectivityManager.Stub { } thisNet.setTeardownRequested(false); thisNet.updateNetworkSettings(); - handleConnectivityChange(); + handleConnectivityChange(type); sendConnectedBroadcast(info); } @@ -1170,38 +1167,29 @@ public class ConnectivityService extends IConnectivityManager.Stub { } /** - * After any kind of change in the connectivity state of any network, - * make sure that anything that depends on the connectivity state of - * more than one network is set up correctly. We're mainly concerned - * with making sure that the list of DNS servers is set up according - * to which networks are connected, and ensuring that the right routing - * table entries exist. + * After a change in the connectivity state of any network, We're mainly + * concerned with making sure that the list of DNS servers is setupup + * according to which networks are connected, and ensuring that the + * right routing table entries exist. */ - private void handleConnectivityChange() { + private void handleConnectivityChange(int netType) { /* * If a non-default network is enabled, add the host routes that - * will allow it's DNS servers to be accessed. Only - * If both mobile and wifi are enabled, add the host routes that - * will allow MMS traffic to pass on the mobile network. But - * remove the default route for the mobile network, so that there - * will be only one default route, to ensure that all traffic - * except MMS will travel via Wi-Fi. + * will allow it's DNS servers to be accessed. */ - handleDnsConfigurationChange(); + handleDnsConfigurationChange(netType); - for (int netType : mPriorityList) { - if (mNetTrackers[netType].getNetworkInfo().isConnected()) { - if (mNetAttributes[netType].isDefault()) { - mNetTrackers[netType].addDefaultRoute(); - } else { - mNetTrackers[netType].addPrivateDnsRoutes(); - } + if (mNetTrackers[netType].getNetworkInfo().isConnected()) { + if (mNetAttributes[netType].isDefault()) { + mNetTrackers[netType].addDefaultRoute(); } else { - if (mNetAttributes[netType].isDefault()) { - mNetTrackers[netType].removeDefaultRoute(); - } else { - mNetTrackers[netType].removePrivateDnsRoutes(); - } + mNetTrackers[netType].addPrivateDnsRoutes(); + } + } else { + if (mNetAttributes[netType].isDefault()) { + mNetTrackers[netType].removeDefaultRoute(); + } else { + mNetTrackers[netType].removePrivateDnsRoutes(); } } } @@ -1272,41 +1260,36 @@ public class ConnectivityService extends IConnectivityManager.Stub { SystemProperties.set("net.dnschange", "" + (n+1)); } - private void handleDnsConfigurationChange() { + private void handleDnsConfigurationChange(int netType) { // add default net's dns entries - for (int x = mPriorityList.length-1; x>= 0; x--) { - int netType = mPriorityList[x]; - NetworkStateTracker nt = mNetTrackers[netType]; - if (nt != null && nt.getNetworkInfo().isConnected() && - !nt.isTeardownRequested()) { - String[] dnsList = nt.getNameServers(); - if (mNetAttributes[netType].isDefault()) { - int j = 1; - for (String dns : dnsList) { - if (dns != null && !TextUtils.equals(dns, "0.0.0.0")) { - if (DBG) { - Slog.d(TAG, "adding dns " + dns + " for " + - nt.getNetworkInfo().getTypeName()); - } - SystemProperties.set("net.dns" + j++, dns); + NetworkStateTracker nt = mNetTrackers[netType]; + if (nt != null && nt.getNetworkInfo().isConnected() && !nt.isTeardownRequested()) { + String[] dnsList = nt.getNameServers(); + if (mNetAttributes[netType].isDefault()) { + int j = 1; + for (String dns : dnsList) { + if (dns != null && !TextUtils.equals(dns, "0.0.0.0")) { + if (DBG) { + Slog.d(TAG, "adding dns " + dns + " for " + + nt.getNetworkInfo().getTypeName()); } + SystemProperties.set("net.dns" + j++, dns); } - for (int k=j ; k