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

Commit c99c24d3 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add a setting screen for what to show during low light." into main

parents 4100a734 b0fb26af
Loading
Loading
Loading
Loading
+43 −0
Original line number Diff line number Diff line
@@ -155,6 +155,8 @@ public class DreamBackend {
    private final boolean mDreamsActivatedOnSleepByDefault;
    private final boolean mDreamsActivatedOnDockByDefault;
    private final boolean mDreamsActivatedOnPosturedByDefault;
    private final boolean mLowLightDisplayBehaviorEnabledDefault;
    private final int mLowLightDisplayBehaviorDefault;
    private final Set<ComponentName> mDisabledDreams;
    private final List<String> mLoggableDreamPrefixes;
    private Set<Integer> mSupportedComplications;
@@ -182,6 +184,10 @@ public class DreamBackend {
                com.android.internal.R.bool.config_dreamsActivatedOnDockByDefault);
        mDreamsActivatedOnPosturedByDefault = resources.getBoolean(
                com.android.internal.R.bool.config_dreamsActivatedOnPosturedByDefault);
        mLowLightDisplayBehaviorEnabledDefault = resources.getBoolean(
                com.android.internal.R.bool.config_lowLightDisplayBehaviorEnabledDefault);
        mLowLightDisplayBehaviorDefault = resources.getInteger(
                com.android.internal.R.integer.config_lowLightDisplayBehaviorDefault);
        mDisabledDreams = Arrays.stream(resources.getStringArray(
                        com.android.internal.R.array.config_disabledDreamComponents))
                .map(ComponentName::unflattenFromString)
@@ -292,6 +298,43 @@ public class DreamBackend {
        return null;
    }

    /**
     * Return whether the low light display behavior is enabled.
     */
    public boolean getLowLightDisplayBehaviorEnabled() {
        return Settings.Secure.getInt(
                mContext.getContentResolver(),
                Settings.Secure.LOW_LIGHT_DISPLAY_BEHAVIOR_ENABLED,
                mLowLightDisplayBehaviorEnabledDefault ? 1 : 0) != 0;
    }

    /**
     * Enable or disable the low light display behavior.
     */
    public void setLowLightDisplayBehaviorEnabled(boolean enabled) {
        Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.LOW_LIGHT_DISPLAY_BEHAVIOR_ENABLED, enabled ? 1 : 0);
    }

    /**
     * Get the value of the current low light display behavior.
     */
    @Settings.Secure.LowLightDisplayBehavior
    public int getLowLightDisplayBehavior() {
        return Settings.Secure.getInt(
                mContext.getContentResolver(),
                Settings.Secure.LOW_LIGHT_DISPLAY_BEHAVIOR,
                mLowLightDisplayBehaviorDefault);
    }

    /**
     * Set the low light display behavior to the given value.
     */
    public void setLowLightDisplayBehavior(int behavior) {
        Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.LOW_LIGHT_DISPLAY_BEHAVIOR, behavior);
    }

    @WhenToDream
    public int getWhenToDreamSetting() {
        return isActivatedOnDock() && isActivatedOnSleep() ? WHILE_CHARGING_OR_DOCKED
+16 −0
Original line number Diff line number Diff line
@@ -245,6 +245,22 @@ public final class DreamBackendTest {
        assertThat(mBackend.getRestrictToWirelessCharging()).isTrue();
    }

    @Test
    public void testLowLightDisplayBehavior() {
        mBackend.setLowLightDisplayBehavior(100);
        assertThat(mBackend.getLowLightDisplayBehavior()).isEqualTo(100);
    }


    @Test
    public void testLowLightDisplayBehaviorEnabled() {
        mBackend.setLowLightDisplayBehaviorEnabled(false);
        assertThat(mBackend.getLowLightDisplayBehaviorEnabled()).isFalse();

        mBackend.setLowLightDisplayBehaviorEnabled(true);
        assertThat(mBackend.getLowLightDisplayBehaviorEnabled()).isTrue();
    }

    private void setControlsEnabledOnLockscreen(boolean enabled) {
        Settings.Secure.putInt(
                mContext.getContentResolver(),