Deprecated UserManager.getUsers(excludeDying) / added getAliveUsers()
The existing method is confusing (the argument used to be called
includeDying) and it puts the burden on the caller (which need to
understand what the parameter means).
Furthermore:
- The majority of calls are for getUsers(excludeDying=true).
- The calls for getUsers(excludeDying=false) are equivalent to
calls to getUsers()
Test: m
Test: a VpnTest ConnectivityServiceTest PermissionMonitorTest
Bug: 157921703
Change-Id: Ife767a40b7b7790ba28b5377046de822ddbf275c
Merged-In: Ife767a40b7b7790ba28b5377046de822ddbf275c
(cherry picked from commit 72eeb557e7)
This commit is contained in:
@@ -174,7 +174,7 @@ public class PermissionMonitor implements PackageManagerInternal.PackageListObse
|
||||
netdPermsUids.put(uid, netdPermsUids.get(uid) | otherNetdPerms);
|
||||
}
|
||||
|
||||
List<UserInfo> users = mUserManager.getUsers(true); // exclude dying users
|
||||
List<UserInfo> users = mUserManager.getAliveUsers();
|
||||
if (users != null) {
|
||||
for (UserInfo user : users) {
|
||||
mUsers.add(user.id);
|
||||
|
||||
@@ -1233,7 +1233,7 @@ public class ConnectivityServiceTest {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mMetricsService.defaultNetworkMetrics()).thenReturn(mDefaultNetworkMetrics);
|
||||
|
||||
when(mUserManager.getUsers(eq(true))).thenReturn(
|
||||
when(mUserManager.getAliveUsers()).thenReturn(
|
||||
Arrays.asList(new UserInfo[] {
|
||||
new UserInfo(VPN_USER, "", 0),
|
||||
}));
|
||||
|
||||
@@ -123,7 +123,7 @@ public class PermissionMonitorTest {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
when(mContext.getSystemService(eq(Context.USER_SERVICE))).thenReturn(mUserManager);
|
||||
when(mUserManager.getUsers(eq(true))).thenReturn(
|
||||
when(mUserManager.getAliveUsers()).thenReturn(
|
||||
Arrays.asList(new UserInfo[] {
|
||||
new UserInfo(MOCK_USER1, "", 0),
|
||||
new UserInfo(MOCK_USER2, "", 0),
|
||||
|
||||
@@ -1325,15 +1325,14 @@ public class VpnTest {
|
||||
* @see UserManagerService#getUsers(boolean)
|
||||
*/
|
||||
doAnswer(invocation -> {
|
||||
final boolean excludeDying = (boolean) invocation.getArguments()[0];
|
||||
final ArrayList<UserInfo> result = new ArrayList<>(users.length);
|
||||
for (UserInfo ui : users) {
|
||||
if (!excludeDying || (ui.isEnabled() && !ui.partial)) {
|
||||
if (ui.isEnabled() && !ui.partial) {
|
||||
result.add(ui);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}).when(mUserManager).getUsers(anyBoolean());
|
||||
}).when(mUserManager).getAliveUsers();
|
||||
|
||||
doAnswer(invocation -> {
|
||||
final int id = (int) invocation.getArguments()[0];
|
||||
|
||||
Reference in New Issue
Block a user