diff options
author | Glen Kuhne <kuh@google.com> | 2017-03-01 15:05:57 -0800 |
---|---|---|
committer | Glen Kuhne <kuh@google.com> | 2017-03-28 16:03:52 -0700 |
commit | 653cd53f0906a90fbf5b1d9d0bd30917043d1bfc (patch) | |
tree | 2d79d254cfd4dd7b6e0ac65955f470f3d1d04c50 | |
parent | f139f833426aec5258c80fa582ca7007c079c0a2 (diff) |
Check validity of staticIpConfigurations
Added a check ensuring Static IP wificonfigurations have a non-null
StaticIpConfiguration and ipAddress.
This fixes a potential stalling of WifiStateMachine in ObtainingIpState
indefinitely.
Bug: 35849629
Test: Added unit test. Existing pass
Change-Id: Ibc55050db99f71acdb821f9c62e0433fda18632f
3 files changed, 41 insertions, 18 deletions
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java index d715fae63..646e81185 100644 --- a/service/java/com/android/server/wifi/WifiServiceImpl.java +++ b/service/java/com/android/server/wifi/WifiServiceImpl.java @@ -42,8 +42,10 @@ import android.database.ContentObserver; import android.net.ConnectivityManager; import android.net.DhcpInfo; import android.net.DhcpResults; +import android.net.IpConfiguration; import android.net.Network; import android.net.NetworkUtils; +import android.net.StaticIpConfiguration; import android.net.Uri; import android.net.ip.IpManager; import android.net.wifi.IWifiManager; @@ -1794,6 +1796,15 @@ public class WifiServiceImpl extends IWifiManager.Stub { return "not PSK or 8021X"; } } + if (config.getIpAssignment() == IpConfiguration.IpAssignment.STATIC) { + StaticIpConfiguration staticIpConf = config.getStaticIpConfiguration(); + if (staticIpConf == null) { + return "null StaticIpConfiguration"; + } + if (staticIpConf.ipAddress == null) { + return "null static ip Address"; + } + } return null; } diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java index 17b8b2f40..aa0b9fafa 100644 --- a/service/java/com/android/server/wifi/WifiStateMachine.java +++ b/service/java/com/android/server/wifi/WifiStateMachine.java @@ -5733,30 +5733,22 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss if (!TextUtils.isEmpty(mTcpBufferSizes)) { mIpManager.setTcpBufferSizes(mTcpBufferSizes); } - + final IpManager.ProvisioningConfiguration prov; if (!isUsingStaticIp) { - final IpManager.ProvisioningConfiguration prov = - IpManager.buildProvisioningConfiguration() + prov = IpManager.buildProvisioningConfiguration() .withPreDhcpAction() .withApfCapabilities(mWifiNative.getApfCapabilities()) .build(); - mIpManager.startProvisioning(prov); - // Get Link layer stats so as we get fresh tx packet counters - getWifiLinkLayerStats(); } else { - StaticIpConfiguration config = currentConfig.getStaticIpConfiguration(); - if (config.ipAddress == null) { - logd("Static IP lacks address"); - sendMessage(CMD_IPV4_PROVISIONING_FAILURE); - } else { - final IpManager.ProvisioningConfiguration prov = - IpManager.buildProvisioningConfiguration() - .withStaticConfiguration(config) - .withApfCapabilities(mWifiNative.getApfCapabilities()) - .build(); - mIpManager.startProvisioning(prov); - } + StaticIpConfiguration staticIpConfig = currentConfig.getStaticIpConfiguration(); + prov = IpManager.buildProvisioningConfiguration() + .withStaticConfiguration(staticIpConfig) + .withApfCapabilities(mWifiNative.getApfCapabilities()) + .build(); } + mIpManager.startProvisioning(prov); + // Get Link layer stats so as we get fresh tx packet counters + getWifiLinkLayerStats(); } @Override diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java index 4a4caec81..fa34e07f9 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java @@ -18,6 +18,7 @@ package com.android.server.wifi; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; @@ -25,6 +26,7 @@ import static org.mockito.Mockito.*; import android.content.Context; import android.content.res.Resources; +import android.net.IpConfiguration; import android.net.wifi.WifiConfiguration; import android.os.Handler; import android.os.HandlerThread; @@ -176,6 +178,24 @@ public class WifiServiceImplTest { } /** + * Tests the isValid() check for StaticIpConfigurations, ensuring that configurations with null + * ipAddress are rejected, and configurations with ipAddresses are valid. + */ + @Test + public void testStaticIpConfigurationValidityCheck() { + WifiConfiguration conf = WifiConfigurationTestUtil.createOpenNetwork(); + IpConfiguration ipConf = + WifiConfigurationTestUtil.createStaticIpConfigurationWithStaticProxy(); + conf.setIpConfiguration(ipConf); + // Ensure staticIpConfiguration with IP Address is valid + assertTrue(mWifiServiceImpl.isValid(conf)); + ipConf.staticIpConfiguration.ipAddress = null; + // Ensure staticIpConfiguration with null IP Address it is not valid + conf.setIpConfiguration(ipConf); + assertFalse(mWifiServiceImpl.isValid(conf)); + } + + /** * Ensure WifiMetrics.dump() is the only dump called when 'dumpsys wifi WifiMetricsProto' is * called. This is required to support simple metrics collection via dumpsys */ |