Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 511c616f authored by Matt Pietal's avatar Matt Pietal Committed by Android (Google) Code Review
Browse files

Merge "A11Y - Allow switch click on alternate bouncer UDFPS" into main

parents c7833ce6 ade0fc8a
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -193,8 +193,6 @@ public class UdfpsControllerTest extends SysuiTestCase {
    @Mock
    private UdfpsOverlayInteractor mUdfpsOverlayInteractor;
    @Mock
    private UdfpsKeyguardAccessibilityDelegate mUdfpsKeyguardAccessibilityDelegate;
    @Mock
    private SelectedUserInteractor mSelectedUserInteractor;

    // Capture listeners so that they can be used to send events
@@ -321,7 +319,6 @@ public class UdfpsControllerTest extends SysuiTestCase {
                mAlternateBouncerInteractor,
                mInputManager,
                mock(DeviceEntryFaceAuthInteractor.class),
                mUdfpsKeyguardAccessibilityDelegate,
                mSelectedUserInteractor,
                mKeyguardTransitionInteractor,
                mDeviceEntryUdfpsTouchOverlayViewModel,
+0 −86
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.systemui.biometrics

import android.testing.TestableLooper
import android.view.View
import android.view.accessibility.AccessibilityNodeInfo
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager
import com.android.systemui.util.mockito.argumentCaptor
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers.anyBoolean
import org.mockito.Mock
import org.mockito.Mockito.mock
import org.mockito.Mockito.verify
import org.mockito.MockitoAnnotations

@RunWith(AndroidJUnit4::class)
@SmallTest
@TestableLooper.RunWithLooper
class UdfpsKeyguardAccessibilityDelegateTest : SysuiTestCase() {

    @Mock private lateinit var keyguardViewManager: StatusBarKeyguardViewManager
    @Mock private lateinit var hostView: View
    private lateinit var underTest: UdfpsKeyguardAccessibilityDelegate

    @Before
    fun setUp() {
        MockitoAnnotations.initMocks(this)
        underTest =
            UdfpsKeyguardAccessibilityDelegate(
                context.resources,
                keyguardViewManager,
            )
    }

    @Test
    fun onInitializeAccessibilityNodeInfo_clickActionAdded() {
        // WHEN node is initialized
        val mockedNodeInfo = mock(AccessibilityNodeInfo::class.java)
        underTest.onInitializeAccessibilityNodeInfo(hostView, mockedNodeInfo)

        // THEN a11y action is added
        val argumentCaptor = argumentCaptor<AccessibilityNodeInfo.AccessibilityAction>()
        verify(mockedNodeInfo).addAction(argumentCaptor.capture())

        // AND the a11y action is a click action
        assertEquals(
            AccessibilityNodeInfo.AccessibilityAction.ACTION_CLICK.id,
            argumentCaptor.value.id
        )
    }

    @Test
    fun performAccessibilityAction_actionClick_showsPrimaryBouncer() {
        // WHEN click action is performed
        val mockedNodeInfo = mock(AccessibilityNodeInfo::class.java)
        underTest.performAccessibilityAction(
            hostView,
            AccessibilityNodeInfo.AccessibilityAction.ACTION_CLICK.id,
            null
        )

        // THEN primary bouncer shows
        verify(keyguardViewManager).showPrimaryBouncer(anyBoolean())
    }
}
+0 −4
Original line number Diff line number Diff line
@@ -179,7 +179,6 @@ public class UdfpsController implements DozeReceiver, Dumpable {
    @NonNull private final PowerInteractor mPowerInteractor;
    @NonNull private final CoroutineScope mScope;
    @NonNull private final InputManager mInputManager;
    @NonNull private final UdfpsKeyguardAccessibilityDelegate mUdfpsKeyguardAccessibilityDelegate;
    @NonNull private final SelectedUserInteractor mSelectedUserInteractor;
    private final boolean mIgnoreRefreshRate;
    private final KeyguardTransitionInteractor mKeyguardTransitionInteractor;
@@ -292,7 +291,6 @@ public class UdfpsController implements DozeReceiver, Dumpable {
                            mActivityTransitionAnimator,
                        mPrimaryBouncerInteractor,
                        mAlternateBouncerInteractor,
                        mUdfpsKeyguardAccessibilityDelegate,
                        mKeyguardTransitionInteractor,
                        mSelectedUserInteractor,
                        mDeviceEntryUdfpsTouchOverlayViewModel,
@@ -691,7 +689,6 @@ public class UdfpsController implements DozeReceiver, Dumpable {
            @NonNull AlternateBouncerInteractor alternateBouncerInteractor,
            @NonNull InputManager inputManager,
            @NonNull DeviceEntryFaceAuthInteractor deviceEntryFaceAuthInteractor,
            @NonNull UdfpsKeyguardAccessibilityDelegate udfpsKeyguardAccessibilityDelegate,
            @NonNull SelectedUserInteractor selectedUserInteractor,
            @NonNull KeyguardTransitionInteractor keyguardTransitionInteractor,
            Lazy<DeviceEntryUdfpsTouchOverlayViewModel> deviceEntryUdfpsTouchOverlayViewModel,
@@ -742,7 +739,6 @@ public class UdfpsController implements DozeReceiver, Dumpable {
        mPowerInteractor = powerInteractor;
        mScope = scope;
        mInputManager = inputManager;
        mUdfpsKeyguardAccessibilityDelegate = udfpsKeyguardAccessibilityDelegate;
        mSelectedUserInteractor = selectedUserInteractor;
        mKeyguardTransitionInteractor = keyguardTransitionInteractor;

+0 −1
Original line number Diff line number Diff line
@@ -107,7 +107,6 @@ constructor(
    private val primaryBouncerInteractor: PrimaryBouncerInteractor,
    private val alternateBouncerInteractor: AlternateBouncerInteractor,
    private val isDebuggable: Boolean = Build.IS_DEBUGGABLE,
    private val udfpsKeyguardAccessibilityDelegate: UdfpsKeyguardAccessibilityDelegate,
    private val transitionInteractor: KeyguardTransitionInteractor,
    private val selectedUserInteractor: SelectedUserInteractor,
    private val deviceEntryUdfpsTouchOverlayViewModel: Lazy<DeviceEntryUdfpsTouchOverlayViewModel>,
+0 −54
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.systemui.biometrics

import android.content.res.Resources
import android.os.Bundle
import android.view.View
import android.view.accessibility.AccessibilityNodeInfo
import com.android.systemui.res.R
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager
import javax.inject.Inject

@SysUISingleton
class UdfpsKeyguardAccessibilityDelegate
@Inject
constructor(
    @Main private val resources: Resources,
    private val keyguardViewManager: StatusBarKeyguardViewManager,
) : View.AccessibilityDelegate() {
    override fun onInitializeAccessibilityNodeInfo(host: View, info: AccessibilityNodeInfo) {
        super.onInitializeAccessibilityNodeInfo(host, info)
        val clickAction =
            AccessibilityNodeInfo.AccessibilityAction(
                AccessibilityNodeInfo.AccessibilityAction.ACTION_CLICK.id,
                resources.getString(R.string.accessibility_bouncer)
            )
        info.addAction(clickAction)
    }

    override fun performAccessibilityAction(host: View, action: Int, args: Bundle?): Boolean {
        // when an a11y service is enabled, double tapping on the fingerprint sensor should
        // show the primary bouncer
        return if (action == AccessibilityNodeInfo.AccessibilityAction.ACTION_CLICK.id) {
            keyguardViewManager.showPrimaryBouncer(/* scrimmed */ true)
            true
        } else super.performAccessibilityAction(host, action, args)
    }
}
Loading