From 62e8e4d3d5c345ec0a239eb8985e042176c35743 Mon Sep 17 00:00:00 2001 From: Robert Greenwalt Date: Thu, 19 Jun 2014 16:26:03 -0700 Subject: [PATCH] DO NOT MERGE Don't tear down based on NetworkFactory input. NetworkFactory only indicates if we're interested in new connections. It shouldn't be used to tear down existing connections (they have unwanted callbacks for that). Supports linger properly as well as dealing with tie scores. bug:15612739 Change-Id: Ib3dfe673d3645b9dc4756c176958409a64ec32e4 (cherry picked from commit 8b07ee36a23d5d87b40bfc2e10761051c0232498) --- .../ethernet/EthernetNetworkFactory.java | 51 +++++++++---------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java b/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java index 483f983fb7..b1b98d2692 100644 --- a/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java +++ b/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java @@ -114,7 +114,6 @@ class EthernetNetworkFactory { onRequestNetwork(); } protected void stopNetwork() { - onCancelRequest(); } } @@ -202,13 +201,13 @@ class EthernetNetworkFactory { return; Log.d(TAG, "Stopped tracking interface " + iface); - onCancelRequest(); synchronized (this) { mIface = ""; mHwAddr = null; mNetworkInfo.setExtraInfo(null); mNetworkInfo = new NetworkInfo(ConnectivityManager.TYPE_ETHERNET, 0, NETWORK_TYPE, ""); mLinkProperties = new LinkProperties(); + updateAgent(); } } @@ -283,6 +282,10 @@ class EthernetNetworkFactory { } synchronized(EthernetNetworkFactory.this) { + if (mNetworkAgent != null) { + Log.e(TAG, "Already have a NetworkAgent - aborting new request"); + return; + } mLinkProperties = linkProperties; mNetworkInfo.setIsAvailable(true); mNetworkInfo.setDetailedState(DetailedState.CONNECTED, null, mHwAddr); @@ -292,7 +295,25 @@ class EthernetNetworkFactory { NETWORK_TYPE, mNetworkInfo, mNetworkCapabilities, mLinkProperties, NETWORK_SCORE) { public void unwanted() { - EthernetNetworkFactory.this.onCancelRequest(); + synchronized(EthernetNetworkFactory.this) { + if (this == mNetworkAgent) { + NetworkUtils.stopDhcp(mIface); + + mLinkProperties.clear(); + mNetworkInfo.setDetailedState(DetailedState.DISCONNECTED, null, + mHwAddr); + updateAgent(); + mNetworkAgent = null; + try { + mNMService.clearInterfaceAddresses(mIface); + } catch (Exception e) { + Log.e(TAG, "Failed to clear addresses or disable ipv6" + e); + } + } else { + Log.d(TAG, "Ignoring unwanted as we have a more modern " + + "instance"); + } + } }; }; } @@ -301,28 +322,6 @@ class EthernetNetworkFactory { dhcpThread.start(); } - /** - * Clears layer 3 properties and reports disconnect. - * Does not touch interface state variables such as link state and MAC address. - * Called when the tracked interface loses link or disappears. - */ - public void onCancelRequest() { - NetworkUtils.stopDhcp(mIface); - - synchronized(this) { - mLinkProperties.clear(); - mNetworkInfo.setDetailedState(DetailedState.DISCONNECTED, null, mHwAddr); - updateAgent(); - mNetworkAgent = null; - } - - try { - mNMService.clearInterfaceAddresses(mIface); - } catch (Exception e) { - Log.e(TAG, "Failed to clear addresses or disable ipv6" + e); - } - } - /** * Begin monitoring connectivity */ @@ -379,12 +378,12 @@ class EthernetNetworkFactory { } public synchronized void stop() { - onCancelRequest(); mIface = ""; mHwAddr = null; mLinkUp = false; mNetworkInfo = new NetworkInfo(ConnectivityManager.TYPE_ETHERNET, 0, NETWORK_TYPE, ""); mLinkProperties = new LinkProperties(); + updateAgent(); mFactory.unregister(); }