diff options
author | Roshan Pius <rpius@google.com> | 2016-12-01 22:23:27 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-12-01 22:23:27 +0000 |
commit | 9560d5358a62b46482725ad62a4b94267e4a9893 (patch) | |
tree | 44a3d77acbd78fa99040f2bba17ecce77c3db64b /tests | |
parent | 506ef7c01800526c9654965532648c048bbc2e86 (diff) | |
parent | 1cb361461f6ecc684761fc3940c1db622192cad1 (diff) |
WifiConfigManager: Disconnect from private network on user switch
am: 1cb361461f
Change-Id: I655871a43cf36fcd3d372bd5e63427bca8a67ad8
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java | 71 |
1 files changed, 69 insertions, 2 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java index 40cfb9910..6ea309a7c 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java @@ -1817,6 +1817,16 @@ public class WifiConfigManagerTest { when(mWifiConfigStore.read()).thenReturn(loadStoreData); assertTrue(mWifiConfigManager.loadFromStore()); + // Fetch the network ID assigned to the user 1 network initially. + int user1NetworkId = WifiConfiguration.INVALID_NETWORK_ID; + List<WifiConfiguration> retrievedNetworks = + mWifiConfigManager.getConfiguredNetworksWithPasswords(); + for (WifiConfiguration network : retrievedNetworks) { + if (network.configKey().equals(user1Network.configKey())) { + user1NetworkId = network.networkId; + } + } + // Set up the user 2 store data that is loaded at user switch. List<WifiConfiguration> user2Networks = new ArrayList<WifiConfiguration>() { { @@ -1830,7 +1840,8 @@ public class WifiConfigManagerTest { .thenReturn(newUserStoreData); // Now switch the user to user 2 and ensure that user 1's private network has been removed. when(mUserManager.isUserUnlockingOrUnlocked(user2)).thenReturn(true); - mWifiConfigManager.handleUserSwitch(user2); + Set<Integer> removedNetworks = mWifiConfigManager.handleUserSwitch(user2); + assertTrue((removedNetworks.size() == 1) && (removedNetworks.contains(user1NetworkId))); // Set the expected networks to be |sharedNetwork| and |user2Network|. List<WifiConfiguration> expectedNetworks = new ArrayList<WifiConfiguration>() { @@ -1841,12 +1852,68 @@ public class WifiConfigManagerTest { }; WifiConfigurationTestUtil.assertConfigurationsEqualForConfigManagerAddOrUpdate( expectedNetworks, mWifiConfigManager.getConfiguredNetworksWithPasswords()); + + // Send another user switch indication with the same user 2. This should be ignored and + // hence should not remove any new networks. + when(mUserManager.isUserUnlockingOrUnlocked(user2)).thenReturn(true); + removedNetworks = mWifiConfigManager.handleUserSwitch(user2); + assertTrue(removedNetworks.isEmpty()); + } + + /** + * Verifies the foreground user switch using {@link WifiConfigManager#handleUserSwitch(int)} + * and ensures that user switch from a user with no private networks is handled. + * Test scenario: + * 1. Load the shared networks from shared store and emptu user 1 store. + * 2. Switch to user 2 and ensure that no private networks were removed. + */ + @Test + public void testHandleUserSwitchWithNoOldUserPrivateNetworks() throws Exception { + int user1 = TEST_DEFAULT_USER; + int user2 = TEST_DEFAULT_USER + 1; + setupUserProfiles(user2); + + int appId = 674; + + // Create 2 networks. 1 for user2 and 1 shared. + final WifiConfiguration user2Network = WifiConfigurationTestUtil.createPskNetwork(); + user2Network.shared = false; + user2Network.creatorUid = UserHandle.getUid(user2, appId); + final WifiConfiguration sharedNetwork = WifiConfigurationTestUtil.createPskNetwork(); + + // Set up the store data that is loaded initially. + List<WifiConfiguration> sharedNetworks = new ArrayList<WifiConfiguration>() { + { + add(sharedNetwork); + } + }; + WifiConfigStoreData loadStoreData = + new WifiConfigStoreData(sharedNetworks, new ArrayList<WifiConfiguration>(), + new HashSet<String>()); + when(mWifiConfigStore.read()).thenReturn(loadStoreData); + assertTrue(mWifiConfigManager.loadFromStore()); + + // Set up the user 2 store data that is loaded at user switch. + List<WifiConfiguration> user2Networks = new ArrayList<WifiConfiguration>() { + { + add(user2Network); + } + }; + WifiConfigStoreData newUserStoreData = + new WifiConfigStoreData(new ArrayList<WifiConfiguration>(), user2Networks, + new HashSet<String>()); + when(mWifiConfigStore.switchUserStoreAndRead(any(WifiConfigStore.StoreFile.class))) + .thenReturn(newUserStoreData); + // Now switch the user to user 2 and ensure that no private network has been removed. + when(mUserManager.isUserUnlockingOrUnlocked(user2)).thenReturn(true); + Set<Integer> removedNetworks = mWifiConfigManager.handleUserSwitch(user2); + assertTrue(removedNetworks.isEmpty()); } /** * Verifies the foreground user switch using {@link WifiConfigManager#handleUserSwitch(int)} * and ensures that any non current user private networks are moved to shared store file. - * This test simultates the following test case: + * This test simulates the following test case: * 1. Loads the shared networks from shared store at bootup. * 2. Load the private networks from user store on user 1 unlock. * 3. Switch to user 2 and ensure that the user 2's private network has been moved to user 2's |