diff options
author | Lorenzo Colitti <lorenzo@google.com> | 2014-08-19 19:44:57 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-08-19 19:44:57 +0000 |
commit | 6620ea245591d1cbf897e1c3512c135c79f1464f (patch) | |
tree | b98f5e7f6976f749c0a3a1cd173614cf9134001a | |
parent | 4d918aa164b69a155cef4b1fc4feeb6dc3e9e7de (diff) | |
parent | 41a372f13a7d19807d91e09f2e955b8a61f02d5c (diff) | |
download | android_frameworks_opt_net_ethernet-6620ea245591d1cbf897e1c3512c135c79f1464f.tar.gz android_frameworks_opt_net_ethernet-6620ea245591d1cbf897e1c3512c135c79f1464f.tar.bz2 android_frameworks_opt_net_ethernet-6620ea245591d1cbf897e1c3512c135c79f1464f.zip |
am 41a372f1: Stop using LinkProperties for static configuration.
* commit '41a372f13a7d19807d91e09f2e955b8a61f02d5c':
Stop using LinkProperties for static configuration.
3 files changed, 41 insertions, 33 deletions
diff --git a/java/com/android/server/ethernet/EthernetConfigStore.java b/java/com/android/server/ethernet/EthernetConfigStore.java index 7a428a8..676bc99 100644 --- a/java/com/android/server/ethernet/EthernetConfigStore.java +++ b/java/com/android/server/ethernet/EthernetConfigStore.java @@ -19,7 +19,6 @@ package com.android.server.ethernet; import android.net.IpConfiguration; import android.net.IpConfiguration.IpAssignment; import android.net.IpConfiguration.ProxySettings; -import android.net.LinkProperties; import android.os.Environment; import android.util.Log; import android.util.SparseArray; @@ -44,7 +43,7 @@ public class EthernetConfigStore extends IpConfigStore { if (networks.size() == 0) { Log.w(TAG, "No Ethernet configuration found. Using default."); - return new IpConfiguration(IpAssignment.DHCP, ProxySettings.NONE, new LinkProperties()); + return new IpConfiguration(IpAssignment.DHCP, ProxySettings.NONE, null, null); } if (networks.size() > 1) { diff --git a/java/com/android/server/ethernet/EthernetNetworkFactory.java b/java/com/android/server/ethernet/EthernetNetworkFactory.java index 3f0037c..c65a5b2 100644 --- a/java/com/android/server/ethernet/EthernetNetworkFactory.java +++ b/java/com/android/server/ethernet/EthernetNetworkFactory.java @@ -33,6 +33,7 @@ import android.net.NetworkInfo; import android.net.NetworkInfo.DetailedState; import android.net.NetworkRequest; import android.net.EthernetManager; +import android.net.StaticIpConfiguration; import android.os.Handler; import android.os.IBinder; import android.os.INetworkManagementService; @@ -211,24 +212,23 @@ class EthernetNetworkFactory { } } - private void setStaticIpAddress(LinkProperties linkProperties) { - Log.i(TAG, "Applying static IPv4 configuration to " + mIface + ": " + mLinkProperties); - try { - InterfaceConfiguration config = mNMService.getInterfaceConfig(mIface); - for (LinkAddress address: linkProperties.getLinkAddresses()) { - // IPv6 uses autoconfiguration. - if (address.getAddress() instanceof Inet4Address) { - config.setLinkAddress(address); - // This API only supports one IPv4 address. - mNMService.setInterfaceConfig(mIface, config); - break; - } + private boolean setStaticIpAddress(StaticIpConfiguration staticConfig) { + if (staticConfig.ipAddress != null && + staticConfig.gateway != null && + staticConfig.dnsServers.size() > 0) { + try { + Log.i(TAG, "Applying static IPv4 configuration to " + mIface + ": " + staticConfig); + InterfaceConfiguration config = mNMService.getInterfaceConfig(mIface); + config.setLinkAddress(staticConfig.ipAddress); + mNMService.setInterfaceConfig(mIface, config); + return true; + } catch(RemoteException|IllegalStateException e) { + Log.e(TAG, "Setting static IP address failed: " + e.getMessage()); } - } catch(RemoteException e) { - Log.e(TAG, "Setting static IP address failed: " + e.getMessage()); - } catch(IllegalStateException e) { - Log.e(TAG, "Setting static IP address failed: " + e.getMessage()); + } else { + Log.e(TAG, "Invalid static IP configuration."); } + return false; } public void updateAgent() { @@ -260,9 +260,12 @@ class EthernetNetworkFactory { IpConfiguration config = mEthernetManager.getConfiguration(); - if (config.ipAssignment == IpAssignment.STATIC) { - linkProperties = config.linkProperties; - setStaticIpAddress(linkProperties); + if (config.getIpAssignment() == IpAssignment.STATIC) { + if (!setStaticIpAddress(config.getStaticIpConfiguration())) { + // We've already logged an error. + return; + } + linkProperties = config.getStaticIpConfiguration().toLinkProperties(mIface); } else { mNetworkInfo.setDetailedState(DetailedState.OBTAINING_IPADDR, null, mHwAddr); @@ -277,11 +280,11 @@ class EthernetNetworkFactory { mFactory.setScoreFilter(-1); return; } - linkProperties = dhcpResults.linkProperties; - linkProperties.setInterfaceName(mIface); + linkProperties = dhcpResults.toLinkProperties(mIface); } - if (config.proxySettings == ProxySettings.STATIC) { - linkProperties.setHttpProxy(config.linkProperties.getHttpProxy()); + if (config.getProxySettings() == ProxySettings.STATIC || + config.getProxySettings() == ProxySettings.PAC) { + linkProperties.setHttpProxy(config.getHttpProxy()); } linkProperties.setTcpBufferSizes(TCP_BUFFER_SIZES_ETHERNET); @@ -383,12 +386,21 @@ class EthernetNetworkFactory { } public synchronized void stop() { + NetworkUtils.stopDhcp(mIface); + // ConnectivityService will only forget our NetworkAgent if we send it a NetworkInfo object + // with a state of DISCONNECTED or SUSPENDED. So we can't simply clear our NetworkInfo here: + // that sets the state to IDLE, and ConnectivityService will still think we're connected. + // + // TODO: stop using explicit comparisons to DISCONNECTED / SUSPENDED in ConnectivityService, + // and instead use isConnectedOrConnecting(). + mNetworkInfo.setDetailedState(DetailedState.DISCONNECTED, null, mHwAddr); + mLinkUp = false; + updateAgent(); + mLinkProperties = new LinkProperties(); + mNetworkAgent = null; mIface = ""; mHwAddr = null; - mLinkUp = false; mNetworkInfo = new NetworkInfo(ConnectivityManager.TYPE_ETHERNET, 0, NETWORK_TYPE, ""); - mLinkProperties = new LinkProperties(); - updateAgent(); mFactory.unregister(); } diff --git a/java/com/android/server/ethernet/EthernetServiceImpl.java b/java/com/android/server/ethernet/EthernetServiceImpl.java index 08a2e9a..1534aab 100644 --- a/java/com/android/server/ethernet/EthernetServiceImpl.java +++ b/java/com/android/server/ethernet/EthernetServiceImpl.java @@ -25,11 +25,11 @@ import android.net.IpConfiguration; import android.net.IpConfiguration.IpAssignment; import android.net.IpConfiguration.ProxySettings; import android.net.LinkAddress; -import android.net.LinkProperties; import android.net.NetworkAgent; import android.net.NetworkInfo; import android.net.NetworkRequest; import android.net.RouteInfo; +import android.net.StaticIpConfiguration; import android.os.Binder; import android.os.IBinder; import android.os.Handler; @@ -143,10 +143,7 @@ public class EthernetServiceImpl extends IEthernetManager.Stub { // TODO: this does not check proxy settings, gateways, etc. // Fix this by making IpConfiguration a complete representation of static configuration. if (!config.equals(mIpConfiguration)) { - mIpConfiguration.ipAssignment = config.ipAssignment; - mIpConfiguration.proxySettings = config.proxySettings; - mIpConfiguration.linkProperties = new LinkProperties(config.linkProperties); - + mIpConfiguration = new IpConfiguration(config); mTracker.stop(); mTracker.start(mContext, mHandler); } |