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

Commit 5ac75884 authored by Santos Cordon's avatar Santos Cordon
Browse files

Remove EvenDimmer Toggle

Bug: 372342802
Test: Manually verify toggle is gone
Flag: com.android.server.display.feature.flags.even_dimmer
Change-Id: I15583fda2bc164627a5ef9b60f09f66bdb95cddd
parent 3770da60
Loading
Loading
Loading
Loading
+0 −5
Original line number Diff line number Diff line
@@ -3149,11 +3149,6 @@
    </string>
    <!-- Dark UI screen footer action text linking to Modes settings. [CHAR LIMIT=NONE] -->
    <string name="dark_ui_modes_footer_action">Modes settings</string>
    <!-- Even Dimmer setting title. Allows device to reduce brightness even further than standard range. [CHAR LIMIT=NONE] -->
    <string name="even_dimmer_display_title">Extra dim</string>
    <!-- Even Dimmer setting summary. [CHAR LIMIT=NONE] -->
    <string name="even_dimmer_display_summary">Allow device to go dimmer than usual</string>
    <!-- Sound & display settings screen, setting option name to change screen timeout -->
    <string name="screen_timeout">Screen timeout</string>
+0 −7
Original line number Diff line number Diff line
@@ -62,13 +62,6 @@
            settings:keywords="@string/keywords_reduce_bright_colors"
            settings:controller="com.android.settings.accessibility.ReduceBrightColorsPreferenceController"/>

        <SwitchPreferenceCompat
            android:key="even_dimmer_activated"
            android:title="@string/even_dimmer_display_title"
            android:summary="@string/even_dimmer_display_summary"
            android:icon="@drawable/ic_reduce_bright_colors"
            settings:controller="com.android.settings.display.EvenDimmerPreferenceController"/>

        <Preference
            android:fragment="com.android.settings.accessibility.ToggleScreenMagnificationPreferenceFragment"
            android:key="magnification_preference_screen"
+0 −5
Original line number Diff line number Diff line
@@ -41,11 +41,6 @@
            settings:userRestriction="no_config_brightness"
            settings:controller="com.android.settings.display.AutoBrightnessPreferenceController" />

        <SwitchPreferenceCompat
            android:key="even_dimmer_activated"
            android:title="@string/even_dimmer_display_title"
            android:summary="@string/even_dimmer_display_summary"
            settings:controller="com.android.settings.display.EvenDimmerPreferenceController"/>
    </PreferenceCategory>

    <PreferenceCategory
+0 −83
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.display;

import android.content.Context;
import android.content.res.Resources;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.Log;

import androidx.annotation.NonNull;

import com.android.server.display.feature.flags.Flags;
import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;

/**
 * Controller for the settings toggle which allows screen brightness to go even dimmer than usual.
 *
 */
public class EvenDimmerPreferenceController extends TogglePreferenceController {

    private static final String TAG = "EvenDimmerPreferenceController";

    private final Resources mResources;

    public EvenDimmerPreferenceController(@NonNull Context context, @NonNull String key) {
        super(context, key);
        mResources = context.getResources();
    }

    @Override
    public int getAvailabilityStatus() {
        // enable based on flag and config.xml
        final boolean enabledInConfig = mResources.getBoolean(
                com.android.internal.R.bool.config_evenDimmerEnabled);

        if (Flags.evenDimmer() && enabledInConfig) {
            return AVAILABLE;
        } else {
            return UNSUPPORTED_ON_DEVICE;
        }
    }

    @Override
    public boolean isChecked() {
        return getEvenDimmerActivated();
    }

    @Override
    public boolean setChecked(boolean isChecked) {
        final float enabled = getAvailabilityStatus() == AVAILABLE && isChecked ? 1 : 0;
        Log.i(TAG, "setChecked to : " + enabled);

        return Settings.Secure.putFloat(
                mContext.getContentResolver(), Settings.Secure.EVEN_DIMMER_ACTIVATED, enabled);
    }

    @Override
    public int getSliceHighlightMenuRes() {
        return R.string.menu_key_display;
    }

