From 789f05202755254d591fca488048209765d7bd23 Mon Sep 17 00:00:00 2001 From: Will Date: Fri, 4 Mar 2022 15:20:06 -0800 Subject: [PATCH] Add the ability to restrict dreams to the system user. By default, this functionality is disabled. Which means that all users should continue to be able to start dreams. Bug: 213906883 Test: Manually with the following steps: Step 0: Have 2 or more users on the device. Enable screen saver in display settings. Optionally set the screen timeout to 15 seconds for faster dreaming. Step 1: With the system user (the first user created) as the selected user, allow the device to fall into a dream. Make sure the dream appears. Switch to a different user. Allow the device to fall into a dream. Verify that the device behaves the same way it would without this change (depending on other configuration settings, it may or may not dream, but this change itself does not prevent any user from dreaming). Step 2: To verify that this change does prevent non-system users from dreaming, set the config_dreamsOnlyEnabledForSystemUser config value to true in core/res/res/values/config.xml and push the change to a device. Switch to a non-system user and allow the device to fall into a dream. The device should not display a dream (and instead, should just display a black screen). Change-Id: I2fa7a16ee7c6250a7a3ac49e82bb4c8085451391 --- core/res/res/values/config.xml | 2 ++ core/res/res/values/symbols.xml | 1 + .../android/server/dreams/DreamManagerService.java | 13 +++++++++++++ 3 files changed, 16 insertions(+) diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index 60d875c2ca39a..05a742c4bc742 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -2403,6 +2403,8 @@ 5 900000 + + false diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index dd69fa0bebb20..ba598ad0bdfff 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -2216,6 +2216,7 @@ + diff --git a/services/core/java/com/android/server/dreams/DreamManagerService.java b/services/core/java/com/android/server/dreams/DreamManagerService.java index 436c434ccbca7..f68d22acd6aba 100644 --- a/services/core/java/com/android/server/dreams/DreamManagerService.java +++ b/services/core/java/com/android/server/dreams/DreamManagerService.java @@ -92,6 +92,7 @@ public final class DreamManagerService extends SystemService { private boolean mCurrentDreamIsDozing; private boolean mCurrentDreamIsWaking; private boolean mForceAmbientDisplayEnabled; + private boolean mDreamsOnlyEnabledForSystemUser; private int mCurrentDreamDozeScreenState = Display.STATE_UNKNOWN; private int mCurrentDreamDozeScreenBrightness = PowerManager.BRIGHTNESS_DEFAULT; @@ -115,6 +116,8 @@ public final class DreamManagerService extends SystemService { mContext.getResources().getString(R.string.config_loggable_dream_prefix)); AmbientDisplayConfiguration adc = new AmbientDisplayConfiguration(mContext); mAmbientDisplayComponent = ComponentName.unflattenFromString(adc.ambientDisplayComponent()); + mDreamsOnlyEnabledForSystemUser = + mContext.getResources().getBoolean(R.bool.config_dreamsOnlyEnabledForSystemUser); } @Override @@ -156,6 +159,7 @@ public final class DreamManagerService extends SystemService { pw.println("mCurrentDreamIsDozing=" + mCurrentDreamIsDozing); pw.println("mCurrentDreamIsWaking=" + mCurrentDreamIsWaking); pw.println("mForceAmbientDisplayEnabled=" + mForceAmbientDisplayEnabled); + pw.println("mDreamsOnlyEnabledForSystemUser=" + mDreamsOnlyEnabledForSystemUser); pw.println("mCurrentDreamDozeScreenState=" + Display.stateToString(mCurrentDreamDozeScreenState)); pw.println("mCurrentDreamDozeScreenBrightness=" + mCurrentDreamDozeScreenBrightness); @@ -314,6 +318,11 @@ public final class DreamManagerService extends SystemService { } private ComponentName[] getDreamComponentsForUser(int userId) { + if (!dreamsEnabledForUser(userId)) { + // Don't return any dream components if the user is not allowed to dream. + return null; + } + String names = Settings.Secure.getStringForUser(mContext.getContentResolver(), Settings.Secure.SCREENSAVER_COMPONENTS, userId); @@ -367,6 +376,10 @@ public final class DreamManagerService extends SystemService { } + private boolean dreamsEnabledForUser(int userId) { + return !mDreamsOnlyEnabledForSystemUser || (userId == UserHandle.USER_SYSTEM); + } + private ServiceInfo getServiceInfo(ComponentName name) { try { return name != null ? mContext.getPackageManager().getServiceInfo(name,