summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlen Kuhne <kuh@google.com>2017-04-05 20:27:56 +0000
committerandroid-build-merger <android-build-merger@google.com>2017-04-05 20:27:56 +0000
commit6b1209d5f2066d9f17074f2572333f29679d0e0b (patch)
treef72b66aa4f041871e3bcfbdcf6cd8ebf468fe18c
parent03e86a9700434d0a8938479610a4b091ed94dbdf (diff)
parenta805f151c790272d2c016cf59b89b052981bb7ae (diff)
Merge "Check validity of staticIpConfigurations" into oc-dev
am: a805f151c7 Change-Id: I60ff78aac5d429c4a828355d308b13c68b02aeaa
-rw-r--r--service/java/com/android/server/wifi/WifiServiceImpl.java11
-rw-r--r--service/java/com/android/server/wifi/WifiStateMachine.java28
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java20
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 e24f720db..a327fa7b1 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;
@@ -1804,6 +1806,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 fb807b7a0..8f62288c8 100644
--- a/service/java/com/android/server/wifi/WifiStateMachine.java
+++ b/service/java/com/android/server/wifi/WifiStateMachine.java
@@ -5784,30 +5784,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 e5289ac32..71ca0204f 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
@@ -22,6 +22,7 @@ import static com.android.server.wifi.WifiController.CMD_WIFI_TOGGLED;
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;
@@ -30,6 +31,7 @@ import static org.mockito.Mockito.*;
import android.content.ContentResolver;
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;
@@ -194,6 +196,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
*/