Fix missing declared accessibility PreferenceControllers.
This includes 3 fixes: Adds missing settings:controller attribute for bold & high-contrast text preferences. Separates VibrationSettings into two fragments, one per fragment XML resource. Instead of using a conditional to choose the XML resource ID, we now use the conditional to choose which fragment to launch. This allows both fragment's preference controllers to be inspected by CodeInspectionTest#runSliceControllerInXmlInspection. Also updates the preference keys which must be unique per XML in order to appear in Settings Search. Adds Magnification preference controllers to exempt-not-in-XML list. These controllers are for fragments that are not declared in an XML. See ToggleScreenMagnificationPreferenceFragment #getPreferenceScreenResId. Bug: 289967175 Test: atest SettingsRoboTests:com.android.settings.accessibility Test: atest CodeInspectionTest#runSliceControllerInXmlInspection; Observe no errors in the accessibility package. Test: Open Settings > Accessibility > Vibration & haptics; observe vibration intensity page is shown (behavior unchanged). Hardcode config_vibration_supported_intensity_levels=1; observe vibration page with toggles is shown (behavior unchanged). Change-Id: I257b5ad390371bedb1623af6289016b06d478707
This commit is contained in:
@@ -18,14 +18,20 @@ package com.android.settings.accessibility;
|
||||
|
||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Vibrator;
|
||||
import android.platform.test.annotations.RequiresFlagsEnabled;
|
||||
import android.platform.test.flag.junit.CheckFlagsRule;
|
||||
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
@@ -33,8 +39,10 @@ import androidx.preference.PreferenceScreen;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.flags.Flags;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
@@ -44,6 +52,9 @@ import org.robolectric.RobolectricTestRunner;
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class VibrationPreferenceControllerTest {
|
||||
|
||||
@Rule
|
||||
public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
|
||||
|
||||
private static final String PREFERENCE_KEY = "preference_key";
|
||||
private static final int OFF = 0;
|
||||
private static final int ON = 1;
|
||||
@@ -52,13 +63,17 @@ public class VibrationPreferenceControllerTest {
|
||||
@Mock private PreferenceScreen mScreen;
|
||||
|
||||
private Context mContext;
|
||||
private Resources mResources;
|
||||
private Preference mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||
mResources = spy(mContext.getResources());
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
when(mContext.getSystemService(Context.VIBRATOR_SERVICE)).thenReturn(mVibrator);
|
||||
when(mVibrator.hasVibrator()).thenReturn(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -85,7 +100,6 @@ public class VibrationPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void getSummary_vibrateSettingNotSet_returnsOnText() {
|
||||
when(mVibrator.hasVibrator()).thenReturn(true);
|
||||
Settings.System.putString(mContext.getContentResolver(), Settings.System.VIBRATE_ON,
|
||||
/* value= */ null);
|
||||
VibrationPreferenceController controller = createPreferenceController();
|
||||
@@ -97,7 +111,6 @@ public class VibrationPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void getSummary_vibrateSettingOn_returnsOnText() {
|
||||
when(mVibrator.hasVibrator()).thenReturn(true);
|
||||
Settings.System.putInt(mContext.getContentResolver(), Settings.System.VIBRATE_ON, ON);
|
||||
VibrationPreferenceController controller = createPreferenceController();
|
||||
controller.updateState(mPreference);
|
||||
@@ -108,7 +121,6 @@ public class VibrationPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void getSummary_vibrateSettingOff_returnsOffText() {
|
||||
when(mVibrator.hasVibrator()).thenReturn(true);
|
||||
Settings.System.putInt(mContext.getContentResolver(), Settings.System.VIBRATE_ON, OFF);
|
||||
VibrationPreferenceController controller = createPreferenceController();
|
||||
controller.updateState(mPreference);
|
||||
@@ -117,11 +129,39 @@ public class VibrationPreferenceControllerTest {
|
||||
mContext.getString(R.string.accessibility_vibration_settings_state_off));
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresFlagsEnabled(Flags.FLAG_SEPARATE_ACCESSIBILITY_VIBRATION_SETTINGS_FRAGMENTS)
|
||||
public void handlePreferenceTreeClick_oneIntensityLevel_opensVibrationSettings() {
|
||||
when(mResources.getInteger(R.integer.config_vibration_supported_intensity_levels))
|
||||
.thenReturn(1);
|
||||
VibrationPreferenceController controller = spy(createPreferenceController());
|
||||
|
||||
doNothing().when(controller).launchVibrationSettingsFragment(any());
|
||||
controller.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
verify(controller).launchVibrationSettingsFragment(eq(VibrationSettings.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresFlagsEnabled(Flags.FLAG_SEPARATE_ACCESSIBILITY_VIBRATION_SETTINGS_FRAGMENTS)
|
||||
public void handlePreferenceTreeClick_multipleIntensityLevels_opensVibrationIntensity() {
|
||||
when(mResources.getInteger(R.integer.config_vibration_supported_intensity_levels))
|
||||
.thenReturn(2);
|
||||
VibrationPreferenceController controller = spy(createPreferenceController());
|
||||
|
||||
doNothing().when(controller).launchVibrationSettingsFragment(any());
|
||||
controller.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
verify(controller).launchVibrationSettingsFragment(
|
||||
eq(VibrationIntensitySettingsFragment.class));
|
||||
}
|
||||
|
||||
private VibrationPreferenceController createPreferenceController() {
|
||||
VibrationPreferenceController controller =
|
||||
new VibrationPreferenceController(mContext, PREFERENCE_KEY);
|
||||
mPreference = new Preference(mContext);
|
||||
mPreference.setSummary("Test summary");
|
||||
mPreference.setKey(PREFERENCE_KEY);
|
||||
when(mScreen.findPreference(controller.getPreferenceKey())).thenReturn(mPreference);
|
||||
controller.displayPreference(mScreen);
|
||||
return controller;
|
||||
|
Reference in New Issue
Block a user