From 60d1feed92bcca9f437a9b323152609d8d5fc714 Mon Sep 17 00:00:00 2001 From: Michal Karpinski Date: Wed, 14 Dec 2016 13:47:37 +0000 Subject: [PATCH] [DPM] Allow lower strong auth timeout on debuggable builds Timeout can be set to lower than 1h on debuggable builds (eng, user-debug) using persist.sys.min_strong_auth_timeout system property. Bug: 29825955 Change-Id: I51d421c3e10625787ecfdbe011f9128cd47cb2a2 --- .../devicepolicy/DevicePolicyManagerService.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index aafc432f9a554..3972b886a5134 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -4343,8 +4343,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { Preconditions.checkArgument(timeoutMs >= 0, "Timeout must not be a negative number."); // timeoutMs with value 0 means that the admin doesn't participate // timeoutMs is clamped to the interval in case the internal constants change in the future - if (timeoutMs != 0 && timeoutMs < MINIMUM_STRONG_AUTH_TIMEOUT_MS) { - timeoutMs = MINIMUM_STRONG_AUTH_TIMEOUT_MS; + final long minimumStrongAuthTimeout = getMinimumStrongAuthTimeoutMs(); + if (timeoutMs != 0 && timeoutMs < minimumStrongAuthTimeout) { + timeoutMs = minimumStrongAuthTimeout; } if (timeoutMs > DevicePolicyManager.DEFAULT_STRONG_AUTH_TIMEOUT_MS) { timeoutMs = DevicePolicyManager.DEFAULT_STRONG_AUTH_TIMEOUT_MS; @@ -4388,10 +4389,19 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { strongAuthUnlockTimeout = Math.min(timeout, strongAuthUnlockTimeout); } } - return Math.max(strongAuthUnlockTimeout, MINIMUM_STRONG_AUTH_TIMEOUT_MS); + return Math.max(strongAuthUnlockTimeout, getMinimumStrongAuthTimeoutMs()); } } + private long getMinimumStrongAuthTimeoutMs() { + if (!mInjector.isBuildDebuggable()) { + return MINIMUM_STRONG_AUTH_TIMEOUT_MS; + } + return Math.min(mInjector.systemPropertiesGetLong("persist.sys.min_strong_auth_timeout", + MINIMUM_STRONG_AUTH_TIMEOUT_MS), + MINIMUM_STRONG_AUTH_TIMEOUT_MS); + } + @Override public void lockNow(boolean parent) { if (!mHasFeature) {