From 4bcbefdc5f24702dbbae485d016997e3efb5e5cc Mon Sep 17 00:00:00 2001 From: "Mike J. Chen" Date: Fri, 30 Sep 2011 18:05:44 -0700 Subject: Fix disconnect from wired ethernet issues. When a cable was unplugged, we were telling the driver to release the ip address so if a cable on a different network was plugged in, it would still try to use it's old ip address on the new network, which probably didn't work. Also, we didn't notify ConnectivityService about the state change in the unplug case. Some of this was done in the interface removed case, but we never remove the interface in Tungsten, just unplug. So refactor the common disconnect code into a disconnect() function that's called by both the link status change (unplug) and interface removal (only applies to things like USB ethernet dongles) cases. Signed-off-by: Mike J. Chen --- core/java/android/net/EthernetDataTracker.java | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/core/java/android/net/EthernetDataTracker.java b/core/java/android/net/EthernetDataTracker.java index 21ecc22..02e81b6 100644 --- a/core/java/android/net/EthernetDataTracker.java +++ b/core/java/android/net/EthernetDataTracker.java @@ -79,10 +79,7 @@ public class EthernetDataTracker implements NetworkStateTracker { if (up) { mTracker.reconnect(); } else { - NetworkUtils.stopDhcp(mIface); - mTracker.mNetworkInfo.setIsAvailable(false); - mTracker.mNetworkInfo.setDetailedState(DetailedState.DISCONNECTED, - null, null); + mTracker.disconnect(); } } } @@ -129,11 +126,7 @@ public class EthernetDataTracker implements NetworkStateTracker { runDhcp(); } - private void interfaceRemoved(String iface) { - if (!iface.equals(mIface)) - return; - - Log.d(TAG, "Removing " + iface); + public void disconnect() { NetworkUtils.stopDhcp(mIface); @@ -147,6 +140,21 @@ public class EthernetDataTracker implements NetworkStateTracker { msg = mCsHandler.obtainMessage(EVENT_STATE_CHANGED, mNetworkInfo); msg.sendToTarget(); + IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE); + INetworkManagementService service = INetworkManagementService.Stub.asInterface(b); + try { + service.clearInterfaceAddresses(mIface); + } catch (Exception e) { + Log.e(TAG, "Failed to clear addresses or disable ipv6" + e); + } + } + + private void interfaceRemoved(String iface) { + if (!iface.equals(mIface)) + return; + + Log.d(TAG, "Removing " + iface); + disconnect(); mIface = ""; } -- cgit v1.1