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

Commit 7c8cf662 authored by Chun-Ku Lin's avatar Chun-Ku Lin
Browse files

Delete unused code

Bug: 406052931
Test: atest com.android.settings.accessibility
Test: manually verify the extra dim screen and interactions
Flag: EXEMPT low risk
Change-Id: I79f9dab77681556b8f544ccb0631647efef1c15d
parent fa8ec71a
Loading
Loading
Loading
Loading
+0 −41
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  Copyright (C) 2020 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.
  -->

<PreferenceScreen
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:settings="http://schemas.android.com/apk/res-auto"
    android:persistent="false"
    android:title="@string/reduce_bright_colors_preference_title">

    <com.android.settings.widget.LabeledSeekBarPreference
        android:key="rbc_intensity"
        android:persistent="false"
        android:title="@string/reduce_bright_colors_intensity_preference_title"
        settings:textStart="@string/reduce_bright_colors_intensity_start_label"
        settings:textEnd="@string/reduce_bright_colors_intensity_end_label"
        settings:tickMark="@android:color/transparent"
    />

    <!-- The term `restarts` is usually used for indicating restarting devices.
         Therefore, We wouldn't want `Keep on after device restarts` preference in the Extra Dim
         shows up as the search result when the user searches `restart`-->
    <SwitchPreferenceCompat
        android:key="rbc_persist"
        android:persistent="false"
        android:title="@string/reduce_bright_colors_persist_preference_title"
        settings:searchable="false"/>
</PreferenceScreen>
+0 −93
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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.accessibility;

import android.content.Context;
import android.hardware.display.ColorDisplayManager;
import android.provider.Settings;

import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;

import com.android.settings.core.SliderPreferenceController;
import com.android.settings.widget.SeekBarPreference;

/** PreferenceController for feature intensity. */
public class ReduceBrightColorsIntensityPreferenceController extends SliderPreferenceController {

    private final ColorDisplayManager mColorDisplayManager;

    public ReduceBrightColorsIntensityPreferenceController(Context context, String key) {
        super(context, key);
        mColorDisplayManager = context.getSystemService(ColorDisplayManager.class);
    }

    @Override
    public int getAvailabilityStatus() {
        if (!ColorDisplayManager.isReduceBrightColorsAvailable(mContext)) {
            return UNSUPPORTED_ON_DEVICE;
        }
        if (!mColorDisplayManager.isReduceBrightColorsActivated()) {
            return DISABLED_DEPENDENT_SETTING;
        }
        return AVAILABLE;
    }

    @Override
    public void displayPreference(PreferenceScreen screen) {
        super.displayPreference(screen);
        final SeekBarPreference preference = screen.findPreference(getPreferenceKey());
        preference.setContinuousUpdates(true);
        preference.setMax(getMax());
        preference.setMin(getMin());
        preference.setHapticFeedbackMode(SeekBarPreference.HAPTIC_FEEDBACK_MODE_ON_ENDS);
        updateState(preference);
    }

    @Override
    public final void updateState(Preference preference) {
        super.updateState(preference);
        preference.setEnabled(mColorDisplayManager.isReduceBrightColorsActivated());
    }

    @Override
    public int getSliderPosition() {
        final int settingValue = Settings.Secure.getInt(
                mContext.getContentResolver(),
                Settings.Secure.REDUCE_BRIGHT_COLORS_LEVEL,
                /* fallback= */ 0);

        return getMax() - settingValue;
    }

    @Override
    public boolean setSliderPosition(int position) {
        return Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.REDUCE_BRIGHT_COLORS_LEVEL,
                getMax() - position);
    }

    @Override
    public int getMax() {
        return 100;
    }

    @Override
    public int getMin() {
        return 0;
    }
}
+0 −71
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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.accessibility;

import android.content.Context;
import android.hardware.display.ColorDisplayManager;
import android.provider.Settings;

import androidx.preference.Preference;

import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;

/** PreferenceController for persisting feature activation state after a restart. */
public class ReduceBrightColorsPersistencePreferenceController extends TogglePreferenceController {
    private final ColorDisplayManager mColorDisplayManager;

    public ReduceBrightColorsPersistencePreferenceController(
            Context context, String preferenceKey) {
        super(context, preferenceKey);
        mColorDisplayManager = context.getSystemService(ColorDisplayManager.class);
    }

    @Override
    public int getAvailabilityStatus() {
        if (!ColorDisplayManager.isReduceBrightColorsAvailable(mContext)) {
            return UNSUPPORTED_ON_DEVICE;
        }
        if (!mColorDisplayManager.isReduceBrightColorsActivated()) {
            return DISABLED_DEPENDENT_SETTING;
        }
        return AVAILABLE;
    }

