am c0cfe2ee: Stop using LinkProperties for static configuration.
* commit 'c0cfe2ee04622e16e4623ffe1612e5afbbaf41ae': Stop using LinkProperties for static configuration.
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user