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

Commit ee9cb2d1 authored by sallyyuen's avatar sallyyuen
Browse files

Get Extra Dim availability through ColorDisplayManager

Test: atest ReduceBrightColorsIntensityPreferenceControllerTest
Bug: 170970675
Change-Id: Ibccca13d6491e8861263887e33021dd467fc227f
parent 9aff8550
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ 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;
@@ -38,10 +37,10 @@ public class ReduceBrightColorsIntensityPreferenceController extends SliderPrefe

    @Override
    public int getAvailabilityStatus() {
        if (!ColorDisplayManager.isColorTransformAccelerated(mContext)) {
        if (!ColorDisplayManager.isReduceBrightColorsAvailable(mContext)) {
            return UNSUPPORTED_ON_DEVICE;
        } else if (Settings.Secure.getInt(mContext.getContentResolver(),
                Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 0) != 1) {
        }
        if (!mColorDisplayManager.isReduceBrightColorsActivated()) {
            return DISABLED_DEPENDENT_SETTING;
        }
        return AVAILABLE;
+9 −1
Original line number Diff line number Diff line
@@ -17,21 +17,29 @@
package com.android.settings.accessibility;

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

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() {
        // TODO(b/170970675): call into CDS to get availability/config status
        if (!ColorDisplayManager.isReduceBrightColorsAvailable(mContext)) {
            return UNSUPPORTED_ON_DEVICE;
        }
        if (!mColorDisplayManager.isReduceBrightColorsActivated()) {
            return DISABLED_DEPENDENT_SETTING;
        }
        return AVAILABLE;
    }

+1 −1
Original line number Diff line number Diff line
@@ -87,7 +87,7 @@ public class ReduceBrightColorsPreferenceController extends TogglePreferenceCont

    @Override
    public int getAvailabilityStatus() {
        return ColorDisplayManager.isColorTransformAccelerated(mContext) ? AVAILABLE
        return ColorDisplayManager.isReduceBrightColorsAvailable(mContext) ? AVAILABLE
                : UNSUPPORTED_ON_DEVICE;
    }

+2 −2
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static com.android.settings.accessibility.AccessibilityUtil.State.ON;

import android.app.settings.SettingsEnums;
import android.content.Context;
import android.hardware.display.ColorDisplayManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
@@ -175,8 +176,7 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre
            new BaseSearchIndexProvider(R.xml.reduce_bright_colors_settings) {
                @Override
                protected boolean isPageSearchEnabled(Context context) {
                    // TODO(b/170970675): call into CDS to get availability/config status
                    return true;
                    return ColorDisplayManager.isReduceBrightColorsAvailable(context);
                }
            };
}
+3 −3
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ public class ReduceBrightColorsIntensityPreferenceControllerTest {
        Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 1);
        doReturn(true).when(mResources).getBoolean(
                com.android.internal.R.bool.config_setColorTransformAccelerated);
                R.bool.config_reduceBrightColorsAvailable);
        assertThat(mPreferenceController.isAvailable()).isTrue();
    }
    @Test
@@ -64,7 +64,7 @@ public class ReduceBrightColorsIntensityPreferenceControllerTest {
        Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 0);
        doReturn(true).when(mResources).getBoolean(
                com.android.internal.R.bool.config_setColorTransformAccelerated);
                R.bool.config_reduceBrightColorsAvailable);
        assertThat(mPreferenceController.isAvailable()).isTrue();
    }
    @Test
@@ -72,7 +72,7 @@ public class ReduceBrightColorsIntensityPreferenceControllerTest {
        Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 1);
        doReturn(false).when(mResources).getBoolean(
                com.android.internal.R.bool.config_setColorTransformAccelerated);
                R.bool.config_reduceBrightColorsAvailable);
        assertThat(mPreferenceController.isAvailable()).isFalse();
    }