summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorlesl <lesl@google.com>2019-11-27 17:25:50 +0800
committerlesl <lesl@google.com>2019-12-03 14:04:41 +0800
commit74f344ddbdc469becfe23611a4c79abb45a43f36 (patch)
tree8ae4315e6a72d38c3e7e62daaf2a4035de19f2be /tests
parent23b40bd2cc909950103cc55cffacc9142f584751 (diff)
wifi: Use SoftApConfiguration to replace WifiConfiguration for SoftAp
1. Use SoftApConfiguration to replace WifiConfiguration 2. Add new APIs with SoftApConfiguration to enable, set/get configuration for SoftAp. Bug: 142752869 Test: atest frameworks/opt/net/wifi/tests/wifitests Test: Manual Test, softAP enable/disable/configuration change. Change-Id: I5962a439709a8e4d9df8e241c7c2480e3ce235fb
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/ActiveModeWardenTest.java31
-rw-r--r--tests/wifitests/src/com/android/server/wifi/HostapdHalTest.java180
-rw-r--r--tests/wifitests/src/com/android/server/wifi/LocalOnlyHotspotRequestInfoTest.java15
-rw-r--r--tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java205
-rw-r--r--tests/wifitests/src/com/android/server/wifi/SoftApStoreDataTest.java82
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java357
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java17
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiNativeInterfaceManagementTest.java4
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java232
-rw-r--r--tests/wifitests/src/com/android/server/wifi/util/ApConfigUtilTest.java56
10 files changed, 680 insertions, 499 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/ActiveModeWardenTest.java b/tests/wifitests/src/com/android/server/wifi/ActiveModeWardenTest.java
index 029e423f8..89e38b378 100644
--- a/tests/wifitests/src/com/android/server/wifi/ActiveModeWardenTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/ActiveModeWardenTest.java
@@ -45,9 +45,10 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Resources;
import android.location.LocationManager;
+import android.net.wifi.SoftApConfiguration;
+import android.net.wifi.SoftApConfiguration.Builder;
import android.net.wifi.SoftApInfo;
import android.net.wifi.WifiClient;
-import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.os.BatteryStats;
import android.os.BatteryStatsManager;
@@ -725,10 +726,10 @@ public class ActiveModeWardenTest extends WifiBaseTest {
*/
@Test
public void testConfigIsPassedToWifiInjector() throws Exception {
- WifiConfiguration config = new WifiConfiguration();
- config.SSID = "ThisIsAConfig";
- SoftApModeConfiguration softApConfig =
- new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, config);
+ Builder configBuilder = new SoftApConfiguration.Builder();
+ configBuilder.setSsid("ThisIsAConfig");
+ SoftApModeConfiguration softApConfig = new SoftApModeConfiguration(
+ WifiManager.IFACE_IP_MODE_TETHERED, configBuilder.build());
enterSoftApActiveMode(softApConfig);
}
@@ -751,14 +752,14 @@ public class ActiveModeWardenTest extends WifiBaseTest {
@Test
public void testStartSoftApModeTwiceWithTwoConfigs() throws Exception {
when(mWifiInjector.getWifiApConfigStore()).thenReturn(mWifiApConfigStore);
- WifiConfiguration config1 = new WifiConfiguration();
- config1.SSID = "ThisIsAConfig";
- SoftApModeConfiguration softApConfig1 =
- new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, config1);
- WifiConfiguration config2 = new WifiConfiguration();
- config2.SSID = "ThisIsASecondConfig";
- SoftApModeConfiguration softApConfig2 =
- new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, config2);
+ Builder configBuilder1 = new SoftApConfiguration.Builder();
+ configBuilder1.setSsid("ThisIsAConfig");
+ SoftApModeConfiguration softApConfig1 = new SoftApModeConfiguration(
+ WifiManager.IFACE_IP_MODE_TETHERED, configBuilder1.build());
+ Builder configBuilder2 = new SoftApConfiguration.Builder();
+ configBuilder2.setSsid("ThisIsASecondConfig");
+ SoftApModeConfiguration softApConfig2 = new SoftApModeConfiguration(
+ WifiManager.IFACE_IP_MODE_TETHERED, configBuilder2.build());
doAnswer(new Answer<SoftApManager>() {
public SoftApManager answer(InvocationOnMock invocation) {
@@ -924,8 +925,8 @@ public class ActiveModeWardenTest extends WifiBaseTest {
when(mWifiInjector.getWifiApConfigStore()).thenReturn(mWifiApConfigStore);
SoftApModeConfiguration tetherConfig =
new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, null);
- WifiConfiguration lohsConfigWC = WifiApConfigStore.generateLocalOnlyHotspotConfig(mContext,
- WifiConfiguration.AP_BAND_2GHZ, null);
+ SoftApConfiguration lohsConfigWC = WifiApConfigStore.generateLocalOnlyHotspotConfig(
+ mContext, SoftApConfiguration.BAND_2GHZ, null);
SoftApModeConfiguration lohsConfig =
new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_LOCAL_ONLY, lohsConfigWC);
diff --git a/tests/wifitests/src/com/android/server/wifi/HostapdHalTest.java b/tests/wifitests/src/com/android/server/wifi/HostapdHalTest.java
index 94f5eb77c..49c6123a1 100644
--- a/tests/wifitests/src/com/android/server/wifi/HostapdHalTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/HostapdHalTest.java
@@ -30,7 +30,8 @@ import android.hardware.wifi.hostapd.V1_0.IHostapd;
import android.hardware.wifi.hostapd.V1_1.IHostapdCallback;
import android.hidl.manager.V1_0.IServiceManager;
import android.hidl.manager.V1_0.IServiceNotification;
-import android.net.wifi.WifiConfiguration;
+import android.net.wifi.SoftApConfiguration;
+import android.net.wifi.SoftApConfiguration.Builder;
import android.os.Handler;
import android.os.IHwBinder;
import android.os.RemoteException;
@@ -220,15 +221,15 @@ public class HostapdHalTest extends WifiBaseTest {
executeAndValidateInitializationSequence();
final int apChannel = 6;
- WifiConfiguration configuration = new WifiConfiguration();
- configuration.SSID = NETWORK_SSID;
- configuration.hiddenSSID = false;
- configuration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA2_PSK);
- configuration.preSharedKey = NETWORK_PSK;
- configuration.apChannel = apChannel;
- configuration.apBand = WifiConfiguration.AP_BAND_2GHZ;
+ Builder configurationBuilder = new SoftApConfiguration.Builder();
+ configurationBuilder.setSsid(NETWORK_SSID);
+ configurationBuilder.setHiddenSsid(false);
+ configurationBuilder.setWpa2Passphrase(NETWORK_PSK);
+ configurationBuilder.setChannel(apChannel);
+ configurationBuilder.setBand(SoftApConfiguration.BAND_2GHZ);
- assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME, configuration, mSoftApListener));
+ assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME,
+ configurationBuilder.build(), mSoftApListener));
verify(mIHostapdMock).addAccessPoint(any(), any());
assertEquals(IFACE_NAME, mIfaceParamsCaptor.getValue().ifaceName);
@@ -254,14 +255,14 @@ public class HostapdHalTest extends WifiBaseTest {
executeAndValidateInitializationSequence();
final int apChannel = 18;
- WifiConfiguration configuration = new WifiConfiguration();
- configuration.SSID = NETWORK_SSID;
- configuration.hiddenSSID = true;
- configuration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
- configuration.apChannel = apChannel;
- configuration.apBand = WifiConfiguration.AP_BAND_5GHZ;
+ Builder configurationBuilder = new SoftApConfiguration.Builder();
+ configurationBuilder.setSsid(NETWORK_SSID);
+ configurationBuilder.setHiddenSsid(true);
+ configurationBuilder.setChannel(apChannel);
+ configurationBuilder.setBand(SoftApConfiguration.BAND_5GHZ);
- assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME, configuration, mSoftApListener));
+ assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME,
+ configurationBuilder.build(), mSoftApListener));
verify(mIHostapdMock).addAccessPoint(any(), any());
assertEquals(IFACE_NAME, mIfaceParamsCaptor.getValue().ifaceName);
@@ -287,15 +288,15 @@ public class HostapdHalTest extends WifiBaseTest {
executeAndValidateInitializationSequence();
final int apChannel = 18;
- WifiConfiguration configuration = new WifiConfiguration();
- configuration.SSID = NETWORK_SSID;
- configuration.hiddenSSID = true;
- configuration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA2_PSK);
- configuration.preSharedKey = NETWORK_PSK;
- configuration.apChannel = apChannel;
- configuration.apBand = WifiConfiguration.AP_BAND_5GHZ;
+ Builder configurationBuilder = new SoftApConfiguration.Builder();
+ configurationBuilder.setSsid(NETWORK_SSID);
+ configurationBuilder.setHiddenSsid(true);
+ configurationBuilder.setWpa2Passphrase(NETWORK_PSK);
+ configurationBuilder.setChannel(apChannel);
+ configurationBuilder.setBand(SoftApConfiguration.BAND_5GHZ);
- assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME, configuration, mSoftApListener));
+ assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME,
+ configurationBuilder.build(), mSoftApListener));
verify(mIHostapdMock).addAccessPoint(any(), any());
assertEquals(IFACE_NAME, mIfaceParamsCaptor.getValue().ifaceName);
@@ -325,15 +326,15 @@ public class HostapdHalTest extends WifiBaseTest {
executeAndValidateInitializationSequence();
final int apChannel = 6;
- WifiConfiguration configuration = new WifiConfiguration();
- configuration.SSID = NETWORK_SSID;
- configuration.hiddenSSID = false;
- configuration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA2_PSK);
- configuration.preSharedKey = NETWORK_PSK;
- configuration.apChannel = apChannel;
- configuration.apBand = WifiConfiguration.AP_BAND_2GHZ;
+ Builder configurationBuilder = new SoftApConfiguration.Builder();
+ configurationBuilder.setSsid(NETWORK_SSID);
+ configurationBuilder.setHiddenSsid(false);
+ configurationBuilder.setWpa2Passphrase(NETWORK_PSK);
+ configurationBuilder.setChannel(apChannel);
+ configurationBuilder.setBand(SoftApConfiguration.BAND_2GHZ);
- assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME, configuration, mSoftApListener));
+ assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME,
+ configurationBuilder.build(), mSoftApListener));
verify(mIHostapdMock).addAccessPoint(any(), any());
assertEquals(IFACE_NAME, mIfaceParamsCaptor.getValue().ifaceName);
@@ -363,15 +364,15 @@ public class HostapdHalTest extends WifiBaseTest {
executeAndValidateInitializationSequence();
final int apChannel = 6;
- WifiConfiguration configuration = new WifiConfiguration();
- configuration.SSID = NETWORK_SSID;
- configuration.hiddenSSID = false;
- configuration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA2_PSK);
- configuration.preSharedKey = NETWORK_PSK;
- configuration.apChannel = apChannel;
- configuration.apBand = WifiConfiguration.AP_BAND_2GHZ;
+ Builder configurationBuilder = new SoftApConfiguration.Builder();
+ configurationBuilder.setSsid(NETWORK_SSID);
+ configurationBuilder.setHiddenSsid(false);
+ configurationBuilder.setWpa2Passphrase(NETWORK_PSK);
+ configurationBuilder.setChannel(apChannel);
+ configurationBuilder.setBand(SoftApConfiguration.BAND_2GHZ);
- assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME, configuration, mSoftApListener));
+ assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME,
+ configurationBuilder.build(), mSoftApListener));
verify(mIHostapdMock).addAccessPoint(any(), any());
assertEquals(IFACE_NAME, mIfaceParamsCaptor.getValue().ifaceName);
@@ -400,15 +401,15 @@ public class HostapdHalTest extends WifiBaseTest {
executeAndValidateInitializationSequence();
final int apChannel = 6;
- WifiConfiguration configuration = new WifiConfiguration();
- configuration.SSID = NETWORK_SSID;
- configuration.hiddenSSID = false;
- configuration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA2_PSK);
- configuration.preSharedKey = NETWORK_PSK;
- configuration.apChannel = apChannel;
- configuration.apBand = WifiConfiguration.AP_BAND_ANY;
+ Builder configurationBuilder = new SoftApConfiguration.Builder();
+ configurationBuilder.setSsid(NETWORK_SSID);
+ configurationBuilder.setHiddenSsid(false);
+ configurationBuilder.setWpa2Passphrase(NETWORK_PSK);
+ configurationBuilder.setChannel(apChannel);
+ configurationBuilder.setBand(SoftApConfiguration.BAND_ANY);
- assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME, configuration, mSoftApListener));
+ assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME,
+ configurationBuilder.build(), mSoftApListener));
verify(mIHostapdMock).addAccessPoint(any(), any());
assertEquals(IFACE_NAME, mIfaceParamsCaptor.getValue().ifaceName);
@@ -438,15 +439,15 @@ public class HostapdHalTest extends WifiBaseTest {
executeAndValidateInitializationSequence();
final int apChannel = 6;
- WifiConfiguration configuration = new WifiConfiguration();
- configuration.SSID = NETWORK_SSID;
- configuration.hiddenSSID = false;
- configuration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA2_PSK);
- configuration.preSharedKey = NETWORK_PSK;
- configuration.apChannel = apChannel;
- configuration.apBand = WifiConfiguration.AP_BAND_ANY;
+ Builder configurationBuilder = new SoftApConfiguration.Builder();
+ configurationBuilder.setSsid(NETWORK_SSID);
+ configurationBuilder.setHiddenSsid(false);
+ configurationBuilder.setWpa2Passphrase(NETWORK_PSK);
+ configurationBuilder.setChannel(apChannel);
+ configurationBuilder.setBand(SoftApConfiguration.BAND_ANY);
- assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME, configuration, mSoftApListener));
+ assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME,
+ configurationBuilder.build(), mSoftApListener));
verify(mIHostapdMock).addAccessPoint(any(), any());
assertEquals(IFACE_NAME, mIfaceParamsCaptor.getValue().ifaceName);
@@ -504,14 +505,15 @@ public class HostapdHalTest extends WifiBaseTest {
executeAndValidateInitializationSequenceV1_1(false);
- WifiConfiguration configuration = new WifiConfiguration();
- configuration.SSID = NETWORK_SSID;
- configuration.hiddenSSID = false;
- configuration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA2_PSK);
- configuration.preSharedKey = NETWORK_PSK;
- configuration.apBand = WifiConfiguration.AP_BAND_ANY;
+ Builder configurationBuilder = new SoftApConfiguration.Builder();
+ configurationBuilder.setSsid(NETWORK_SSID);
+ configurationBuilder.setHiddenSsid(false);
+ configurationBuilder.setWpa2Passphrase(NETWORK_PSK);
+ configurationBuilder.setBand(SoftApConfiguration.BAND_ANY);
- assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME, configuration, mSoftApListener));
+
+ assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME,
+ configurationBuilder.build(), mSoftApListener));
verify(mIHostapdMockV1_1).addAccessPoint_1_1(any(), any());
assertEquals(IFACE_NAME, mIfaceParamsCaptorV1_1.getValue().V1_0.ifaceName);
@@ -532,23 +534,6 @@ public class HostapdHalTest extends WifiBaseTest {
}
/**
- * Verifies the failure handling in addition of access point with an invalid band.
- */
- @Test
- public void testAddAccessPointInvalidBandFailure() throws Exception {
- executeAndValidateInitializationSequence();
-
- WifiConfiguration configuration = new WifiConfiguration();
- configuration.SSID = NETWORK_SSID;
- configuration.hiddenSSID = true;
- configuration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
- configuration.apBand = WifiConfiguration.AP_BAND_5GHZ + 1;
-
- assertFalse(mHostapdHal.addAccessPoint(IFACE_NAME, configuration, mSoftApListener));
- verify(mIHostapdMock, never()).addAccessPoint(any(), any());
- }
-
- /**
* Verifies the failure handling in addition of access point.
*/
@Test
@@ -556,14 +541,14 @@ public class HostapdHalTest extends WifiBaseTest {
executeAndValidateInitializationSequence();
when(mIHostapdMock.addAccessPoint(any(), any())).thenReturn(mStatusFailure);
- WifiConfiguration configuration = new WifiConfiguration();
- configuration.SSID = NETWORK_SSID;
- configuration.hiddenSSID = true;
- configuration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
- configuration.apChannel = 6;
- configuration.apBand = WifiConfiguration.AP_BAND_2GHZ;
+ Builder configurationBuilder = new SoftApConfiguration.Builder();
+ configurationBuilder.setSsid(NETWORK_SSID);
+ configurationBuilder.setHiddenSsid(true);
+ configurationBuilder.setChannel(6);
+ configurationBuilder.setBand(SoftApConfiguration.BAND_2GHZ);
- assertFalse(mHostapdHal.addAccessPoint(IFACE_NAME, configuration, mSoftApListener));
+ assertFalse(mHostapdHal.addAccessPoint(IFACE_NAME,
+ configurationBuilder.build(), mSoftApListener));
verify(mIHostapdMock).addAccessPoint(any(), any());
}
@@ -575,13 +560,13 @@ public class HostapdHalTest extends WifiBaseTest {
executeAndValidateInitializationSequence();
doThrow(new RemoteException()).when(mIHostapdMock).addAccessPoint(any(), any());
- WifiConfiguration configuration = new WifiConfiguration();
- configuration.SSID = NETWORK_SSID;
- configuration.hiddenSSID = true;
- configuration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
- configuration.apChannel = 6;
+ Builder configurationBuilder = new SoftApConfiguration.Builder();
+ configurationBuilder.setSsid(NETWORK_SSID);
+ configurationBuilder.setHiddenSsid(true);
+ configurationBuilder.setChannel(6);
- assertFalse(mHostapdHal.addAccessPoint(IFACE_NAME, configuration, mSoftApListener));
+ assertFalse(mHostapdHal.addAccessPoint(IFACE_NAME,
+ configurationBuilder.build(), mSoftApListener));
verify(mIHostapdMock).addAccessPoint(any(), any());
}
@@ -633,11 +618,12 @@ public class HostapdHalTest extends WifiBaseTest {
.thenReturn(mStatusSuccess);
executeAndValidateInitializationSequenceV1_1(false);
- WifiConfiguration configuration = new WifiConfiguration();
- configuration.SSID = NETWORK_SSID;
- configuration.apBand = WifiConfiguration.AP_BAND_2GHZ;
+ Builder configurationBuilder = new SoftApConfiguration.Builder();
+ configurationBuilder.setSsid(NETWORK_SSID);
+ configurationBuilder.setBand(SoftApConfiguration.BAND_2GHZ);
- assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME, configuration, mSoftApListener));
+ assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME,
+ configurationBuilder.build(), mSoftApListener));
verify(mIHostapdMockV1_1).addAccessPoint_1_1(any(), any());
// Trigger on failure.
diff --git a/tests/wifitests/src/com/android/server/wifi/LocalOnlyHotspotRequestInfoTest.java b/tests/wifitests/src/com/android/server/wifi/LocalOnlyHotspotRequestInfoTest.java
index 31ede2fd0..ddb1ad962 100644
--- a/tests/wifitests/src/com/android/server/wifi/LocalOnlyHotspotRequestInfoTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/LocalOnlyHotspotRequestInfoTest.java
@@ -29,8 +29,11 @@ import android.os.RemoteException;
import androidx.test.filters.SmallTest;
+import com.android.server.wifi.util.ApConfigUtil;
+
import org.junit.Before;
import org.junit.Test;
+import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@@ -149,9 +152,17 @@ public class LocalOnlyHotspotRequestInfoTest extends WifiBaseTest {
@Test
public void verifySendStartedMessage() throws Exception {
mLOHSRequestInfo = new LocalOnlyHotspotRequestInfo(mCallback, mDeathCallback, null);
- WifiConfiguration config = mock(WifiConfiguration.class);
+ SoftApConfiguration config = mock(SoftApConfiguration.class);
mLOHSRequestInfo.sendHotspotStartedMessage(config);
- verify(mCallback).onHotspotStarted(config);
+ WifiConfiguration expectedConfig = ApConfigUtil.convertToWifiConfiguration(config);
+ expectedConfig.networkId = WifiConfiguration.LOCAL_ONLY_NETWORK_ID;
+ ArgumentCaptor<WifiConfiguration> mWifiConfigCaptor =
+ ArgumentCaptor.forClass(WifiConfiguration.class);
+
+ verify(mCallback).onHotspotStarted(mWifiConfigCaptor.capture());
+ WifiConfigurationTestUtil.assertConfigurationEqualForSoftAp(
+ expectedConfig, mWifiConfigCaptor.getValue());
+
}
/**
diff --git a/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java b/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java
index 17dd4c6a9..b71492de5 100644
--- a/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java
@@ -16,7 +16,7 @@
package com.android.server.wifi;
-import static android.net.wifi.WifiConfiguration.KeyMgmt.WPA_PSK;
+
import static android.net.wifi.WifiManager.EXTRA_PREVIOUS_WIFI_AP_STATE;
import static android.net.wifi.WifiManager.EXTRA_WIFI_AP_FAILURE_REASON;
import static android.net.wifi.WifiManager.EXTRA_WIFI_AP_INTERFACE_NAME;
@@ -29,7 +29,9 @@ import static android.net.wifi.WifiManager.WIFI_AP_STATE_ENABLED;
import static android.net.wifi.WifiManager.WIFI_AP_STATE_ENABLING;
import static android.net.wifi.WifiManager.WIFI_AP_STATE_FAILED;
+
import static com.android.server.wifi.LocalOnlyHotspotRequestInfo.HOTSPOT_NO_ERROR;
+import static com.android.server.wifi.util.ApConfigUtil.DEFAULT_AP_CHANNEL;
import static com.google.common.truth.Truth.assertThat;
@@ -55,10 +57,12 @@ import android.database.ContentObserver;
import android.net.MacAddress;
import android.net.Uri;
import android.net.wifi.IApInterfaceEventCallback;
+import android.net.wifi.SoftApConfiguration;
+import android.net.wifi.SoftApConfiguration.Builder;
import android.net.wifi.SoftApInfo;
import android.net.wifi.WifiClient;
-import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
+import android.net.wifi.WifiScanner;
import android.os.UserHandle;
import android.os.test.TestLooper;
import android.provider.Settings;
@@ -110,7 +114,7 @@ public class SoftApManagerTest extends WifiBaseTest {
IApInterfaceEventCallback.BANDWIDTH_20;
private static final int TEST_AP_BANDWIDTH_IN_SOFTAPINFO = SoftApInfo.CHANNEL_WIDTH_20MHZ;
- private final WifiConfiguration mDefaultApConfig = createDefaultApConfig();
+ private final SoftApConfiguration mDefaultApConfig = createDefaultApConfig();
private ContentObserver mContentObserver;
private TestLooper mLooper;
@@ -161,14 +165,14 @@ public class SoftApManagerTest extends WifiBaseTest {
mTestSoftApInfo.setBandwidth(TEST_AP_BANDWIDTH_IN_SOFTAPINFO);
}
- private WifiConfiguration createDefaultApConfig() {
- WifiConfiguration defaultConfig = new WifiConfiguration();
- defaultConfig.SSID = DEFAULT_SSID;
- return defaultConfig;
+ private SoftApConfiguration createDefaultApConfig() {
+ Builder defaultConfigBuilder = new SoftApConfiguration.Builder();
+ defaultConfigBuilder.setSsid(DEFAULT_SSID);
+ return defaultConfigBuilder.build();
}
private SoftApManager createSoftApManager(SoftApModeConfiguration config, String countryCode) {
- if (config.getWifiConfiguration() == null) {
+ if (config.getSoftApConfiguration() == null) {
when(mWifiApConfigStore.getApConfiguration()).thenReturn(mDefaultApConfig);
}
SoftApManager newSoftApManager = new SoftApManager(mContext,
@@ -199,11 +203,11 @@ public class SoftApManagerTest extends WifiBaseTest {
/** Verifies startSoftAp will use provided config and start AP. */
@Test
public void startSoftApWithConfig() throws Exception {
- WifiConfiguration config = new WifiConfiguration();
- config.apBand = WifiConfiguration.AP_BAND_2GHZ;
- config.SSID = TEST_SSID;
- SoftApModeConfiguration apConfig =
- new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, config);
+ Builder configBuilder = new SoftApConfiguration.Builder();
+ configBuilder.setBand(SoftApConfiguration.BAND_2GHZ);
+ configBuilder.setSsid(TEST_SSID);
+ SoftApModeConfiguration apConfig = new SoftApModeConfiguration(
+ WifiManager.IFACE_IP_MODE_TETHERED, configBuilder.build());
startSoftApAndVerifyEnabled(apConfig);
}
@@ -213,12 +217,12 @@ public class SoftApManagerTest extends WifiBaseTest {
*/
@Test
public void startSoftApWithHiddenSsidTrueInConfig() throws Exception {
- WifiConfiguration config = new WifiConfiguration();
- config.apBand = WifiConfiguration.AP_BAND_2GHZ;
- config.SSID = TEST_SSID;
- config.hiddenSSID = true;
- SoftApModeConfiguration apConfig =
- new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, config);
+ Builder configBuilder = new SoftApConfiguration.Builder();
+ configBuilder.setBand(SoftApConfiguration.BAND_2GHZ);
+ configBuilder.setSsid(TEST_SSID);
+ configBuilder.setHiddenSsid(true);
+ SoftApModeConfiguration apConfig = new SoftApModeConfiguration(
+ WifiManager.IFACE_IP_MODE_TETHERED, configBuilder.build());
startSoftApAndVerifyEnabled(apConfig);
}
@@ -228,13 +232,12 @@ public class SoftApManagerTest extends WifiBaseTest {
*/
@Test
public void startSoftApWithPassphraseInConfig() throws Exception {
- WifiConfiguration config = new WifiConfiguration();
- config.apBand = WifiConfiguration.AP_BAND_5GHZ;
- config.SSID = TEST_SSID;
- config.allowedKeyManagement.set(WPA_PSK);
- config.preSharedKey = TEST_PASSWORD;
- SoftApModeConfiguration apConfig =
- new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, config);
+ Builder configBuilder = new SoftApConfiguration.Builder();
+ configBuilder.setBand(SoftApConfiguration.BAND_2GHZ);
+ configBuilder.setSsid(TEST_SSID);
+ configBuilder.setWpa2Passphrase(TEST_PASSWORD);
+ SoftApModeConfiguration apConfig = new SoftApModeConfiguration(
+ WifiManager.IFACE_IP_MODE_TETHERED, configBuilder.build());
startSoftApAndVerifyEnabled(apConfig);
}
@@ -287,7 +290,7 @@ public class SoftApManagerTest extends WifiBaseTest {
when(mWifiNative.setupInterfaceForSoftApMode(any())).thenReturn(null);
SoftApModeConfiguration config = new SoftApModeConfiguration(
- WifiManager.IFACE_IP_MODE_TETHERED, new WifiConfiguration());
+ WifiManager.IFACE_IP_MODE_TETHERED, new SoftApConfiguration.Builder().build());
when(mWifiApConfigStore.getApConfiguration()).thenReturn(null);
SoftApModeConfiguration nullApConfig =
@@ -332,7 +335,7 @@ public class SoftApManagerTest extends WifiBaseTest {
when(mWifiNative.setupInterfaceForSoftApMode(any())).thenReturn("");
SoftApModeConfiguration config = new SoftApModeConfiguration(
- WifiManager.IFACE_IP_MODE_TETHERED, new WifiConfiguration());
+ WifiManager.IFACE_IP_MODE_TETHERED, new SoftApConfiguration.Builder().build());
when(mWifiApConfigStore.getApConfiguration()).thenReturn(null);
SoftApModeConfiguration nullApConfig =
@@ -373,11 +376,11 @@ public class SoftApManagerTest extends WifiBaseTest {
*/
@Test
public void startSoftApOn5GhzFailGeneralErrorForNoCountryCode() throws Exception {
- WifiConfiguration config = new WifiConfiguration();
- config.apBand = WifiConfiguration.AP_BAND_5GHZ;
- config.SSID = TEST_SSID;
- SoftApModeConfiguration softApConfig =
- new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, config);
+ Builder configBuilder = new SoftApConfiguration.Builder();
+ configBuilder.setBand(SoftApConfiguration.BAND_5GHZ);
+ configBuilder.setSsid(TEST_SSID);
+ SoftApModeConfiguration softApConfig = new SoftApModeConfiguration(
+ WifiManager.IFACE_IP_MODE_TETHERED, configBuilder.build());
when(mWifiNative.setupInterfaceForSoftApMode(any())).thenReturn(TEST_INTERFACE_NAME);
@@ -418,11 +421,11 @@ public class SoftApManagerTest extends WifiBaseTest {
*/
@Test
public void startSoftApOn5GhzFailGeneralErrorForCountryCodeSetFailure() throws Exception {
- WifiConfiguration config = new WifiConfiguration();
- config.apBand = WifiConfiguration.AP_BAND_5GHZ;
- config.SSID = TEST_SSID;
- SoftApModeConfiguration softApConfig =
- new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, config);
+ Builder configBuilder = new SoftApConfiguration.Builder();
+ configBuilder.setBand(SoftApConfiguration.BAND_5GHZ);
+ configBuilder.setSsid(TEST_SSID);
+ SoftApModeConfiguration softApConfig = new SoftApModeConfiguration(
+ WifiManager.IFACE_IP_MODE_TETHERED, configBuilder.build());
when(mWifiNative.setupInterfaceForSoftApMode(any())).thenReturn(TEST_INTERFACE_NAME);
when(mWifiNative.setCountryCodeHal(
@@ -467,11 +470,11 @@ public class SoftApManagerTest extends WifiBaseTest {
*/
@Test
public void startSoftApOn24GhzNoFailForNoCountryCode() throws Exception {
- WifiConfiguration config = new WifiConfiguration();
- config.apBand = WifiConfiguration.AP_BAND_2GHZ;
- config.SSID = TEST_SSID;
- SoftApModeConfiguration softApConfig =
- new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, config);
+ Builder configBuilder = new SoftApConfiguration.Builder();
+ configBuilder.setBand(SoftApConfiguration.BAND_2GHZ);
+ configBuilder.setSsid(TEST_SSID);
+ SoftApModeConfiguration softApConfig = new SoftApModeConfiguration(
+ WifiManager.IFACE_IP_MODE_TETHERED, configBuilder.build());
startSoftApAndVerifyEnabled(softApConfig, null);
verify(mWifiNative, never()).setCountryCodeHal(eq(TEST_INTERFACE_NAME), any());
@@ -483,11 +486,11 @@ public class SoftApManagerTest extends WifiBaseTest {
*/
@Test
public void startSoftApOnAnyGhzNoFailForNoCountryCode() throws Exception {
- WifiConfiguration config = new WifiConfiguration();
- config.apBand = WifiConfiguration.AP_BAND_ANY;
- config.SSID = TEST_SSID;
- SoftApModeConfiguration softApConfig =
- new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, config);
+ Builder configBuilder = new SoftApConfiguration.Builder();
+ configBuilder.setBand(SoftApConfiguration.BAND_ANY);
+ configBuilder.setSsid(TEST_SSID);
+ SoftApModeConfiguration softApConfig = new SoftApModeConfiguration(
+ WifiManager.IFACE_IP_MODE_TETHERED, configBuilder.build());
startSoftApAndVerifyEnabled(softApConfig, null);
verify(mWifiNative, never()).setCountryCodeHal(eq(TEST_INTERFACE_NAME), any());
@@ -499,11 +502,11 @@ public class SoftApManagerTest extends WifiBaseTest {
*/
@Test
public void startSoftApOn2GhzNoFailForCountryCodeSetFailure() throws Exception {
- WifiConfiguration config = new WifiConfiguration();
- config.apBand = WifiConfiguration.AP_BAND_2GHZ;
- config.SSID = TEST_SSID;
- SoftApModeConfiguration softApConfig =
- new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, config);
+ Builder configBuilder = new SoftApConfiguration.Builder();
+ configBuilder.setBand(SoftApConfiguration.BAND_2GHZ);
+ configBuilder.setSsid(TEST_SSID);
+ SoftApModeConfiguration softApConfig = new SoftApModeConfiguration(
+ WifiManager.IFACE_IP_MODE_TETHERED, configBuilder.build());
when(mWifiNative.setCountryCodeHal(eq(TEST_INTERFACE_NAME), any())).thenReturn(false);
@@ -518,11 +521,11 @@ public class SoftApManagerTest extends WifiBaseTest {
*/
@Test
public void startSoftApOnAnyNoFailForCountryCodeSetFailure() throws Exception {
- WifiConfiguration config = new WifiConfiguration();
- config.apBand = WifiConfiguration.AP_BAND_ANY;
- config.SSID = TEST_SSID;
- SoftApModeConfiguration softApConfig =
- new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, config);
+ Builder configBuilder = new SoftApConfiguration.Builder();
+ configBuilder.setBand(SoftApConfiguration.BAND_ANY);
+ configBuilder.setSsid(TEST_SSID);
+ SoftApModeConfiguration softApConfig = new SoftApModeConfiguration(
+ WifiManager.IFACE_IP_MODE_TETHERED, configBuilder.build());
when(mWifiNative.setCountryCodeHal(eq(TEST_INTERFACE_NAME), any())).thenReturn(false);
@@ -537,13 +540,14 @@ public class SoftApManagerTest extends WifiBaseTest {
*/
@Test
public void startSoftApFailNoChannel() throws Exception {
- WifiConfiguration config = new WifiConfiguration();
- config.apBand = -2;
- config.apChannel = 0;
- config.SSID = TEST_SSID;
- SoftApModeConfiguration softApConfig =
- new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, config);
-
+ Builder configBuilder = new SoftApConfiguration.Builder();
+ configBuilder.setBand(SoftApConfiguration.BAND_5GHZ);
+ configBuilder.setChannel(0);
+ configBuilder.setSsid(TEST_SSID);
+ SoftApModeConfiguration softApConfig = new SoftApModeConfiguration(
+ WifiManager.IFACE_IP_MODE_TETHERED, configBuilder.build());
+
+ when(mWifiNative.getChannelsForBand(WifiScanner.WIFI_BAND_5_GHZ)).thenReturn(null);
when(mWifiNative.setupInterfaceForSoftApMode(any())).thenReturn(TEST_INTERFACE_NAME);
when(mWifiNative.isHalStarted()).thenReturn(true);
@@ -834,11 +838,12 @@ public class SoftApManagerTest extends WifiBaseTest {
@Test
public void updatesMetricsOnChannelSwitchedEventDetectsBandUnsatisfiedOnBand2Ghz()
throws Exception {
- WifiConfiguration config = createDefaultApConfig();
- config.apBand = WifiConfiguration.AP_BAND_2GHZ;
+ SoftApConfiguration config = createDefaultApConfig();
+ Builder configBuilder = new SoftApConfiguration.Builder(config);
+ configBuilder.setBand(SoftApConfiguration.BAND_2GHZ);
- SoftApModeConfiguration apConfig =
- new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, config);
+ SoftApModeConfiguration apConfig = new SoftApModeConfiguration(
+ WifiManager.IFACE_IP_MODE_TETHERED, configBuilder.build());
startSoftApAndVerifyEnabled(apConfig);
final int channelFrequency = 5180;
@@ -855,11 +860,12 @@ public class SoftApManagerTest extends WifiBaseTest {
@Test
public void updatesMetricsOnChannelSwitchedEventDetectsBandUnsatisfiedOnBand5Ghz()
throws Exception {
- WifiConfiguration config = createDefaultApConfig();
- config.apBand = WifiConfiguration.AP_BAND_5GHZ;
+ SoftApConfiguration config = createDefaultApConfig();
+ Builder configBuilder = new SoftApConfiguration.Builder(config);
+ configBuilder.setBand(SoftApConfiguration.BAND_5GHZ);
- SoftApModeConfiguration apConfig =
- new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, config);
+ SoftApModeConfiguration apConfig = new SoftApModeConfiguration(
+ WifiManager.IFACE_IP_MODE_TETHERED, configBuilder.build());
startSoftApAndVerifyEnabled(apConfig);
final int channelFrequency = 2437;
@@ -876,11 +882,12 @@ public class SoftApManagerTest extends WifiBaseTest {
@Test
public void updatesMetricsOnChannelSwitchedEventDoesNotDetectBandUnsatisfiedOnBandAny()
throws Exception {
- WifiConfiguration config = createDefaultApConfig();
- config.apBand = WifiConfiguration.AP_BAND_ANY;
+ SoftApConfiguration config = createDefaultApConfig();
+ Builder configBuilder = new SoftApConfiguration.Builder(config);
+ configBuilder.setBand(SoftApConfiguration.BAND_ANY);
- SoftApModeConfiguration apConfig =
- new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, config);
+ SoftApModeConfiguration apConfig = new SoftApModeConfiguration(
+ WifiManager.IFACE_IP_MODE_TETHERED, configBuilder.build());
startSoftApAndVerifyEnabled(apConfig);
final int channelFrequency = 5220;
@@ -1238,12 +1245,13 @@ public class SoftApManagerTest extends WifiBaseTest {
@Test
public void resetsFactoryMacWhenRandomizationOff() throws Exception {
- WifiConfiguration config = new WifiConfiguration();
- config.apBand = WifiConfiguration.AP_BAND_2GHZ;
- config.SSID = TEST_SSID;
- config.BSSID = null;
- SoftApModeConfiguration apConfig =
- new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, config);
+ Builder configBuilder = new SoftApConfiguration.Builder();
+ configBuilder.setBand(SoftApConfiguration.BAND_2GHZ);
+ configBuilder.setSsid(TEST_SSID);
+ configBuilder.setBssid(null);
+
+ SoftApModeConfiguration apConfig = new SoftApModeConfiguration(
+ WifiManager.IFACE_IP_MODE_TETHERED, configBuilder.build());
ArgumentCaptor<MacAddress> mac = ArgumentCaptor.forClass(MacAddress.class);
when(mWifiNative.getFactoryMacAddress(TEST_INTERFACE_NAME)).thenReturn(TEST_MAC_ADDRESS);
when(mWifiNative.setMacAddress(eq(TEST_INTERFACE_NAME), mac.capture())).thenReturn(true);
@@ -1255,12 +1263,12 @@ public class SoftApManagerTest extends WifiBaseTest {
@Test
public void setsCustomMac() throws Exception {
- WifiConfiguration config = new WifiConfiguration();
- config.apBand = WifiConfiguration.AP_BAND_2GHZ;
- config.SSID = TEST_SSID;
- config.BSSID = "23:34:45:56:67:78";
+ Builder configBuilder = new SoftApConfiguration.Builder();
+ configBuilder.setBand(SoftApConfiguration.BAND_2GHZ);
+ configBuilder.setSsid(TEST_SSID);
+ configBuilder.setBssid(MacAddress.fromString("23:34:45:56:67:78"));
SoftApModeConfiguration apConfig = new SoftApModeConfiguration(
- IFACE_IP_MODE_LOCAL_ONLY, config);
+ IFACE_IP_MODE_LOCAL_ONLY, configBuilder.build());
ArgumentCaptor<MacAddress> mac = ArgumentCaptor.forClass(MacAddress.class);
when(mWifiNative.setMacAddress(eq(TEST_INTERFACE_NAME), mac.capture())).thenReturn(true);
@@ -1291,16 +1299,22 @@ public class SoftApManagerTest extends WifiBaseTest {
/** Starts soft AP and verifies that it is enabled successfully. */
protected void startSoftApAndVerifyEnabled(
SoftApModeConfiguration softApConfig, String countryCode) throws Exception {
- WifiConfiguration expectedConfig;
+ SoftApConfiguration expectedConfig;
InOrder order = inOrder(mCallback, mWifiNative);
mSoftApManager = createSoftApManager(softApConfig, countryCode);
- WifiConfiguration config = softApConfig.getWifiConfiguration();
+ SoftApConfiguration config = softApConfig.getSoftApConfiguration();
if (config == null) {
when(mWifiApConfigStore.getApConfiguration()).thenReturn(mDefaultApConfig);
- expectedConfig = new WifiConfiguration(mDefaultApConfig);
+ expectedConfig = new SoftApConfiguration.Builder(mDefaultApConfig)
+ .setBand(SoftApConfiguration.BAND_2GHZ)
+ .setChannel(DEFAULT_AP_CHANNEL)
+ .build();
} else {
- expectedConfig = new WifiConfiguration(config);
+ expectedConfig = new SoftApConfiguration.Builder(config)
+ .setBand(SoftApConfiguration.BAND_2GHZ)
+ .setChannel(DEFAULT_AP_CHANNEL)
+ .build();
}
ArgumentCaptor<ContentObserver> observerCaptor = ArgumentCaptor.forClass(
@@ -1310,16 +1324,17 @@ public class SoftApManagerTest extends WifiBaseTest {
when(mWifiNative.setupInterfaceForSoftApMode(any()))
.thenReturn(TEST_INTERFACE_NAME);
+
mSoftApManager.start();
mLooper.dispatchAll();
order.verify(mWifiNative).setupInterfaceForSoftApMode(
mWifiNativeInterfaceCallbackCaptor.capture());
- ArgumentCaptor<WifiConfiguration> configCaptor =
- ArgumentCaptor.forClass(WifiConfiguration.class);
+ ArgumentCaptor<SoftApConfiguration> configCaptor =
+ ArgumentCaptor.forClass(SoftApConfiguration.class);
order.verify(mCallback).onStateChanged(WifiManager.WIFI_AP_STATE_ENABLING, 0);
order.verify(mWifiNative).startSoftAp(eq(TEST_INTERFACE_NAME),
configCaptor.capture(), mSoftApListenerCaptor.capture());
- WifiConfigurationTestUtil.assertConfigurationEqual(expectedConfig, configCaptor.getValue());
+ assertThat(configCaptor.getValue()).isEqualTo(expectedConfig);
mWifiNativeInterfaceCallbackCaptor.getValue().onUp(TEST_INTERFACE_NAME);
mLooper.dispatchAll();
order.verify(mCallback).onStateChanged(WifiManager.WIFI_AP_STATE_ENABLED, 0);
diff --git a/tests/wifitests/src/com/android/server/wifi/SoftApStoreDataTest.java b/tests/wifitests/src/com/android/server/wifi/SoftApStoreDataTest.java
index 577767c16..d368e9510 100644
--- a/tests/wifitests/src/com/android/server/wifi/SoftApStoreDataTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/SoftApStoreDataTest.java
@@ -18,14 +18,13 @@ package com.android.server.wifi;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import android.net.wifi.WifiConfiguration;
+import android.net.wifi.SoftApConfiguration;
import android.util.Xml;
import androidx.test.filters.SmallTest;
@@ -51,18 +50,20 @@ import java.nio.charset.StandardCharsets;
@SmallTest
public class SoftApStoreDataTest extends WifiBaseTest {
private static final String TEST_SSID = "SSID";
- private static final String TEST_PRESHARED_KEY = "Test";
+ private static final String TEST_WPA2_PASSPHRASE = "Test";
private static final boolean TEST_HIDDEN = false;
- private static final int TEST_BAND = WifiConfiguration.AP_BAND_ANY;
+ private static final int TEST_BAND = SoftApConfiguration.BAND_ANY;
private static final int TEST_CHANNEL = 0;
+ private static final int TEST_SECURITY = SoftApConfiguration.SECURITY_TYPE_WPA2_PSK;
+
private static final String TEST_SOFTAP_CONFIG_XML_STRING =
"<string name=\"SSID\">" + TEST_SSID + "</string>\n"
+ "<int name=\"Band\" value=\"" + TEST_BAND + "\" />\n"
+ "<int name=\"Channel\" value=\"" + TEST_CHANNEL + "\" />\n"
+ "<boolean name=\"HiddenSSID\" value=\"" + TEST_HIDDEN + "\" />\n"
- + "<byte-array name=\"AllowedKeyMgmt\" num=\"1\">02</byte-array>\n"
- + "<string name=\"PreSharedKey\">" + TEST_PRESHARED_KEY + "</string>\n";
+ + "<int name=\"SecurityType\" value=\"" + TEST_SECURITY + "\" />\n"
+ + "<string name=\"Wpa2Passphrase\">" + TEST_WPA2_PASSPHRASE + "</string>\n";
@Mock SoftApStoreData.DataSource mDataSource;
SoftApStoreData mSoftApStoreData;
@@ -134,14 +135,13 @@ public class SoftApStoreDataTest extends WifiBaseTest {
*/
@Test
public void serializeSoftAp() throws Exception {
- WifiConfiguration softApConfig = new WifiConfiguration();
- softApConfig.SSID = TEST_SSID;
- softApConfig.preSharedKey = TEST_PRESHARED_KEY;
- softApConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
- softApConfig.apBand = TEST_BAND;
- softApConfig.apChannel = TEST_CHANNEL;
-
- when(mDataSource.toSerialize()).thenReturn(softApConfig);
+ SoftApConfiguration.Builder softApConfigBuilder = new SoftApConfiguration.Builder();
+ softApConfigBuilder.setSsid(TEST_SSID);
+ softApConfigBuilder.setWpa2Passphrase(TEST_WPA2_PASSPHRASE);
+ softApConfigBuilder.setBand(TEST_BAND);
+ softApConfigBuilder.setChannel(TEST_CHANNEL);
+
+ when(mDataSource.toSerialize()).thenReturn(softApConfigBuilder.build());
byte[] actualData = serializeData();
assertEquals(TEST_SOFTAP_CONFIG_XML_STRING, new String(actualData));
}
@@ -155,17 +155,17 @@ public class SoftApStoreDataTest extends WifiBaseTest {
public void deserializeSoftAp() throws Exception {
deserializeData(TEST_SOFTAP_CONFIG_XML_STRING.getBytes());
- ArgumentCaptor<WifiConfiguration> softapConfigCaptor =
- ArgumentCaptor.forClass(WifiConfiguration.class);
+ ArgumentCaptor<SoftApConfiguration> softapConfigCaptor =
+ ArgumentCaptor.forClass(SoftApConfiguration.class);
verify(mDataSource).fromDeserialized(softapConfigCaptor.capture());
- WifiConfiguration softApConfig = softapConfigCaptor.getValue();
+ SoftApConfiguration softApConfig = softapConfigCaptor.getValue();
assertNotNull(softApConfig);
- assertEquals(softApConfig.SSID, TEST_SSID);
- assertEquals(softApConfig.preSharedKey, TEST_PRESHARED_KEY);
- assertTrue(softApConfig.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.WPA_PSK));
- assertEquals(softApConfig.hiddenSSID, TEST_HIDDEN);
- assertEquals(softApConfig.apBand, TEST_BAND);
- assertEquals(softApConfig.apChannel, TEST_CHANNEL);
+ assertEquals(softApConfig.getSsid(), TEST_SSID);
+ assertEquals(softApConfig.getWpa2Passphrase(), TEST_WPA2_PASSPHRASE);
+ assertEquals(softApConfig.getSecurityType(), SoftApConfiguration.SECURITY_TYPE_WPA2_PSK);
+ assertEquals(softApConfig.isHiddenSsid(), TEST_HIDDEN);
+ assertEquals(softApConfig.getBand(), TEST_BAND);
+ assertEquals(softApConfig.getChannel(), TEST_CHANNEL);
}
/**
@@ -175,31 +175,33 @@ public class SoftApStoreDataTest extends WifiBaseTest {
*/
@Test
public void serializeDeserializeSoftAp() throws Exception {
- WifiConfiguration softApConfig = new WifiConfiguration();
- softApConfig.SSID = TEST_SSID;
- softApConfig.preSharedKey = TEST_PRESHARED_KEY;
- softApConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
- softApConfig.apBand = TEST_BAND;
- softApConfig.apChannel = TEST_CHANNEL;
+ SoftApConfiguration.Builder softApConfigBuilder = new SoftApConfiguration.Builder();
+ softApConfigBuilder.setSsid(TEST_SSID);
+ softApConfigBuilder.setWpa2Passphrase(TEST_WPA2_PASSPHRASE);
+ softApConfigBuilder.setBand(TEST_BAND);
+ softApConfigBuilder.setChannel(TEST_CHANNEL);
+
+ SoftApConfiguration softApConfig = softApConfigBuilder.build();
// Serialize first.
- when(mDataSource.toSerialize()).thenReturn(softApConfig);
+ when(mDataSource.toSerialize()).thenReturn(softApConfigBuilder.build());
byte[] serializedData = serializeData();
// Now deserialize first.
deserializeData(serializedData);
- ArgumentCaptor<WifiConfiguration> softapConfigCaptor =
- ArgumentCaptor.forClass(WifiConfiguration.class);
+ ArgumentCaptor<SoftApConfiguration> softapConfigCaptor =
+ ArgumentCaptor.forClass(SoftApConfiguration.class);
verify(mDataSource).fromDeserialized(softapConfigCaptor.capture());
- WifiConfiguration softApConfigDeserialized = softapConfigCaptor.getValue();
+ SoftApConfiguration softApConfigDeserialized = softapConfigCaptor.getValue();
assertNotNull(softApConfigDeserialized);
- assertEquals(softApConfig.SSID, softApConfigDeserialized.SSID);
- assertEquals(softApConfig.preSharedKey, softApConfigDeserialized.preSharedKey);
- assertEquals(softApConfig.allowedKeyManagement,
- softApConfigDeserialized.allowedKeyManagement);
- assertEquals(softApConfig.hiddenSSID, softApConfigDeserialized.hiddenSSID);
- assertEquals(softApConfig.apBand, softApConfigDeserialized.apBand);
- assertEquals(softApConfig.apChannel, softApConfigDeserialized.apChannel);
+ assertEquals(softApConfig.getSsid(), softApConfigDeserialized.getSsid());
+ assertEquals(softApConfig.getWpa2Passphrase(),
+ softApConfigDeserialized.getWpa2Passphrase());
+ assertEquals(softApConfig.getSecurityType(),
+ softApConfigDeserialized.getSecurityType());
+ assertEquals(softApConfig.isHiddenSsid(), softApConfigDeserialized.isHiddenSsid());
+ assertEquals(softApConfig.getBand(), softApConfigDeserialized.getBand());
+ assertEquals(softApConfig.getChannel(), softApConfigDeserialized.getChannel());
}
}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java b/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java
index ba3fbeeff..d0670181d 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java
@@ -16,6 +16,8 @@
package com.android.server.wifi;
+import static android.net.wifi.SoftApConfiguration.SECURITY_TYPE_WPA2_PSK;
+
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
@@ -32,8 +34,7 @@ import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.net.MacAddress;
import android.net.wifi.SoftApConfiguration;
-import android.net.wifi.WifiConfiguration;
-import android.net.wifi.WifiConfiguration.KeyMgmt;
+import android.net.wifi.SoftApConfiguration.Builder;
import android.os.Build;
import android.os.Handler;
import android.os.test.TestLooper;
@@ -152,71 +153,69 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
}
/**
- * Generate a WifiConfiguration based on the specified parameters.
+ * Generate a SoftApConfiguration based on the specified parameters.
*/
- private WifiConfiguration setupApConfig(
+ private SoftApConfiguration setupApConfig(
String ssid, String preSharedKey, int keyManagement, int band, int channel,
boolean hiddenSSID) {
- WifiConfiguration config = new WifiConfiguration();
- config.SSID = ssid;
- config.preSharedKey = preSharedKey;
- config.allowedKeyManagement.set(keyManagement);
- config.apBand = band;
- config.apChannel = channel;
- config.hiddenSSID = hiddenSSID;
- return config;
+ Builder configBuilder = new SoftApConfiguration.Builder();
+ configBuilder.setSsid(ssid);
+ configBuilder.setWpa2Passphrase(preSharedKey);
+ configBuilder.setBand(band);
+ configBuilder.setChannel(channel);
+ configBuilder.setHiddenSsid(hiddenSSID);
+ return configBuilder.build();
}
- private void writeLegacyApConfigFile(WifiConfiguration config) throws Exception {
+ private void writeLegacyApConfigFile(SoftApConfiguration config) throws Exception {
try (DataOutputStream out = new DataOutputStream(new BufferedOutputStream(
new FileOutputStream(mLegacyApConfigFile)))) {
out.writeInt(WifiApConfigStore.AP_CONFIG_FILE_VERSION);
- out.writeUTF(config.SSID);
- out.writeInt(config.apBand);
- out.writeInt(config.apChannel);
- out.writeBoolean(config.hiddenSSID);
- int authType = config.getAuthType();
- out.writeInt(authType);
- if (authType != KeyMgmt.NONE) {
- out.writeUTF(config.preSharedKey);
+ out.writeUTF(config.getSsid());
+ out.writeInt(config.getBand());
+ out.writeInt(config.getChannel());
+ out.writeBoolean(config.isHiddenSsid());
+ int securityType = config.getSecurityType();
+ out.writeInt(securityType);
+ if (securityType == SECURITY_TYPE_WPA2_PSK) {
+ out.writeUTF(config.getWpa2Passphrase());
}
} catch (IOException e) {
fail("Error writing hotspot configuration" + e);
}
}
- private void verifyApConfig(WifiConfiguration config1, WifiConfiguration config2) {
- assertEquals(config1.SSID, config2.SSID);
- assertEquals(config1.preSharedKey, config2.preSharedKey);
- assertEquals(config1.allowedKeyManagement, config2.allowedKeyManagement);
- assertEquals(config1.getAuthType(), config2.getAuthType());
- assertEquals(config1.apBand, config2.apBand);
- assertEquals(config1.apChannel, config2.apChannel);
- assertEquals(config1.hiddenSSID, config2.hiddenSSID);
+ private void verifyApConfig(SoftApConfiguration config1, SoftApConfiguration config2) {
+ assertEquals(config1.getSsid(), config2.getSsid());
+ assertEquals(config1.getWpa2Passphrase(), config2.getWpa2Passphrase());
+ assertEquals(config1.getSecurityType(), config2.getSecurityType());
+ assertEquals(config1.getBand(), config2.getBand());
+ assertEquals(config1.getChannel(), config2.getChannel());
+ assertEquals(config1.isHiddenSsid(), config2.isHiddenSsid());
}
- private void verifyDefaultApConfig(WifiConfiguration config, String expectedSsid) {
- String[] splitSsid = config.SSID.split("_");
+ private void verifyDefaultApConfig(SoftApConfiguration config, String expectedSsid) {
+ String[] splitSsid = config.getSsid().split("_");
assertEquals(2, splitSsid.length);
assertEquals(expectedSsid, splitSsid[0]);
- assertEquals(WifiConfiguration.AP_BAND_2GHZ, config.apBand);
- assertFalse(config.hiddenSSID);
+ assertEquals(SoftApConfiguration.BAND_2GHZ, config.getBand());
+ assertFalse(config.isHiddenSsid());
int randomPortion = Integer.parseInt(splitSsid[1]);
assertTrue(randomPortion >= RAND_SSID_INT_MIN && randomPortion <= RAND_SSID_INT_MAX);
- assertTrue(config.allowedKeyManagement.get(KeyMgmt.WPA2_PSK));
- assertEquals(15, config.preSharedKey.length());
+ assertEquals(SECURITY_TYPE_WPA2_PSK, config.getSecurityType());
+ assertEquals(15, config.getWpa2Passphrase().length());
}
- private void verifyDefaultLocalOnlyApConfig(WifiConfiguration config, String expectedSsid,
+ private void verifyDefaultLocalOnlyApConfig(SoftApConfiguration config, String expectedSsid,
int expectedApBand) {
- String[] splitSsid = config.SSID.split("_");
+ String[] splitSsid = config.getSsid().split("_");
assertEquals(2, splitSsid.length);
assertEquals(expectedSsid, splitSsid[0]);
- assertEquals(expectedApBand, config.apBand);
+ assertEquals(expectedApBand, config.getBand());
int randomPortion = Integer.parseInt(splitSsid[1]);
assertTrue(randomPortion >= RAND_SSID_INT_MIN && randomPortion <= RAND_SSID_INT_MAX);
- assertTrue(config.allowedKeyManagement.get(KeyMgmt.WPA2_PSK));
- assertEquals(15, config.preSharedKey.length());
+ assertEquals(SECURITY_TYPE_WPA2_PSK, config.getSecurityType());
+ assertEquals(15, config.getWpa2Passphrase().length());
}
@@ -237,13 +236,13 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
*/
@Test
public void initWithExistingConfigurationInLegacyFile() throws Exception {
- WifiConfiguration expectedConfig = setupApConfig(
- "ConfiguredAP", /* SSID */
- "randomKey", /* preshared key */
- KeyMgmt.WPA_EAP, /* key management */
- 1, /* AP band (5GHz) */
- 40, /* AP channel */
- true /* Hidden SSID */);
+ SoftApConfiguration expectedConfig = setupApConfig(
+ "ConfiguredAP", /* SSID */
+ "randomKey", /* preshared key */
+ SECURITY_TYPE_WPA2_PSK, /* security type */
+ 1, /* AP band (5GHz) */
+ 40, /* AP channel */
+ true /* Hidden SSID */);
/* Create a temporary file for AP config file storage. */
mLegacyApConfigFile = File.createTempFile(TEST_AP_CONFIG_FILE_PREFIX, "");
@@ -273,13 +272,13 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
@Test
public void setNullApConfiguration() throws Exception {
/* Initialize WifiApConfigStore with existing configuration. */
- WifiConfiguration expectedConfig = setupApConfig(
- "ConfiguredAP", /* SSID */
- "randomKey", /* preshared key */
- KeyMgmt.WPA_EAP, /* key management */
- 1, /* AP band (5GHz) */
- 40, /* AP channel */
- true /* Hidden SSID */);
+ SoftApConfiguration expectedConfig = setupApConfig(
+ "ConfiguredAP", /* SSID */
+ "randomKey", /* preshared key */
+ SECURITY_TYPE_WPA2_PSK, /* security type */
+ 1, /* AP band (5GHz) */
+ 40, /* AP channel */
+ true /* Hidden SSID */);
WifiApConfigStore store = createWifiApConfigStore();
mDataStoreSource.fromDeserialized(expectedConfig);
verifyApConfig(expectedConfig, store.getApConfiguration());
@@ -303,11 +302,11 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
verify(mWifiConfigManager).saveToStore(true);
/* Update with a valid configuration. */
- WifiConfiguration expectedConfig = setupApConfig(
+ SoftApConfiguration expectedConfig = setupApConfig(
"ConfiguredAP", /* SSID */
"randomKey", /* preshared key */
- KeyMgmt.WPA_EAP, /* key management */
- WifiConfiguration.AP_BAND_2GHZ, /* AP band */
+ SECURITY_TYPE_WPA2_PSK, /* security type */
+ SoftApConfiguration.BAND_2GHZ, /* AP band */
40, /* AP channel */
true /* Hidden SSID */);
store.setApConfiguration(expectedConfig);
@@ -330,19 +329,19 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
verify(mWifiConfigManager).saveToStore(true);
/* Update with a valid configuration. */
- WifiConfiguration providedConfig = setupApConfig(
+ SoftApConfiguration providedConfig = setupApConfig(
"ConfiguredAP", /* SSID */
"randomKey", /* preshared key */
- KeyMgmt.WPA_EAP, /* key management */
- WifiConfiguration.AP_BAND_ANY, /* AP band (ANY) */
+ SECURITY_TYPE_WPA2_PSK, /* security type */
+ SoftApConfiguration.BAND_ANY, /* AP band (ANY) */
40, /* AP channel */
false /* Hidden SSID */);
- WifiConfiguration expectedConfig = setupApConfig(
+ SoftApConfiguration expectedConfig = setupApConfig(
"ConfiguredAP", /* SSID */
"randomKey", /* preshared key */
- KeyMgmt.WPA_EAP, /* key management */
- WifiConfiguration.AP_BAND_5GHZ, /* AP band (5GHz) */
+ SECURITY_TYPE_WPA2_PSK, /* security type */
+ SoftApConfiguration.BAND_5GHZ, /* AP band (5GHz) */
WifiApConfigStore.AP_CHANNEL_DEFAULT, /* AP channel */
false /* Hidden SSID */);
store.setApConfiguration(providedConfig);
@@ -365,11 +364,11 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
verify(mWifiConfigManager).saveToStore(true);
/* Update with a valid configuration. */
- WifiConfiguration expectedConfig = setupApConfig(
+ SoftApConfiguration expectedConfig = setupApConfig(
"ConfiguredAP", /* SSID */
"randomKey", /* preshared key */
- KeyMgmt.WPA_EAP, /* key management */
- WifiConfiguration.AP_BAND_5GHZ, /* AP band */
+ SECURITY_TYPE_WPA2_PSK, /* security type */
+ SoftApConfiguration.BAND_5GHZ, /* AP band */
40, /* AP channel */
false /* Hidden SSID */);
store.setApConfiguration(expectedConfig);
@@ -394,19 +393,19 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
verify(mWifiConfigManager).saveToStore(true);
/* Update with a valid configuration. */
- WifiConfiguration providedConfig = setupApConfig(
+ SoftApConfiguration providedConfig = setupApConfig(
"ConfiguredAP", /* SSID */
"randomKey", /* preshared key */
- KeyMgmt.WPA_EAP, /* key management */
- WifiConfiguration.AP_BAND_5GHZ, /* AP band */
+ SECURITY_TYPE_WPA2_PSK, /* security type */
+ SoftApConfiguration.BAND_5GHZ, /* AP band */
40, /* AP channel */
false /* Hidden SSID */);
- WifiConfiguration expectedConfig = setupApConfig(
+ SoftApConfiguration expectedConfig = setupApConfig(
"ConfiguredAP", /* SSID */
"randomKey", /* preshared key */
- KeyMgmt.WPA_EAP, /* key management */
- WifiConfiguration.AP_BAND_ANY, /* AP band */
+ SECURITY_TYPE_WPA2_PSK, /* security type */
+ SoftApConfiguration.BAND_ANY, /* AP band */
WifiApConfigStore.AP_CHANNEL_DEFAULT, /* AP channel */
false /* Hidden SSID */);
store.setApConfiguration(providedConfig);
@@ -431,11 +430,11 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
verify(mWifiConfigManager).saveToStore(true);
/* Update with a valid configuration. */
- WifiConfiguration expectedConfig = setupApConfig(
+ SoftApConfiguration expectedConfig = setupApConfig(
"ConfiguredAP", /* SSID */
"randomKey", /* preshared key */
- KeyMgmt.WPA_EAP, /* key management */
- WifiConfiguration.AP_BAND_ANY, /* AP band */
+ SECURITY_TYPE_WPA2_PSK, /* security type */
+ SoftApConfiguration.BAND_ANY, /* AP band */
40, /* AP channel */
false /* Hidden SSID */);
store.setApConfiguration(expectedConfig);
@@ -453,18 +452,18 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
@Test
public void singleModeDeviceAnyConvertedTo5GhzAtRetrieval() throws Exception {
- WifiConfiguration persistedConfig = setupApConfig(
+ SoftApConfiguration persistedConfig = setupApConfig(
"ConfiguredAP", /* SSID */
"randomKey", /* preshared key */
- KeyMgmt.WPA_EAP, /* key management */
- WifiConfiguration.AP_BAND_ANY, /* AP band */
+ SECURITY_TYPE_WPA2_PSK, /* security type */
+ SoftApConfiguration.BAND_ANY, /* AP band */
40, /* AP channel */
false /* Hidden SSID */);
- WifiConfiguration expectedConfig = setupApConfig(
+ SoftApConfiguration expectedConfig = setupApConfig(
"ConfiguredAP", /* SSID */
"randomKey", /* preshared key */
- KeyMgmt.WPA_EAP, /* key management */
- WifiConfiguration.AP_BAND_5GHZ, /* AP band */
+ SECURITY_TYPE_WPA2_PSK, /* security type */
+ SoftApConfiguration.BAND_5GHZ, /* AP band */
WifiApConfigStore.AP_CHANNEL_DEFAULT, /* AP channel */
false /* Hidden SSID */);
WifiApConfigStore store = createWifiApConfigStore();
@@ -482,11 +481,11 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
*/
@Test
public void singleModeDeviceNotConvertedAtRetrieval() throws Exception {
- WifiConfiguration persistedConfig = setupApConfig(
+ SoftApConfiguration persistedConfig = setupApConfig(
"ConfiguredAP", /* SSID */
"randomKey", /* preshared key */
- KeyMgmt.WPA_EAP, /* key management */
- WifiConfiguration.AP_BAND_5GHZ, /* AP band */
+ SECURITY_TYPE_WPA2_PSK, /* security type */
+ SoftApConfiguration.BAND_5GHZ, /* AP band */
40, /* AP channel */
false /* Hidden SSID */);
@@ -506,18 +505,18 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
public void dualModeDevice5GhzConvertedToAnyAtRetrieval() throws Exception {
mResources.setBoolean(R.bool.config_wifi_convert_apband_5ghz_to_any, true);
- WifiConfiguration persistedConfig = setupApConfig(
+ SoftApConfiguration persistedConfig = setupApConfig(
"ConfiguredAP", /* SSID */
"randomKey", /* preshared key */
- KeyMgmt.WPA_EAP, /* key management */
- WifiConfiguration.AP_BAND_5GHZ, /* AP band */
+ SECURITY_TYPE_WPA2_PSK, /* security type */
+ SoftApConfiguration.BAND_5GHZ, /* AP band */
40, /* AP channel */
false /* Hidden SSID */);
- WifiConfiguration expectedConfig = setupApConfig(
+ SoftApConfiguration expectedConfig = setupApConfig(
"ConfiguredAP", /* SSID */
"randomKey", /* preshared key */
- KeyMgmt.WPA_EAP, /* key management */
- WifiConfiguration.AP_BAND_ANY, /* AP band */
+ SECURITY_TYPE_WPA2_PSK, /* security type */
+ SoftApConfiguration.BAND_ANY, /* AP band */
WifiApConfigStore.AP_CHANNEL_DEFAULT, /* AP channel */
false /* Hidden SSID */);
@@ -538,11 +537,11 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
public void dualModeDeviceNotConvertedAtRetrieval() throws Exception {
mResources.setBoolean(R.bool.config_wifi_convert_apband_5ghz_to_any, true);
- WifiConfiguration persistedConfig = setupApConfig(
+ SoftApConfiguration persistedConfig = setupApConfig(
"ConfiguredAP", /* SSID */
"randomKey", /* preshared key */
- KeyMgmt.WPA_EAP, /* key management */
- WifiConfiguration.AP_BAND_ANY, /* AP band */
+ SECURITY_TYPE_WPA2_PSK, /* security type */
+ SoftApConfiguration.BAND_ANY, /* AP band */
40, /* AP channel */
false /* Hidden SSID */);
@@ -554,12 +553,12 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
}
/**
- * Verify a proper WifiConfiguration is generate by getDefaultApConfiguration().
+ * Verify a proper SoftApConfiguration is generate by getDefaultApConfiguration().
*/
@Test
public void getDefaultApConfigurationIsValid() {
WifiApConfigStore store = createWifiApConfigStore();
- WifiConfiguration config = store.getApConfiguration();
+ SoftApConfiguration config = store.getApConfiguration();
assertTrue(WifiApConfigStore.validateApWifiConfiguration(config));
}
@@ -569,12 +568,10 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
*/
@Test
public void generateLocalOnlyHotspotConfigIsValid() {
- WifiConfiguration config = WifiApConfigStore
- .generateLocalOnlyHotspotConfig(mContext, WifiConfiguration.AP_BAND_2GHZ, null);
+ SoftApConfiguration config = WifiApConfigStore
+ .generateLocalOnlyHotspotConfig(mContext, SoftApConfiguration.BAND_2GHZ, null);
verifyDefaultLocalOnlyApConfig(config, TEST_DEFAULT_HOTSPOT_SSID,
- WifiConfiguration.AP_BAND_2GHZ);
- // The LOHS config should also have a specific network id set - check that as well.
- assertEquals(WifiConfiguration.LOCAL_ONLY_NETWORK_ID, config.networkId);
+ SoftApConfiguration.BAND_2GHZ);
// verify that the config passes the validateApWifiConfiguration check
assertTrue(WifiApConfigStore.validateApWifiConfiguration(config));
@@ -585,12 +582,10 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
*/
@Test
public void generateLocalOnlyHotspotConfigIsValid5G() {
- WifiConfiguration config = WifiApConfigStore
- .generateLocalOnlyHotspotConfig(mContext, WifiConfiguration.AP_BAND_5GHZ, null);
+ SoftApConfiguration config = WifiApConfigStore
+ .generateLocalOnlyHotspotConfig(mContext, SoftApConfiguration.BAND_5GHZ, null);
verifyDefaultLocalOnlyApConfig(config, TEST_DEFAULT_HOTSPOT_SSID,
- WifiConfiguration.AP_BAND_5GHZ);
- // The LOHS config should also have a specific network id set - check that as well.
- assertEquals(WifiConfiguration.LOCAL_ONLY_NETWORK_ID, config.networkId);
+ SoftApConfiguration.BAND_5GHZ);
// verify that the config passes the validateApWifiConfiguration check
assertTrue(WifiApConfigStore.validateApWifiConfiguration(config));
@@ -601,46 +596,47 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
SoftApConfiguration customConfig = new SoftApConfiguration.Builder()
.setBssid(MacAddress.fromString("11:22:33:44:55:66"))
.build();
- WifiConfiguration wifiConfig = WifiApConfigStore.generateLocalOnlyHotspotConfig(
- mContext, WifiConfiguration.AP_BAND_2GHZ, customConfig);
- assertThat(wifiConfig.BSSID).isNotEmpty();
- assertThat(MacAddress.fromString(wifiConfig.BSSID)).isEqualTo(
+ SoftApConfiguration softApConfig = WifiApConfigStore.generateLocalOnlyHotspotConfig(
+ mContext, SoftApConfiguration.BAND_2GHZ, customConfig);
+ assertThat(softApConfig.getBssid().toString()).isNotEmpty();
+ assertThat(softApConfig.getBssid()).isEqualTo(
MacAddress.fromString("11:22:33:44:55:66"));
}
@Test
public void randomizeBssid_randomizesWhenEnabled() {
mResources.setBoolean(R.bool.config_wifi_ap_mac_randomization_supported, true);
- WifiConfiguration baseConfig = new WifiConfiguration();
+ SoftApConfiguration baseConfig = new SoftApConfiguration.Builder().build();
WifiApConfigStore store = createWifiApConfigStore();
- WifiConfiguration config = store.randomizeBssidIfUnset(mContext, baseConfig);
+ SoftApConfiguration config = store.randomizeBssidIfUnset(mContext, baseConfig);
- assertEquals(TEST_RANDOMIZED_MAC.toString(), config.BSSID);
+ assertEquals(TEST_RANDOMIZED_MAC, config.getBssid());
}
@Test
public void randomizeBssid_usesFactoryMacWhenRandomizationOff() {
mResources.setBoolean(R.bool.config_wifi_ap_mac_randomization_supported, false);
- WifiConfiguration baseConfig = new WifiConfiguration();
+ SoftApConfiguration baseConfig = new SoftApConfiguration.Builder().build();
WifiApConfigStore store = createWifiApConfigStore();
- WifiConfiguration config = store.randomizeBssidIfUnset(mContext, baseConfig);
+ SoftApConfiguration config = store.randomizeBssidIfUnset(mContext, baseConfig);
- assertThat(config.BSSID).isNull();
+ assertThat(config.getBssid()).isNull();
}
@Test
public void randomizeBssid_forwardsCustomMac() {
mResources.setBoolean(R.bool.config_wifi_ap_mac_randomization_supported, true);
- WifiConfiguration baseConfig = new WifiConfiguration();
- baseConfig.BSSID = "11:22:33:44:55:66";
+ Builder baseConfigBuilder = new SoftApConfiguration.Builder();
+ baseConfigBuilder.setBssid(MacAddress.fromString("11:22:33:44:55:66"));
WifiApConfigStore store = createWifiApConfigStore();
- WifiConfiguration config = store.randomizeBssidIfUnset(mContext, baseConfig);
+ SoftApConfiguration config = store.randomizeBssidIfUnset(mContext,
+ baseConfigBuilder.build());
- assertThat(config.BSSID).isNotEmpty();
- assertThat(MacAddress.fromString(config.BSSID)).isEqualTo(
+ assertThat(config.getBssid().toString()).isNotEmpty();
+ assertThat(config.getBssid()).isEqualTo(
MacAddress.fromString("11:22:33:44:55:66"));
}
@@ -667,42 +663,40 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
* Verify the SSID checks in validateApWifiConfiguration.
*
* Cases to check and verify they trigger failed verification:
- * null WifiConfiguration.SSID
- * empty WifiConfiguration.SSID
+ * null SoftApConfiguration.SSID
+ * empty SoftApConfiguration.SSID
* invalid WifiConfiguaration.SSID length
*
* Additionally check a valid SSID with a random (within valid ranges) length.
*/
@Test
public void testSsidVerificationInValidateApWifiConfigurationCheck() {
- WifiConfiguration config = new WifiConfiguration();
- config.SSID = null;
- assertFalse(WifiApConfigStore.validateApWifiConfiguration(config));
- config.SSID = "";
- assertFalse(WifiApConfigStore.validateApWifiConfiguration(config));
+ Builder configBuilder = new SoftApConfiguration.Builder();
+ configBuilder.setSsid(null);
+ assertFalse(WifiApConfigStore.validateApWifiConfiguration(configBuilder.build()));
// check a string if it's larger than 32 bytes with UTF-8 encode
// Case 1 : one byte per character (use english words and Arabic numerals)
- config.SSID = generateRandomString(WifiApConfigStore.SSID_MAX_LEN + 1);
- assertFalse(WifiApConfigStore.validateApWifiConfiguration(config));
+ configBuilder.setSsid(generateRandomString(WifiApConfigStore.SSID_MAX_LEN + 1));
+ assertFalse(WifiApConfigStore.validateApWifiConfiguration(configBuilder.build()));
// Case 2 : two bytes per character
- config.SSID = TEST_STRING_UTF8_WITH_34_BYTES;
- assertFalse(WifiApConfigStore.validateApWifiConfiguration(config));
+ configBuilder.setSsid(TEST_STRING_UTF8_WITH_34_BYTES);
+ assertFalse(WifiApConfigStore.validateApWifiConfiguration(configBuilder.build()));
// Case 3 : three bytes per character
- config.SSID = TEST_STRING_UTF8_WITH_33_BYTES;
- assertFalse(WifiApConfigStore.validateApWifiConfiguration(config));
+ configBuilder.setSsid(TEST_STRING_UTF8_WITH_33_BYTES);
+ assertFalse(WifiApConfigStore.validateApWifiConfiguration(configBuilder.build()));
// now check a valid SSID within 32 bytes
// Case 1 : one byte per character with random length
int validLength = WifiApConfigStore.SSID_MAX_LEN - WifiApConfigStore.SSID_MIN_LEN;
- config.SSID = generateRandomString(
- mRandom.nextInt(validLength) + WifiApConfigStore.SSID_MIN_LEN);
- assertTrue(WifiApConfigStore.validateApWifiConfiguration(config));
+ configBuilder.setSsid(generateRandomString(
+ mRandom.nextInt(validLength) + WifiApConfigStore.SSID_MIN_LEN));
+ assertTrue(WifiApConfigStore.validateApWifiConfiguration(configBuilder.build()));
// Case 2 : two bytes per character
- config.SSID = TEST_STRING_UTF8_WITH_32_BYTES;
- assertTrue(WifiApConfigStore.validateApWifiConfiguration(config));
+ configBuilder.setSsid(TEST_STRING_UTF8_WITH_32_BYTES);
+ assertTrue(WifiApConfigStore.validateApWifiConfiguration(configBuilder.build()));
// Case 3 : three bytes per character
- config.SSID = TEST_STRING_UTF8_WITH_30_BYTES;
- assertTrue(WifiApConfigStore.validateApWifiConfiguration(config));
+ configBuilder.setSsid(TEST_STRING_UTF8_WITH_30_BYTES);
+ assertTrue(WifiApConfigStore.validateApWifiConfiguration(configBuilder.build()));
}
/**
@@ -714,18 +708,10 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
*/
@Test
public void testOpenNetworkConfigInValidateApWifiConfigurationCheck() {
- WifiConfiguration config = new WifiConfiguration();
- config.SSID = TEST_DEFAULT_HOTSPOT_SSID;
-
- config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
- config.preSharedKey = TEST_DEFAULT_HOTSPOT_PSK;
- assertFalse(WifiApConfigStore.validateApWifiConfiguration(config));
-
- // open networks should not have a password set
- config.preSharedKey = null;
- assertTrue(WifiApConfigStore.validateApWifiConfiguration(config));
- config.preSharedKey = "";
- assertTrue(WifiApConfigStore.validateApWifiConfiguration(config));
+ assertTrue(WifiApConfigStore.validateApWifiConfiguration(
+ new SoftApConfiguration.Builder()
+ .setSsid(TEST_DEFAULT_HOTSPOT_SSID)
+ .build()));
}
/**
@@ -736,67 +722,36 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
*/
@Test
public void testWpa2PskNetworkConfigInValidateApWifiConfigurationCheck() {
- WifiConfiguration config = new WifiConfiguration();
- config.SSID = TEST_DEFAULT_HOTSPOT_SSID;
-
- config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA2_PSK);
- config.preSharedKey = null;
- assertFalse(WifiApConfigStore.validateApWifiConfiguration(config));
- config.preSharedKey = "";
- assertFalse(WifiApConfigStore.validateApWifiConfiguration(config));
+ Builder configBuilder = new SoftApConfiguration.Builder();
+ configBuilder.setSsid(TEST_DEFAULT_HOTSPOT_SSID);
+ // Builder will auto check auth type and passphrase
// test too short
- config.preSharedKey =
- generateRandomString(WifiApConfigStore.PSK_MIN_LEN - 1);
- assertFalse(WifiApConfigStore.validateApWifiConfiguration(config));
+ configBuilder.setWpa2Passphrase(
+ generateRandomString(WifiApConfigStore.PSK_MIN_LEN - 1));
+ assertFalse(WifiApConfigStore.validateApWifiConfiguration(configBuilder.build()));
// test too long
- config.preSharedKey =
- generateRandomString(WifiApConfigStore.PSK_MAX_LEN + 1);
- assertFalse(WifiApConfigStore.validateApWifiConfiguration(config));
+ configBuilder.setWpa2Passphrase(
+ generateRandomString(WifiApConfigStore.PSK_MAX_LEN + 1));
+ assertFalse(WifiApConfigStore.validateApWifiConfiguration(configBuilder.build()));
// explicitly test min length
- config.preSharedKey =
- generateRandomString(WifiApConfigStore.PSK_MIN_LEN);
- assertTrue(WifiApConfigStore.validateApWifiConfiguration(config));
+ configBuilder.setWpa2Passphrase(
+ generateRandomString(WifiApConfigStore.PSK_MIN_LEN));
+ assertTrue(WifiApConfigStore.validateApWifiConfiguration(configBuilder.build()));
// explicitly test max length
- config.preSharedKey =
- generateRandomString(WifiApConfigStore.PSK_MAX_LEN);
- assertTrue(WifiApConfigStore.validateApWifiConfiguration(config));
+ configBuilder.setWpa2Passphrase(
+ generateRandomString(WifiApConfigStore.PSK_MAX_LEN));
+ assertTrue(WifiApConfigStore.validateApWifiConfiguration(configBuilder.build()));
// test random (valid length)
int maxLen = WifiApConfigStore.PSK_MAX_LEN;
int minLen = WifiApConfigStore.PSK_MIN_LEN;
- config.preSharedKey =
- generateRandomString(mRandom.nextInt(maxLen - minLen) + minLen);
- assertTrue(WifiApConfigStore.validateApWifiConfiguration(config));
- }
-
- /**
- * Verify an invalid AuthType setting (that would trigger an IllegalStateException)
- * returns false when triggered in the validateApWifiConfiguration.
- */
- @Test
- public void testInvalidAuthTypeInValidateApWifiConfigurationCheck() {
- WifiConfiguration config = new WifiConfiguration();
- config.SSID = TEST_DEFAULT_HOTSPOT_SSID;
-
- config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA2_PSK);
- config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
- assertFalse(WifiApConfigStore.validateApWifiConfiguration(config));
- }
-
- /**
- * Verify an unsupported authType returns false for validateApWifiConfigurationCheck.
- */
- @Test
- public void testUnsupportedAuthTypeInValidateApWifiConfigurationCheck() {
- WifiConfiguration config = new WifiConfiguration();
- config.SSID = TEST_DEFAULT_HOTSPOT_SSID;
-
- config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
- assertFalse(WifiApConfigStore.validateApWifiConfiguration(config));
+ configBuilder.setWpa2Passphrase(
+ generateRandomString(mRandom.nextInt(maxLen - minLen) + minLen));
+ assertTrue(WifiApConfigStore.validateApWifiConfiguration(configBuilder.build()));
}
/**
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java
index 66b84f7ee..23f068410 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java
@@ -536,7 +536,6 @@ public class WifiConfigurationTestUtil {
return new ScanDetail(ssid, bssid, caps, level, frequency, tsf, seen);
}
-
/**
* Asserts that the 2 WifiConfigurations are equal in the elements saved for both backup/restore
* and config store.
@@ -561,6 +560,22 @@ public class WifiConfigurationTestUtil {
assertEquals(expected.getIpConfiguration(), actual.getIpConfiguration());
}
+
+ /**
+ * Asserts that the 2 WifiConfigurations are equal. This only compares the elements saved
+ * for softAp used.
+ */
+ public static void assertConfigurationEqualForSoftAp(
+ WifiConfiguration expected, WifiConfiguration actual) {
+ assertEquals(expected.SSID, actual.SSID);
+ assertEquals(expected.BSSID, actual.BSSID);
+ assertEquals(expected.apBand, actual.apBand);
+ assertEquals(expected.apChannel, actual.apChannel);
+ assertEquals(expected.preSharedKey, actual.preSharedKey);
+ assertEquals(expected.getAuthType(), actual.getAuthType());
+ assertEquals(expected.hiddenSSID, actual.hiddenSSID);
+ }
+
/**
* Asserts that the 2 WifiConfigurations are equal. This only compares the elements saved
* for backup/restore.
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNativeInterfaceManagementTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNativeInterfaceManagementTest.java
index 804f7badb..648faa55a 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiNativeInterfaceManagementTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiNativeInterfaceManagementTest.java
@@ -39,7 +39,7 @@ import android.app.test.MockAnswerUtil;
import android.net.InterfaceConfiguration;
import android.net.wifi.IApInterface;
import android.net.wifi.IClientInterface;
-import android.net.wifi.WifiConfiguration;
+import android.net.wifi.SoftApConfiguration;
import android.net.wifi.WifiScanner;
import android.os.Handler;
import android.os.INetworkManagementService;
@@ -795,7 +795,7 @@ public class WifiNativeInterfaceManagementTest extends WifiBaseTest {
mNetworkObserverCaptor0);
// Start softap
- assertTrue(mWifiNative.startSoftAp(IFACE_NAME_0, new WifiConfiguration(),
+ assertTrue(mWifiNative.startSoftAp(IFACE_NAME_0, new SoftApConfiguration.Builder().build(),
mock(WifiNative.SoftApListener.class)));
mInOrder.verify(mWificondControl).registerApListener(any(), any());
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
index 6282abed1..38060843d 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
@@ -140,6 +140,7 @@ import com.android.internal.util.AsyncChannel;
import com.android.server.wifi.WifiServiceImpl.LocalOnlyRequestorCallback;
import com.android.server.wifi.hotspot2.PasspointManager;
import com.android.server.wifi.hotspot2.PasspointProvisioningTestUtil;
+import com.android.server.wifi.util.ApConfigUtil;
import com.android.server.wifi.util.WifiAsyncChannel;
import com.android.server.wifi.util.WifiPermissionsUtil;
import com.android.server.wifi.util.WifiPermissionsWrapper;
@@ -962,12 +963,13 @@ public class WifiServiceImplTest extends WifiBaseTest {
@Test
public void testSetWifiApConfigurationSuccess() throws Exception {
when(mWifiPermissionsUtil.checkConfigOverridePermission(anyInt())).thenReturn(true);
- WifiConfiguration apConfig = createValidSoftApConfiguration();
+ WifiConfiguration wifiApConfig = createValidWifiApConfiguration();
- assertTrue(mWifiServiceImpl.setWifiApConfiguration(apConfig, TEST_PACKAGE_NAME));
+ assertTrue(mWifiServiceImpl.setWifiApConfiguration(wifiApConfig, TEST_PACKAGE_NAME));
mLooper.dispatchAll();
verifyCheckChangePermission(TEST_PACKAGE_NAME);
- verify(mWifiApConfigStore).setApConfiguration(eq(apConfig));
+ verify(mWifiApConfigStore).setApConfiguration(eq(
+ ApConfigUtil.fromWifiConfiguration(wifiApConfig)));
}
/**
@@ -977,7 +979,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
public void testSetWifiApConfigurationNullConfigNotSaved() throws Exception {
when(mWifiPermissionsUtil.checkConfigOverridePermission(anyInt())).thenReturn(true);
assertFalse(mWifiServiceImpl.setWifiApConfiguration(null, TEST_PACKAGE_NAME));
- verify(mWifiApConfigStore, never()).setApConfiguration(isNull(WifiConfiguration.class));
+ verify(mWifiApConfigStore, never()).setApConfiguration(isNull(SoftApConfiguration.class));
}
/**
@@ -992,6 +994,96 @@ public class WifiServiceImplTest extends WifiBaseTest {
}
/**
+ * Ensure unpermitted callers cannot write the SoftApConfiguration.
+ */
+ @Test
+ public void testSetSoftApConfigurationNotSavedWithoutPermission() throws Exception {
+ doThrow(new SecurityException()).when(mContext)
+ .enforceCallingOrSelfPermission(eq(android.Manifest.permission.NETWORK_SETTINGS),
+ eq("WifiService"));
+ SoftApConfiguration apConfig = createValidSoftApConfiguration();
+ try {
+ mWifiServiceImpl.setSoftApConfiguration(apConfig, TEST_PACKAGE_NAME);
+ fail("Expected SecurityException");
+ } catch (SecurityException e) { }
+ }
+
+ /**
+ * Ensure softap config is written when the caller has the correct permission.
+ */
+ @Test
+ public void testSetSoftApConfigurationSuccess() throws Exception {
+ doNothing().when(mContext)
+ .enforceCallingOrSelfPermission(eq(android.Manifest.permission.NETWORK_SETTINGS),
+ eq("WifiService"));
+ SoftApConfiguration apConfig = createValidSoftApConfiguration();
+
+ assertTrue(mWifiServiceImpl.setSoftApConfiguration(apConfig, TEST_PACKAGE_NAME));
+ mLooper.dispatchAll();
+ verify(mWifiApConfigStore).setApConfiguration(eq(apConfig));
+ verify(mContext).enforceCallingOrSelfPermission(
+ eq(android.Manifest.permission.NETWORK_SETTINGS), eq("WifiService"));
+ }
+
+ /**
+ * Ensure that a null config does not overwrite the saved ap config.
+ */
+ @Test
+ public void testSetSoftApConfigurationNullConfigNotSaved() throws Exception {
+ doNothing().when(mContext)
+ .enforceCallingOrSelfPermission(eq(android.Manifest.permission.NETWORK_SETTINGS),
+ eq("WifiService"));
+ assertFalse(mWifiServiceImpl.setSoftApConfiguration(null, TEST_PACKAGE_NAME));
+ verify(mWifiApConfigStore, never()).setApConfiguration(isNull(SoftApConfiguration.class));
+ verify(mContext).enforceCallingOrSelfPermission(
+ eq(android.Manifest.permission.NETWORK_SETTINGS), eq("WifiService"));
+ }
+
+ /**
+ * Ensure that an invalid config does not overwrite the saved ap config.
+ */
+ @Test
+ public void testSetSoftApConfigurationWithInvalidConfigNotSaved() throws Exception {
+ doNothing().when(mContext)
+ .enforceCallingOrSelfPermission(eq(android.Manifest.permission.NETWORK_SETTINGS),
+ eq("WifiService"));
+ assertFalse(mWifiServiceImpl.setSoftApConfiguration(
+ new SoftApConfiguration.Builder().build(), TEST_PACKAGE_NAME));
+ verify(mWifiApConfigStore, never()).setApConfiguration(any());
+ verify(mContext).enforceCallingOrSelfPermission(
+ eq(android.Manifest.permission.NETWORK_SETTINGS), eq("WifiService"));
+ }
+
+ /**
+ * Ensure unpermitted callers are not able to retrieve the softap config.
+ */
+ @Test
+ public void testGetSoftApConfigurationNotReturnedWithoutPermission() throws Exception {
+ when(mWifiPermissionsUtil.checkConfigOverridePermission(anyInt())).thenReturn(false);
+ try {
+ mWifiServiceImpl.getSoftApConfiguration();
+ fail("Expected a SecurityException");
+ } catch (SecurityException e) {
+ }
+ }
+
+ /**
+ * Ensure permitted callers are able to retrieve the softap config.
+ */
+ @Test
+ public void testGetSoftApConfigurationSuccess() throws Exception {
+ when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false);
+ when(mWifiPermissionsUtil.checkConfigOverridePermission(anyInt())).thenReturn(true);
+ SoftApConfiguration apConfig = createValidSoftApConfiguration();
+ when(mWifiApConfigStore.getApConfiguration()).thenReturn(apConfig);
+
+ mLooper.startAutoDispatch();
+ assertThat(apConfig).isEqualTo(mWifiServiceImpl.getSoftApConfiguration());
+
+ mLooper.stopAutoDispatchAndIgnoreExceptions();
+ }
+
+ /**
* Ensure unpermitted callers are not able to retrieve the softap config.
*/
@Test
@@ -1011,11 +1103,14 @@ public class WifiServiceImplTest extends WifiBaseTest {
public void testGetWifiApConfigurationSuccess() throws Exception {
when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false);
when(mWifiPermissionsUtil.checkConfigOverridePermission(anyInt())).thenReturn(true);
- WifiConfiguration apConfig = new WifiConfiguration();
+ SoftApConfiguration apConfig = new SoftApConfiguration.Builder().build();
when(mWifiApConfigStore.getApConfiguration()).thenReturn(apConfig);
mLooper.startAutoDispatch();
- assertEquals(apConfig, mWifiServiceImpl.getWifiApConfiguration());
+ WifiConfigurationTestUtil.assertConfigurationEqualForSoftAp(
+ ApConfigUtil.convertToWifiConfiguration(apConfig),
+ mWifiServiceImpl.getWifiApConfiguration());
+
mLooper.stopAutoDispatchAndIgnoreExceptions();
}
@@ -1094,7 +1189,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
boolean result = mWifiServiceImpl.startSoftAp(null);
assertTrue(result);
verify(mActiveModeWarden).startSoftAp(mSoftApModeConfigCaptor.capture());
- assertNull(mSoftApModeConfigCaptor.getValue().getWifiConfiguration());
+ assertNull(mSoftApModeConfigCaptor.getValue().getSoftApConfiguration());
}
/**
@@ -1112,11 +1207,13 @@ public class WifiServiceImplTest extends WifiBaseTest {
*/
@Test
public void testStartSoftApWithPermissionsAndValidConfig() {
- WifiConfiguration config = createValidSoftApConfiguration();
+ WifiConfiguration config = createValidWifiApConfiguration();
boolean result = mWifiServiceImpl.startSoftAp(config);
assertTrue(result);
verify(mActiveModeWarden).startSoftAp(mSoftApModeConfigCaptor.capture());
- assertEquals(config, mSoftApModeConfigCaptor.getValue().getWifiConfiguration());
+ WifiConfigurationTestUtil.assertConfigurationEqualForSoftAp(
+ config, ApConfigUtil.convertToWifiConfiguration(
+ mSoftApModeConfigCaptor.getValue().getSoftApConfiguration()));
}
/**
@@ -1140,11 +1237,77 @@ public class WifiServiceImplTest extends WifiBaseTest {
public void testStartSoftApWithoutNetworkStackWithMainlineNetworkStackSucceeds() {
when(mContext.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_STACK))
.thenReturn(PackageManager.PERMISSION_DENIED);
- WifiConfiguration config = createValidSoftApConfiguration();
+ WifiConfiguration config = createValidWifiApConfiguration();
boolean result = mWifiServiceImpl.startSoftAp(config);
assertTrue(result);
verify(mActiveModeWarden).startSoftAp(mSoftApModeConfigCaptor.capture());
- assertEquals(config, mSoftApModeConfigCaptor.getValue().getWifiConfiguration());
+ WifiConfigurationTestUtil.assertConfigurationEqualForSoftAp(
+ config, ApConfigUtil.convertToWifiConfiguration(
+ mSoftApModeConfigCaptor.getValue().getSoftApConfiguration()));
+ verify(mContext).enforceCallingOrSelfPermission(
+ eq(NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK), any());
+ }
+
+ /**
+ * Verify caller with proper permission can call startTetheredHotspot.
+ */
+ @Test
+ public void testStartTetheredHotspotWithPermissionsAndNullConfig() {
+ boolean result = mWifiServiceImpl.startTetheredHotspot(null);
+ assertTrue(result);
+ verify(mActiveModeWarden).startSoftAp(mSoftApModeConfigCaptor.capture());
+ assertNull(mSoftApModeConfigCaptor.getValue().getSoftApConfiguration());
+ }
+
+ /**
+ * Verify caller with proper permissions but an invalid config does not start softap.
+ */
+ @Test
+ public void testStartTetheredHotspotWithPermissionsAndInvalidConfig() {
+ boolean result = mWifiServiceImpl.startTetheredHotspot(
+ new SoftApConfiguration.Builder().build());
+ assertFalse(result);
+ verifyZeroInteractions(mActiveModeWarden);
+ }
+
+ /**
+ * Verify caller with proper permission and valid config does start softap.
+ */
+ @Test
+ public void testStartTetheredHotspotWithPermissionsAndValidConfig() {
+ SoftApConfiguration config = createValidSoftApConfiguration();
+ boolean result = mWifiServiceImpl.startTetheredHotspot(config);
+ assertTrue(result);
+ verify(mActiveModeWarden).startSoftAp(mSoftApModeConfigCaptor.capture());
+ assertThat(config).isEqualTo(mSoftApModeConfigCaptor.getValue().getSoftApConfiguration());
+ }
+
+ /**
+ * Verify a SecurityException is thrown when a caller without the correct permission attempts to
+ * start softap.
+ */
+ @Test(expected = SecurityException.class)
+ public void testStartTetheredHotspotWithoutPermissionThrowsException() throws Exception {
+ when(mContext.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_STACK))
+ .thenReturn(PackageManager.PERMISSION_DENIED);
+ doThrow(new SecurityException()).when(mContext).enforceCallingOrSelfPermission(
+ eq(NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK), any());
+ mWifiServiceImpl.startTetheredHotspot(null);
+ }
+
+ /**
+ * Verify that startTetheredHotspot() succeeds if the caller does not have the
+ * NETWORK_STACK permission but does have the MAINLINE_NETWORK_STACK permission.
+ */
+ @Test
+ public void testStartTetheredHotspotWithoutNetworkStackWithMainlineNetworkStackSucceeds() {
+ when(mContext.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_STACK))
+ .thenReturn(PackageManager.PERMISSION_DENIED);
+ SoftApConfiguration config = createValidSoftApConfiguration();
+ boolean result = mWifiServiceImpl.startTetheredHotspot(config);
+ assertTrue(result);
+ verify(mActiveModeWarden).startSoftAp(mSoftApModeConfigCaptor.capture());
+ assertThat(config).isEqualTo(mSoftApModeConfigCaptor.getValue().getSoftApConfiguration());
verify(mContext).enforceCallingOrSelfPermission(
eq(NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK), any());
}
@@ -1541,10 +1704,33 @@ public class WifiServiceImplTest extends WifiBaseTest {
*/
@Test
public void testTetheringDoesNotStartWhenAlreadyTetheringActive() throws Exception {
- WifiConfiguration config = createValidSoftApConfiguration();
+ WifiConfiguration config = createValidWifiApConfiguration();
assertTrue(mWifiServiceImpl.startSoftAp(config));
verify(mActiveModeWarden).startSoftAp(mSoftApModeConfigCaptor.capture());
- assertEquals(config, mSoftApModeConfigCaptor.getValue().getWifiConfiguration());
+ WifiConfigurationTestUtil.assertConfigurationEqualForSoftAp(
+ config, ApConfigUtil.convertToWifiConfiguration(
+ mSoftApModeConfigCaptor.getValue().getSoftApConfiguration()));
+ mStateMachineSoftApCallback.onStateChanged(WIFI_AP_STATE_ENABLED, 0);
+ mWifiServiceImpl.updateInterfaceIpState(WIFI_IFACE_NAME, IFACE_IP_MODE_TETHERED);
+ mLooper.dispatchAll();
+ assertEquals(WIFI_AP_STATE_ENABLED, mWifiServiceImpl.getWifiApEnabledState());
+ reset(mActiveModeWarden);
+
+ // Start another session without a stop, that should fail.
+ assertFalse(mWifiServiceImpl.startSoftAp(createValidWifiApConfiguration()));
+
+ verifyNoMoreInteractions(mActiveModeWarden);
+ }
+
+ /**
+ * Only start tethering if we are not tethering in new API: startTetheredHotspot.
+ */
+ @Test
+ public void testStartTetheredHotspotDoesNotStartWhenAlreadyTetheringActive() throws Exception {
+ SoftApConfiguration config = createValidSoftApConfiguration();
+ assertTrue(mWifiServiceImpl.startTetheredHotspot(config));
+ verify(mActiveModeWarden).startSoftAp(mSoftApModeConfigCaptor.capture());
+ assertThat(config).isEqualTo(mSoftApModeConfigCaptor.getValue().getSoftApConfiguration());
mStateMachineSoftApCallback.onStateChanged(WIFI_AP_STATE_ENABLED, 0);
mWifiServiceImpl.updateInterfaceIpState(WIFI_IFACE_NAME, IFACE_IP_MODE_TETHERED);
mLooper.dispatchAll();
@@ -1552,7 +1738,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
reset(mActiveModeWarden);
// Start another session without a stop, that should fail.
- assertFalse(mWifiServiceImpl.startSoftAp(createValidSoftApConfiguration()));
+ assertFalse(mWifiServiceImpl.startTetheredHotspot(config));
verifyNoMoreInteractions(mActiveModeWarden);
}
@@ -1562,7 +1748,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
*/
@Test
public void testHotspotDoesNotStartWhenAlreadyTethering() throws Exception {
- WifiConfiguration config = createValidSoftApConfiguration();
+ WifiConfiguration config = createValidWifiApConfiguration();
assertTrue(mWifiServiceImpl.startSoftAp(config));
mStateMachineSoftApCallback.onStateChanged(WIFI_AP_STATE_ENABLED, 0);
mWifiServiceImpl.updateInterfaceIpState(WIFI_IFACE_NAME, IFACE_IP_MODE_TETHERED);
@@ -1686,8 +1872,8 @@ public class WifiServiceImplTest extends WifiBaseTest {
private void verifyLohsBand(int expectedBand) {
verify(mActiveModeWarden).startSoftAp(mSoftApModeConfigCaptor.capture());
- final WifiConfiguration configuration =
- mSoftApModeConfigCaptor.getValue().getWifiConfiguration();
+ final WifiConfiguration configuration = ApConfigUtil.convertToWifiConfiguration(
+ mSoftApModeConfigCaptor.getValue().getSoftApConfiguration());
assertNotNull(configuration);
assertEquals(expectedBand, configuration.apBand);
}
@@ -2417,7 +2603,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
mWifiServiceImpl.updateInterfaceIpState(WIFI_IFACE_NAME, IFACE_IP_MODE_LOCAL_ONLY);
mLooper.dispatchAll();
- verify(mRequestInfo).sendHotspotStartedMessage(any(WifiConfiguration.class));
+ verify(mRequestInfo).sendHotspotStartedMessage(any(SoftApConfiguration.class));
mLooper.dispatchAll();
verify(mLohsCallback).onHotspotStarted(notNull());
@@ -3300,7 +3486,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
AppOpsManager.OPSTR_CHANGE_WIFI_STATE, Process.myUid(), callingPackageName);
}
- private WifiConfiguration createValidSoftApConfiguration() {
+ private WifiConfiguration createValidWifiApConfiguration() {
WifiConfiguration apConfig = new WifiConfiguration();
apConfig.SSID = "TestAp";
apConfig.preSharedKey = "thisIsABadPassword";
@@ -3310,6 +3496,14 @@ public class WifiServiceImplTest extends WifiBaseTest {
return apConfig;
}
+ private SoftApConfiguration createValidSoftApConfiguration() {
+ return new SoftApConfiguration.Builder()
+ .setSsid("TestAp")
+ .setWpa2Passphrase("thisIsABadPassword")
+ .setBand(SoftApConfiguration.BAND_2GHZ)
+ .build();
+ }
+
/**
* Verifies that sim state change does not set or reset the country code
*/
diff --git a/tests/wifitests/src/com/android/server/wifi/util/ApConfigUtilTest.java b/tests/wifitests/src/com/android/server/wifi/util/ApConfigUtilTest.java
index d02a790c4..26cb7c72c 100644
--- a/tests/wifitests/src/com/android/server/wifi/util/ApConfigUtilTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/util/ApConfigUtilTest.java
@@ -20,7 +20,8 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
-import android.net.wifi.WifiConfiguration;
+import android.net.wifi.SoftApConfiguration;
+import android.net.wifi.SoftApConfiguration.Builder;
import android.net.wifi.WifiScanner;
import androidx.test.filters.SmallTest;
@@ -147,7 +148,7 @@ public class ApConfigUtilTest extends WifiBaseTest {
@Test
public void chooseApChannel2GBandWithNoAllowedChannel() throws Exception {
assertEquals(ApConfigUtil.DEFAULT_AP_CHANNEL, ApConfigUtil.chooseApChannel(
- WifiConfiguration.AP_BAND_2GHZ, null, ALLOWED_5G_FREQS));
+ SoftApConfiguration.BAND_2GHZ, null, ALLOWED_5G_FREQS));
}
/**
@@ -156,7 +157,7 @@ public class ApConfigUtilTest extends WifiBaseTest {
@Test
public void chooseApChannel2GBandWithAllowedChannels() throws Exception {
int channel = ApConfigUtil.chooseApChannel(
- WifiConfiguration.AP_BAND_2GHZ, mAllowed2GChannels, ALLOWED_5G_FREQS);
+ SoftApConfiguration.BAND_2GHZ, mAllowed2GChannels, ALLOWED_5G_FREQS);
assertTrue(mAllowed2GChannels.contains(channel));
}
@@ -166,7 +167,7 @@ public class ApConfigUtilTest extends WifiBaseTest {
@Test
public void chooseApChannel5GBandWithAllowedChannels() throws Exception {
int channel = ApConfigUtil.chooseApChannel(
- WifiConfiguration.AP_BAND_5GHZ, mAllowed2GChannels, ALLOWED_5G_FREQS);
+ SoftApConfiguration.BAND_5GHZ, mAllowed2GChannels, ALLOWED_5G_FREQS);
assertTrue(ArrayUtils.contains(ALLOWED_5G_CHANNELS, channel));
}
@@ -177,7 +178,7 @@ public class ApConfigUtilTest extends WifiBaseTest {
@Test
public void chooseApChannel5GBandWithNoAllowedChannels() throws Exception {
assertEquals(-1, ApConfigUtil.chooseApChannel(
- WifiConfiguration.AP_BAND_5GHZ, mAllowed2GChannels, null));
+ SoftApConfiguration.BAND_5GHZ, mAllowed2GChannels, null));
}
/**
@@ -186,16 +187,17 @@ public class ApConfigUtilTest extends WifiBaseTest {
*/
@Test
public void updateApChannelConfigWithoutHal() throws Exception {
- WifiConfiguration config = new WifiConfiguration();
- config.apChannel = 36;
- config.apBand = WifiConfiguration.AP_BAND_5GHZ;
+ Builder configBuilder = new SoftApConfiguration.Builder();
+ configBuilder.setChannel(36);
+ configBuilder.setBand(SoftApConfiguration.BAND_5GHZ);
+
when(mWifiNative.isHalStarted()).thenReturn(false);
assertEquals(ApConfigUtil.SUCCESS,
- ApConfigUtil.updateApChannelConfig(
- mWifiNative, TEST_COUNTRY_CODE, mAllowed2GChannels, config));
+ ApConfigUtil.updateApChannelConfig(mWifiNative, TEST_COUNTRY_CODE,
+ mAllowed2GChannels, configBuilder, configBuilder.build()));
/* Verify default band and channel is used. */
- assertEquals(ApConfigUtil.DEFAULT_AP_BAND, config.apBand);
- assertEquals(ApConfigUtil.DEFAULT_AP_CHANNEL, config.apChannel);
+ assertEquals(ApConfigUtil.DEFAULT_AP_BAND, configBuilder.build().getBand());
+ assertEquals(ApConfigUtil.DEFAULT_AP_CHANNEL, configBuilder.build().getChannel());
}
/**
@@ -204,12 +206,12 @@ public class ApConfigUtilTest extends WifiBaseTest {
*/
@Test
public void updateApChannelConfig5GBandNoCountryCode() throws Exception {
- WifiConfiguration config = new WifiConfiguration();
- config.apBand = WifiConfiguration.AP_BAND_5GHZ;
+ Builder configBuilder = new SoftApConfiguration.Builder();
+ configBuilder.setBand(SoftApConfiguration.BAND_5GHZ);
when(mWifiNative.isHalStarted()).thenReturn(true);
assertEquals(ApConfigUtil.ERROR_GENERIC,
- ApConfigUtil.updateApChannelConfig(
- mWifiNative, null, mAllowed2GChannels, config));
+ ApConfigUtil.updateApChannelConfig(mWifiNative, null, mAllowed2GChannels,
+ configBuilder, configBuilder.build()));
}
/**
@@ -217,15 +219,15 @@ public class ApConfigUtilTest extends WifiBaseTest {
*/
@Test
public void updateApChannelConfigWithChannelSpecified() throws Exception {
- WifiConfiguration config = new WifiConfiguration();
- config.apBand = WifiConfiguration.AP_BAND_5GHZ;
- config.apChannel = 36;
+ Builder configBuilder = new SoftApConfiguration.Builder();
+ configBuilder.setBand(SoftApConfiguration.BAND_5GHZ);
+ configBuilder.setChannel(36);
when(mWifiNative.isHalStarted()).thenReturn(true);
assertEquals(ApConfigUtil.SUCCESS,
- ApConfigUtil.updateApChannelConfig(
- mWifiNative, TEST_COUNTRY_CODE, mAllowed2GChannels, config));
- assertEquals(WifiConfiguration.AP_BAND_5GHZ, config.apBand);
- assertEquals(36, config.apChannel);
+ ApConfigUtil.updateApChannelConfig(mWifiNative, TEST_COUNTRY_CODE,
+ mAllowed2GChannels, configBuilder, configBuilder.build()));
+ assertEquals(SoftApConfiguration.BAND_5GHZ, configBuilder.build().getBand());
+ assertEquals(36, configBuilder.build().getChannel());
}
/**
@@ -234,13 +236,13 @@ public class ApConfigUtilTest extends WifiBaseTest {
*/
@Test
public void updateApChannelConfigWith5GBandNoChannelAllowed() throws Exception {
- WifiConfiguration config = new WifiConfiguration();
- config.apBand = WifiConfiguration.AP_BAND_5GHZ;
+ Builder configBuilder = new SoftApConfiguration.Builder();
+ configBuilder.setBand(SoftApConfiguration.BAND_5GHZ);
when(mWifiNative.isHalStarted()).thenReturn(true);
when(mWifiNative.getChannelsForBand(WifiScanner.WIFI_BAND_5_GHZ))
.thenReturn(null);
assertEquals(ApConfigUtil.ERROR_NO_CHANNEL,
- ApConfigUtil.updateApChannelConfig(
- mWifiNative, TEST_COUNTRY_CODE, mAllowed2GChannels, config));
+ ApConfigUtil.updateApChannelConfig(mWifiNative, TEST_COUNTRY_CODE,
+ mAllowed2GChannels, configBuilder, configBuilder.build()));
}
}