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

Commit 9739cf5b authored by Edward Savage-Jones's avatar Edward Savage-Jones Committed by Piotr Wilczyński
Browse files

Add support for default doze values

Add resources to configure ambient display doze configuration:

config_dozeEnabled
config_dozeTapGestureEnabled
config_dozeDoubleTapGestureEnabled

Bug: 279161929
Test: DozeConfigurationTest
Flag: com.android.server.display.feature.flags.configurable_default_doze_values
Change-Id: Id0618b7e031ca3808a1e4512597f69d8abac6a7b
parent 84a5e8d0
Loading
Loading
Loading
Loading
+19 −3
Original line number Diff line number Diff line
@@ -45,6 +45,9 @@ public class AmbientDisplayConfiguration {
    private final boolean mAlwaysOnByDefault;
    private final boolean mPickupGestureEnabledByDefault;
    private final boolean mScreenOffUdfpsAvailable;
    private final boolean mDozeEnabledByDefault;
    private final boolean mTapGestureEnabledByDefault;
    private final boolean mDoubleTapGestureEnabledByDefault;

    /** Copied from android.provider.Settings.Secure since these keys are hidden. */
    private static final String[] DOZE_SETTINGS = {
@@ -74,6 +77,16 @@ public class AmbientDisplayConfiguration {
                mContext.getResources().getBoolean(R.bool.config_dozePickupGestureEnabled);
        mScreenOffUdfpsAvailable =
                mContext.getResources().getBoolean(R.bool.config_screen_off_udfps_enabled);
        mDozeEnabledByDefault =
                !com.android.server.display.feature.flags.Flags.configurableDefaultDozeValues()
                        || mContext.getResources().getBoolean(R.bool.config_dozeEnabled);
        mTapGestureEnabledByDefault =
                !com.android.server.display.feature.flags.Flags.configurableDefaultDozeValues()
                        || mContext.getResources().getBoolean(R.bool.config_dozeTapGestureEnabled);
        mDoubleTapGestureEnabledByDefault =
                !com.android.server.display.feature.flags.Flags.configurableDefaultDozeValues()
                        || mContext.getResources().getBoolean(
                        R.bool.config_dozeDoubleTapGestureEnabled);
    }

    /** @hide */
@@ -92,7 +105,8 @@ public class AmbientDisplayConfiguration {

    /** @hide */
    public boolean pulseOnNotificationEnabled(int user) {
        return boolSettingDefaultOn(Settings.Secure.DOZE_ENABLED, user)
        return boolSetting(Settings.Secure.DOZE_ENABLED, user,
                mDozeEnabledByDefault ? 1 : 0)
                && pulseOnNotificationAvailable();
    }

@@ -116,7 +130,8 @@ public class AmbientDisplayConfiguration {

    /** @hide */
    public boolean tapGestureEnabled(int user) {
        return boolSettingDefaultOn(Settings.Secure.DOZE_TAP_SCREEN_GESTURE, user)
        return boolSetting(Settings.Secure.DOZE_TAP_SCREEN_GESTURE, user,
                mTapGestureEnabledByDefault ? 1 : 0)
                && tapSensorAvailable();
    }

@@ -132,7 +147,8 @@ public class AmbientDisplayConfiguration {

    /** @hide */
    public boolean doubleTapGestureEnabled(int user) {
        return boolSettingDefaultOn(Settings.Secure.DOZE_DOUBLE_TAP_GESTURE, user)
        return boolSetting(Settings.Secure.DOZE_DOUBLE_TAP_GESTURE, user,
                mDoubleTapGestureEnabledByDefault ? 1 : 0)
                && doubleTapSensorAvailable();
    }

+12 −0
Original line number Diff line number Diff line
@@ -2964,6 +2964,18 @@
     during initialization when the setting is still null. -->
    <bool name="config_dozePickupGestureEnabled">true</bool>

    <!-- Control whether doze is enabled by default. This value will be used during initialization
     when the setting is still null. -->
    <bool name="config_dozeEnabled">true</bool>

    <!-- Control whether the single tap gesture is enabled by default. This value will be used
     during initialization when the setting is still null. -->
    <bool name="config_dozeTapGestureEnabled">true</bool>

    <!-- Control whether the double tap gesture is enabled by default. This value will be used
     during initialization when the setting is still null. -->
    <bool name="config_dozeDoubleTapGestureEnabled">true</bool>

    <!-- Control whether the always on display mode is enabled by default. This value will be used
         during initialization when the setting is still null. -->
    <bool name="config_dozeAlwaysOnEnabled">true</bool>
+3 −0
Original line number Diff line number Diff line
@@ -4248,6 +4248,9 @@
  <java-symbol type="integer" name="config_autoGroupAtCount" />
  <java-symbol type="bool" name="config_dozeAlwaysOnDisplayAvailable" />
  <java-symbol type="bool" name="config_dozePickupGestureEnabled" />
  <java-symbol type="bool" name="config_dozeEnabled" />
  <java-symbol type="bool" name="config_dozeTapGestureEnabled" />
  <java-symbol type="bool" name="config_dozeDoubleTapGestureEnabled" />
  <java-symbol type="bool" name="config_dozeAlwaysOnEnabled" />
  <java-symbol type="bool" name="config_dozeSupportsAodWallpaper" />
  <java-symbol type="bool" name="config_displayBlanksAfterDoze" />
+66 −1
Original line number Diff line number Diff line
@@ -16,15 +16,20 @@

package com.android.systemui.doze;

import static com.google.common.truth.Truth.assertThat;

import static junit.framework.TestCase.assertEquals;

import android.hardware.display.AmbientDisplayConfiguration;
import android.os.UserHandle;
import android.platform.test.annotations.EnableFlags;
import android.provider.Settings;

import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;

import com.android.internal.R;
import com.android.server.display.feature.flags.Flags;
import com.android.systemui.SysuiTestCase;

import org.junit.Before;
@@ -39,11 +44,19 @@ public class DozeConfigurationTest extends SysuiTestCase {

    @Before
    public void setup() {
        mContext.getOrCreateTestableResources().addOverride(
                R.bool.config_pulseOnNotificationsAvailable, true);
        mContext.getOrCreateTestableResources().addOverride(R.string.config_dozeComponent,
                "FakeDozeComponent");
        mContext.getOrCreateTestableResources().addOverride(
                R.array.config_dozeTapSensorPostureMapping, new String[]{"posture1", "posture2"});
        mContext.getOrCreateTestableResources().addOverride(R.string.config_dozeDoubleTapSensorType,
                "FakeDoubleTapSensorType");
        mDozeConfig = new AmbientDisplayConfiguration(mContext);
    }

    @Test
    public void alwaysOn_followsConfigByDefault() throws Exception {
    public void alwaysOn_followsConfigByDefault() {
        if (!mDozeConfig.alwaysOnAvailable()) {
            return;
        }
@@ -54,4 +67,56 @@ public class DozeConfigurationTest extends SysuiTestCase {
                .getBoolean(com.android.internal.R.bool.config_dozeAlwaysOnEnabled);
        assertEquals(defaultValue, mDozeConfig.alwaysOnEnabled(UserHandle.USER_CURRENT));
    }

    @Test
    @EnableFlags(Flags.FLAG_CONFIGURABLE_DEFAULT_DOZE_VALUES)
    public void pulseOnNotificationEnabledByDefault() {
        mContext.getOrCreateTestableResources().addOverride(R.bool.config_dozeEnabled, true);
        mDozeConfig = new AmbientDisplayConfiguration(mContext);
        assertThat(mDozeConfig.pulseOnNotificationEnabled(UserHandle.USER_CURRENT)).isTrue();
    }

    @Test
    @EnableFlags(Flags.FLAG_CONFIGURABLE_DEFAULT_DOZE_VALUES)
    public void pulseOnNotificationDisabledByDefault() {
        mContext.getOrCreateTestableResources().addOverride(R.bool.config_dozeEnabled, false);
        mDozeConfig = new AmbientDisplayConfiguration(mContext);
        assertThat(mDozeConfig.pulseOnNotificationEnabled(UserHandle.USER_CURRENT)).isFalse();
    }

    @Test
    @EnableFlags(Flags.FLAG_CONFIGURABLE_DEFAULT_DOZE_VALUES)
    public void tapGestureEnabledByDefault() {
        mContext.getOrCreateTestableResources().addOverride(R.bool.config_dozeTapGestureEnabled,
                true);
        mDozeConfig = new AmbientDisplayConfiguration(mContext);
        assertThat(mDozeConfig.tapGestureEnabled(UserHandle.USER_CURRENT)).isTrue();
    }

    @Test
    @EnableFlags(Flags.FLAG_CONFIGURABLE_DEFAULT_DOZE_VALUES)
    public void tapGestureDisabledByDefault() {
        mContext.getOrCreateTestableResources().addOverride(R.bool.config_dozeTapGestureEnabled,
                false);
        mDozeConfig = new AmbientDisplayConfiguration(mContext);
        assertThat(mDozeConfig.tapGestureEnabled(UserHandle.USER_CURRENT)).isFalse();
    }

    @Test
    @EnableFlags(Flags.FLAG_CONFIGURABLE_DEFAULT_DOZE_VALUES)
    public void doubleTapGestureEnabledByDefault() {
        mContext.getOrCreateTestableResources().addOverride(
                R.bool.config_dozeDoubleTapGestureEnabled, true);
        mDozeConfig = new AmbientDisplayConfiguration(mContext);
        assertThat(mDozeConfig.doubleTapGestureEnabled(UserHandle.USER_CURRENT)).isTrue();
    }

    @Test
    @EnableFlags(Flags.FLAG_CONFIGURABLE_DEFAULT_DOZE_VALUES)
    public void doubleTapGestureDisabledByDefault() {
        mContext.getOrCreateTestableResources().addOverride(
                R.bool.config_dozeDoubleTapGestureEnabled, false);
        mDozeConfig = new AmbientDisplayConfiguration(mContext);
        assertThat(mDozeConfig.doubleTapGestureEnabled(UserHandle.USER_CURRENT)).isFalse();
    }
}
+7 −0
Original line number Diff line number Diff line
@@ -77,6 +77,13 @@ flag {
    is_fixed_read_only: true
}

flag {
    name: "configurable_default_doze_values"
    namespace: "display_manager"
    description: "Specify the default doze values in config.xml"
    bug: "279161929"
}

flag {
    name: "brightness_wear_bedtime_mode_clamper"
    namespace: "display_manager"