From e011ffe22a80129bf7a1f1e54ac0fd8ca99feda2 Mon Sep 17 00:00:00 2001 From: Alex Johnston Date: Wed, 19 May 2021 14:10:09 +0100 Subject: [PATCH] Add DPMS reset password metrics PDD: https://eldar.corp.google.com/assessments/875507949 RESET_PASSWORD We log this when the admin forces a new password for the device or the managed profile. There is no log data (only the event). RESET_PASSWORD_WITH_TOKEN We log this when the admin forces a new password for the device or the managed profile. The admin can change the password even before the device is unlocked, as long as the password reset token was previously provisioned. There is no log data (only the event). Bug: 186740337 Test: atest com.android.server.devicepolicy.DevicePolicyManagerTest atest com.android.cts.devicepolicy.MixedDeviceOwnerTest#testResetPasswordWithToken Change-Id: I07b66904e423bc6e1f4bdd4ae44aad0cae6d537b --- .../DevicePolicyManagerService.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index 23a67b72c7346..e418d343183f4 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -4929,10 +4929,16 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { final CallerIdentity caller = getCallerIdentity(); final int userHandle = caller.getUserId(); - // As of R, only privlleged caller holding RESET_PASSWORD can call resetPassword() to + // As of R, only privileged caller holding RESET_PASSWORD can call resetPassword() to // set password to an unsecured user. if (hasCallingPermission(permission.RESET_PASSWORD)) { - return setPasswordPrivileged(password, flags, caller); + final boolean result = setPasswordPrivileged(password, flags, caller); + if (result) { + DevicePolicyEventLogger + .createEvent(DevicePolicyEnums.RESET_PASSWORD) + .write(); + } + return result; } // If caller has PO (or DO) throw or fail silently depending on its target SDK level. @@ -15226,8 +15232,15 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { DevicePolicyData policy = getUserData(caller.getUserId()); if (policy.mPasswordTokenHandle != 0) { final String password = passwordOrNull != null ? passwordOrNull : ""; - return resetPasswordInternal(password, policy.mPasswordTokenHandle, token, - flags, caller); + final boolean result = resetPasswordInternal(password, policy.mPasswordTokenHandle, + token, flags, caller); + if (result) { + DevicePolicyEventLogger + .createEvent(DevicePolicyEnums.RESET_PASSWORD_WITH_TOKEN) + .setAdmin(caller.getComponentName()) + .write(); + } + return result; } else { Slogf.w(LOG_TAG, "No saved token handle"); }