summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2019-10-23 14:18:38 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2019-10-23 14:18:38 +0000
commit2b675f5fc532687617bd8d29474657cab35285a0 (patch)
tree7fec9fd720dc189e32a174ac62f5fcc279b217c7 /tests
parenta0f3319245acfcb29a868ffb016bf657d89b5fbd (diff)
parentf81c5db682f0e5f12705d0c5c9d6577cbeb333f6 (diff)
Merge "WifiStack: More user manager @hide cleanups"
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/ConfigurationMapTest.java17
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java24
-rw-r--r--tests/wifitests/src/com/android/server/wifi/util/WifiPermissionsUtilTest.java4
3 files changed, 24 insertions, 21 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/ConfigurationMapTest.java b/tests/wifitests/src/com/android/server/wifi/ConfigurationMapTest.java
index 4a0e4e598..0b3cc45e8 100644
--- a/tests/wifitests/src/com/android/server/wifi/ConfigurationMapTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/ConfigurationMapTest.java
@@ -19,7 +19,7 @@ package com.android.server.wifi;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
-import static org.mockito.Mockito.anyInt;
+import static org.mockito.Mockito.any;
import static org.mockito.Mockito.when;
import android.content.pm.UserInfo;
@@ -85,11 +85,13 @@ public class ConfigurationMapTest extends WifiBaseTest {
MockitoAnnotations.initMocks(this);
// by default, return false
- when(mUserManager.isSameProfileGroup(anyInt(), anyInt())).thenReturn(false);
+ when(mUserManager.isSameProfileGroup(any(), any())).thenReturn(false);
// return true for these 2 userids
- when(mUserManager.isSameProfileGroup(UserHandle.USER_SYSTEM, SYSTEM_MANAGE_PROFILE_USER_ID))
+ when(mUserManager.isSameProfileGroup(UserHandle.SYSTEM,
+ UserHandle.of(SYSTEM_MANAGE_PROFILE_USER_ID)))
.thenReturn(true);
- when(mUserManager.isSameProfileGroup(SYSTEM_MANAGE_PROFILE_USER_ID, UserHandle.USER_SYSTEM))
+ when(mUserManager.isSameProfileGroup(UserHandle.of(SYSTEM_MANAGE_PROFILE_USER_ID),
+ UserHandle.SYSTEM))
.thenReturn(true);
mConfigs = new ConfigurationMap(mUserManager);
}
@@ -134,9 +136,10 @@ public class ConfigurationMapTest extends WifiBaseTest {
// user. Also, check that *ForAllUsers() methods can be used to access all network
// configurations, irrespective of their visibility to the current user.
for (WifiConfiguration config : configs) {
- int creatorUserId = UserHandle.getUserHandleForUid(config.creatorUid).getIdentifier();
- if (config.shared || creatorUserId == mCurrentUserId
- || mUserManager.isSameProfileGroup(mCurrentUserId, creatorUserId)) {
+ final UserHandle currentUser = UserHandle.of(mCurrentUserId);
+ final UserHandle creatorUser = UserHandle.getUserHandleForUid(config.creatorUid);
+ if (config.shared || currentUser.equals(creatorUser)
+ || mUserManager.isSameProfileGroup(currentUser, creatorUser)) {
configsForCurrentUser.add(config);
if (config.status != WifiConfiguration.Status.DISABLED) {
enabledConfigsForCurrentUser.add(config);
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
index 406922b22..98fcd95cb 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
@@ -3072,7 +3072,7 @@ public class WifiConfigManagerTest extends WifiBaseTest {
};
setupStoreDataForUserRead(user2Networks, new HashMap<>());
// Now switch the user to user 2 and ensure that shared network's IDs have not changed.
- when(mUserManager.isUserUnlockingOrUnlocked(user2)).thenReturn(true);
+ when(mUserManager.isUserUnlockingOrUnlocked(UserHandle.of(user2))).thenReturn(true);
mWifiConfigManager.handleUserSwitch(user2);
verify(mWifiConfigStore).switchUserStoresAndRead(any(List.class));
@@ -3150,7 +3150,7 @@ public class WifiConfigManagerTest extends WifiBaseTest {
};
setupStoreDataForUserRead(user2Networks, new HashMap<>());
// Now switch the user to user 2 and ensure that user 1's private network has been removed.
- when(mUserManager.isUserUnlockingOrUnlocked(user2)).thenReturn(true);
+ when(mUserManager.isUserUnlockingOrUnlocked(UserHandle.of(user2))).thenReturn(true);
Set<Integer> removedNetworks = mWifiConfigManager.handleUserSwitch(user2);
verify(mWifiConfigStore).switchUserStoresAndRead(any(List.class));
assertTrue((removedNetworks.size() == 1) && (removedNetworks.contains(user1NetworkId)));
@@ -3167,7 +3167,7 @@ public class WifiConfigManagerTest extends WifiBaseTest {
// 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);
+ when(mUserManager.isUserUnlockingOrUnlocked(UserHandle.of(user2))).thenReturn(true);
removedNetworks = mWifiConfigManager.handleUserSwitch(user2);
assertTrue(removedNetworks.isEmpty());
}
@@ -3211,7 +3211,7 @@ public class WifiConfigManagerTest extends WifiBaseTest {
};
setupStoreDataForUserRead(user2Networks, new HashMap<>());
// Now switch the user to user 2 and ensure that no private network has been removed.
- when(mUserManager.isUserUnlockingOrUnlocked(user2)).thenReturn(true);
+ when(mUserManager.isUserUnlockingOrUnlocked(UserHandle.of(user2))).thenReturn(true);
Set<Integer> removedNetworks = mWifiConfigManager.handleUserSwitch(user2);
verify(mWifiConfigStore).switchUserStoresAndRead(any(List.class));
assertTrue(removedNetworks.isEmpty());
@@ -3275,7 +3275,7 @@ public class WifiConfigManagerTest extends WifiBaseTest {
// Now switch the user to user2 and ensure that user 2's private network has been moved to
// the user store.
- when(mUserManager.isUserUnlockingOrUnlocked(user2)).thenReturn(true);
+ when(mUserManager.isUserUnlockingOrUnlocked(UserHandle.of(user2))).thenReturn(true);
mWifiConfigManager.handleUserSwitch(user2);
// Set the expected network list before comparing. user1Network should be in shared data.
// Note: In the real world, user1Network will no longer be visible now because it should
@@ -3365,7 +3365,7 @@ public class WifiConfigManagerTest extends WifiBaseTest {
setupStoreDataForUserRead(new ArrayList<>(), new HashMap<>());
// user2 is unlocked and switched to foreground.
- when(mUserManager.isUserUnlockingOrUnlocked(user2)).thenReturn(true);
+ when(mUserManager.isUserUnlockingOrUnlocked(UserHandle.of(user2))).thenReturn(true);
mWifiConfigManager.handleUserSwitch(user2);
// Ensure that the read was invoked.
mContextConfigStoreMockOrder.verify(mWifiConfigStore)
@@ -3387,7 +3387,7 @@ public class WifiConfigManagerTest extends WifiBaseTest {
assertTrue(mWifiConfigManager.loadFromStore());
// user2 is locked and switched to foreground.
- when(mUserManager.isUserUnlockingOrUnlocked(user2)).thenReturn(false);
+ when(mUserManager.isUserUnlockingOrUnlocked(UserHandle.of(user2))).thenReturn(false);
mWifiConfigManager.handleUserSwitch(user2);
// Ensure that the read was not invoked.
@@ -3420,7 +3420,7 @@ public class WifiConfigManagerTest extends WifiBaseTest {
assertTrue(mWifiConfigManager.loadFromStore());
// Try stopping background user2 first, this should not do anything.
- when(mUserManager.isUserUnlockingOrUnlocked(user2)).thenReturn(false);
+ when(mUserManager.isUserUnlockingOrUnlocked(UserHandle.of(user2))).thenReturn(false);
mWifiConfigManager.handleUserStop(user2);
mContextConfigStoreMockOrder.verify(mWifiConfigStore, never())
.switchUserStoresAndRead(any(List.class));
@@ -3644,7 +3644,7 @@ public class WifiConfigManagerTest extends WifiBaseTest {
setupStoreDataForUserRead(new ArrayList<>(), new HashMap<>());
// user2 is unlocked and switched to foreground.
- when(mUserManager.isUserUnlockingOrUnlocked(user2)).thenReturn(true);
+ when(mUserManager.isUserUnlockingOrUnlocked(UserHandle.of(user2))).thenReturn(true);
mWifiConfigManager.handleUserSwitch(user2);
// Ensure that the read was invoked.
mContextConfigStoreMockOrder.verify(mWifiConfigStore)
@@ -3685,7 +3685,7 @@ public class WifiConfigManagerTest extends WifiBaseTest {
int user2 = TEST_DEFAULT_USER + 1;
setupUserProfiles(user2);
- when(mUserManager.isUserUnlockingOrUnlocked(user2)).thenReturn(false);
+ when(mUserManager.isUserUnlockingOrUnlocked(UserHandle.of(user2))).thenReturn(false);
mWifiConfigManager.handleUserSwitch(user2);
// Create a network for user2 try adding it. This should be rejected.
@@ -3746,7 +3746,7 @@ public class WifiConfigManagerTest extends WifiBaseTest {
setupStoreDataForUserRead(new ArrayList<>(), new HashMap<>());
// Now switch the user to user 2.
- when(mUserManager.isUserUnlockingOrUnlocked(user2)).thenReturn(true);
+ when(mUserManager.isUserUnlockingOrUnlocked(UserHandle.of(user2))).thenReturn(true);
mWifiConfigManager.handleUserSwitch(user2);
// Ensure that the read was invoked.
mContextConfigStoreMockOrder.verify(mWifiConfigStore)
@@ -5464,7 +5464,7 @@ public class WifiConfigManagerTest extends WifiBaseTest {
* @param userId Id of the user.
*/
private void setupUserProfiles(int userId) {
- when(mUserManager.isUserUnlockingOrUnlocked(userId)).thenReturn(true);
+ when(mUserManager.isUserUnlockingOrUnlocked(UserHandle.of(userId))).thenReturn(true);
}
private void verifyRemoveNetworksForApp() {
diff --git a/tests/wifitests/src/com/android/server/wifi/util/WifiPermissionsUtilTest.java b/tests/wifitests/src/com/android/server/wifi/util/WifiPermissionsUtilTest.java
index 6c675af79..8e3c1bb71 100644
--- a/tests/wifitests/src/com/android/server/wifi/util/WifiPermissionsUtilTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/util/WifiPermissionsUtilTest.java
@@ -1261,8 +1261,8 @@ public class WifiPermissionsUtilTest extends WifiBaseTest {
anyString(), anyInt());
doAnswer(mReturnPermission).when(mMockPermissionsWrapper).getUidPermission(
anyString(), anyInt());
- when(mMockUserManager.isSameProfileGroup(UserHandle.USER_SYSTEM,
- UserHandle.getUserHandleForUid(MANAGED_PROFILE_UID).getIdentifier()))
+ when(mMockUserManager.isSameProfileGroup(UserHandle.SYSTEM,
+ UserHandle.getUserHandleForUid(MANAGED_PROFILE_UID)))
.thenReturn(true);
when(mMockPermissionsWrapper.getCurrentUser()).thenReturn(mCurrentUser);
when(mMockPermissionsWrapper.getUidPermission(mManifestStringCoarse, mUid))