From b7c8877ba14e47c3a6d02a77b87ad7f36542e96f Mon Sep 17 00:00:00 2001 From: Felipe Leme Date: Tue, 3 Nov 2020 12:04:05 -0800 Subject: [PATCH] Do not power off display on lockNow() on automotive builds. Test: manual verification Fixes: 171517112 Change-Id: I410e06b911b099c0ed4b7b4e3ac493c9a272fa6b Merged-In: I410e06b911b099c0ed4b7b4e3ac493c9a272fa6b (cherry picked from commit fc586009b1fc381dbbc4061f876fc52c11a79814) --- .../app/admin/DevicePolicyManager.java | 6 ++++++ .../DevicePolicyManagerService.java | 20 ++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java index 322cac81d58b3..e2e8049c2980f 100644 --- a/core/java/android/app/admin/DevicePolicyManager.java +++ b/core/java/android/app/admin/DevicePolicyManager.java @@ -4263,6 +4263,9 @@ public class DevicePolicyManager { * This method can be called on the {@link DevicePolicyManager} instance returned by * {@link #getParentProfileInstance(ComponentName)} in order to lock the parent profile. *

+ * NOTE: on {@link android.content.pm.PackageManager#FEATURE_AUTOMOTIVE automotive builds}, this + * method doesn't turn off the screen as it would be a driving safety distraction. + *

* Equivalent to calling {@link #lockNow(int)} with no flags. * * @throws SecurityException if the calling application does not own an active administrator @@ -4306,6 +4309,9 @@ public class DevicePolicyManager { * Calling the method twice in this order ensures that all users are locked and does not * stop the device admin on the managed profile from issuing a second call to lock its own * profile. + *

+ * NOTE: on {@link android.content.pm.PackageManager#FEATURE_AUTOMOTIVE automotive builds}, this + * method doesn't turn off the screen as it would be a driving safety distraction. * * @param flags May be 0 or {@link #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY}. * @throws SecurityException if the calling application does not own an active administrator diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index c6b93d6ca4f48..ce3cdeab232a5 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -640,6 +640,11 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { */ final boolean mIsWatch; + /** + * Whether or not this device is an automotive. + */ + private final boolean mIsAutomotive; + /** * Whether this device has the telephony feature. */ @@ -2567,6 +2572,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { .hasSystemFeature(PackageManager.FEATURE_WATCH); mHasTelephonyFeature = mInjector.getPackageManager() .hasSystemFeature(PackageManager.FEATURE_TELEPHONY); + mIsAutomotive = mInjector.getPackageManager() + .hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE); mBackgroundHandler = BackgroundThread.getHandler(); // Needed when mHasFeature == false, because it controls the certificate warning text. @@ -6080,9 +6087,16 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { // Require authentication for the device or profile if (userToLock == UserHandle.USER_ALL) { - // Power off the display - mInjector.powerManagerGoToSleep(SystemClock.uptimeMillis(), - PowerManager.GO_TO_SLEEP_REASON_DEVICE_ADMIN, 0); + if (mIsAutomotive) { + if (VERBOSE_LOG) { + Slog.v(LOG_TAG, "lockNow(): not powering off display on automotive" + + " build"); + } + } else { + // Power off the display + mInjector.powerManagerGoToSleep(SystemClock.uptimeMillis(), + PowerManager.GO_TO_SLEEP_REASON_DEVICE_ADMIN, 0); + } mInjector.getIWindowManager().lockNow(null); } else { mInjector.getTrustManager().setDeviceLockedForUser(userToLock, true);