diff options
author | Nate Jiang <qiangjiang@google.com> | 2020-07-23 09:55:23 -0700 |
---|---|---|
committer | Nate Jiang <qiangjiang@google.com> | 2020-07-28 00:11:40 +0000 |
commit | 5564f3900cb37d76d769cd9e185a53c26e0cea82 (patch) | |
tree | af6d71ad24b8fc467ffa2d951b7a8d844606c13f /tests | |
parent | 6eea218042c68bce1ec6568247744a33d988b308 (diff) |
Remove all ephemeral networks when user switch
Every time switch user, remove all ephemeral nerworks to avoil uid
mismatch
Bug: 161841383
Test: atest com.android.server.wifi
Merged-In: I0caf8e08215055154a1f45714731d3a25ddac012
Change-Id: I0caf8e08215055154a1f45714731d3a25ddac012
(cherry picked from commit 9d4b4f2697baef0f927e6912e36882a8ee7f0038)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java index d2584adbc..3de8cb98b 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java @@ -2915,6 +2915,7 @@ public class WifiConfigManagerTest extends WifiBaseTest { Set<Integer> removedNetworks = mWifiConfigManager.handleUserSwitch(user2); verify(mWifiConfigStore).switchUserStoresAndRead(any(List.class)); assertTrue((removedNetworks.size() == 1) && (removedNetworks.contains(user1NetworkId))); + verify(mWcmListener).onNetworkRemoved(any()); // Set the expected networks to be |sharedNetwork| and |user2Network|. List<WifiConfiguration> expectedNetworks = new ArrayList<WifiConfiguration>() { @@ -2933,6 +2934,66 @@ public class WifiConfigManagerTest extends WifiBaseTest { assertTrue(removedNetworks.isEmpty()); } + @Test + public void testHandleUserSwitchRemovesOldUserEphemeralNetworks() throws Exception { + int user1 = TEST_DEFAULT_USER; + int user2 = TEST_DEFAULT_USER + 1; + setupUserProfiles(user2); + + int appId = 674; + + // Create 2 networks. 1 ephemeral network for user1 and 1 shared. + final WifiConfiguration sharedNetwork = WifiConfigurationTestUtil.createPskNetwork(); + + // Set up the store data that is loaded initially. + List<WifiConfiguration> sharedNetworks = new ArrayList<WifiConfiguration>() { + { + add(sharedNetwork); + } + }; + setupStoreDataForRead(sharedNetworks, Collections.EMPTY_LIST); + assertTrue(mWifiConfigManager.loadFromStore()); + verify(mWifiConfigStore).read(); + + WifiConfiguration ephemeralNetwork = WifiConfigurationTestUtil.createEphemeralNetwork(); + verifyAddEphemeralNetworkToWifiConfigManager(ephemeralNetwork); + + // Fetch the network ID assigned to the user 1 network initially. + int ephemeralNetworkId = WifiConfiguration.INVALID_NETWORK_ID; + List<WifiConfiguration> retrievedNetworks = + mWifiConfigManager.getConfiguredNetworksWithPasswords(); + for (WifiConfiguration network : retrievedNetworks) { + if (network.getKey().equals(ephemeralNetwork.getKey())) { + ephemeralNetworkId = network.networkId; + } + } + + // Now switch the user to user 2 and ensure that user 1's private network has been removed. + when(mUserManager.isUserUnlockingOrUnlocked(UserHandle.of(user2))).thenReturn(true); + Set<Integer> removedNetworks = mWifiConfigManager.handleUserSwitch(user2); + verify(mWifiConfigStore).switchUserStoresAndRead(any(List.class)); + assertTrue((removedNetworks.size() == 1)); + assertTrue(removedNetworks.contains(ephemeralNetworkId)); + verifyNetworkRemoveBroadcast(); + verify(mWcmListener).onNetworkRemoved(any()); + + + // Set the expected networks to be |sharedNetwork|. + List<WifiConfiguration> expectedNetworks = new ArrayList<WifiConfiguration>() { + { + add(sharedNetwork); + } + }; + 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(UserHandle.of(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. |