am e300b8c1: Merge "DO NOT MERGE Always set/remove default routes." into gingerbread

Merge commit 'e300b8c10c306b575bbbec29d5572ba92a97785e' into gingerbread-plus-aosp

* commit 'e300b8c10c306b575bbbec29d5572ba92a97785e':
  DO NOT MERGE Always set/remove default routes.
This commit is contained in:
Robert Greenwalt
2010-08-13 16:03:29 -07:00
committed by Android Git Automerger
3 changed files with 54 additions and 70 deletions

View File

@@ -45,7 +45,6 @@ public abstract class NetworkStateTracker extends Handler {
protected String[] mDnsPropNames; protected String[] mDnsPropNames;
private boolean mPrivateDnsRouteSet; private boolean mPrivateDnsRouteSet;
protected int mDefaultGatewayAddr; protected int mDefaultGatewayAddr;
private boolean mDefaultRouteSet;
private boolean mTeardownRequested; private boolean mTeardownRequested;
private static boolean DBG = true; private static boolean DBG = true;
@@ -153,25 +152,22 @@ public abstract class NetworkStateTracker extends Handler {
} }
public void addDefaultRoute() { public void addDefaultRoute() {
if ((mInterfaceName != null) && (mDefaultGatewayAddr != 0) && if ((mInterfaceName != null) && (mDefaultGatewayAddr != 0)) {
mDefaultRouteSet == false) {
if (DBG) { if (DBG) {
Log.d(TAG, "addDefaultRoute for " + mNetworkInfo.getTypeName() + Log.d(TAG, "addDefaultRoute for " + mNetworkInfo.getTypeName() +
" (" + mInterfaceName + "), GatewayAddr=" + mDefaultGatewayAddr); " (" + mInterfaceName + "), GatewayAddr=" + mDefaultGatewayAddr);
} }
NetworkUtils.setDefaultRoute(mInterfaceName, mDefaultGatewayAddr); NetworkUtils.setDefaultRoute(mInterfaceName, mDefaultGatewayAddr);
mDefaultRouteSet = true;
} }
} }
public void removeDefaultRoute() { public void removeDefaultRoute() {
if (mInterfaceName != null && mDefaultRouteSet == true) { if (mInterfaceName != null) {
if (DBG) { if (DBG) {
Log.d(TAG, "removeDefaultRoute for " + mNetworkInfo.getTypeName() + " (" + Log.d(TAG, "removeDefaultRoute for " + mNetworkInfo.getTypeName() + " (" +
mInterfaceName + ")"); mInterfaceName + ")");
} }
NetworkUtils.removeDefaultRoute(mInterfaceName); NetworkUtils.removeDefaultRoute(mInterfaceName);
mDefaultRouteSet = false;
} }
} }

View File

