diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2017-04-05 02:53:38 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2017-04-05 02:53:39 +0000 |
commit | 24ee320f5ef7359514bd5167a4a11e31813e5019 (patch) | |
tree | e1802e16c65c6c88657cb70c6074093b95eb9e26 /tests | |
parent | 19c1d955a4784f12c49714662569c022b51707e6 (diff) | |
parent | dc5eab67d9ca3e0453318071746e76b5d16990d6 (diff) |
Merge "WSM: Support add/update/enable network in any state" into oc-dev
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java | 58 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java | 46 |
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 69049a6a1..987c50937 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java @@ -115,6 +115,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. @@ -171,6 +172,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); @@ -202,6 +205,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)} */ @@ -2378,8 +2393,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()); } @@ -2399,8 +2413,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()); } @@ -2920,8 +2933,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 @@ -2933,7 +2945,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 @@ -2945,7 +2957,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 @@ -3181,7 +3193,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; } @@ -3472,17 +3484,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 8f3761a96..5c3504906 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(); @@ -1498,4 +1501,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)); + } } |