Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ae6e2df3 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Set default values for screen dim feature" into main am: 2a6357c5

parents 95c4f7a4 2a6357c5
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -2767,6 +2767,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. -->
+5 −0
Original line number Diff line number Diff line
@@ -4381,6 +4381,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" />

+24 −20
Original line number Diff line number Diff line
@@ -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);

    }

+6 −4
Original line number Diff line number Diff line
@@ -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;
@@ -48,6 +47,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}
@@ -60,7 +60,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);
@@ -87,7 +88,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*/);
@@ -107,10 +109,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);