ethernet: Fix the connect fail issue when switch DHCP to Static config at Ethernet interface.
am: 89ffed793f
Change-Id: Ieaade184b2a88f9eb6c8ceb821a54f3db006f261
This commit is contained in:
@@ -248,25 +248,6 @@ class EthernetNetworkFactory {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Log.e(TAG, "Invalid static IP configuration.");
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateAgent() {
|
public void updateAgent() {
|
||||||
if (mNetworkAgent == null) return;
|
if (mNetworkAgent == null) return;
|
||||||
if (DBG) {
|
if (DBG) {
|
||||||
@@ -332,55 +313,52 @@ class EthernetNetworkFactory {
|
|||||||
mNetworkInfo));
|
mNetworkInfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
LinkProperties linkProperties;
|
|
||||||
|
|
||||||
IpConfiguration config = mEthernetManager.getConfiguration();
|
IpConfiguration config = mEthernetManager.getConfiguration();
|
||||||
|
|
||||||
if (config.getIpAssignment() == IpAssignment.STATIC) {
|
mNetworkInfo.setDetailedState(DetailedState.OBTAINING_IPADDR, null, mHwAddr);
|
||||||
if (!setStaticIpAddress(config.getStaticIpConfiguration())) {
|
IpManager.Callback ipmCallback = new IpManager.Callback() {
|
||||||
// We've already logged an error.
|
@Override
|
||||||
return;
|
public void onProvisioningSuccess(LinkProperties newLp) {
|
||||||
}
|
mHandler.post(() -> onIpLayerStarted(newLp));
|
||||||
linkProperties = config.getStaticIpConfiguration().toLinkProperties(mIface);
|
|
||||||
} else {
|
|
||||||
mNetworkInfo.setDetailedState(DetailedState.OBTAINING_IPADDR, null, mHwAddr);
|
|
||||||
IpManager.Callback ipmCallback = new IpManager.Callback() {
|
|
||||||
@Override
|
|
||||||
public void onProvisioningSuccess(LinkProperties newLp) {
|
|
||||||
mHandler.post(() -> onIpLayerStarted(newLp));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onProvisioningFailure(LinkProperties newLp) {
|
|
||||||
mHandler.post(() -> onIpLayerStopped(newLp));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLinkPropertiesChange(LinkProperties newLp) {
|
|
||||||
mHandler.post(() -> updateLinkProperties(newLp));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
stopIpManager();
|
|
||||||
mIpManager = new IpManager(mContext, mIface, ipmCallback);
|
|
||||||
|
|
||||||
if (config.getProxySettings() == ProxySettings.STATIC ||
|
|
||||||
config.getProxySettings() == ProxySettings.PAC) {
|
|
||||||
mIpManager.setHttpProxy(config.getHttpProxy());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final String tcpBufferSizes = mContext.getResources().getString(
|
@Override
|
||||||
com.android.internal.R.string.config_ethernet_tcp_buffers);
|
public void onProvisioningFailure(LinkProperties newLp) {
|
||||||
if (!TextUtils.isEmpty(tcpBufferSizes)) {
|
mHandler.post(() -> onIpLayerStopped(newLp));
|
||||||
mIpManager.setTcpBufferSizes(tcpBufferSizes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final ProvisioningConfiguration provisioningConfiguration =
|
@Override
|
||||||
mIpManager.buildProvisioningConfiguration()
|
public void onLinkPropertiesChange(LinkProperties newLp) {
|
||||||
.withProvisioningTimeoutMs(0)
|
mHandler.post(() -> updateLinkProperties(newLp));
|
||||||
.build();
|
}
|
||||||
mIpManager.startProvisioning(provisioningConfiguration);
|
};
|
||||||
|
|
||||||
|
stopIpManager();
|
||||||
|
mIpManager = new IpManager(mContext, mIface, ipmCallback);
|
||||||
|
|
||||||
|
if (config.getProxySettings() == ProxySettings.STATIC ||
|
||||||
|
config.getProxySettings() == ProxySettings.PAC) {
|
||||||
|
mIpManager.setHttpProxy(config.getHttpProxy());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final String tcpBufferSizes = mContext.getResources().getString(
|
||||||
|
com.android.internal.R.string.config_ethernet_tcp_buffers);
|
||||||
|
if (!TextUtils.isEmpty(tcpBufferSizes)) {
|
||||||
|
mIpManager.setTcpBufferSizes(tcpBufferSizes);
|
||||||
|
}
|
||||||
|
|
||||||
|
final ProvisioningConfiguration provisioningConfiguration;
|
||||||
|
if (config.getIpAssignment() == IpAssignment.STATIC) {
|
||||||
|
provisioningConfiguration = IpManager.buildProvisioningConfiguration()
|
||||||
|
.withStaticConfiguration(config.getStaticIpConfiguration())
|
||||||
|
.build();
|
||||||
|
} else {
|
||||||
|
provisioningConfiguration = mIpManager.buildProvisioningConfiguration()
|
||||||
|
.withProvisioningTimeoutMs(0)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
mIpManager.startProvisioning(provisioningConfiguration);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user