@@ -582,7 +582,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
!network.isTeardownRequested()) { !network.isTeardownRequested()) {
if (ni.isConnected() == true) { if (ni.isConnected() == true) {
// add the pid-specific dns // add the pid-specific dns
handleDnsConfigurationChange(); handleDnsConfigurationChange(networkType);
if (DBG) Slog.d(TAG, "special network already active"); if (DBG) Slog.d(TAG, "special network already active");
return Phone.APN_ALREADY_ACTIVE; return Phone.APN_ALREADY_ACTIVE;
} }
@@ -914,7 +914,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
} }
} }
// do this before we broadcast the change // do this before we broadcast the change
handleConnectivityChange(); handleConnectivityChange(prevNetType);
sendStickyBroadcast(intent); sendStickyBroadcast(intent);
/* /*
@@ -1070,9 +1070,6 @@ public class ConnectivityService extends IConnectivityManager.Stub {
} }
} }
// do this before we broadcast the change
handleConnectivityChange();
sendStickyBroadcast(intent); sendStickyBroadcast(intent);
/* /*
* If the failover network is already connected, then immediately send * If the failover network is already connected, then immediately send
@@ -1143,7 +1140,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
} }
thisNet.setTeardownRequested(false); thisNet.setTeardownRequested(false);
thisNet.updateNetworkSettings(); thisNet.updateNetworkSettings();
handleConnectivityChange(); handleConnectivityChange(type);
sendConnectedBroadcast(info); sendConnectedBroadcast(info);
} }
@@ -1170,38 +1167,29 @@ public class ConnectivityService extends IConnectivityManager.Stub {
} }
/** /**
* After any kind of change in the connectivity state of any network, * After a change in the connectivity state of any network, We're mainly
* make sure that anything that depends on the connectivity state of * concerned with making sure that the list of DNS servers is setupup
* more than one network is set up correctly. We're mainly concerned * according to which networks are connected, and ensuring that the
* with making sure that the list of DNS servers is set up according * right routing table entries exist.
* 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 * If a non-default network is enabled, add the host routes that
* will allow it's DNS servers to be accessed. Only * will allow it's DNS servers to be accessed.
* 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.
*/ */
handleDnsConfigurationChange(); handleDnsConfigurationChange(netType);
for (int netType : mPriorityList) { if (mNetTrackers[netType].getNetworkInfo().isConnected()) {
if (mNetTrackers[netType].getNetworkInfo().isConnected()) { if (mNetAttributes[netType].isDefault()) {
if (mNetAttributes[netType].isDefault()) { mNetTrackers[netType].addDefaultRoute();
mNetTrackers[netType].addDefaultRoute();
} else {
mNetTrackers[netType].addPrivateDnsRoutes();
}
} else { } else {
if (mNetAttributes[netType].isDefault()) { mNetTrackers[netType].addPrivateDnsRoutes();
mNetTrackers[netType].removeDefaultRoute(); }
} else { } else {
mNetTrackers[netType].removePrivateDnsRoutes(); 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)); SystemProperties.set("net.dnschange", "" + (n+1));
} }
private void handleDnsConfigurationChange() { private void handleDnsConfigurationChange(int netType) {
// add default net's dns entries // add default net's dns entries
for (int x = mPriorityList.length-1; x>= 0; x--) { NetworkStateTracker nt = mNetTrackers[netType];
int netType = mPriorityList[x]; if (nt != null && nt.getNetworkInfo().isConnected() && !nt.isTeardownRequested()) {
NetworkStateTracker nt = mNetTrackers[netType]; String[] dnsList = nt.getNameServers();
if (nt != null && nt.getNetworkInfo().isConnected() && if (mNetAttributes[netType].isDefault()) {
!nt.isTeardownRequested()) { int j = 1;
String[] dnsList = nt.getNameServers(); for (String dns : dnsList) {
if (mNetAttributes[netType].isDefault()) { if (dns != null && !TextUtils.equals(dns, "0.0.0.0")) {
int j = 1; if (DBG) {
for (String dns : dnsList) { Slog.d(TAG, "adding dns " + dns + " for " +
if (dns != null && !TextUtils.equals(dns, "0.0.0.0")) { nt.getNetworkInfo().getTypeName());
if (DBG) {
Slog.d(TAG, "adding dns " + dns + " for " +
nt.getNetworkInfo().getTypeName());
}
SystemProperties.set("net.dns" + j++, dns);
} }
SystemProperties.set("net.dns" + j++, dns);
} }
for (int k=j ; k<mNumDnsEntries; k++) { }
if (DBG) Slog.d(TAG, "erasing net.dns" + k); for (int k=j ; k<mNumDnsEntries; k++) {
SystemProperties.set("net.dns" + k, ""); if (DBG) Slog.d(TAG, "erasing net.dns" + k);
} SystemProperties.set("net.dns" + k, "");
mNumDnsEntries = j; }
} else { mNumDnsEntries = j;
// set per-pid dns for attached secondary nets } else {
List pids = mNetRequestersPids[netType]; // set per-pid dns for attached secondary nets
for (int y=0; y< pids.size(); y++) { List pids = mNetRequestersPids[netType];
Integer pid = (Integer)pids.get(y); for (int y=0; y< pids.size(); y++) {
writePidDns(dnsList, pid.intValue()); Integer pid = (Integer)pids.get(y);
} writePidDns(dnsList, pid.intValue());
} }
} }
} }
bumpDns(); bumpDns();
} }
@@ -1437,9 +1420,12 @@ public class ConnectivityService extends IConnectivityManager.Stub {
case NetworkStateTracker.EVENT_NOTIFICATION_CHANGED: case NetworkStateTracker.EVENT_NOTIFICATION_CHANGED:
handleNotificationChange(msg.arg1 == 1, msg.arg2, handleNotificationChange(msg.arg1 == 1, msg.arg2,
(Notification) msg.obj); (Notification) msg.obj);
break;
case NetworkStateTracker.EVENT_CONFIGURATION_CHANGED: case NetworkStateTracker.EVENT_CONFIGURATION_CHANGED:
handleDnsConfigurationChange(); info = (NetworkInfo) msg.obj;
type = info.getType();
handleDnsConfigurationChange(type);
break; break;
case NetworkStateTracker.EVENT_ROAMING_CHANGED: case NetworkStateTracker.EVENT_ROAMING_CHANGED:

View File

@@ -1124,7 +1124,8 @@ public class WifiStateTracker extends NetworkStateTracker {
setDetailedState(DetailedState.CONNECTED); setDetailedState(DetailedState.CONNECTED);
sendNetworkStateChangeBroadcast(mWifiInfo.getBSSID()); sendNetworkStateChangeBroadcast(mWifiInfo.getBSSID());
} else { } else {
mTarget.sendEmptyMessage(EVENT_CONFIGURATION_CHANGED); msg = mTarget.obtainMessage(EVENT_CONFIGURATION_CHANGED, mNetworkInfo);
msg.sendToTarget();
} }
if (LOCAL_LOGD) Log.v(TAG, "IP configuration: " + mDhcpInfo); if (LOCAL_LOGD) Log.v(TAG, "IP configuration: " + mDhcpInfo);
// Wi-Fi interface configuration state changed: // Wi-Fi interface configuration state changed:
@@ -2468,7 +2469,8 @@ public class WifiStateTracker extends NetworkStateTracker {
resetConnections(true); resetConnections(true);
configureInterface(); configureInterface();
if (mUseStaticIp) { if (mUseStaticIp) {
mTarget.sendEmptyMessage(EVENT_CONFIGURATION_CHANGED); Message msg = mTarget.obtainMessage(EVENT_CONFIGURATION_CHANGED, mNetworkInfo);
msg.sendToTarget();
} }
} }
} }