diff options
5 files changed, 100 insertions, 6 deletions
diff --git a/packages/SystemUI/res-keyguard/layout/keyguard_bouncer_user_switcher.xml b/packages/SystemUI/res-keyguard/layout/keyguard_bouncer_user_switcher.xml index 01e3de2315af..898935fc7e99 100644 --- a/packages/SystemUI/res-keyguard/layout/keyguard_bouncer_user_switcher.xml +++ b/packages/SystemUI/res-keyguard/layout/keyguard_bouncer_user_switcher.xml @@ -35,7 +35,7 @@ <!-- need to keep this outer view in order to have a correctly sized anchor for the dropdown menu, as well as dropdown background in the right place --> - <LinearLayout + <com.android.keyguard.KeyguardUserSwitcherAnchor android:id="@+id/user_switcher_anchor" android:orientation="horizontal" android:layout_height="wrap_content" @@ -48,7 +48,7 @@ android:textDirection="locale" android:layout_width="@dimen/bouncer_user_switcher_width" android:layout_height="wrap_content" /> - </LinearLayout>> + </com.android.keyguard.KeyguardUserSwitcherAnchor> </LinearLayout> diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml index 9c2542cbd05f..1bf30377d7ff 100644 --- a/packages/SystemUI/res/values/strings.xml +++ b/packages/SystemUI/res/values/strings.xml @@ -887,7 +887,8 @@ <!-- Accessibility label for the button that opens the user switcher. --> <string name="accessibility_multi_user_switch_switcher">Switch user</string> - <!-- Accessibility label for the button that opens the user switcher and announces the current user. --> + <!-- Accessibility role description for the element that opens the user switcher list. --> + <string name="accessibility_multi_user_list_switcher">pulldown menu</string> <!-- Accessibility label for the user icon on the lock screen. --> diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java index f697e256dfb0..3517d22ae50d 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java @@ -1129,11 +1129,13 @@ public class KeyguardSecurityContainer extends FrameLayout { Log.e(TAG, "Current user in user switcher is null."); return; } + final String currentUserName = mUserSwitcherController.getCurrentUserName(); Drawable userIcon = findUserIcon(currentUser.info.id); ((ImageView) mView.findViewById(R.id.user_icon)).setImageDrawable(userIcon); - mUserSwitcher.setText(mUserSwitcherController.getCurrentUserName()); + mUserSwitcher.setText(currentUserName); + + KeyguardUserSwitcherAnchor anchor = mView.findViewById(R.id.user_switcher_anchor); - ViewGroup anchor = mView.findViewById(R.id.user_switcher_anchor); BaseUserAdapter adapter = new BaseUserAdapter(mUserSwitcherController) { @Override public View getView(int position, View convertView, ViewGroup parent) { @@ -1213,7 +1215,6 @@ public class KeyguardSecurityContainer extends FrameLayout { anchor.setOnClickListener((v) -> { if (mFalsingManager.isFalseTap(LOW_PENALTY)) return; - mPopup = new KeyguardUserSwitcherPopupMenu(v.getContext(), mFalsingManager); mPopup.setAnchorView(anchor); mPopup.setAdapter(adapter); diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardUserSwitcherAnchor.kt b/packages/SystemUI/src/com/android/keyguard/KeyguardUserSwitcherAnchor.kt new file mode 100644 index 000000000000..5f3ba72d445b --- /dev/null +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardUserSwitcherAnchor.kt @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2022 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.keyguard + +import android.content.Context +import android.util.AttributeSet +import android.view.accessibility.AccessibilityNodeInfo +import android.widget.LinearLayout +import androidx.core.view.accessibility.AccessibilityNodeInfoCompat +import com.android.systemui.R + +/** + * Custom View for the multi-user switcher pull-down menu anchor + */ +class KeyguardUserSwitcherAnchor @JvmOverloads constructor( + context: Context, + attrs: AttributeSet? = null +) : LinearLayout(context, attrs) { + + override fun createAccessibilityNodeInfo(): AccessibilityNodeInfo { + val info = super.createAccessibilityNodeInfo() + AccessibilityNodeInfoCompat.wrap(info).roleDescription = + context.getString(R.string.accessibility_multi_user_list_switcher) + return info + } +} diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUserSwitcherAnchorTest.kt b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUserSwitcherAnchorTest.kt new file mode 100644 index 000000000000..08185af1238e --- /dev/null +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUserSwitcherAnchorTest.kt @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2022 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.keyguard + +import android.testing.AndroidTestingRunner +import androidx.core.view.accessibility.AccessibilityNodeInfoCompat +import androidx.test.filters.SmallTest +import com.android.systemui.R +import com.android.systemui.SysuiTestCase +import com.google.common.truth.Truth.assertThat +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith + +@RunWith(AndroidTestingRunner::class) +@SmallTest +class KeyguardUserSwitcherAnchorTest : SysuiTestCase() { + + private lateinit var keyguardUserSwitcherAnchor: KeyguardUserSwitcherAnchor + + @Before + fun setUp() { + keyguardUserSwitcherAnchor = KeyguardUserSwitcherAnchor(context) + } + + @Test + fun roleDescription_is_set_to_pulldown_menu() { + // GIVEN + val roleDescriptionString = + context.getString(R.string.accessibility_multi_user_list_switcher) + + // WHEN + val result = keyguardUserSwitcherAnchor.createAccessibilityNodeInfo() + + // THEN + assertThat( + AccessibilityNodeInfoCompat.wrap(result).roleDescription + ).isEqualTo(roleDescriptionString) + } +} |