Fix a bug where the wrong profile is queried

UserManager#isManagedProfile() is not aware of the user
handle of the context the UM instance is created on.
Instead, call isManagedProfile(int).

Bug: 183625645
Test: ConnectivityServiceTest
Change-Id: I1fef22d67d75df25a8c2d0694f857c3e1c1a1306
This commit is contained in:
Chalard Jean
2021-04-02 19:24:44 +09:00
parent a5323dd580
commit 0a04bdb730
2 changed files with 3 additions and 8 deletions

View File

@@ -9211,14 +9211,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
throw new IllegalArgumentException("Must explicitly specify a user handle ("
+ "UserHandle.CURRENT not supported)");
}
final UserManager um;
try {
um = mContext.createContextAsUser(profile, 0 /* flags */)
.getSystemService(UserManager.class);
} catch (IllegalStateException e) {
throw new IllegalArgumentException("Profile does not exist");
}
if (!um.isManagedProfile()) {
final UserManager um = mContext.getSystemService(UserManager.class);
if (!um.isManagedProfile(profile.getIdentifier())) {
throw new IllegalArgumentException("Profile must be a managed profile");
}
// Strictly speaking, mOemNetworkPreferences should only be touched on the

View File

@@ -572,6 +572,7 @@ public class ConnectivityServiceTest {
final UserManager umMock = createContextAsUser(userHandle, 0 /* flags */)
.getSystemService(UserManager.class);
doReturn(value).when(umMock).isManagedProfile();
doReturn(value).when(mUserManager).isManagedProfile(eq(userHandle.getIdentifier()));
}
@Override