summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElvis Chien <elvis.chien@mediatek.com>2017-10-19 07:45:43 +0000
committerandroid-build-merger <android-build-merger@google.com>2017-10-19 07:45:43 +0000
commit7fdb2fd4499a733926d14e30602212394130eabe (patch)
treeecb0e9a80a3d94ec64f79f3d7b1cbd188ba1de32
parent56241dc8efbfd5bd6e5e0ad16f661d93fc0ec489 (diff)
parente0603837fa5d15fcb0ce2d50001abbcdb18bc520 (diff)
downloadethernet-7fdb2fd4499a733926d14e30602212394130eabe.tar.gz
ethernet: Fix the connect fail issue when switch DHCP to Static config at Ethernet interface.
am: e0603837fa Change-Id: Ieaade184b2a88f9eb6c8ceb821a54f3db006f261
-rw-r--r--java/com/android/server/ethernet/EthernetNetworkFactory.java94
1 files changed, 36 insertions, 58 deletions
diff --git a/java/com/android/server/ethernet/EthernetNetworkFactory.java b/java/com/android/server/ethernet/EthernetNetworkFactory.java
index d6d0def..2d54fd2 100644
--- a/java/com/android/server/ethernet/EthernetNetworkFactory.java
+++ b/java/com/android/server/ethernet/EthernetNetworkFactory.java
@@ -248,25 +248,6 @@ class EthernetNetworkFactory {
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() {
if (mNetworkAgent == null) return;
if (DBG) {
@@ -332,55 +313,52 @@ class EthernetNetworkFactory {
mNetworkInfo));
}
- LinkProperties linkProperties;
-
IpConfiguration config = mEthernetManager.getConfiguration();
- if (config.getIpAssignment() == IpAssignment.STATIC) {
- if (!setStaticIpAddress(config.getStaticIpConfiguration())) {
- // We've already logged an error.
- return;
+ mNetworkInfo.setDetailedState(DetailedState.OBTAINING_IPADDR, null, mHwAddr);
+ IpManager.Callback ipmCallback = new IpManager.Callback() {
+ @Override
+ 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 onProvisioningFailure(LinkProperties newLp) {
+ mHandler.post(() -> onIpLayerStopped(newLp));
+ }
- @Override
- public void onLinkPropertiesChange(LinkProperties newLp) {
- mHandler.post(() -> updateLinkProperties(newLp));
- }
- };
+ @Override
+ public void onLinkPropertiesChange(LinkProperties newLp) {
+ mHandler.post(() -> updateLinkProperties(newLp));
+ }
+ };
- stopIpManager();
- mIpManager = new IpManager(mContext, mIface, ipmCallback);
+ stopIpManager();
+ mIpManager = new IpManager(mContext, mIface, ipmCallback);
- if (config.getProxySettings() == ProxySettings.STATIC ||
- config.getProxySettings() == ProxySettings.PAC) {
- mIpManager.setHttpProxy(config.getHttpProxy());
- }
+ 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 String tcpBufferSizes = mContext.getResources().getString(
+ com.android.internal.R.string.config_ethernet_tcp_buffers);
+ if (!TextUtils.isEmpty(tcpBufferSizes)) {
+ mIpManager.setTcpBufferSizes(tcpBufferSizes);
+ }
- final ProvisioningConfiguration provisioningConfiguration =
- mIpManager.buildProvisioningConfiguration()
- .withProvisioningTimeoutMs(0)
- .build();
- mIpManager.startProvisioning(provisioningConfiguration);
+ 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);
}
/**