From f800656f89a2d48f8210ceb796e42efe4fea95a4 Mon Sep 17 00:00:00 2001 From: "Mike J. Chen" Date: Fri, 30 Sep 2011 18:05:44 -0700 Subject: [PATCH] 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. Change-Id: Ia16648d576187de21b667f026ed3454ac4116bb6 Signed-off-by: Mike J. Chen --- .../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 21ecc22c10ffa..02e81b6a8697b 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 = ""; }