Connect reduce bright colors settings
Connection through new CDS APIs to come once that CL is merged. Bug: 168065315 Test: atest SettingsUnitTests:com.android.settings.accessibility.ReduceBrightColorsIntensityPreferenceControllerTest Change-Id: I9cc6a20ea5ea8a11c5fb3ef8a36e372d9c12b4bc
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
package com.android.settings.accessibility;
|
package com.android.settings.accessibility;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.hardware.display.ColorDisplayManager;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
@@ -34,7 +35,12 @@ public class ReduceBrightColorsIntensityPreferenceController extends SliderPrefe
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAvailabilityStatus() {
|
public int getAvailabilityStatus() {
|
||||||
// TODO(b/170970675): Call into ColorDisplayService (CDS) to get availability/config status
|
if (!ColorDisplayManager.isColorTransformAccelerated(mContext)) {
|
||||||
|
return UNSUPPORTED_ON_DEVICE;
|
||||||
|
} else if (Settings.Secure.getInt(mContext.getContentResolver(),
|
||||||
|
Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 0) != 1) {
|
||||||
|
return DISABLED_DEPENDENT_SETTING;
|
||||||
|
}
|
||||||
return AVAILABLE;
|
return AVAILABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,14 +65,14 @@ public class ReduceBrightColorsIntensityPreferenceController extends SliderPrefe
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getSliderPosition() {
|
public int getSliderPosition() {
|
||||||
// TODO(b/170970675): Call into CDS to get intensity
|
return Settings.Secure.getInt(mContext.getContentResolver(),
|
||||||
return 0;
|
Settings.Secure.REDUCE_BRIGHT_COLORS_LEVEL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setSliderPosition(int position) {
|
public boolean setSliderPosition(int position) {
|
||||||
// TODO(b/170970675): Call into CDS to set intensity
|
return Settings.Secure.putInt(mContext.getContentResolver(),
|
||||||
return true;
|
Settings.Secure.REDUCE_BRIGHT_COLORS_LEVEL, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
package com.android.settings.accessibility;
|
package com.android.settings.accessibility;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.hardware.display.ColorDisplayManager;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
@@ -37,7 +38,7 @@ public class ReduceBrightColorsPreferenceController extends BasePreferenceContro
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAvailabilityStatus() {
|
public int getAvailabilityStatus() {
|
||||||
// TODO(b/170970675): call into CDS to get availability/config status
|
return ColorDisplayManager.isColorTransformAccelerated(mContext) ? AVAILABLE
|
||||||
return AVAILABLE;
|
: UNSUPPORTED_ON_DEVICE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -18,32 +18,69 @@ package com.android.settings.accessibility;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.res.Resources;
|
||||||
|
import android.provider.Settings;
|
||||||
|
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
/** TODO(b/170970675): Update and add tests after ColorDisplayService work is integrated */
|
|
||||||
public class ReduceBrightColorsIntensityPreferenceControllerTest {
|
public class ReduceBrightColorsIntensityPreferenceControllerTest {
|
||||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
|
||||||
private final ReduceBrightColorsIntensityPreferenceController mPreferenceController =
|
private Context mContext;
|
||||||
new ReduceBrightColorsIntensityPreferenceController(mContext,
|
private Resources mResources;
|
||||||
"rbc_intensity");
|
private ReduceBrightColorsIntensityPreferenceController mPreferenceController;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||||
|
mResources = spy(mContext.getResources());
|
||||||
|
when(mContext.getResources()).thenReturn(mResources);
|
||||||
|
mPreferenceController = new ReduceBrightColorsIntensityPreferenceController(mContext,
|
||||||
|
"rbc_intensity");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAvailable_configuredRbcAvailable_enabledRbc_shouldReturnTrue() {
|
public void isAvailable_configuredRbcAvailable_enabledRbc_shouldReturnTrue() {
|
||||||
|
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||||
|
Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 1);
|
||||||
|
doReturn(true).when(mResources).getBoolean(
|
||||||
|
com.android.internal.R.bool.config_setColorTransformAccelerated);
|
||||||
assertThat(mPreferenceController.isAvailable()).isTrue();
|
assertThat(mPreferenceController.isAvailable()).isTrue();
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void isAvailable_configuredRbcAvailable_disabledRbc_shouldReturnFalse() {
|
public void isAvailable_configuredRbcAvailable_disabledRbc_shouldReturnTrue() {
|
||||||
|
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||||
|
Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 0);
|
||||||
|
doReturn(true).when(mResources).getBoolean(
|
||||||
|
com.android.internal.R.bool.config_setColorTransformAccelerated);
|
||||||
assertThat(mPreferenceController.isAvailable()).isTrue();
|
assertThat(mPreferenceController.isAvailable()).isTrue();
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void isAvailable_configuredRbcUnavailable_enabledRbc_shouldReturnFalse() {
|
public void isAvailable_configuredRbcUnavailable_enabledRbc_shouldReturnFalse() {
|
||||||
assertThat(mPreferenceController.isAvailable()).isTrue();
|
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||||
|
Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 1);
|
||||||
|
doReturn(false).when(mResources).getBoolean(
|
||||||
|
com.android.internal.R.bool.config_setColorTransformAccelerated);
|
||||||
|
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(20);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user