summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java58
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java46
2 files changed, 77 insertions, 27 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
index 951f8e114..b1f4a2453 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
@@ -114,6 +114,7 @@ public class WifiConfigManagerTest {
private InOrder mContextConfigStoreMockOrder;
private InOrder mNetworkListStoreDataMockOrder;
private WifiConfigManager mWifiConfigManager;
+ private boolean mStoreReadTriggered = false;
/**
* Setup the mocks and an instance of WifiConfigManager before each test.
@@ -170,6 +171,8 @@ public class WifiConfigManagerTest {
.thenReturn(true);
when(mWifiConfigStore.areStoresPresent()).thenReturn(true);
+ setupStoreDataForRead(new ArrayList<WifiConfiguration>(),
+ new ArrayList<WifiConfiguration>(), new HashSet<String>());
when(mDevicePolicyManagerInternal.isActiveAdminWithPolicy(anyInt(), anyInt()))
.thenReturn(false);
@@ -200,6 +203,18 @@ public class WifiConfigManagerTest {
}
/**
+ * Verifies that network addition via
+ * {@link WifiConfigManager#addOrUpdateNetwork(WifiConfiguration, int)} fails if we have not
+ * yet loaded data from store.
+ */
+ @Test
+ public void testAddNetworkBeforeLoadFromStore() {
+ WifiConfiguration openNetwork = WifiConfigurationTestUtil.createOpenNetwork();
+ assertFalse(
+ mWifiConfigManager.addOrUpdateNetwork(openNetwork, TEST_CREATOR_UID).isSuccess());
+ }
+
+ /**
* Verifies the addition of a single network using
* {@link WifiConfigManager#addOrUpdateNetwork(WifiConfiguration, int)}
*/
@@ -2367,8 +2382,7 @@ public class WifiConfigManagerTest {
// Create a network for user2 try adding it. This should be rejected.
final WifiConfiguration user2Network = WifiConfigurationTestUtil.createPskNetwork();
- NetworkUpdateResult result =
- mWifiConfigManager.addOrUpdateNetwork(user2Network, creatorUid);
+ NetworkUpdateResult result = addNetworkToWifiConfigManager(user2Network, creatorUid);
assertFalse(result.isSuccess());
}
@@ -2388,8 +2402,7 @@ public class WifiConfigManagerTest {
// Create a network for user2 try adding it. This should be rejected.
final WifiConfiguration user2Network = WifiConfigurationTestUtil.createPskNetwork();
- NetworkUpdateResult result =
- mWifiConfigManager.addOrUpdateNetwork(user2Network, TEST_SYSUI_UID);
+ NetworkUpdateResult result = addNetworkToWifiConfigManager(user2Network, TEST_SYSUI_UID);
assertTrue(result.isSuccess());
}
@@ -2909,8 +2922,7 @@ public class WifiConfigManagerTest {
public void testUpdateNetworkAddProxyWithPermissionAndSystem() {
// Testing updating network with uid permission OVERRIDE_WIFI_CONFIG
WifiConfiguration network = WifiConfigurationTestUtil.createOpenHiddenNetwork();
- NetworkUpdateResult result =
- mWifiConfigManager.addOrUpdateNetwork(network, TEST_CREATOR_UID);
+ NetworkUpdateResult result = addNetworkToWifiConfigManager(network, TEST_CREATOR_UID);
assertTrue(result.getNetworkId() != WifiConfiguration.INVALID_NETWORK_ID);
verifyAddOrUpdateNetworkWithProxySettingsAndPermissions(
true, // withConfOverride
@@ -2922,7 +2934,7 @@ public class WifiConfigManagerTest {
// Testing updating network with proxy while holding Profile Owner policy
network = WifiConfigurationTestUtil.createOpenHiddenNetwork();
- result = mWifiConfigManager.addOrUpdateNetwork(network, TEST_NO_PERM_UID);
+ result = addNetworkToWifiConfigManager(network, TEST_NO_PERM_UID);
assertTrue(result.getNetworkId() != WifiConfiguration.INVALID_NETWORK_ID);
verifyAddOrUpdateNetworkWithProxySettingsAndPermissions(
false, // withConfOverride
@@ -2934,7 +2946,7 @@ public class WifiConfigManagerTest {
// Testing updating network with proxy while holding Device Owner Policy
network = WifiConfigurationTestUtil.createOpenHiddenNetwork();
- result = mWifiConfigManager.addOrUpdateNetwork(network, TEST_NO_PERM_UID);
+ result = addNetworkToWifiConfigManager(network, TEST_NO_PERM_UID);
assertTrue(result.getNetworkId() != WifiConfiguration.INVALID_NETWORK_ID);
verifyAddOrUpdateNetworkWithProxySettingsAndPermissions(
false, // withConfOverride
@@ -3170,7 +3182,7 @@ public class WifiConfigManagerTest {
when(mWifiPermissionsUtil.checkConfigOverridePermission(anyInt()))
.thenReturn(withConfOverride);
int uid = withConfOverride ? TEST_CREATOR_UID : TEST_NO_PERM_UID;
- NetworkUpdateResult result = mWifiConfigManager.addOrUpdateNetwork(network, uid);
+ NetworkUpdateResult result = addNetworkToWifiConfigManager(network, uid);
assertEquals(assertSuccess, result.getNetworkId() != WifiConfiguration.INVALID_NETWORK_ID);
return result;
}
@@ -3461,17 +3473,41 @@ public class WifiConfigManagerTest {
WifiManager.CHANGE_REASON_REMOVED);
}
+ private void verifyWifiConfigStoreRead() {
+ assertTrue(mWifiConfigManager.loadFromStore());
+ mContextConfigStoreMockOrder.verify(mContext)
+ .sendBroadcastAsUser(any(Intent.class), any(UserHandle.class));
+ }
+
+ private void triggerStoreReadIfNeeded() {
+ // Trigger a store read if not already done.
+ if (!mStoreReadTriggered) {
+ verifyWifiConfigStoreRead();
+ mStoreReadTriggered = true;
+ }
+ }
+
+ /**
+ * Adds the provided configuration to WifiConfigManager with uid = TEST_CREATOR_UID.
+ */
+ private NetworkUpdateResult addNetworkToWifiConfigManager(WifiConfiguration configuration) {
+ return addNetworkToWifiConfigManager(configuration, TEST_CREATOR_UID);
+ }
+
/**
* Adds the provided configuration to WifiConfigManager and modifies the provided configuration
* with creator/update uid, package name and time. This also sets defaults for fields not
* populated.
* These fields are populated internally by WifiConfigManager and hence we need
* to modify the configuration before we compare the added network with the retrieved network.
+ * This method also triggers a store read if not already done.
*/
- private NetworkUpdateResult addNetworkToWifiConfigManager(WifiConfiguration configuration) {
+ private NetworkUpdateResult addNetworkToWifiConfigManager(WifiConfiguration configuration,
+ int uid) {
+ triggerStoreReadIfNeeded();
when(mClock.getWallClockMillis()).thenReturn(TEST_WALLCLOCK_CREATION_TIME_MILLIS);
NetworkUpdateResult result =
- mWifiConfigManager.addOrUpdateNetwork(configuration, TEST_CREATOR_UID);
+ mWifiConfigManager.addOrUpdateNetwork(configuration, uid);
setDefaults(configuration);
setCreationDebugParams(configuration);
configuration.networkId = result.getNetworkId();
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
index 80e29c6b1..74efd14c9 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
@@ -629,7 +629,7 @@ public class WifiStateMachineTest {
public void canRemoveNetworkConfigInClientMode() throws Exception {
boolean result;
when(mWifiConfigManager.removeNetwork(eq(0), anyInt())).thenReturn(true);
- addNetworkAndVerifySuccess();
+ initializeAndAddNetworkAndVerifySuccess();
mLooper.startAutoDispatch();
result = mWsm.syncRemoveNetwork(mWsmAsyncChannel, 0);
mLooper.stopAutoDispatch();
@@ -657,7 +657,7 @@ public class WifiStateMachineTest {
@Test
public void canForgetNetworkConfigInClientMode() throws Exception {
when(mWifiConfigManager.removeNetwork(eq(0), anyInt())).thenReturn(true);
- addNetworkAndVerifySuccess();
+ initializeAndAddNetworkAndVerifySuccess();
mWsm.sendMessage(WifiManager.FORGET_NETWORK, 0, MANAGED_PROFILE_UID);
mLooper.dispatchAll();
verify(mWifiConfigManager).removeNetwork(anyInt(), anyInt());
@@ -697,13 +697,7 @@ public class WifiStateMachineTest {
mLooper.dispatchAll();
}
- private void addNetworkAndVerifySuccess() throws Exception {
- addNetworkAndVerifySuccess(false);
- }
-
private void addNetworkAndVerifySuccess(boolean isHidden) throws Exception {
- loadComponentsInStaMode();
-
WifiConfiguration config = new WifiConfiguration();
config.SSID = sSSID;
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
@@ -730,6 +724,15 @@ public class WifiStateMachineTest {
assertTrue(config2.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.NONE));
}
+ private void initializeAndAddNetworkAndVerifySuccess() throws Exception {
+ initializeAndAddNetworkAndVerifySuccess(false);
+ }
+
+ private void initializeAndAddNetworkAndVerifySuccess(boolean isHidden) throws Exception {
+ loadComponentsInStaMode();
+ addNetworkAndVerifySuccess(isHidden);
+ }
+
/**
* Helper method to retrieve WifiConfiguration by SSID.
*
@@ -781,7 +784,7 @@ public class WifiStateMachineTest {
@Test
public void scan() throws Exception {
- addNetworkAndVerifySuccess();
+ initializeAndAddNetworkAndVerifySuccess();
mWsm.setOperationalMode(WifiStateMachine.CONNECT_MODE);
mWsm.startScan(-1, 0, null, null);
@@ -794,7 +797,7 @@ public class WifiStateMachineTest {
@Test
public void scanWithHiddenNetwork() throws Exception {
- addNetworkAndVerifySuccess(true);
+ initializeAndAddNetworkAndVerifySuccess(true);
Set<String> hiddenNetworkSet = new HashSet<>();
hiddenNetworkSet.add(sSSID);
@@ -814,7 +817,7 @@ public class WifiStateMachineTest {
@Test
public void connect() throws Exception {
- addNetworkAndVerifySuccess();
+ initializeAndAddNetworkAndVerifySuccess();
when(mWifiConfigManager.enableNetwork(eq(0), eq(true), anyInt())).thenReturn(true);
when(mWifiConfigManager.checkAndUpdateLastConnectUid(eq(0), anyInt())).thenReturn(true);
@@ -852,7 +855,7 @@ public class WifiStateMachineTest {
@Test
public void connectWithNoEnablePermission() throws Exception {
- addNetworkAndVerifySuccess();
+ initializeAndAddNetworkAndVerifySuccess();
when(mWifiConfigManager.enableNetwork(eq(0), eq(true), anyInt())).thenReturn(false);
when(mWifiConfigManager.checkAndUpdateLastConnectUid(eq(0), anyInt())).thenReturn(false);
@@ -890,7 +893,7 @@ public class WifiStateMachineTest {
@Test
public void enableWithInvalidNetworkId() throws Exception {
- addNetworkAndVerifySuccess();
+ initializeAndAddNetworkAndVerifySuccess();
when(mWifiConfigManager.getConfiguredNetwork(eq(0))).thenReturn(null);
mWsm.setOperationalMode(WifiStateMachine.CONNECT_MODE);
@@ -914,7 +917,7 @@ public class WifiStateMachineTest {
*/
@Test
public void reconnectToConnectedNetwork() throws Exception {
- addNetworkAndVerifySuccess();
+ initializeAndAddNetworkAndVerifySuccess();
mWsm.setOperationalMode(WifiStateMachine.CONNECT_MODE);
mLooper.dispatchAll();
@@ -945,7 +948,7 @@ public class WifiStateMachineTest {
@Test
public void testDhcpFailure() throws Exception {
- addNetworkAndVerifySuccess();
+ initializeAndAddNetworkAndVerifySuccess();
mWsm.setOperationalMode(WifiStateMachine.CONNECT_MODE);
mLooper.dispatchAll();
@@ -973,7 +976,7 @@ public class WifiStateMachineTest {
@Test
public void testBadNetworkEvent() throws Exception {
- addNetworkAndVerifySuccess();
+ initializeAndAddNetworkAndVerifySuccess();
mWsm.setOperationalMode(WifiStateMachine.CONNECT_MODE);
mLooper.dispatchAll();
@@ -1503,4 +1506,15 @@ public class WifiStateMachineTest {
assertEquals(SupplicantState.DISCONNECTED, wifiInfo.getSupplicantState());
assertNull(wifiInfo.getBSSID());
}
+
+ /**
+ * Adds the network without putting WifiStateMachine into ConnectMode.
+ */
+ @Test
+ public void addNetworkInInitialState() throws Exception {
+ // We should not be in initial state now.
+ assertTrue("InitialState".equals(getCurrentState().getName()));
+ addNetworkAndVerifySuccess(false);
+ verify(mWifiConnectivityManager, never()).setUserConnectChoice(eq(0));
+ }
}