From 9d90bbc9fdf740a116b719c6d6f841320cb24d67 Mon Sep 17 00:00:00 2001 From: Pavel Grafov Date: Mon, 3 Apr 2023 14:20:38 +0000 Subject: [PATCH] Ensure correct admin name is logged. Currently if permission checks aren't enabled, caller.getPackageName() will return null and it will be passed to metrics and security log. This CL changes it so that caller always has package. Bug: 266588263 Test: atest OrgOwnedProfileOwnerTest#testSecurityLogging Change-Id: I55ce06b89563421af50280d893029ac7a41f8081 --- .../server/devicepolicy/DevicePolicyManagerService.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index 96cc36bb135ee..39337660c55c1 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -2315,7 +2315,6 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { * Creates a new {@link CallerIdentity} object to represent the caller's identity. */ private CallerIdentity getCallerIdentity(@Nullable String callerPackage) { - return getCallerIdentity(null, callerPackage); } @@ -5305,11 +5304,8 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { Preconditions.checkArgument(allowedModes.contains(passwordComplexity), "Provided complexity is not one of the allowed values."); - CallerIdentity caller; - if (isPermissionCheckFlagEnabled()) { - caller = getCallerIdentity(callerPackageName); - } else { - caller = getCallerIdentity(); + CallerIdentity caller = getCallerIdentity(callerPackageName); + if (!isPermissionCheckFlagEnabled()) { Preconditions.checkCallAuthorization( isDefaultDeviceOwner(caller) || isProfileOwner(caller)); Preconditions.checkArgument(!calledOnParent || isProfileOwner(caller));