From bc1b12db3ab49c4e19e4abea74254b44270e1948 Mon Sep 17 00:00:00 2001 From: Nikki Moteva Date: Mon, 25 Nov 2024 22:38:08 +0000 Subject: [PATCH] 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 --- res/xml/app_notification_settings.xml | 3 ++- .../widget/SettingsMainSwitchPreference.java | 5 ++++ .../SettingsMainSwitchPreferenceTest.java | 23 +++++++++++++++++-- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/res/xml/app_notification_settings.xml b/res/xml/app_notification_settings.xml index 1eee0cb8a77..30a57a24bb7 100644 --- a/res/xml/app_notification_settings.xml +++ b/res/xml/app_notification_settings.xml @@ -21,7 +21,8 @@ + android:layout="@layout/settings_entity_header" + android:selectable="false" /> diff --git a/src/com/android/settings/widget/SettingsMainSwitchPreference.java b/src/com/android/settings/widget/SettingsMainSwitchPreference.java index 5e0a5a722e7..046320fe376 100644 --- a/src/com/android/settings/widget/SettingsMainSwitchPreference.java +++ b/src/com/android/settings/widget/SettingsMainSwitchPreference.java @@ -240,6 +240,11 @@ public class SettingsMainSwitchPreference extends TwoStatePreference implements if (mMainSwitchBar != null) { mMainSwitchBar.setTitle(getTitle()); mMainSwitchBar.setDisabledByAdmin(mEnforcedAdmin); + + // Disable the focusability of the switch bar. The parent FrameLayout + // will be the only focusable view for the Main Switch Bar to avoid + // duplicate a11y focus. + mMainSwitchBar.setFocusable(false); } } diff --git a/tests/robotests/src/com/android/settings/widget/SettingsMainSwitchPreferenceTest.java b/tests/robotests/src/com/android/settings/widget/SettingsMainSwitchPreferenceTest.java index a5ebdade033..498a2c2b9df 100644 --- a/tests/robotests/src/com/android/settings/widget/SettingsMainSwitchPreferenceTest.java +++ b/tests/robotests/src/com/android/settings/widget/SettingsMainSwitchPreferenceTest.java @@ -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(); + } }