[Accessibility] Add contrast control screen UI and setup entry point

Bug: 241805782
Test: atest, local raven device
Screenshot: attached on bug
Flag: aconfig
com.android.settings.accessibility.enable_color_contrast_control

Change-Id: I7fcc01b822b460c6585c41a5831575ba0ffbcc93
This commit is contained in:
marcusge
2024-02-09 00:03:00 +00:00
parent 7d58a1f3e8
commit cddd7b3660
40 changed files with 1639 additions and 0 deletions

View File

@@ -0,0 +1,86 @@
/*
* Copyright (C) 2024 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 static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.app.UiModeManager;
import android.content.Context;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.R;
import com.android.settings.testutils.XmlTestUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import java.util.List;
/** Tests for {@link ColorContrastFragment}. */
@RunWith(RobolectricTestRunner.class)
public class ColorContrastFragmentTest {
private ColorContrastFragment mFragment;
private Context mContext;
@Mock
private UiModeManager mUiService;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mFragment = spy(new ColorContrastFragment());
mContext = spy(ApplicationProvider.getApplicationContext());
when(mFragment.getContext()).thenReturn(mContext);
when(mContext.getSystemService(UiModeManager.class)).thenReturn(mUiService);
}
@Test
public void getMetricsCategory_returnsCorrectCategory() {
assertThat(mFragment.getMetricsCategory()).isEqualTo(0);
}
@Test
public void getPreferenceScreenResId_returnsCorrectXml() {
assertThat(mFragment.getPreferenceScreenResId()).isEqualTo(
R.xml.accessibility_color_contrast);
}
@Test
public void getLogTag_returnsCorrectTag() {
assertThat(mFragment.getLogTag()).isEqualTo("ColorContrastFragment");
}
@Test
public void getNonIndexableKeys_existInXmlLayout() {
final List<String> niks =
ShortcutsSettingsFragment.SEARCH_INDEX_DATA_PROVIDER
.getNonIndexableKeys(mContext);
final List<String> keys =
XmlTestUtils.getKeysFromPreferenceXml(mContext,
R.xml.accessibility_color_contrast);
assertThat(keys).containsAtLeastElementsIn(niks);
}
}

View File

@@ -0,0 +1,70 @@
/*
* Copyright (C) 2024 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.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.platform.test.flag.junit.SetFlagsRule;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.core.BasePreferenceController;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
/** Tests for {@link ContrastPreferenceController}. */
@RunWith(RobolectricTestRunner.class)
public class ContrastPreferenceControllerTest {
@Rule
public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
@Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
private static final String PREFERENCE_KEY = "preference_key";
private Context mContext;
private ContrastPreferenceController mController;
@Before
public void setUp() {
mContext = ApplicationProvider.getApplicationContext();
mController = new ContrastPreferenceController(mContext, PREFERENCE_KEY);
}
@Test
public void getAvailabilityStatus_flagsEnabled_shouldReturnAvailable() {
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_COLOR_CONTRAST_CONTROL);
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.AVAILABLE);
}
@Test
public void getAvailabilityStatus_flagsDisabled_shouldReturnUnsupported() {
mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_COLOR_CONTRAST_CONTROL);
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
}
}

View File

@@ -0,0 +1,115 @@
/*
* Copyright (C) 2024 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 static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.UiModeManager;
import android.content.Context;
import android.widget.FrameLayout;
import androidx.preference.PreferenceScreen;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.widget.LayoutPreference;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import java.util.concurrent.Executor;
/** Tests for {@link ContrastSelectorPreferenceController}. */
@RunWith(RobolectricTestRunner.class)
public class ContrastSelectorPreferenceControllerTest {
private static final String PREFERENCE_KEY = "color_contrast_selector";
@Mock
private UiModeManager mUiService;
@Mock
private Executor mExecutor;
@Mock
private PreferenceScreen mScreen;
@Mock
private FrameLayout mFrameLayout;
@Mock
private LayoutPreference mLayoutPreference;
private Context mContext;
private ContrastSelectorPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(ApplicationProvider.getApplicationContext());
when(mContext.getMainExecutor()).thenReturn(mExecutor);
when(mContext.getSystemService(UiModeManager.class)).thenReturn(mUiService);
mController = new ContrastSelectorPreferenceController(mContext, PREFERENCE_KEY);
when(mScreen.findPreference(PREFERENCE_KEY)).thenReturn(mLayoutPreference);
when(mLayoutPreference.findViewById(anyInt())).thenReturn(mFrameLayout);
}
@Test
public void getAvailabilityStatus_byDefault_shouldReturnAvailable() {
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.AVAILABLE);
}
@Test
public void onStart_shouldAddContrastListener() {
mController.displayPreference(mScreen);
mController.onStart();
verify(mUiService).addContrastChangeListener(mExecutor, mController);
}
@Test
public void onStop_shouldRemoveContrastListener() {
mController.displayPreference(mScreen);
mController.onStart();
mController.onStop();
verify(mUiService).removeContrastChangeListener(mController);
}
@Test
public void displayPreference_shouldAddClickListener() {
mController.displayPreference(mScreen);
verify(mFrameLayout, times(3)).setOnClickListener(any());
}
@Test
public void onContrastChanged_buttonShouldBeSelected() {
mController.displayPreference(mScreen);
mController.onContrastChanged(1);
verify(mFrameLayout, times(2)).setSelected(true);
}
}