Call into ColorDisplayManager for RBC slider range
Test: atest ReduceBrightColorsIntensityPreferenceControllerTest
Bug: b/179805222
Change-Id: I0927f41fad27e6b9b54c374e2c6a7cc6e0c5240d
diff --git a/src/com/android/settings/accessibility/ReduceBrightColorsIntensityPreferenceController.java b/src/com/android/settings/accessibility/ReduceBrightColorsIntensityPreferenceController.java
index ea7fb7c..3b220e4 100644
--- a/src/com/android/settings/accessibility/ReduceBrightColorsIntensityPreferenceController.java
+++ b/src/com/android/settings/accessibility/ReduceBrightColorsIntensityPreferenceController.java
@@ -29,8 +29,11 @@
/** 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
@@ -59,31 +62,26 @@
@Override
public final void updateState(Preference preference) {
super.updateState(preference);
- preference.setEnabled(Settings.Secure.getInt(mContext.getContentResolver(),
- Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 0) == 1);
+ preference.setEnabled(mColorDisplayManager.isReduceBrightColorsActivated());
}
@Override
public int getSliderPosition() {
- return Settings.Secure.getInt(mContext.getContentResolver(),
- Settings.Secure.REDUCE_BRIGHT_COLORS_LEVEL, 0);
+ return mColorDisplayManager.getReduceBrightColorsStrength();
}
@Override
public boolean setSliderPosition(int position) {
- return Settings.Secure.putInt(mContext.getContentResolver(),
- Settings.Secure.REDUCE_BRIGHT_COLORS_LEVEL, position);
+ return mColorDisplayManager.setReduceBrightColorsStrength(position);
}
@Override
public int getMax() {
- // TODO(b/170970675): Call into CDS to get config max intensity
- return 100;
+ return ColorDisplayManager.getMaximumReduceBrightColorsStrength(mContext);
}
@Override
public int getMin() {
- // TODO(b/170970675): Call into CDS to get config min intensity
- return 0;
+ return ColorDisplayManager.getMinimumReduceBrightColorsStrength(mContext);
}
}
diff --git a/tests/unit/src/com/android/settings/accessibility/ReduceBrightColorsIntensityPreferenceControllerTest.java b/tests/unit/src/com/android/settings/accessibility/ReduceBrightColorsIntensityPreferenceControllerTest.java
index dee8817..8dac893 100644
--- a/tests/unit/src/com/android/settings/accessibility/ReduceBrightColorsIntensityPreferenceControllerTest.java
+++ b/tests/unit/src/com/android/settings/accessibility/ReduceBrightColorsIntensityPreferenceControllerTest.java
@@ -24,11 +24,14 @@
import android.content.Context;
import android.content.res.Resources;
+import android.hardware.display.ColorDisplayManager;
import android.provider.Settings;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
+import com.android.internal.R;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -79,8 +82,19 @@
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))
+ assertThat(
+ mContext.getSystemService(
+ ColorDisplayManager.class).getReduceBrightColorsStrength())
.isEqualTo(20);
}
+
+ @Test
+ public void rangeOfSlider_staysWithinValidRange() {
+ when(mResources.getInteger(
+ R.integer.config_reduceBrightColorsStrengthMax)).thenReturn(90);
+ when(mResources.getInteger(
+ R.integer.config_reduceBrightColorsStrengthMin)).thenReturn(10);
+ assertThat(mPreferenceController.getMax() - mPreferenceController.getMin())
+ .isEqualTo(80);
+ }
}