diff --git a/res/values/strings.xml b/res/values/strings.xml
index c3e5d8172d8..9ee2800f9aa 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -5239,6 +5239,18 @@
Blue-yellow
+
+
+ Reduce Bright Colors
+
+ Use Reduce Bright Colors
+
+ Reduce Bright Colors reduces screen brightness.
+
+ Intensity
+
+ Keeps feature on after a restart
+
- Short (%1$s second)
diff --git a/res/xml/accessibility_settings.xml b/res/xml/accessibility_settings.xml
index 4a88ef03636..fcc6bccb6d9 100644
--- a/res/xml/accessibility_settings.xml
+++ b/res/xml/accessibility_settings.xml
@@ -231,6 +231,14 @@
android:summary="@string/accessibility_shortcut_description"
settings:controller="com.android.settings.accessibility.AccessibilityShortcutPreferenceController"/>
+
+
+
diff --git a/res/xml/reduce_bright_colors_settings.xml b/res/xml/reduce_bright_colors_settings.xml
new file mode 100644
index 00000000000..b9ca8549204
--- /dev/null
+++ b/res/xml/reduce_bright_colors_settings.xml
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+
+
+
diff --git a/src/com/android/settings/accessibility/AccessibilitySettings.java b/src/com/android/settings/accessibility/AccessibilitySettings.java
index fca49f917f4..e5bc3f5666e 100644
--- a/src/com/android/settings/accessibility/AccessibilitySettings.java
+++ b/src/com/android/settings/accessibility/AccessibilitySettings.java
@@ -97,6 +97,8 @@ public class AccessibilitySettings extends DashboardFragment {
"magnification_preference_screen";
private static final String DISPLAY_DALTONIZER_PREFERENCE_SCREEN =
"daltonizer_preference";
+ private static final String DISPLAY_REDUCE_BRIGHT_COLORS_PREFERENCE_SCREEN =
+ "reduce_bright_colors_preference";
// Extras passed to sub-fragments.
static final String EXTRA_PREFERENCE_KEY = "preference_key";
@@ -170,6 +172,8 @@ public class AccessibilitySettings extends DashboardFragment {
private Preference mDisplayMagnificationPreferenceScreen;
private Preference mDisplayDaltonizerPreferenceScreen;
private Preference mToggleInversionPreference;
+ private Preference mReduceBrightColorsPreference;
+
/**
* Check if the color transforms are color accelerated. Some transforms are experimental only
@@ -335,6 +339,10 @@ public class AccessibilitySettings extends DashboardFragment {
// Display color adjustments.
mDisplayDaltonizerPreferenceScreen = findPreference(DISPLAY_DALTONIZER_PREFERENCE_SCREEN);
+
+ // Reduce brightness.
+ mReduceBrightColorsPreference =
+ findPreference(DISPLAY_REDUCE_BRIGHT_COLORS_PREFERENCE_SCREEN);
}
private void updateAllPreferences() {
@@ -488,6 +496,7 @@ public class AccessibilitySettings extends DashboardFragment {
mCategoryToPrefCategoryMap.get(CATEGORY_DISPLAY);
experimentalCategory.removePreference(mToggleInversionPreference);
experimentalCategory.removePreference(mDisplayDaltonizerPreferenceScreen);
+ experimentalCategory.removePreference(mReduceBrightColorsPreference);
mDisplayMagnificationPreferenceScreen.setSummary(
ToggleScreenMagnificationPreferenceFragment.getServiceSummary(getContext()));
mDisplayDaltonizerPreferenceScreen.setOrder(
@@ -502,8 +511,13 @@ public class AccessibilitySettings extends DashboardFragment {
mToggleLargePointerIconPreference.getOrder() + 1);
mToggleInversionPreference.setSummary(AccessibilityUtil.getSummary(
getContext(), Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED));
+ mReduceBrightColorsPreference.setOrder(
+ mToggleDisableAnimationsPreference.getOrder() + 1);
+ mReduceBrightColorsPreference.setSummary(AccessibilityUtil.getSummary(
+ getContext(), Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED));
displayCategory.addPreference(mToggleInversionPreference);
displayCategory.addPreference(mDisplayDaltonizerPreferenceScreen);
+ displayCategory.addPreference(mReduceBrightColorsPreference);
}
}
diff --git a/src/com/android/settings/accessibility/ReduceBrightColorsIntensityPreferenceController.java b/src/com/android/settings/accessibility/ReduceBrightColorsIntensityPreferenceController.java
new file mode 100644
index 00000000000..b9a6d399529
--- /dev/null
+++ b/src/com/android/settings/accessibility/ReduceBrightColorsIntensityPreferenceController.java
@@ -0,0 +1,82 @@
+/*
+ * 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.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 {
+
+ public ReduceBrightColorsIntensityPreferenceController(Context context, String key) {
+ super(context, key);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ // TODO(b/170970675): Call into ColorDisplayService (CDS) to get availability/config status
+ 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());
+ updateState(preference);
+ }
+
+
+ @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);
+ }
+
+ @Override
+ public int getSliderPosition() {
+ // TODO(b/170970675): Call into CDS to get intensity
+ return 0;
+ }
+
+ @Override
+ public boolean setSliderPosition(int position) {
+ // TODO(b/170970675): Call into CDS to set intensity
+ return true;
+ }
+
+ @Override
+ public int getMax() {
+ // TODO(b/170970675): Call into CDS to get config max intensity
+ return 100;
+ }
+
+ @Override
+ public int getMin() {
+ // TODO(b/170970675): Call into CDS to get config min intensity
+ return 0;
+ }
+}
diff --git a/src/com/android/settings/accessibility/ReduceBrightColorsPersistencePreferenceController.java b/src/com/android/settings/accessibility/ReduceBrightColorsPersistencePreferenceController.java
new file mode 100644
index 00000000000..bf8cda79160
--- /dev/null
+++ b/src/com/android/settings/accessibility/ReduceBrightColorsPersistencePreferenceController.java
@@ -0,0 +1,49 @@
+/*
+ * 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.provider.Settings;
+
+import com.android.settings.core.TogglePreferenceController;
+
+/** PreferenceController for persisting feature activation state after a restart. */
+public class ReduceBrightColorsPersistencePreferenceController extends TogglePreferenceController {
+
+ public ReduceBrightColorsPersistencePreferenceController(
+ Context context, String preferenceKey) {
+ super(context, preferenceKey);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ // TODO(b/170970675): call into CDS to get availability/config status
+ 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));
+ }
+}
diff --git a/src/com/android/settings/accessibility/ReduceBrightColorsPreferenceController.java b/src/com/android/settings/accessibility/ReduceBrightColorsPreferenceController.java
new file mode 100644
index 00000000000..c5ce77caac0
--- /dev/null
+++ b/src/com/android/settings/accessibility/ReduceBrightColorsPreferenceController.java
@@ -0,0 +1,43 @@
+/*
+ * 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.provider.Settings;
+
+import com.android.settings.core.BasePreferenceController;
+
+/** PreferenceController that shows the Reduce Bright Colors summary */
+public class ReduceBrightColorsPreferenceController extends BasePreferenceController {
+
+ public ReduceBrightColorsPreferenceController(Context context,
+ String preferenceKey) {
+ super(context, preferenceKey);
+ }
+
+ @Override
+ public CharSequence getSummary() {
+ return AccessibilityUtil.getSummary(mContext,
+ Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ // TODO(b/170970675): call into CDS to get availability/config status
+ return AVAILABLE;
+ }
+}
diff --git a/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java
new file mode 100644
index 00000000000..84133f324e1
--- /dev/null
+++ b/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java
@@ -0,0 +1,200 @@
+/*
+ * 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.android.settings.accessibility.AccessibilityUtil.State.OFF;
+import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
+
+import android.app.settings.SettingsEnums;
+import android.content.Context;
+import android.net.Uri;
+import android.os.Bundle;
+import android.os.Handler;
+import android.provider.Settings;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+import androidx.preference.SwitchPreference;
+
+import com.android.internal.accessibility.AccessibilityShortcutController;
+import com.android.settings.R;
+import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settingslib.search.SearchIndexable;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/** Settings for reducing brightness. */
+@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
+public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePreferenceFragment {
+ private static final String REDUCE_BRIGHT_COLORS_ACTIVATED_KEY =
+ Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED;
+ private static final String KEY_INTENSITY = "rbc_intensity";
+ private static final String KEY_PERSIST = "rbc_persist";
+
+ private final Handler mHandler = new Handler();
+ private SettingsContentObserver mSettingsContentObserver;
+ private ReduceBrightColorsIntensityPreferenceController mRbcIntensityPreferenceController;
+ private ReduceBrightColorsPersistencePreferenceController mRbcPersistencePreferenceController;
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+
+ // TODO(b/170973645): Add banner
+ mComponentName = AccessibilityShortcutController.REDUCE_BRIGHT_COLORS_COMPONENT_NAME;
+ mPackageName = getText(R.string.reduce_bright_colors_preference_title);
+ mHtmlDescription = getText(R.string.reduce_bright_colors_preference_subtitle);
+ final List enableServiceFeatureKeys = new ArrayList<>(/* initialCapacity= */ 1);
+ enableServiceFeatureKeys.add(REDUCE_BRIGHT_COLORS_ACTIVATED_KEY);
+ mRbcIntensityPreferenceController =
+ new ReduceBrightColorsIntensityPreferenceController(getContext(), KEY_INTENSITY);
+ mRbcPersistencePreferenceController =
+ new ReduceBrightColorsPersistencePreferenceController(getContext(), KEY_PERSIST);
+ mRbcIntensityPreferenceController.displayPreference(getPreferenceScreen());
+ mRbcPersistencePreferenceController.displayPreference(getPreferenceScreen());
+ mSettingsContentObserver = new SettingsContentObserver(mHandler, enableServiceFeatureKeys) {
+ @Override
+ public void onChange(boolean selfChange, Uri uri) {
+ updateSwitchBarToggleSwitch();
+ }
+ };
+
+ return super.onCreateView(inflater, container, savedInstanceState);
+ }
+
+ @Override
+ public void onViewCreated(View view, Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+ updatePreferenceOrder();
+ }
+
+ /** Customizes the order by preference key. */
+ private List getPreferenceOrderList() {
+ final List lists = new ArrayList<>();
+ lists.add(KEY_USE_SERVICE_PREFERENCE);
+ lists.add(KEY_INTENSITY);
+ lists.add(KEY_PERSIST);
+ lists.add(KEY_GENERAL_CATEGORY);
+ lists.add(KEY_INTRODUCTION_CATEGORY);
+ return lists;
+ }
+
+ private void updatePreferenceOrder() {
+ final List lists = getPreferenceOrderList();
+ final PreferenceScreen preferenceScreen = getPreferenceScreen();
+ preferenceScreen.setOrderingAsAdded(false);
+
+ final int size = lists.size();
+ for (int i = 0; i < size; i++) {
+ final Preference preference = preferenceScreen.findPreference(lists.get(i));
+ if (preference != null) {
+ preference.setOrder(i);
+ }
+ }
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ updateSwitchBarToggleSwitch();
+ mSettingsContentObserver.register(getContentResolver());
+ }
+
+ @Override
+ public void onPause() {
+ mSettingsContentObserver.unregister(getContentResolver());
+ super.onPause();
+ }
+
+ @Override
+ public int getMetricsCategory() {
+ return SettingsEnums.REDUCE_BRIGHT_COLORS_SETTINGS;
+ }
+
+ @Override
+ public int getHelpResource() {
+ // TODO(170973645): Link to help support page
+ return 0;
+ }
+
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.reduce_bright_colors_settings;
+ }
+
+
+ @Override
+ protected void onPreferenceToggled(String preferenceKey, boolean enabled) {
+ AccessibilityStatsLogUtils.logAccessibilityServiceEnabled(mComponentName, enabled);
+ Settings.Secure.putInt(getContentResolver(),
+ REDUCE_BRIGHT_COLORS_ACTIVATED_KEY, enabled ? ON : OFF);
+ }
+
+ @Override
+ protected void onRemoveSwitchPreferenceToggleSwitch() {
+ super.onRemoveSwitchPreferenceToggleSwitch();
+ mToggleServiceDividerSwitchPreference.setOnPreferenceClickListener(
+ /* onPreferenceClickListener= */ null);
+ }
+
+ @Override
+ protected void updateToggleServiceTitle(SwitchPreference switchPreference) {
+ switchPreference.setTitle(R.string.reduce_bright_colors_switch_title);
+ }
+
+ @Override
+ protected void onInstallSwitchPreferenceToggleSwitch() {
+ super.onInstallSwitchPreferenceToggleSwitch();
+ updateSwitchBarToggleSwitch();
+ mToggleServiceDividerSwitchPreference.setOnPreferenceClickListener((preference) -> {
+ boolean checked = ((SwitchPreference) preference).isChecked();
+ onPreferenceToggled(mPreferenceKey, checked);
+ return false;
+ });
+ }
+
+ @Override
+ int getUserShortcutTypes() {
+ return AccessibilityUtil.getUserShortcutTypesFromSettings(getPrefContext(),
+ mComponentName);
+ }
+
+ private void updateSwitchBarToggleSwitch() {
+ final boolean checked = Settings.Secure.getInt(getContentResolver(),
+ REDUCE_BRIGHT_COLORS_ACTIVATED_KEY, OFF) == ON;
+ mRbcIntensityPreferenceController.updateState(getPreferenceScreen()
+ .findPreference(KEY_INTENSITY));
+ mRbcPersistencePreferenceController.updateState(getPreferenceScreen()
+ .findPreference(KEY_PERSIST));
+ if (mToggleServiceDividerSwitchPreference.isChecked() != checked) {
+ mToggleServiceDividerSwitchPreference.setChecked(checked);
+ }
+ }
+
+ public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+ 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;
+ }
+ };
+}
diff --git a/tests/robotests/assets/exempt_slice_controller_not_in_xml b/tests/robotests/assets/exempt_slice_controller_not_in_xml
index 5cd855f6c94..d711833d1b0 100644
--- a/tests/robotests/assets/exempt_slice_controller_not_in_xml
+++ b/tests/robotests/assets/exempt_slice_controller_not_in_xml
@@ -8,4 +8,6 @@ com.android.settings.testutils.FakeToggleController
com.android.settings.testutils.FakeSliderController
com.android.settings.testutils.FakeInvalidSliderController
com.android.settings.wifi.details2.WifiAutoConnectPreferenceController2
+com.android.settings.accessibility.ReduceBrightColorsIntensityPreferenceController
+com.android.settings.accessibility.ReduceBrightColorsPersistencePreferenceController
diff --git a/tests/robotests/src/com/android/settings/accessibility/ReduceBrightColorsIntensityPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accessibility/ReduceBrightColorsIntensityPreferenceControllerTest.java
new file mode 100644
index 00000000000..4cc17dcc87c
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/accessibility/ReduceBrightColorsIntensityPreferenceControllerTest.java
@@ -0,0 +1,49 @@
+/*
+ * 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.content.Context;
+
+import androidx.test.core.app.ApplicationProvider;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AndroidJUnit4.class)
+/** TODO(b/170970675): Update and add tests after ColorDisplayService work is integrated */
+public class ReduceBrightColorsIntensityPreferenceControllerTest {
+ private final Context mContext = ApplicationProvider.getApplicationContext();
+ private final ReduceBrightColorsIntensityPreferenceController mPreferenceController =
+ new ReduceBrightColorsIntensityPreferenceController(mContext,
+ "rbc_intensity");
+
+ @Test
+ public void isAvailable_configuredRbcAvailable_enabledRbc_shouldReturnTrue() {
+ assertThat(mPreferenceController.isAvailable()).isTrue();
+ }
+ @Test
+ public void isAvailable_configuredRbcAvailable_disabledRbc_shouldReturnFalse() {
+ assertThat(mPreferenceController.isAvailable()).isTrue();
+ }
+ @Test
+ public void isAvailable_configuredRbcUnavailable_enabledRbc_shouldReturnFalse() {
+ assertThat(mPreferenceController.isAvailable()).isTrue();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/accessibility/ReduceBrightColorsPersistencePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accessibility/ReduceBrightColorsPersistencePreferenceControllerTest.java
new file mode 100644
index 00000000000..ef27d73119d
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/accessibility/ReduceBrightColorsPersistencePreferenceControllerTest.java
@@ -0,0 +1,82 @@
+/*
+ * 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.content.Context;
+import android.provider.Settings;
+
+import androidx.preference.SwitchPreference;
+import androidx.test.core.app.ApplicationProvider;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+
+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;
+
+ private final Context mContext = 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);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/accessibility/ReduceBrightColorsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accessibility/ReduceBrightColorsPreferenceControllerTest.java
new file mode 100644
index 00000000000..39a663ed654
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/accessibility/ReduceBrightColorsPreferenceControllerTest.java
@@ -0,0 +1,60 @@
+/*
+ * 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.content.Context;
+import android.provider.Settings;
+
+import androidx.test.core.app.ApplicationProvider;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+
+import com.android.settings.R;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AndroidJUnit4.class)
+public class ReduceBrightColorsPreferenceControllerTest {
+ private static final String PREF_KEY = "rbc_preference";
+ private static final String RBC_ACTIVATED =
+ Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED;
+ private static final int ON = 1;
+ private static final int OFF = 0;
+
+ private final Context mContext = ApplicationProvider.getApplicationContext();
+ private final ReduceBrightColorsPreferenceController mController =
+ new ReduceBrightColorsPreferenceController(mContext, PREF_KEY);
+
+ @Test
+ public void getSummary_enabledRbc_shouldReturnOnSummary() {
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ RBC_ACTIVATED, ON);
+
+ assertThat(mController.getSummary().toString().contains(
+ mContext.getText(R.string.accessibility_feature_state_on))).isTrue();
+ }
+ @Test
+ public void getSummary_disabledRbc_shouldReturnOffSummary() {
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ RBC_ACTIVATED, OFF);
+
+ assertThat(mController.getSummary().toString().contains(
+ mContext.getText(R.string.accessibility_feature_state_off))).isTrue();
+ }
+}