Settings: Fix the a11y focus issues in App Notifications subpage

There are duplicate a11y focuses in the App Notifications subpage.
See the bug for more details.

To fix the App, we will make the LayoutPreference unselectable,
which makes the internal FrameLayout unfocusable.

To fix the Switch, we can disable its focusability.
This will make the FrameLayout the only focusable view for the
Main Switch Bar. This a11y fix applies to all instances of
SettingsMainSwitchPreference in the Settings app.

Bug: 306725248
Flag: EXEMPT bugfix
Test:
atest SettingsMainSwitchPreferenceTest
Manually tested the UI. The SettingsMainSwitchPreference
is also used in `Display & Touch > Adaptive brightness`,
`Accessibility > Caption Preference`, etc. The toggle acts as
expected in the pages.

Change-Id: I52b4965ac0ffc8d1576e8bc650715eb80ab4e8c7
This commit is contained in:
Nikki Moteva
2024-11-25 22:38:08 +00:00
parent c87fd1a92f
commit bc1b12db3a
3 changed files with 28 additions and 3 deletions

View File

@@ -41,6 +41,7 @@ public class SettingsMainSwitchPreferenceTest {
private EnforcedAdmin mEnforcedAdmin;
private SettingsMainSwitchPreference mPreference;
private PreferenceViewHolder mHolder;
private View mRootView;
@Before
public void setUp() {
@@ -50,9 +51,9 @@ public class SettingsMainSwitchPreferenceTest {
mPreference = new SettingsMainSwitchPreference(context);
ReflectionHelpers.setField(mPreference, "mEnforcedAdmin", mEnforcedAdmin);
ReflectionHelpers.setField(mPreference, "mMainSwitchBar", switchBar);
final View rootView = View.inflate(context, com.android.settings.R.layout.preference_widget_main_switch,
mRootView = View.inflate(context, com.android.settings.R.layout.preference_widget_main_switch,
null /* parent */);
mHolder = PreferenceViewHolder.createInstanceForTests(rootView);
mHolder = PreferenceViewHolder.createInstanceForTests(mRootView);
}
@Test
@@ -74,4 +75,22 @@ public class SettingsMainSwitchPreferenceTest {
assertThat(mPreference.isShowing()).isFalse();
assertThat(mPreference.isVisible()).isFalse();
}
@Test
public void focusability_mainSwitchBarIsNotFocusable() {
mPreference.show();
mPreference.onBindViewHolder(mHolder);
assertThat(mPreference.getSwitchBar().isFocusable()).isFalse();
}
@Test
public void focusability_mainSwitchBarFrameLayoutIsFocusable() {
mPreference.show();
mPreference.onBindViewHolder(mHolder);
assertThat(mRootView.isFocusable()).isTrue();
}
}