    @Override
    public boolean isChecked() {
        return Settings.Secure.getInt(mContext.getContentResolver(),
                Settings.Secure.REDUCE_BRIGHT_COLORS_PERSIST_ACROSS_REBOOTS, 0) == 1;
    }

    @Override
    public boolean setChecked(boolean isChecked) {
        return Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.REDUCE_BRIGHT_COLORS_PERSIST_ACROSS_REBOOTS, (isChecked ? 1 : 0));
    }

    @Override
    public final void updateState(Preference preference) {
        super.updateState(preference);
        preference.setEnabled(mColorDisplayManager.isReduceBrightColorsActivated());
    }

    @Override
    public int getSliceHighlightMenuRes() {
        return R.string.menu_key_accessibility;
    }
}
+0 −189
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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.accessibility;

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

import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings;
import android.testing.TestableContext;
import android.testing.TestableResources;

import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.android.internal.R;
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;

/** Tests for {@link ReduceBrightColorsIntensityPreferenceController} */
@RunWith(AndroidJUnit4.class)
public class ReduceBrightColorsIntensityPreferenceControllerTest {

    @Rule
    public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
    @Rule
    public final TestableContext mContext =
            new TestableContext(ApplicationProvider.getApplicationContext());

    private TestableResources mResources = mContext.getOrCreateTestableResources();
    private ReduceBrightColorsIntensityPreferenceController mPreferenceController;

    @Before
    public void setUp() {
        mPreferenceController = new ReduceBrightColorsIntensityPreferenceController(mContext,
                "rbc_intensity");
    }

    @Test
    @DisableFlags(Flags.FLAG_EVEN_DIMMER)
    public void isAvailable_whenEvenDimmerOffAndDisabled_RbcOnAndAvailable_returnTrue() {
        mResources.addOverride(com.android.internal.R.bool.config_evenDimmerEnabled, false);
        Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 1);
        mResources.addOverride(R.bool.config_reduceBrightColorsAvailable, true);

        assertThat(mPreferenceController.isAvailable()).isTrue();
    }

    @Test
    @DisableFlags(Flags.FLAG_EVEN_DIMMER)
    public void isAvailable_whenEvenDimmerOffAndDisabled_RbcOffAndAvailable_returnTrue() {
        mResources.addOverride(com.android.internal.R.bool.config_evenDimmerEnabled, false);
        Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 0);
        mResources.addOverride(
                R.bool.config_reduceBrightColorsAvailable, true);

        assertThat(mPreferenceController.isAvailable()).isTrue();
    }

    @Test
    @DisableFlags(Flags.FLAG_EVEN_DIMMER)
    public void isAvailable_whenEvenDimmerOffAndDisabled_RbcOnAndUnavailable_returnFalse() {
        mResources.addOverride(com.android.internal.R.bool.config_evenDimmerEnabled, false);
        Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 1);
        mResources.addOverride(R.bool.config_reduceBrightColorsAvailable, false);

        assertThat(mPreferenceController.isAvailable()).isFalse();
    }

    @Test
    @EnableFlags(Flags.FLAG_EVEN_DIMMER)
    public void isAvailable_whenEvenDimmerOnAndDisabled_RbcOnAndAvailable_returnTrue() {
        mResources.addOverride(com.android.internal.R.bool.config_evenDimmerEnabled, false);
        Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 1);
        mResources.addOverride(R.bool.config_reduceBrightColorsAvailable, true);

        assertThat(mPreferenceController.isAvailable()).isTrue();
    }

    @Test
    @EnableFlags(Flags.FLAG_EVEN_DIMMER)
    public void isAvailable_whenEvenDimmerOnAndDisabled_RbcOffAndAvailable_returnTrue() {
        mResources.addOverride(com.android.internal.R.bool.config_evenDimmerEnabled, false);
        Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 0);
        mResources.addOverride(R.bool.config_reduceBrightColorsAvailable, true);

        assertThat(mPreferenceController.isAvailable()).isTrue();
    }

    @Test
    @EnableFlags(Flags.FLAG_EVEN_DIMMER)
    public void isAvailable_whenEvenDimmerOnAndDisabled_RbcOnAndUnavailable_returnFalse() {
        mResources.addOverride(com.android.internal.R.bool.config_evenDimmerEnabled, false);
        Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 1);
        mResources.addOverride(R.bool.config_reduceBrightColorsAvailable, false);

        assertThat(mPreferenceController.isAvailable()).isFalse();
    }

    @Test
    @EnableFlags(Flags.FLAG_EVEN_DIMMER)
    public void isAvailable_whenEvenDimmerOnAndEnabled_RbcOnAndAvailable_returnFalse() {
        mResources.addOverride(com.android.internal.R.bool.config_evenDimmerEnabled, true);
        Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 1);
        mResources.addOverride(R.bool.config_reduceBrightColorsAvailable, true);

        assertThat(mPreferenceController.isAvailable()).isFalse();
    }

    @Test
    @EnableFlags(Flags.FLAG_EVEN_DIMMER)
    public void isAvailable_whenEvenDimmerOnAndEnabled_RbcOffAndAvailable_returnFalse() {
        mResources.addOverride(com.android.internal.R.bool.config_evenDimmerEnabled, true);
        Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 0);
        mResources.addOverride(R.bool.config_reduceBrightColorsAvailable, true);

        assertThat(mPreferenceController.isAvailable()).isFalse();
    }

    @Test
    @EnableFlags(Flags.FLAG_EVEN_DIMMER)
    public void isAvailable_whenEvenDimmerOnAndEnabled_RbcOnAndUnavailable_returnFalse() {
        mResources.addOverride(com.android.internal.R.bool.config_evenDimmerEnabled, true);
        Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 1);
        mResources.addOverride(R.bool.config_reduceBrightColorsAvailable, false);

        assertThat(mPreferenceController.isAvailable()).isFalse();
    }

    @Test
    public void onPreferenceChange_changesTemperature() {
        Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 1);
        mPreferenceController.onPreferenceChange(/* preference= */ null, 20);
        assertThat(
                Settings.Secure.getInt(mContext.getContentResolver(),
                        Settings.Secure.REDUCE_BRIGHT_COLORS_LEVEL, 0))
                .isEqualTo(80);
    }

    // Slider range should represent percentage.
    @Test
    public void rangeOfSlider_isPercentage() {
        assertThat(mPreferenceController.getMax()).isEqualTo(100);
        assertThat(mPreferenceController.getMin()).isEqualTo(0);
        assertThat(mPreferenceController.getMax() - mPreferenceController.getMin())
                .isEqualTo(100);
    }

    // Slider should be of range 100 - 0.
    @Test
    public void rangeOfSlider_isInverted() {
        Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 1);
        mPreferenceController.onPreferenceChange(/* preference= */ null, 2);
        assertThat(
                Settings.Secure.getInt(mContext.getContentResolver(),
                        Settings.Secure.REDUCE_BRIGHT_COLORS_LEVEL, 0))
                .isEqualTo(98);
    }
}
+0 −85
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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.accessibility;

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