    private boolean getEvenDimmerActivated() {
        return Settings.Secure.getFloatForUser(mContext.getContentResolver(),
                Settings.Secure.EVEN_DIMMER_ACTIVATED,
                /* def= */ 1.0f, UserHandle.USER_CURRENT) == 1.0f;
    }
}
+0 −131
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.display;


import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;

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

import static org.mockito.Mockito.when;

import android.content.Context;
import android.content.res.Resources;
import android.platform.test.annotations.RequiresFlagsDisabled;
import android.platform.test.annotations.RequiresFlagsEnabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.provider.Settings;

import com.android.server.display.feature.flags.Flags;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;

@RunWith(RobolectricTestRunner.class)
public class EvenDimmerPreferenceControllerTest {

    private EvenDimmerPreferenceController mController;
    @Mock
    private Context mContext;
    @Mock
    private Resources mResources;

    @Rule
    public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        when(mContext.getResources()).thenReturn(mResources);
        mController = new EvenDimmerPreferenceController(mContext, "key");
    }

    @RequiresFlagsDisabled(Flags.FLAG_EVEN_DIMMER)
    @Test
    public void testGetAvailabilityStatus_flagOffConfigTrue() {
        when(mContext.getResources()).thenReturn(mResources);
        when(mResources.getBoolean(
                com.android.internal.R.bool.config_evenDimmerEnabled)).thenReturn(true);
        // setup
        mController = new EvenDimmerPreferenceController(mContext, "key");

        assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
    }

    @RequiresFlagsDisabled(Flags.FLAG_EVEN_DIMMER)
    @Test
    public void testGetCheckedStatus_setTrue() throws Settings.SettingNotFoundException {
        // setup
        mController = new EvenDimmerPreferenceController(mContext, "key");
        mController.setChecked(true);

        assertThat(Settings.Secure.getFloat(mContext.getContentResolver(),
                Settings.Secure.EVEN_DIMMER_ACTIVATED)).isEqualTo(0.0f); // false
    }

    @RequiresFlagsEnabled(Flags.FLAG_EVEN_DIMMER)
    @Test
    public void testGetAvailabilityStatus_flagOnConfigTrue() {
        when(mContext.getResources()).thenReturn(mResources);
        when(mResources.getBoolean(
                com.android.internal.R.bool.config_evenDimmerEnabled)).thenReturn(true);
        // setup
        mController = new EvenDimmerPreferenceController(mContext, "key");

        assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
    }


    @RequiresFlagsEnabled(Flags.FLAG_EVEN_DIMMER)
    @Test
    public void testGetAvailabilityStatus_flagOnConfigFalse() {
        when(mContext.getResources()).thenReturn(mResources);
        when(mResources.getBoolean(
                com.android.internal.R.bool.config_evenDimmerEnabled)).thenReturn(false);
        // setup
        mController = new EvenDimmerPreferenceController(mContext, "key");

        assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
    }

    @Test
    @RequiresFlagsEnabled(Flags.FLAG_EVEN_DIMMER)
    public void testSetChecked_enable() throws Settings.SettingNotFoundException {
        when(mResources.getBoolean(
                com.android.internal.R.bool.config_evenDimmerEnabled)).thenReturn(true);
        mController.setChecked(true);
        assertThat(Settings.Secure.getFloat(mContext.getContentResolver(),
                Settings.Secure.EVEN_DIMMER_ACTIVATED)).isEqualTo(1.0f); // true
    }

    @Test
    @RequiresFlagsEnabled(Flags.FLAG_EVEN_DIMMER)
    public void testSetChecked_disable() throws Settings.SettingNotFoundException {
        when(mResources.getBoolean(
                com.android.internal.R.bool.config_evenDimmerEnabled)).thenReturn(true);
        mController.setChecked(false);
        assertThat(Settings.Secure.getFloat(mContext.getContentResolver(),
                Settings.Secure.EVEN_DIMMER_ACTIVATED)).isEqualTo(0.0f); // false
    }
}