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 8b07ee36a2)
This commit is contained in:
Robert Greenwalt
2014-06-19 16:26:03 -07:00
parent 579d5d8aeb
commit 62e8e4d3d5

View File

@@ -114,7 +114,6 @@ class EthernetNetworkFactory {
onRequestNetwork(); onRequestNetwork();
} }
protected void stopNetwork() { protected void stopNetwork() {
onCancelRequest();
} }
} }
@@ -202,13 +201,13 @@ class EthernetNetworkFactory {
return; return;
Log.d(TAG, "Stopped tracking interface " + iface); Log.d(TAG, "Stopped tracking interface " + iface);
onCancelRequest();
synchronized (this) { synchronized (this) {
mIface = ""; mIface = "";
mHwAddr = null; mHwAddr = null;
mNetworkInfo.setExtraInfo(null); mNetworkInfo.setExtraInfo(null);
mNetworkInfo = new NetworkInfo(ConnectivityManager.TYPE_ETHERNET, 0, NETWORK_TYPE, ""); mNetworkInfo = new NetworkInfo(ConnectivityManager.TYPE_ETHERNET, 0, NETWORK_TYPE, "");
mLinkProperties = new LinkProperties(); mLinkProperties = new LinkProperties();
updateAgent();
} }
} }
@@ -283,6 +282,10 @@ class EthernetNetworkFactory {
} }
synchronized(EthernetNetworkFactory.this) { synchronized(EthernetNetworkFactory.this) {
if (mNetworkAgent != null) {
Log.e(TAG, "Already have a NetworkAgent - aborting new request");
return;
}
mLinkProperties = linkProperties; mLinkProperties = linkProperties;
mNetworkInfo.setIsAvailable(true); mNetworkInfo.setIsAvailable(true);
mNetworkInfo.setDetailedState(DetailedState.CONNECTED, null, mHwAddr); mNetworkInfo.setDetailedState(DetailedState.CONNECTED, null, mHwAddr);
@@ -292,7 +295,25 @@ class EthernetNetworkFactory {
NETWORK_TYPE, mNetworkInfo, mNetworkCapabilities, mLinkProperties, NETWORK_TYPE, mNetworkInfo, mNetworkCapabilities, mLinkProperties,
NETWORK_SCORE) { NETWORK_SCORE) {
public void unwanted() { 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(); 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 * Begin monitoring connectivity
*/ */
@@ -379,12 +378,12 @@ class EthernetNetworkFactory {
} }
public synchronized void stop() { public synchronized void stop() {
onCancelRequest();
mIface = ""; mIface = "";
mHwAddr = null; mHwAddr = null;
mLinkUp = false; mLinkUp = false;
mNetworkInfo = new NetworkInfo(ConnectivityManager.TYPE_ETHERNET, 0, NETWORK_TYPE, ""); mNetworkInfo = new NetworkInfo(ConnectivityManager.TYPE_ETHERNET, 0, NETWORK_TYPE, "");
mLinkProperties = new LinkProperties(); mLinkProperties = new LinkProperties();
updateAgent();
mFactory.unregister(); mFactory.unregister();
} }