Merge "Lockdown DPMS.getOrganizationNameForUser()" into sc-qpr1-dev

This commit is contained in:
TreeHugger Robot
2021-09-29 23:58:52 +00:00
committed by Android (Google) Code Review
2 changed files with 7 additions and 0 deletions

View File

@@ -14060,6 +14060,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
final CallerIdentity caller = getCallerIdentity();
Preconditions.checkCallAuthorization(hasFullCrossUsersPermission(caller, userHandle));
Preconditions.checkCallAuthorization(canManageUsers(caller));
Preconditions.checkCallAuthorization(isManagedProfile(userHandle),
"You can not get organization name outside a managed profile, userId = %d",
userHandle);

View File

@@ -7753,6 +7753,12 @@ public class DevicePolicyManagerTest extends DpmTestBase {
DpmMockContext.CALLER_SYSTEM_USER_UID, admin1.getPackageName(), MODE_DEFAULT);
}
@Test
public void testGetOrganizationNameForUser_calledByNonPrivilegedApp_throwsException() {
assertExpectException(SecurityException.class, "Calling identity is not authorized",
() -> dpm.getOrganizationNameForUser(UserHandle.USER_SYSTEM));
}
private void setupVpnAuthorization(String userVpnPackage, int userVpnUid) {
final AppOpsManager.PackageOps vpnOp = new AppOpsManager.PackageOps(userVpnPackage,
userVpnUid, List.of(new AppOpsManager.OpEntry(