summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2019-10-17 06:14:51 -0700
committerRoshan Pius <rpius@google.com>2019-10-21 19:48:12 -0700
commitf81c5db682f0e5f12705d0c5c9d6577cbeb333f6 (patch)
tree90cbf2d104ec53d54b4593a62f63d98db8124f9e
parent4b439b9cfa18bafdaf97001f9ab795a3090cdb00 (diff)
WifiStack: More user manager @hide cleanups
Use the newly added @SystemApis. Bug: 142024973 Test: atest com.android.server.wifi Test: Device boots up & connects to wifi networks Change-Id: Ia0135ef0a9b3078d23764675f03ea980691ee30a
-rw-r--r--service/java/com/android/server/wifi/ConfigurationMap.java7
-rw-r--r--service/java/com/android/server/wifi/WifiConfigManager.java14
-rw-r--r--service/java/com/android/server/wifi/util/WifiPermissionsUtil.java6
-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
6 files changed, 39 insertions, 33 deletions
diff --git a/service/java/com/android/server/wifi/ConfigurationMap.java b/service/java/com/android/server/wifi/ConfigurationMap.java
index b01adac8e..02652a81f 100644
--- a/service/java/com/android/server/wifi/ConfigurationMap.java
+++ b/service/java/com/android/server/wifi/ConfigurationMap.java
@@ -44,9 +44,10 @@ public class ConfigurationMap {
// RW methods:
public WifiConfiguration put(WifiConfiguration config) {
final WifiConfiguration current = mPerID.put(config.networkId, config);
- final int creatorUserId = UserHandle.getUserHandleForUid(config.creatorUid).getIdentifier();
- if (config.shared || mCurrentUserId == creatorUserId
- || 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)) {
mPerIDForCurrentUser.put(config.networkId, config);
mScanResultMatchInfoMapForCurrentUser.put(
ScanResultMatchInfo.fromWifiConfiguration(config), config);
diff --git a/service/java/com/android/server/wifi/WifiConfigManager.java b/service/java/com/android/server/wifi/WifiConfigManager.java
index b34084e73..c57407863 100644
--- a/service/java/com/android/server/wifi/WifiConfigManager.java
+++ b/service/java/com/android/server/wifi/WifiConfigManager.java
@@ -950,9 +950,10 @@ public class WifiConfigManager {
if (uid == android.os.Process.SYSTEM_UID || uid == mSystemUiUid) {
return true;
} else {
- int userId = UserHandle.getUserHandleForUid(uid).getIdentifier();
- return userId == mCurrentUserId
- || mUserManager.isSameProfileGroup(mCurrentUserId, userId);
+ UserHandle currentUser = UserHandle.of(mCurrentUserId);
+ UserHandle callingUser = UserHandle.getUserHandleForUid(uid);
+ return currentUser.equals(callingUser)
+ || mUserManager.isSameProfileGroup(currentUser, callingUser);
}
}
@@ -2995,7 +2996,7 @@ public class WifiConfigManager {
mPendingUnlockStoreRead = true;
return new HashSet<>();
}
- if (mUserManager.isUserUnlockingOrUnlocked(mCurrentUserId)) {
+ if (mUserManager.isUserUnlockingOrUnlocked(UserHandle.of(mCurrentUserId))) {
saveToStore(true);
}
// Remove any private networks of the old user before switching the userId.
@@ -3003,7 +3004,7 @@ public class WifiConfigManager {
mConfiguredNetworks.setNewUser(userId);
mCurrentUserId = userId;
- if (mUserManager.isUserUnlockingOrUnlocked(mCurrentUserId)) {
+ if (mUserManager.isUserUnlockingOrUnlocked(UserHandle.of(mCurrentUserId))) {
handleUserUnlockOrSwitch(mCurrentUserId);
} else {
// Cannot read data from new user's CE store file before they log-in.
@@ -3051,7 +3052,8 @@ public class WifiConfigManager {
if (mVerboseLoggingEnabled) {
Log.v(TAG, "Handling user stop for " + userId);
}
- if (userId == mCurrentUserId && mUserManager.isUserUnlockingOrUnlocked(mCurrentUserId)) {
+ if (userId == mCurrentUserId
+ && mUserManager.isUserUnlockingOrUnlocked(UserHandle.of(mCurrentUserId))) {
saveToStore(true);
clearInternalDataForCurrentUser();
}
diff --git a/service/java/com/android/server/wifi/util/WifiPermissionsUtil.java b/service/java/com/android/server/wifi/util/WifiPermissionsUtil.java
index 50595b972..65bcb3c10 100644
--- a/service/java/com/android/server/wifi/util/WifiPermissionsUtil.java
+++ b/service/java/com/android/server/wifi/util/WifiPermissionsUtil.java
@@ -360,9 +360,9 @@ public class WifiPermissionsUtil {
* current user.
*/
private boolean isCurrentProfile(int uid) {
- int currentUser = mWifiPermissionsWrapper.getCurrentUser();
- int callingUser = UserHandle.getUserHandleForUid(uid).getIdentifier();
- return callingUser == currentUser
+ UserHandle currentUser = UserHandle.of(mWifiPermissionsWrapper.getCurrentUser());
+ UserHandle callingUser = UserHandle.getUserHandleForUid(uid);
+ return currentUser.equals(callingUser)
|| mUserManager.isSameProfileGroup(currentUser, callingUser);
}
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))