Loading src/com/android/settings/accessibility/ReduceBrightColorsPreferenceController.java +4 −7 Original line number Diff line number Diff line Loading @@ -42,6 +42,7 @@ public class ReduceBrightColorsPreferenceController extends TogglePreferenceCont private ContentObserver mSettingsContentObserver; private PrimarySwitchPreference mPreference; private final Context mContext; private final ColorDisplayManager mColorDisplayManager; public ReduceBrightColorsPreferenceController(Context context, String preferenceKey) { Loading @@ -56,21 +57,17 @@ public class ReduceBrightColorsPreferenceController extends TogglePreferenceCont } } }; mColorDisplayManager = mContext.getSystemService(ColorDisplayManager.class); } @Override public boolean isChecked() { return Settings.Secure.getIntForUser(mContext.getContentResolver(), Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 0, UserHandle.USER_CURRENT) == 1; return mColorDisplayManager.isReduceBrightColorsActivated(); } @Override public boolean setChecked(boolean isChecked) { return Settings.Secure.putIntForUser(mContext.getContentResolver(), Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, isChecked ? 1 : 0, UserHandle.USER_CURRENT); return mColorDisplayManager.setReduceBrightColorsActivated(isChecked); } @Override Loading src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java +4 −8 Original line number Diff line number Diff line Loading @@ -16,9 +16,6 @@ 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.ContentResolver; import android.content.Context; Loading Loading @@ -57,6 +54,7 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre private SettingsContentObserver mSettingsContentObserver; private ReduceBrightColorsIntensityPreferenceController mRbcIntensityPreferenceController; private ReduceBrightColorsPersistencePreferenceController mRbcPersistencePreferenceController; private ColorDisplayManager mColorDisplayManager; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Loading @@ -83,7 +81,7 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre updateSwitchBarToggleSwitch(); } }; mColorDisplayManager = getContext().getSystemService(ColorDisplayManager.class); final View view = super.onCreateView(inflater, container, savedInstanceState); // Parent sets the title when creating the view, so set it after calling super mToggleServiceSwitchPreference.setTitle(R.string.reduce_bright_colors_switch_title); Loading Loading @@ -141,8 +139,7 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre @Override protected void onPreferenceToggled(String preferenceKey, boolean enabled) { AccessibilityStatsLogUtils.logAccessibilityServiceEnabled(mComponentName, enabled); Settings.Secure.putInt(getContentResolver(), REDUCE_BRIGHT_COLORS_ACTIVATED_KEY, enabled ? ON : OFF); mColorDisplayManager.setReduceBrightColorsActivated(enabled); } @Override Loading @@ -165,8 +162,7 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre @Override protected void updateSwitchBarToggleSwitch() { final boolean checked = Settings.Secure.getInt(getContentResolver(), REDUCE_BRIGHT_COLORS_ACTIVATED_KEY, OFF) == ON; final boolean checked = mColorDisplayManager.isReduceBrightColorsActivated(); mRbcIntensityPreferenceController.updateState(getPreferenceScreen() .findPreference(KEY_INTENSITY)); mRbcPersistencePreferenceController.updateState(getPreferenceScreen() Loading tests/robotests/src/com/android/settings/accessibility/ReduceBrightColorsPreferenceControllerTest.java→tests/unit/src/com/android/settings/accessibility/ReduceBrightColorsPreferenceControllerTest.java +98 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * Copyright (C) 2021 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. Loading @@ -18,30 +18,48 @@ package com.android.settings.accessibility; 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.res.Resources; import android.provider.Settings; import androidx.test.core.app.ApplicationProvider; import androidx.test.ext.junit.runners.AndroidJUnit4; import com.android.settings.R; import com.android.internal.R; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @RunWith(AndroidJUnit4.class) public class ReduceBrightColorsPreferenceControllerTest { private static final String PREF_KEY = "rbc_preference"; private final Context mContext = ApplicationProvider.getApplicationContext(); private final ReduceBrightColorsPreferenceController mController = new ReduceBrightColorsPreferenceController(mContext, PREF_KEY); private Context mContext; private Resources mResources;; private ReduceBrightColorsPreferenceController mController; @Before public void setUp() { mContext = spy(ApplicationProvider.getApplicationContext()); mResources = spy(mContext.getResources()); when(mContext.getResources()).thenReturn(mResources); mController = new ReduceBrightColorsPreferenceController(mContext, PREF_KEY); } @Test public void getSummary_returnSummary() { assertThat(mController.getSummary().toString().contains( mContext.getText(R.string.reduce_bright_colors_preference_summary))).isTrue(); resourceString("reduce_bright_colors_preference_summary"))).isTrue(); } @Ignore("ColorDisplayManager runs in a different thread which results in a race condition") @Test public void isChecked_reduceBrightColorsIsActivated_returnTrue() { Settings.Secure.putInt(mContext.getContentResolver(), Loading @@ -49,10 +67,32 @@ public class ReduceBrightColorsPreferenceControllerTest { assertThat(mController.isChecked()).isTrue(); } @Ignore("ColorDisplayManager runs in a different thread which results in a race condition") @Test public void isChecked_reduceBrightColorsIsNotActivated_returnFalse() { Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 0); assertThat(mController.isChecked()).isFalse(); } @Test public void isAvailable_configuredRbcAvailable_shouldReturnTrue() { doReturn(true).when(mResources).getBoolean( R.bool.config_reduceBrightColorsAvailable); assertThat(mController.isAvailable()).isTrue(); } @Test public void isAvailable_configuredRbcUnAvailable_shouldReturnFalse() { doReturn(false).when(mResources).getBoolean( R.bool.config_reduceBrightColorsAvailable); assertThat(mController.isAvailable()).isFalse(); } private int resourceId(String type, String name) { return mContext.getResources().getIdentifier(name, type, mContext.getPackageName()); } private String resourceString(String name) { return mContext.getResources().getString(resourceId("string", name)); } } Loading
src/com/android/settings/accessibility/ReduceBrightColorsPreferenceController.java +4 −7 Original line number Diff line number Diff line Loading @@ -42,6 +42,7 @@ public class ReduceBrightColorsPreferenceController extends TogglePreferenceCont private ContentObserver mSettingsContentObserver; private PrimarySwitchPreference mPreference; private final Context mContext; private final ColorDisplayManager mColorDisplayManager; public ReduceBrightColorsPreferenceController(Context context, String preferenceKey) { Loading @@ -56,21 +57,17 @@ public class ReduceBrightColorsPreferenceController extends TogglePreferenceCont } } }; mColorDisplayManager = mContext.getSystemService(ColorDisplayManager.class); } @Override public boolean isChecked() { return Settings.Secure.getIntForUser(mContext.getContentResolver(), Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 0, UserHandle.USER_CURRENT) == 1; return mColorDisplayManager.isReduceBrightColorsActivated(); } @Override public boolean setChecked(boolean isChecked) { return Settings.Secure.putIntForUser(mContext.getContentResolver(), Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, isChecked ? 1 : 0, UserHandle.USER_CURRENT); return mColorDisplayManager.setReduceBrightColorsActivated(isChecked); } @Override Loading
src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java +4 −8 Original line number Diff line number Diff line Loading @@ -16,9 +16,6 @@ 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.ContentResolver; import android.content.Context; Loading Loading @@ -57,6 +54,7 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre private SettingsContentObserver mSettingsContentObserver; private ReduceBrightColorsIntensityPreferenceController mRbcIntensityPreferenceController; private ReduceBrightColorsPersistencePreferenceController mRbcPersistencePreferenceController; private ColorDisplayManager mColorDisplayManager; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Loading @@ -83,7 +81,7 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre updateSwitchBarToggleSwitch(); } }; mColorDisplayManager = getContext().getSystemService(ColorDisplayManager.class); final View view = super.onCreateView(inflater, container, savedInstanceState); // Parent sets the title when creating the view, so set it after calling super mToggleServiceSwitchPreference.setTitle(R.string.reduce_bright_colors_switch_title); Loading Loading @@ -141,8 +139,7 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre @Override protected void onPreferenceToggled(String preferenceKey, boolean enabled) { AccessibilityStatsLogUtils.logAccessibilityServiceEnabled(mComponentName, enabled); Settings.Secure.putInt(getContentResolver(), REDUCE_BRIGHT_COLORS_ACTIVATED_KEY, enabled ? ON : OFF); mColorDisplayManager.setReduceBrightColorsActivated(enabled); } @Override Loading @@ -165,8 +162,7 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre @Override protected void updateSwitchBarToggleSwitch() { final boolean checked = Settings.Secure.getInt(getContentResolver(), REDUCE_BRIGHT_COLORS_ACTIVATED_KEY, OFF) == ON; final boolean checked = mColorDisplayManager.isReduceBrightColorsActivated(); mRbcIntensityPreferenceController.updateState(getPreferenceScreen() .findPreference(KEY_INTENSITY)); mRbcPersistencePreferenceController.updateState(getPreferenceScreen() Loading
tests/robotests/src/com/android/settings/accessibility/ReduceBrightColorsPreferenceControllerTest.java→tests/unit/src/com/android/settings/accessibility/ReduceBrightColorsPreferenceControllerTest.java +98 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * Copyright (C) 2021 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. Loading @@ -18,30 +18,48 @@ package com.android.settings.accessibility; 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.res.Resources; import android.provider.Settings; import androidx.test.core.app.ApplicationProvider; import androidx.test.ext.junit.runners.AndroidJUnit4; import com.android.settings.R; import com.android.internal.R; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @RunWith(AndroidJUnit4.class) public class ReduceBrightColorsPreferenceControllerTest { private static final String PREF_KEY = "rbc_preference"; private final Context mContext = ApplicationProvider.getApplicationContext(); private final ReduceBrightColorsPreferenceController mController = new ReduceBrightColorsPreferenceController(mContext, PREF_KEY); private Context mContext; private Resources mResources;; private ReduceBrightColorsPreferenceController mController; @Before public void setUp() { mContext = spy(ApplicationProvider.getApplicationContext()); mResources = spy(mContext.getResources()); when(mContext.getResources()).thenReturn(mResources); mController = new ReduceBrightColorsPreferenceController(mContext, PREF_KEY); } @Test public void getSummary_returnSummary() { assertThat(mController.getSummary().toString().contains( mContext.getText(R.string.reduce_bright_colors_preference_summary))).isTrue(); resourceString("reduce_bright_colors_preference_summary"))).isTrue(); } @Ignore("ColorDisplayManager runs in a different thread which results in a race condition") @Test public void isChecked_reduceBrightColorsIsActivated_returnTrue() { Settings.Secure.putInt(mContext.getContentResolver(), Loading @@ -49,10 +67,32 @@ public class ReduceBrightColorsPreferenceControllerTest { assertThat(mController.isChecked()).isTrue(); } @Ignore("ColorDisplayManager runs in a different thread which results in a race condition") @Test public void isChecked_reduceBrightColorsIsNotActivated_returnFalse() { Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 0); assertThat(mController.isChecked()).isFalse(); } @Test public void isAvailable_configuredRbcAvailable_shouldReturnTrue() { doReturn(true).when(mResources).getBoolean( R.bool.config_reduceBrightColorsAvailable); assertThat(mController.isAvailable()).isTrue(); } @Test public void isAvailable_configuredRbcUnAvailable_shouldReturnFalse() { doReturn(false).when(mResources).getBoolean( R.bool.config_reduceBrightColorsAvailable); assertThat(mController.isAvailable()).isFalse(); } private int resourceId(String type, String name) { return mContext.getResources().getIdentifier(name, type, mContext.getPackageName()); } private String resourceString(String name) { return mContext.getResources().getString(resourceId("string", name)); } }