import android.provider.Settings;
import android.testing.TestableContext;

import androidx.preference.SwitchPreference;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
public class ReduceBrightColorsPersistencePreferenceControllerTest {
    private static final String PREF_KEY = "rbc_persist";
    private static final String RBC_PERSIST =
            Settings.Secure.REDUCE_BRIGHT_COLORS_PERSIST_ACROSS_REBOOTS;
    private static final int ON = 1;
    private static final int OFF = 0;
    private static final int UNKNOWN = -1;

    @Rule
    public final TestableContext mContext =
            new TestableContext(ApplicationProvider.getApplicationContext());
    private final SwitchPreference mPreference = new SwitchPreference(mContext);
    private final ReduceBrightColorsPersistencePreferenceController mController =
            new ReduceBrightColorsPersistencePreferenceController(mContext, PREF_KEY);

    @Test
    public void isChecked_enabledRbc_shouldReturnTrue() {
        Settings.Secure.putInt(mContext.getContentResolver(), RBC_PERSIST, ON);

        mController.updateState(mPreference);

        assertThat(mController.isChecked()).isTrue();
        assertThat(mPreference.isChecked()).isTrue();
    }

    @Test
    public void isChecked_disabledRbc_shouldReturnFalse() {
        Settings.Secure.putInt(mContext.getContentResolver(), RBC_PERSIST, OFF);

        mController.updateState(mPreference);

        assertThat(mController.isChecked()).isFalse();
        assertThat(mPreference.isChecked()).isFalse();
    }

    @Test
    public void setChecked_setTrue_shouldEnableRbc() {
        mController.setChecked(true);

        assertThat(
                Settings.Secure.getInt(mContext.getContentResolver(), RBC_PERSIST, UNKNOWN))
                .isEqualTo(ON);
    }

    @Test
    public void setChecked_setFalse_shouldDisableRbc() {
        mController.setChecked(false);

        assertThat(
                Settings.Secure.getInt(mContext.getContentResolver(), RBC_PERSIST, UNKNOWN))
                .isEqualTo(OFF);
    }
}