diff options
-rw-r--r-- | core/java/android/net/MobileDataStateTracker.java | 41 | ||||
-rw-r--r-- | services/java/com/android/server/ConnectivityService.java | 41 | ||||
-rw-r--r-- | wifi/java/android/net/wifi/WifiStateMachine.java | 10 |
3 files changed, 40 insertions, 52 deletions
diff --git a/core/java/android/net/MobileDataStateTracker.java b/core/java/android/net/MobileDataStateTracker.java index 770f152..f3c863f 100644 --- a/core/java/android/net/MobileDataStateTracker.java +++ b/core/java/android/net/MobileDataStateTracker.java @@ -69,10 +69,6 @@ public class MobileDataStateTracker implements NetworkStateTracker { private boolean mPrivateDnsRouteSet = false; private boolean mDefaultRouteSet = false; - // DEFAULT and HIPRI are the same connection. If we're one of these we need to check if - // the other is also disconnected before we reset sockets - private boolean mIsDefaultOrHipri = false; - private Handler mHandler; private AsyncChannel mDataConnectionTrackerAc; private Messenger mMessenger; @@ -87,12 +83,6 @@ public class MobileDataStateTracker implements NetworkStateTracker { TelephonyManager.getDefault().getNetworkType(), tag, TelephonyManager.getDefault().getNetworkTypeName()); mApnType = networkTypeToApnType(netType); - if (netType == ConnectivityManager.TYPE_MOBILE || - netType == ConnectivityManager.TYPE_MOBILE_HIPRI) { - mIsDefaultOrHipri = true; - } - - mPhoneService = null; } /** @@ -180,8 +170,6 @@ public class MobileDataStateTracker implements NetworkStateTracker { } private class MobileDataStateReceiver extends BroadcastReceiver { - IConnectivityManager mConnectivityManager; - @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(TelephonyIntents. @@ -218,35 +206,6 @@ public class MobileDataStateTracker implements NetworkStateTracker { } setDetailedState(DetailedState.DISCONNECTED, reason, apnName); - boolean doReset = true; - if (mIsDefaultOrHipri == true) { - // both default and hipri must go down before we reset - int typeToCheck = (Phone.APN_TYPE_DEFAULT.equals(mApnType) ? - ConnectivityManager.TYPE_MOBILE_HIPRI : - ConnectivityManager.TYPE_MOBILE); - if (mConnectivityManager == null) { - IBinder b = ServiceManager.getService( - Context.CONNECTIVITY_SERVICE); - mConnectivityManager = IConnectivityManager.Stub.asInterface(b); - } - try { - if (mConnectivityManager != null) { - NetworkInfo info = mConnectivityManager.getNetworkInfo( - typeToCheck); - if (info.isConnected() == true) { - doReset = false; - } - } - } catch (RemoteException e) { - // just go ahead with the reset - loge("Exception trying to contact ConnService: " + e); - } - } - if (doReset && mLinkProperties != null) { - String iface = mLinkProperties.getInterfaceName(); - if (iface != null) NetworkUtils.resetConnections(iface); - } - // TODO - check this // can't do this here - ConnectivityService needs it to clear stuff // it's ok though - just leave it to be refreshed next time // we connect. diff --git a/services/java/com/android/server/ConnectivityService.java b/services/java/com/android/server/ConnectivityService.java index 385448f..383842d 100644 --- a/services/java/com/android/server/ConnectivityService.java +++ b/services/java/com/android/server/ConnectivityService.java @@ -1267,8 +1267,30 @@ public class ConnectivityService extends IConnectivityManager.Stub { } } intent.putExtra(ConnectivityManager.EXTRA_INET_CONDITION, mDefaultInetConditionPublished); + + // Reset interface if no other connections are using the same interface + boolean doReset = true; + LinkProperties linkProperties = mNetTrackers[prevNetType].getLinkProperties(); + if (linkProperties != null) { + String oldIface = linkProperties.getInterfaceName(); + if (TextUtils.isEmpty(oldIface) == false) { + for (NetworkStateTracker networkStateTracker : mNetTrackers) { + if (networkStateTracker == null) continue; + NetworkInfo networkInfo = networkStateTracker.getNetworkInfo(); + if (networkInfo.isConnected() && networkInfo.getType() != prevNetType) { + LinkProperties l = networkStateTracker.getLinkProperties(); + if (l == null) continue; + if (oldIface.equals(l.getInterfaceName())) { + doReset = false; + break; + } + } + } + } + } + // do this before we broadcast the change - handleConnectivityChange(prevNetType); + handleConnectivityChange(prevNetType, doReset); sendStickyBroadcast(intent); /* @@ -1490,7 +1512,7 @@ public class ConnectivityService extends IConnectivityManager.Stub { } thisNet.setTeardownRequested(false); updateNetworkSettings(thisNet); - handleConnectivityChange(type); + handleConnectivityChange(type, false); sendConnectedBroadcast(info); } @@ -1500,7 +1522,7 @@ public class ConnectivityService extends IConnectivityManager.Stub { * according to which networks are connected, and ensuring that the * right routing table entries exist. */ - private void handleConnectivityChange(int netType) { + private void handleConnectivityChange(int netType, boolean doReset) { /* * If a non-default network is enabled, add the host routes that * will allow it's DNS servers to be accessed. @@ -1540,6 +1562,17 @@ public class ConnectivityService extends IConnectivityManager.Stub { removePrivateDnsRoutes(mNetTrackers[netType]); } } + + if (doReset) { + LinkProperties linkProperties = mNetTrackers[netType].getLinkProperties(); + if (linkProperties != null) { + String iface = linkProperties.getInterfaceName(); + if (TextUtils.isEmpty(iface) == false) { + if (DBG) log("resetConnections(" + iface + ")"); + NetworkUtils.resetConnections(iface); + } + } + } } private void addPrivateDnsRoutes(NetworkStateTracker nt) { @@ -1965,7 +1998,7 @@ public class ConnectivityService extends IConnectivityManager.Stub { break; case NetworkStateTracker.EVENT_CONFIGURATION_CHANGED: info = (NetworkInfo) msg.obj; - handleConnectivityChange(info.getType()); + handleConnectivityChange(info.getType(), true); break; case EVENT_CLEAR_NET_TRANSITION_WAKELOCK: String causedBy = null; diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java index 3df3736..4f5349a 100644 --- a/wifi/java/android/net/wifi/WifiStateMachine.java +++ b/wifi/java/android/net/wifi/WifiStateMachine.java @@ -1374,7 +1374,7 @@ public class WifiStateMachine extends StateMachine { intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT | Intent.FLAG_RECEIVER_REPLACE_PENDING); intent.putExtra(WifiManager.EXTRA_NETWORK_INFO, mNetworkInfo); - intent.putExtra(WifiManager.EXTRA_LINK_PROPERTIES, mLinkProperties); + intent.putExtra(WifiManager.EXTRA_LINK_PROPERTIES, new LinkProperties (mLinkProperties)); if (bssid != null) intent.putExtra(WifiManager.EXTRA_BSSID, bssid); mContext.sendStickyBroadcast(intent); @@ -1390,7 +1390,7 @@ public class WifiStateMachine extends StateMachine { private void sendLinkConfigurationChangedBroadcast() { Intent intent = new Intent(WifiManager.LINK_CONFIGURATION_CHANGED_ACTION); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); - intent.putExtra(WifiManager.EXTRA_LINK_PROPERTIES, mLinkProperties); + intent.putExtra(WifiManager.EXTRA_LINK_PROPERTIES, new LinkProperties(mLinkProperties)); mContext.sendBroadcast(intent); } @@ -1454,10 +1454,8 @@ public class WifiStateMachine extends StateMachine { Log.d(TAG, "Reset connections and stopping DHCP"); /* - * Reset connections & stop DHCP + * stop DHCP */ - NetworkUtils.resetConnections(mInterfaceName); - if (mDhcpStateMachine != null) { mDhcpStateMachine.sendMessage(DhcpStateMachine.CMD_STOP_DHCP); mDhcpStateMachine.quit(); @@ -1547,7 +1545,6 @@ public class WifiStateMachine extends StateMachine { if (!linkProperties.equals(mLinkProperties)) { Log.d(TAG, "Link configuration changed for netId: " + mLastNetworkId + " old: " + mLinkProperties + "new: " + linkProperties); - NetworkUtils.resetConnections(mInterfaceName); mLinkProperties = linkProperties; sendLinkConfigurationChangedBroadcast(); } @@ -2820,7 +2817,6 @@ public class WifiStateMachine extends StateMachine { if (mWifiInfo.getNetworkId() == result.getNetworkId()) { if (result.hasIpChanged()) { Log.d(TAG,"Reconfiguring IP on connection"); - NetworkUtils.resetConnections(mInterfaceName); transitionTo(mConnectingState); } if (result.hasProxyChanged()) { |