diff options
| author | 2025-03-04 14:09:26 -0800 | |
|---|---|---|
| committer | 2025-03-04 14:09:26 -0800 | |
| commit | cea36ba24027ebf301c4a0cfca7ece18abc3be61 (patch) | |
| tree | d18d22d8dea18a5762119cb36bed32ed1ebec010 | |
| parent | 22067462fc35fab2822bcd7adbbf7e72c55ff3a7 (diff) | |
| parent | ae6e2df305cc15800819d012b130f3eee89c4001 (diff) | |
Merge "Set default values for screen dim feature" into main am: 2a6357c537 am: ae6e2df305
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2716973
Change-Id: I68b1e401f0a3f058b5f7a24595ea63be37e2a9e7
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
4 files changed, 49 insertions, 24 deletions
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index 9773f557dfaa..8c5b20da73ef 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -2812,6 +2812,20 @@ <integer name="config_dreamsBatteryLevelDrainCutoff">5</integer> <!-- Limit of how long the device can remain unlocked due to attention checking. --> <integer name="config_attentionMaximumExtension">900000</integer> <!-- 15 minutes. --> + + <!-- Enables or disables the 'prevent screen timeout' feature, where when a user manually + undims the screen, the feature acquires a wakelock to prevent screen timeout. + false = disabled, true = enabled. Disabled by default. --> + <bool name="config_defaultPreventScreenTimeoutEnabled">false</bool> + <!-- Default value (in milliseconds) to prevent the screen timeout after user undims it + manually between screen dims, a sign the user is interacting with the device. --> + <integer name="config_defaultPreventScreenTimeoutForMillis">300000</integer> <!-- 5 minutes. --> + <!-- Default max duration (in milliseconds) of the time between undims to still consider them + consecutive. --> + <integer name="config_defaultMaxDurationBetweenUndimsMillis">600000</integer> <!-- 10 min. --> + <!-- Default number of user undims required to trigger preventing screen sleep. --> + <integer name="config_defaultUndimsRequired">2</integer> + <!-- Whether there is to be a chosen Dock User who is the only user allowed to dream. --> <bool name="config_dreamsOnlyEnabledForDockUser">false</bool> <!-- Whether dreams are disabled when ambient mode is suppressed. --> diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 2b7261b62c64..c87ab283e188 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -4442,6 +4442,11 @@ <!-- For Attention Service --> <java-symbol type="integer" name="config_attentionMaximumExtension" /> + <java-symbol type="bool" name="config_defaultPreventScreenTimeoutEnabled" /> + <java-symbol type="integer" name="config_defaultPreventScreenTimeoutForMillis" /> + <java-symbol type="integer" name="config_defaultMaxDurationBetweenUndimsMillis" /> + <java-symbol type="integer" name="config_defaultUndimsRequired" /> + <java-symbol type="string" name="config_incidentReportApproverPackage" /> <java-symbol type="array" name="config_restrictedImagesServices" /> diff --git a/services/core/java/com/android/server/power/ScreenUndimDetector.java b/services/core/java/com/android/server/power/ScreenUndimDetector.java index c4929c210e2c..b376417061db 100644 --- a/services/core/java/com/android/server/power/ScreenUndimDetector.java +++ b/services/core/java/com/android/server/power/ScreenUndimDetector.java @@ -30,11 +30,11 @@ import android.provider.DeviceConfig; import android.util.Slog; import android.view.Display; +import com.android.internal.R; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.FrameworkStatsLog; import java.util.Set; -import java.util.concurrent.TimeUnit; /** * Detects when user manually undims the screen (x times) and acquires a wakelock to keep the screen @@ -48,7 +48,6 @@ public class ScreenUndimDetector { /** DeviceConfig flag: is keep screen on feature enabled. */ static final String KEY_KEEP_SCREEN_ON_ENABLED = "keep_screen_on_enabled"; - private static final boolean DEFAULT_KEEP_SCREEN_ON_ENABLED = true; private static final int OUTCOME_POWER_BUTTON = FrameworkStatsLog.TIMEOUT_AUTO_EXTENDED_REPORTED__OUTCOME__POWER_BUTTON; private static final int OUTCOME_TIMEOUT = @@ -58,15 +57,11 @@ public class ScreenUndimDetector { /** DeviceConfig flag: how long should we keep the screen on. */ @VisibleForTesting static final String KEY_KEEP_SCREEN_ON_FOR_MILLIS = "keep_screen_on_for_millis"; - @VisibleForTesting - static final long DEFAULT_KEEP_SCREEN_ON_FOR_MILLIS = TimeUnit.MINUTES.toMillis(10); private long mKeepScreenOnForMillis; /** DeviceConfig flag: how many user undims required to trigger keeping the screen on. */ @VisibleForTesting static final String KEY_UNDIMS_REQUIRED = "undims_required"; - @VisibleForTesting - static final int DEFAULT_UNDIMS_REQUIRED = 2; private int mUndimsRequired; /** @@ -76,8 +71,6 @@ public class ScreenUndimDetector { @VisibleForTesting static final String KEY_MAX_DURATION_BETWEEN_UNDIMS_MILLIS = "max_duration_between_undims_millis"; - @VisibleForTesting - static final long DEFAULT_MAX_DURATION_BETWEEN_UNDIMS_MILLIS = TimeUnit.MINUTES.toMillis(5); private long mMaxDurationBetweenUndimsMillis; @VisibleForTesting @@ -92,6 +85,7 @@ public class ScreenUndimDetector { private long mUndimOccurredTime = -1; private long mInteractionAfterUndimTime = -1; private InternalClock mClock; + private Context mContext; public ScreenUndimDetector() { mClock = new InternalClock(); @@ -109,12 +103,13 @@ public class ScreenUndimDetector { /** Should be called in parent's systemReady() */ public void systemReady(Context context) { + mContext = context; readValuesFromDeviceConfig(); DeviceConfig.addOnPropertiesChangedListener(NAMESPACE_ATTENTION_MANAGER_SERVICE, - context.getMainExecutor(), + mContext.getMainExecutor(), (properties) -> onDeviceConfigChange(properties.getKeyset())); - final PowerManager powerManager = context.getSystemService(PowerManager.class); + final PowerManager powerManager = mContext.getSystemService(PowerManager.class); mWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, UNDIM_DETECTOR_WAKE_LOCK); @@ -203,36 +198,44 @@ public class ScreenUndimDetector { } } - private boolean readKeepScreenOnNotificationEnabled() { + private boolean readKeepScreenOnEnabled() { + boolean defaultKeepScreenOnEnabled = mContext.getResources().getBoolean( + R.bool.config_defaultPreventScreenTimeoutEnabled); return DeviceConfig.getBoolean(NAMESPACE_ATTENTION_MANAGER_SERVICE, KEY_KEEP_SCREEN_ON_ENABLED, - DEFAULT_KEEP_SCREEN_ON_ENABLED); + defaultKeepScreenOnEnabled); } private long readKeepScreenOnForMillis() { + long defaultKeepScreenOnDuration = mContext.getResources().getInteger( + R.integer.config_defaultPreventScreenTimeoutForMillis); return DeviceConfig.getLong(NAMESPACE_ATTENTION_MANAGER_SERVICE, KEY_KEEP_SCREEN_ON_FOR_MILLIS, - DEFAULT_KEEP_SCREEN_ON_FOR_MILLIS); + defaultKeepScreenOnDuration); } private int readUndimsRequired() { + int defaultUndimsRequired = mContext.getResources().getInteger( + R.integer.config_defaultUndimsRequired); int undimsRequired = DeviceConfig.getInt(NAMESPACE_ATTENTION_MANAGER_SERVICE, KEY_UNDIMS_REQUIRED, - DEFAULT_UNDIMS_REQUIRED); + defaultUndimsRequired); if (undimsRequired < 1 || undimsRequired > 5) { Slog.e(TAG, "Provided undimsRequired=" + undimsRequired - + " is not allowed [1, 5]; using the default=" + DEFAULT_UNDIMS_REQUIRED); - return DEFAULT_UNDIMS_REQUIRED; + + " is not allowed [1, 5]; using the default=" + defaultUndimsRequired); + return defaultUndimsRequired; } return undimsRequired; } private long readMaxDurationBetweenUndimsMillis() { + long defaultMaxDurationBetweenUndimsMillis = mContext.getResources().getInteger( + R.integer.config_defaultMaxDurationBetweenUndimsMillis); return DeviceConfig.getLong(NAMESPACE_ATTENTION_MANAGER_SERVICE, KEY_MAX_DURATION_BETWEEN_UNDIMS_MILLIS, - DEFAULT_MAX_DURATION_BETWEEN_UNDIMS_MILLIS); + defaultMaxDurationBetweenUndimsMillis); } private void onDeviceConfigChange(@NonNull Set<String> keys) { @@ -253,15 +256,16 @@ public class ScreenUndimDetector { @VisibleForTesting void readValuesFromDeviceConfig() { - mKeepScreenOnEnabled = readKeepScreenOnNotificationEnabled(); + mKeepScreenOnEnabled = readKeepScreenOnEnabled(); mKeepScreenOnForMillis = readKeepScreenOnForMillis(); mUndimsRequired = readUndimsRequired(); mMaxDurationBetweenUndimsMillis = readMaxDurationBetweenUndimsMillis(); Slog.i(TAG, "readValuesFromDeviceConfig():" + "\nmKeepScreenOnForMillis=" + mKeepScreenOnForMillis - + "\nmKeepScreenOnNotificationEnabled=" + mKeepScreenOnEnabled - + "\nmUndimsRequired=" + mUndimsRequired); + + "\nmKeepScreenOnEnabled=" + mKeepScreenOnEnabled + + "\nmUndimsRequired=" + mUndimsRequired + + "\nmMaxDurationBetweenUndimsMillis=" + mMaxDurationBetweenUndimsMillis); } diff --git a/services/tests/mockingservicestests/src/com/android/server/power/ScreenUndimDetectorTest.java b/services/tests/mockingservicestests/src/com/android/server/power/ScreenUndimDetectorTest.java index 8ce05e2fa115..c9f86b04be22 100644 --- a/services/tests/mockingservicestests/src/com/android/server/power/ScreenUndimDetectorTest.java +++ b/services/tests/mockingservicestests/src/com/android/server/power/ScreenUndimDetectorTest.java @@ -23,7 +23,6 @@ import static android.hardware.display.DisplayManagerInternal.DisplayPowerReques import static android.provider.DeviceConfig.NAMESPACE_ATTENTION_MANAGER_SERVICE; import static android.view.Display.DEFAULT_DISPLAY_GROUP; -import static com.android.server.power.ScreenUndimDetector.DEFAULT_MAX_DURATION_BETWEEN_UNDIMS_MILLIS; import static com.android.server.power.ScreenUndimDetector.KEY_KEEP_SCREEN_ON_ENABLED; import static com.android.server.power.ScreenUndimDetector.KEY_MAX_DURATION_BETWEEN_UNDIMS_MILLIS; import static com.android.server.power.ScreenUndimDetector.KEY_UNDIMS_REQUIRED; @@ -49,6 +48,7 @@ import org.junit.runners.JUnit4; import java.util.Arrays; import java.util.List; +import java.util.concurrent.TimeUnit; /** * Tests for {@link com.android.server.power.ScreenUndimDetector} @@ -61,7 +61,8 @@ public class ScreenUndimDetectorTest { POLICY_DIM, POLICY_BRIGHT); private static final int OTHER_DISPLAY_GROUP = DEFAULT_DISPLAY_GROUP + 1; - + private static final long DEFAULT_MAX_DURATION_BETWEEN_UNDIMS_MILLIS = + TimeUnit.MINUTES.toMillis(5); @ClassRule public static final TestableContext sContext = new TestableContext( InstrumentationRegistry.getInstrumentation().getTargetContext(), null); @@ -88,7 +89,8 @@ public class ScreenUndimDetectorTest { @Before public void setup() { InstrumentationRegistry.getInstrumentation().waitForIdleSync(); - + DeviceConfig.setProperty(NAMESPACE_ATTENTION_MANAGER_SERVICE, + KEY_KEEP_SCREEN_ON_ENABLED, Boolean.TRUE.toString(), false /*makeDefault*/); DeviceConfig.setProperty(NAMESPACE_ATTENTION_MANAGER_SERVICE, KEY_UNDIMS_REQUIRED, Integer.toString(1), false /*makeDefault*/); @@ -108,10 +110,10 @@ public class ScreenUndimDetectorTest { @Test public void recordScreenPolicy_disabledByFlag_noop() { + setup(); DeviceConfig.setProperty(NAMESPACE_ATTENTION_MANAGER_SERVICE, KEY_KEEP_SCREEN_ON_ENABLED, Boolean.FALSE.toString(), false /*makeDefault*/); mScreenUndimDetector.readValuesFromDeviceConfig(); - mScreenUndimDetector.recordScreenPolicy(DEFAULT_DISPLAY_GROUP, POLICY_DIM); mScreenUndimDetector.recordScreenPolicy(DEFAULT_DISPLAY_GROUP, POLICY_BRIGHT); |