a11y: Only show the cursor following mode setting with detected mouse

This makes sure the cursor following mode setting to be visible only
when a mouse device is detected.

Bug: b/398066000
Flag: com.android.settings.accessibility.enable_magnification_cursor_following_dialog
Test: com.android.settings.accessibility.ToggleScreenMagnificationPreferenceFragmentTest
Change-Id: I7dd27e9d8a841461900e28d8ae07d17f86a0b662
This commit is contained in:
Yongshun Liu
2025-03-11 23:00:19 -07:00
parent a7a7482118
commit 0e1bf4cff6
2 changed files with 66 additions and 2 deletions

View File

@@ -546,6 +546,45 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
assertThat(switchPreference).isNull();
}
@Test
@DisableFlags(com.android.settings.accessibility.Flags
.FLAG_ENABLE_MAGNIFICATION_CURSOR_FOLLOWING_DIALOG)
@Config(shadows = ShadowInputDevice.class)
public void onCreateView_cursorFollowingModeDisabled_settingsPreferenceIsNull() {
addMouseDevice();
mFragController.create(R.id.main_content, /* bundle= */null).start().resume().get();
final Preference preference = mFragController.get().findPreference(
MagnificationCursorFollowingModePreferenceController.PREF_KEY);
assertThat(preference).isNull();
}
@Test
@EnableFlags(com.android.settings.accessibility.Flags
.FLAG_ENABLE_MAGNIFICATION_CURSOR_FOLLOWING_DIALOG)
public void onCreateView_cursorFollowingModeEnabled_settingsPreferenceIsNullWithoutMouse() {
mFragController.create(R.id.main_content, /* bundle= */null).start().resume().get();
final Preference preference = mFragController.get().findPreference(
MagnificationCursorFollowingModePreferenceController.PREF_KEY);
assertThat(preference).isNull();
}
@Test
@EnableFlags(com.android.settings.accessibility.Flags
.FLAG_ENABLE_MAGNIFICATION_CURSOR_FOLLOWING_DIALOG)
@Config(shadows = ShadowInputDevice.class)
public void onCreateView_cursorFollowingModeEnabled_settingsPreferenceIsNotNullWithMouse() {
addMouseDevice();
mFragController.create(R.id.main_content, /* bundle= */null).start().resume().get();
final Preference preference = mFragController.get().findPreference(
MagnificationCursorFollowingModePreferenceController.PREF_KEY);
assertThat(preference).isNotNull();
}
@Test
public void onCreateView_setDialogDelegateAndAddTheControllerToLifeCycleObserver() {
Correspondence instanceOf = Correspondence.transforming(
@@ -903,11 +942,13 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
Flags.FLAG_ENABLE_LOW_VISION_HATS,
com.android.settings.accessibility.Flags
.FLAG_ENABLE_MAGNIFICATION_CURSOR_FOLLOWING_DIALOG})
@Config(shadows = ShadowInputDevice.class)
public void getNonIndexableKeys_hasShortcutAndAllFeaturesEnabled_allItemsSearchable() {
mShadowAccessibilityManager.setAccessibilityShortcutTargets(
TRIPLETAP, List.of(MAGNIFICATION_CONTROLLER_NAME));
setAlwaysOnSupported(true);
setJoystickSupported(true);
addMouseDevice();
final List<String> niks = ToggleScreenMagnificationPreferenceFragment
.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
@@ -1026,6 +1067,14 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
enabled ? ON : OFF);
}
private void addMouseDevice() {
int deviceId = 1;
ShadowInputDevice.sDeviceIds = new int[]{deviceId};
InputDevice device = ShadowInputDevice.makeInputDevicebyIdWithSources(deviceId,
InputDevice.SOURCE_MOUSE);
ShadowInputDevice.addDevice(deviceId, device);
}
private String getStringFromSettings(String key) {
return Settings.Secure.getString(mContext.getContentResolver(), key);
}