diff options
| author | 2023-09-13 17:43:22 +0000 | |
|---|---|---|
| committer | 2023-09-13 17:43:22 +0000 | |
| commit | d9c84d54e761ac950d7e22e589a7aa02c5ae5ba8 (patch) | |
| tree | 4ee55dca1f71f2d8924dc27e8a258aba3dedd076 /packages/SystemUI/tests | |
| parent | c79159b4dace114dbac0051c3edacadf7080a901 (diff) | |
| parent | 55e60b12a3e3fceb1490b32baca3d4072d23e274 (diff) | |
Merge "Remove released flag BIOMETRIC_BP_STRONG." into main
Diffstat (limited to 'packages/SystemUI/tests')
8 files changed, 32 insertions, 640 deletions
diff --git a/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthBiometricFingerprintAndFaceViewTest.kt b/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthBiometricFingerprintAndFaceViewTest.kt deleted file mode 100644 index a93af7dd7450..000000000000 --- a/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthBiometricFingerprintAndFaceViewTest.kt +++ /dev/null @@ -1,164 +0,0 @@ -/* - * 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.systemui.biometrics - -import android.hardware.biometrics.BiometricAuthenticator.TYPE_FACE -import android.hardware.biometrics.BiometricAuthenticator.TYPE_FINGERPRINT -import android.hardware.biometrics.BiometricConstants -import android.hardware.face.FaceManager -import android.testing.TestableLooper -import android.testing.TestableLooper.RunWithLooper -import android.view.View -import androidx.test.ext.junit.runners.AndroidJUnit4 -import androidx.test.filters.SmallTest -import com.android.systemui.R -import com.android.systemui.RoboPilotTest -import com.android.systemui.SysuiTestCase -import com.google.common.truth.Truth.assertThat -import org.junit.After -import org.junit.Before -import org.junit.Rule -import org.junit.Test -import org.junit.runner.RunWith -import org.mockito.Mock -import org.mockito.Mockito.never -import org.mockito.Mockito.verify -import org.mockito.Mockito.times -import org.mockito.junit.MockitoJUnit - - -@RunWith(AndroidJUnit4::class) -@RunWithLooper(setAsMainLooper = true) -@SmallTest -@RoboPilotTest -class AuthBiometricFingerprintAndFaceViewTest : SysuiTestCase() { - - @JvmField - @Rule - var mockitoRule = MockitoJUnit.rule() - - @Mock - private lateinit var callback: AuthBiometricView.Callback - - @Mock - private lateinit var panelController: AuthPanelController - - private lateinit var biometricView: AuthBiometricFingerprintAndFaceView - - @Before - fun setup() { - biometricView = R.layout.auth_biometric_fingerprint_and_face_view - .asTestAuthBiometricView(mContext, callback, panelController) - waitForIdleSync() - } - - @After - fun tearDown() { - biometricView.destroyDialog() - } - - @Test - fun fingerprintSuccessDoesNotRequireExplicitConfirmation() { - biometricView.onDialogAnimatedIn(fingerprintWasStarted = true) - biometricView.onAuthenticationSucceeded(TYPE_FINGERPRINT) - TestableLooper.get(this).moveTimeForward(1000) - waitForIdleSync() - - assertThat(biometricView.isAuthenticated).isTrue() - verify(callback).onAction(AuthBiometricView.Callback.ACTION_AUTHENTICATED) - } - - @Test - fun faceSuccessRequiresExplicitConfirmation() { - biometricView.onDialogAnimatedIn(fingerprintWasStarted = true) - biometricView.onAuthenticationSucceeded(TYPE_FACE) - waitForIdleSync() - - assertThat(biometricView.isAuthenticated).isFalse() - assertThat(biometricView.isAuthenticating).isFalse() - assertThat(biometricView.mConfirmButton.visibility).isEqualTo(View.GONE) - verify(callback, never()).onAction(AuthBiometricView.Callback.ACTION_AUTHENTICATED) - - // icon acts as confirm button - biometricView.mIconView.performClick() - TestableLooper.get(this).moveTimeForward(1000) - waitForIdleSync() - - assertThat(biometricView.isAuthenticated).isTrue() - verify(callback).onAction(AuthBiometricView.Callback.ACTION_AUTHENTICATED_AND_CONFIRMED) - } - - @Test - fun ignoresFaceErrors_faceIsNotClass3_notLockoutError() { - biometricView.onDialogAnimatedIn(fingerprintWasStarted = true) - biometricView.onError(TYPE_FACE, "not a face") - waitForIdleSync() - - assertThat(biometricView.isAuthenticating).isTrue() - verify(callback, never()).onAction(AuthBiometricView.Callback.ACTION_ERROR) - - biometricView.onError(TYPE_FINGERPRINT, "that's a nope") - TestableLooper.get(this).moveTimeForward(1000) - waitForIdleSync() - - verify(callback).onAction(AuthBiometricView.Callback.ACTION_ERROR) - } - - @Test - fun doNotIgnoresFaceErrors_faceIsClass3_notLockoutError() { - biometricView.isFaceClass3 = true - biometricView.onDialogAnimatedIn(fingerprintWasStarted = true) - biometricView.onError(TYPE_FACE, "not a face") - waitForIdleSync() - - assertThat(biometricView.isAuthenticating).isTrue() - verify(callback, never()).onAction(AuthBiometricView.Callback.ACTION_ERROR) - - biometricView.onError(TYPE_FINGERPRINT, "that's a nope") - TestableLooper.get(this).moveTimeForward(1000) - waitForIdleSync() - - verify(callback).onAction(AuthBiometricView.Callback.ACTION_ERROR) - } - - @Test - fun doNotIgnoresFaceErrors_faceIsClass3_lockoutError() { - biometricView.isFaceClass3 = true - biometricView.onDialogAnimatedIn(fingerprintWasStarted = true) - biometricView.onError( - TYPE_FACE, - FaceManager.getErrorString( - biometricView.context, - BiometricConstants.BIOMETRIC_ERROR_LOCKOUT_PERMANENT, - 0 /*vendorCode */ - ) - ) - waitForIdleSync() - - assertThat(biometricView.isAuthenticating).isTrue() - verify(callback).onAction(AuthBiometricView.Callback.ACTION_ERROR) - - biometricView.onError(TYPE_FINGERPRINT, "that's a nope") - TestableLooper.get(this).moveTimeForward(1000) - waitForIdleSync() - - verify(callback, times(2)).onAction(AuthBiometricView.Callback.ACTION_ERROR) - } - - - override fun waitForIdleSync() = TestableLooper.get(this).processAllMessages() -} diff --git a/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthBiometricFingerprintIconControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthBiometricFingerprintIconControllerTest.kt index cac618b21dc7..52bf350bfcc8 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthBiometricFingerprintIconControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthBiometricFingerprintIconControllerTest.kt @@ -27,6 +27,7 @@ import androidx.test.filters.SmallTest import com.airbnb.lottie.LottieAnimationView import com.android.systemui.R import com.android.systemui.SysuiTestCase +import com.android.systemui.biometrics.ui.binder.Spaghetti.BiometricState import com.google.common.truth.Truth.assertThat import org.junit.Before import org.junit.Rule @@ -63,7 +64,7 @@ class AuthBiometricFingerprintIconControllerTest : SysuiTestCase() { setupFingerprintSensorProperties(FingerprintSensorProperties.TYPE_POWER_BUTTON) controller = AuthBiometricFingerprintIconController(context, iconView, iconViewOverlay) - assertThat(controller.getIconContentDescription(AuthBiometricView.STATE_AUTHENTICATING)) + assertThat(controller.getIconContentDescription(BiometricState.STATE_AUTHENTICATING)) .isEqualTo( context.resources.getString( R.string.security_settings_sfps_enroll_find_sensor_message @@ -76,7 +77,7 @@ class AuthBiometricFingerprintIconControllerTest : SysuiTestCase() { setupFingerprintSensorProperties(FingerprintSensorProperties.TYPE_UDFPS_OPTICAL) controller = AuthBiometricFingerprintIconController(context, iconView, iconViewOverlay) - assertThat(controller.getIconContentDescription(AuthBiometricView.STATE_AUTHENTICATING)) + assertThat(controller.getIconContentDescription(BiometricState.STATE_AUTHENTICATING)) .isEqualTo(context.resources.getString(R.string.fingerprint_dialog_touch_sensor)) } diff --git a/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthBiometricFingerprintViewTest.kt b/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthBiometricFingerprintViewTest.kt deleted file mode 100644 index 8e5d96b0a2c6..000000000000 --- a/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthBiometricFingerprintViewTest.kt +++ /dev/null @@ -1,283 +0,0 @@ -/* - * 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.systemui.biometrics - -import android.hardware.biometrics.BiometricAuthenticator -import android.os.Bundle -import androidx.test.ext.junit.runners.AndroidJUnit4 -import android.testing.TestableLooper -import android.testing.TestableLooper.RunWithLooper -import android.view.View -import androidx.test.filters.SmallTest -import com.android.systemui.R -import com.android.systemui.RoboPilotTest -import com.android.systemui.SysuiTestCase -import com.google.common.truth.Truth.assertThat -import org.junit.After -import org.junit.Before -import org.junit.Rule -import org.junit.Test -import org.junit.runner.RunWith -import org.mockito.ArgumentMatchers -import org.mockito.ArgumentMatchers.eq -import org.mockito.Mock -import org.mockito.Mockito.never -import org.mockito.Mockito.verify -import org.mockito.junit.MockitoJUnit - -@RunWith(AndroidJUnit4::class) -@RunWithLooper(setAsMainLooper = true) -@SmallTest -@RoboPilotTest -class AuthBiometricFingerprintViewTest : SysuiTestCase() { - - @JvmField - @Rule - val mockitoRule = MockitoJUnit.rule() - - @Mock - private lateinit var callback: AuthBiometricView.Callback - - @Mock - private lateinit var panelController: AuthPanelController - - private lateinit var biometricView: AuthBiometricView - - private fun createView(allowDeviceCredential: Boolean = false): AuthBiometricFingerprintView { - val view: AuthBiometricFingerprintView = - R.layout.auth_biometric_fingerprint_view.asTestAuthBiometricView( - mContext, callback, panelController, allowDeviceCredential = allowDeviceCredential - ) - waitForIdleSync() - return view - } - - @Before - fun setup() { - biometricView = createView() - } - - @After - fun tearDown() { - biometricView.destroyDialog() - } - - @Test - fun testOnAuthenticationSucceeded_noConfirmationRequired_sendsActionAuthenticated() { - biometricView.onAuthenticationSucceeded(BiometricAuthenticator.TYPE_FINGERPRINT) - TestableLooper.get(this).moveTimeForward(1000) - waitForIdleSync() - - assertThat(biometricView.isAuthenticated).isTrue() - verify(callback).onAction(AuthBiometricView.Callback.ACTION_AUTHENTICATED) - } - - @Test - fun testOnAuthenticationSucceeded_confirmationRequired_updatesDialogContents() { - biometricView.setRequireConfirmation(true) - biometricView.onAuthenticationSucceeded(BiometricAuthenticator.TYPE_FINGERPRINT) - TestableLooper.get(this).moveTimeForward(1000) - waitForIdleSync() - - // TODO: this should be tested in the subclasses - if (biometricView.supportsRequireConfirmation()) { - verify(callback, never()).onAction(ArgumentMatchers.anyInt()) - assertThat(biometricView.mNegativeButton.visibility).isEqualTo(View.GONE) - assertThat(biometricView.mCancelButton.visibility).isEqualTo(View.VISIBLE) - assertThat(biometricView.mCancelButton.isEnabled).isTrue() - assertThat(biometricView.mConfirmButton.isEnabled).isTrue() - assertThat(biometricView.mIndicatorView.text) - .isEqualTo(mContext.getText(R.string.biometric_dialog_tap_confirm)) - assertThat(biometricView.mIndicatorView.visibility).isEqualTo(View.VISIBLE) - } else { - assertThat(biometricView.isAuthenticated).isTrue() - verify(callback).onAction(eq(AuthBiometricView.Callback.ACTION_AUTHENTICATED)) - } - } - - @Test - fun testPositiveButton_sendsActionAuthenticated() { - biometricView.mConfirmButton.performClick() - TestableLooper.get(this).moveTimeForward(1000) - waitForIdleSync() - - verify(callback).onAction(AuthBiometricView.Callback.ACTION_AUTHENTICATED) - assertThat(biometricView.isAuthenticated).isTrue() - } - - @Test - fun testNegativeButton_beforeAuthentication_sendsActionButtonNegative() { - biometricView.onDialogAnimatedIn(fingerprintWasStarted = true) - biometricView.mNegativeButton.performClick() - TestableLooper.get(this).moveTimeForward(1000) - waitForIdleSync() - - verify(callback).onAction(AuthBiometricView.Callback.ACTION_BUTTON_NEGATIVE) - } - - @Test - fun testCancelButton_whenPendingConfirmation_sendsActionUserCanceled() { - biometricView.setRequireConfirmation(true) - biometricView.onAuthenticationSucceeded(BiometricAuthenticator.TYPE_FINGERPRINT) - - assertThat(biometricView.mNegativeButton.visibility).isEqualTo(View.GONE) - biometricView.mCancelButton.performClick() - TestableLooper.get(this).moveTimeForward(1000) - waitForIdleSync() - - verify(callback).onAction(AuthBiometricView.Callback.ACTION_USER_CANCELED) - } - - @Test - fun testTryAgainButton_sendsActionTryAgain() { - biometricView.mTryAgainButton.performClick() - TestableLooper.get(this).moveTimeForward(1000) - waitForIdleSync() - - verify(callback).onAction(AuthBiometricView.Callback.ACTION_BUTTON_TRY_AGAIN) - assertThat(biometricView.mTryAgainButton.visibility).isEqualTo(View.GONE) - assertThat(biometricView.isAuthenticating).isTrue() - } - - @Test - fun testOnErrorSendsActionError() { - biometricView.onError(BiometricAuthenticator.TYPE_FACE, "testError") - TestableLooper.get(this).moveTimeForward(1000) - waitForIdleSync() - - verify(callback).onAction(eq(AuthBiometricView.Callback.ACTION_ERROR)) - } - - @Test - fun testOnErrorShowsMessage() { - // prevent error state from instantly returning to authenticating in the test - biometricView.mAnimationDurationHideDialog = 10_000 - - val message = "another error" - biometricView.onError(BiometricAuthenticator.TYPE_FACE, message) - TestableLooper.get(this).moveTimeForward(1000) - waitForIdleSync() - - assertThat(biometricView.isAuthenticating).isFalse() - assertThat(biometricView.isAuthenticated).isFalse() - assertThat(biometricView.mIndicatorView.visibility).isEqualTo(View.VISIBLE) - assertThat(biometricView.mIndicatorView.text).isEqualTo(message) - } - - @Test - fun testBackgroundClicked_sendsActionUserCanceled() { - val view = View(mContext) - biometricView.setBackgroundView(view) - view.performClick() - - verify(callback).onAction(eq(AuthBiometricView.Callback.ACTION_USER_CANCELED)) - } - - @Test - fun testBackgroundClicked_afterAuthenticated_neverSendsUserCanceled() { - val view = View(mContext) - biometricView.setBackgroundView(view) - biometricView.onAuthenticationSucceeded(BiometricAuthenticator.TYPE_FINGERPRINT) - waitForIdleSync() - view.performClick() - - verify(callback, never()) - .onAction(eq(AuthBiometricView.Callback.ACTION_USER_CANCELED)) - } - - @Test - fun testBackgroundClicked_whenSmallDialog_neverSendsUserCanceled() { - biometricView.mLayoutParams = AuthDialog.LayoutParams(0, 0) - biometricView.updateSize(AuthDialog.SIZE_SMALL) - val view = View(mContext) - biometricView.setBackgroundView(view) - view.performClick() - - verify(callback, never()).onAction(eq(AuthBiometricView.Callback.ACTION_USER_CANCELED)) - } - - @Test - fun testIgnoresUselessHelp() { - biometricView.mAnimationDurationHideDialog = 10_000 - biometricView.onDialogAnimatedIn(fingerprintWasStarted = true) - waitForIdleSync() - - assertThat(biometricView.isAuthenticating).isTrue() - - val helpText = biometricView.mIndicatorView.text - biometricView.onHelp(BiometricAuthenticator.TYPE_FINGERPRINT, "") - waitForIdleSync() - - // text should not change - assertThat(biometricView.mIndicatorView.text).isEqualTo(helpText) - verify(callback, never()).onAction(eq(AuthBiometricView.Callback.ACTION_ERROR)) - } - - @Test - fun testRestoresState() { - val requireConfirmation = true - biometricView.mAnimationDurationHideDialog = 10_000 - val failureMessage = "testFailureMessage" - biometricView.setRequireConfirmation(requireConfirmation) - biometricView.onAuthenticationFailed(BiometricAuthenticator.TYPE_FACE, failureMessage) - waitForIdleSync() - - val state = Bundle() - biometricView.onSaveState(state) - assertThat(biometricView.mTryAgainButton.visibility).isEqualTo(View.GONE) - assertThat(state.getInt(AuthDialog.KEY_BIOMETRIC_TRY_AGAIN_VISIBILITY)) - .isEqualTo(View.GONE) - assertThat(state.getInt(AuthDialog.KEY_BIOMETRIC_STATE)) - .isEqualTo(AuthBiometricView.STATE_ERROR) - assertThat(biometricView.mIndicatorView.visibility).isEqualTo(View.VISIBLE) - assertThat(state.getBoolean(AuthDialog.KEY_BIOMETRIC_INDICATOR_ERROR_SHOWING)).isTrue() - assertThat(biometricView.mIndicatorView.text).isEqualTo(failureMessage) - assertThat(state.getString(AuthDialog.KEY_BIOMETRIC_INDICATOR_STRING)) - .isEqualTo(failureMessage) - - // TODO: Test dialog size. Should move requireConfirmation to buildBiometricPromptBundle - - // Create new dialog and restore the previous state into it - biometricView.destroyDialog() - biometricView = createView() - biometricView.restoreState(state) - biometricView.mAnimationDurationHideDialog = 10_000 - biometricView.setRequireConfirmation(requireConfirmation) - waitForIdleSync() - - assertThat(biometricView.mTryAgainButton.visibility).isEqualTo(View.GONE) - assertThat(biometricView.mIndicatorView.visibility).isEqualTo(View.VISIBLE) - - // TODO: Test restored text. Currently cannot test this, since it gets restored only after - // dialog size is known. - } - - @Test - fun testCredentialButton_whenDeviceCredentialAllowed() { - biometricView.destroyDialog() - biometricView = createView(allowDeviceCredential = true) - - assertThat(biometricView.mUseCredentialButton.visibility).isEqualTo(View.VISIBLE) - assertThat(biometricView.mNegativeButton.visibility).isEqualTo(View.GONE) - - biometricView.mUseCredentialButton.performClick() - waitForIdleSync() - - verify(callback).onAction(AuthBiometricView.Callback.ACTION_USE_DEVICE_CREDENTIAL) - } - - override fun waitForIdleSync() = TestableLooper.get(this).processAllMessages() -} diff --git a/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthContainerViewTest.kt b/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthContainerViewTest.kt index d10b81c7b648..7775a05568e8 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthContainerViewTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthContainerViewTest.kt @@ -105,9 +105,6 @@ open class AuthContainerViewTest : SysuiTestCase() { @Mock lateinit var vibrator: VibratorHelper - // TODO(b/278622168): remove with flag - open val useNewBiometricPrompt = false - private val testScope = TestScope(StandardTestDispatcher()) private val fakeExecutor = FakeExecutor(FakeSystemClock()) private val biometricPromptRepository = FakePromptRepository() @@ -137,7 +134,6 @@ open class AuthContainerViewTest : SysuiTestCase() { @Before fun setup() { displayRepository = FakeDisplayRepository() - featureFlags.set(Flags.BIOMETRIC_BP_STRONG, useNewBiometricPrompt) featureFlags.set(Flags.ONE_WAY_HAPTICS_API_MIGRATION, false) displayStateInteractor = @@ -235,9 +231,7 @@ open class AuthContainerViewTest : SysuiTestCase() { @Test fun testActionCancel_panelInteractionDetectorDisable() { val container = initializeFingerprintContainer() - container.mBiometricCallback.onAction( - AuthBiometricView.Callback.ACTION_USER_CANCELED - ) + container.mBiometricCallback.onUserCanceled() waitForIdleSync() verify(panelInteractionDetector).disable() } @@ -246,9 +240,7 @@ open class AuthContainerViewTest : SysuiTestCase() { @Test fun testActionAuthenticated_sendsDismissedAuthenticated() { val container = initializeFingerprintContainer() - container.mBiometricCallback.onAction( - AuthBiometricView.Callback.ACTION_AUTHENTICATED - ) + container.mBiometricCallback.onAuthenticated() waitForIdleSync() verify(callback).onDismissed( @@ -262,9 +254,7 @@ open class AuthContainerViewTest : SysuiTestCase() { @Test fun testActionUserCanceled_sendsDismissedUserCanceled() { val container = initializeFingerprintContainer() - container.mBiometricCallback.onAction( - AuthBiometricView.Callback.ACTION_USER_CANCELED - ) + container.mBiometricCallback.onUserCanceled() waitForIdleSync() verify(callback).onSystemEvent( @@ -282,9 +272,7 @@ open class AuthContainerViewTest : SysuiTestCase() { @Test fun testActionButtonNegative_sendsDismissedButtonNegative() { val container = initializeFingerprintContainer() - container.mBiometricCallback.onAction( - AuthBiometricView.Callback.ACTION_BUTTON_NEGATIVE - ) + container.mBiometricCallback.onButtonNegative() waitForIdleSync() verify(callback).onDismissed( @@ -300,9 +288,7 @@ open class AuthContainerViewTest : SysuiTestCase() { val container = initializeFingerprintContainer( authenticators = BiometricManager.Authenticators.BIOMETRIC_WEAK ) - container.mBiometricCallback.onAction( - AuthBiometricView.Callback.ACTION_BUTTON_TRY_AGAIN - ) + container.mBiometricCallback.onButtonTryAgain() waitForIdleSync() verify(callback).onTryAgainPressed(authContainer?.requestId ?: 0L) @@ -311,9 +297,7 @@ open class AuthContainerViewTest : SysuiTestCase() { @Test fun testActionError_sendsDismissedError() { val container = initializeFingerprintContainer() - container.mBiometricCallback.onAction( - AuthBiometricView.Callback.ACTION_ERROR - ) + container.mBiometricCallback.onError() waitForIdleSync() verify(callback).onDismissed( @@ -331,9 +315,7 @@ open class AuthContainerViewTest : SysuiTestCase() { authenticators = BiometricManager.Authenticators.BIOMETRIC_WEAK or BiometricManager.Authenticators.DEVICE_CREDENTIAL ) - container.mBiometricCallback.onAction( - AuthBiometricView.Callback.ACTION_USE_DEVICE_CREDENTIAL - ) + container.mBiometricCallback.onUseDeviceCredential() waitForIdleSync() verify(callback).onDeviceCredentialPressed(authContainer?.requestId ?: 0L) diff --git a/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthContainerViewTest2.kt b/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthContainerViewTest2.kt deleted file mode 100644 index b56d05537215..000000000000 --- a/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthContainerViewTest2.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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 androidx.test.ext.junit.runners.AndroidJUnit4 -import androidx.test.filters.SmallTest -import org.junit.runner.RunWith - -// TODO(b/278622168): remove with flag -@RunWith(AndroidJUnit4::class) -@TestableLooper.RunWithLooper(setAsMainLooper = true) -@SmallTest -class AuthContainerViewTest2 : AuthContainerViewTest() { - override val useNewBiometricPrompt = true -} diff --git a/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthControllerTest.java index f3ff669917ee..d0b3833a24a1 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthControllerTest.java @@ -17,7 +17,6 @@ package com.android.systemui.biometrics; import static android.hardware.biometrics.BiometricAuthenticator.TYPE_FINGERPRINT; -import static android.hardware.biometrics.BiometricManager.Authenticators; import static com.google.common.truth.Truth.assertThat; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertFalse; @@ -29,7 +28,6 @@ import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -45,7 +43,6 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; -import android.content.res.Configuration; import android.content.res.Resources; import android.graphics.Point; import android.hardware.biometrics.BiometricAuthenticator; @@ -66,7 +63,6 @@ import android.hardware.fingerprint.FingerprintManager; import android.hardware.fingerprint.FingerprintSensorProperties; import android.hardware.fingerprint.FingerprintSensorPropertiesInternal; import android.hardware.fingerprint.IFingerprintAuthenticatorsRegisteredCallback; -import android.os.Bundle; import android.os.Handler; import android.os.RemoteException; import android.os.UserManager; @@ -91,7 +87,6 @@ import com.android.systemui.biometrics.domain.interactor.PromptSelectorInteracto import com.android.systemui.biometrics.ui.viewmodel.CredentialViewModel; import com.android.systemui.biometrics.ui.viewmodel.PromptViewModel; import com.android.systemui.flags.FakeFeatureFlags; -import com.android.systemui.flags.Flags; import com.android.systemui.keyguard.WakefulnessLifecycle; import com.android.systemui.statusbar.CommandQueue; import com.android.systemui.statusbar.VibratorHelper; @@ -203,10 +198,6 @@ public class AuthControllerTest extends SysuiTestCase { @Before public void setup() throws RemoteException { - // TODO(b/278622168): remove with flag - // AuthController simply passes this through to AuthContainerView (does not impact test) - mFeatureFlags.set(Flags.BIOMETRIC_BP_STRONG, false); - mContextSpy = spy(mContext); mExecution = new FakeExecution(); mTestableLooper = TestableLooper.get(this); @@ -459,7 +450,7 @@ public class AuthControllerTest extends SysuiTestCase { @Test public void testShowInvoked_whenSystemRequested() { showDialog(new int[] {1} /* sensorIds */, false /* credentialAllowed */); - verify(mDialog1).show(any(), any()); + verify(mDialog1).show(any()); } @Test @@ -660,7 +651,7 @@ public class AuthControllerTest extends SysuiTestCase { // 2) Client cancels authentication showDialog(new int[0] /* sensorIds */, true /* credentialAllowed */); - verify(mDialog1).show(any(), any()); + verify(mDialog1).show(any()); final byte[] credentialAttestation = generateRandomHAT(); @@ -676,7 +667,7 @@ public class AuthControllerTest extends SysuiTestCase { @Test public void testShowNewDialog_beforeOldDialogDismissed_SkipsAnimations() { showDialog(new int[] {1} /* sensorIds */, false /* credentialAllowed */); - verify(mDialog1).show(any(), any()); + verify(mDialog1).show(any()); showDialog(new int[] {1} /* sensorIds */, false /* credentialAllowed */); @@ -684,59 +675,7 @@ public class AuthControllerTest extends SysuiTestCase { verify(mDialog1).dismissWithoutCallback(eq(false) /* animate */); // Second dialog should be shown without animation - verify(mDialog2).show(any(), any()); - } - - @Test - public void testConfigurationPersists_whenOnConfigurationChanged() { - showDialog(new int[] {1} /* sensorIds */, false /* credentialAllowed */); - verify(mDialog1).show(any(), any()); - - // Return that the UI is in "showing" state - doAnswer(invocation -> { - Object[] args = invocation.getArguments(); - Bundle savedState = (Bundle) args[0]; - savedState.putBoolean(AuthDialog.KEY_CONTAINER_GOING_AWAY, false); - return null; // onSaveState returns void - }).when(mDialog1).onSaveState(any()); - - mAuthController.onConfigurationChanged(new Configuration()); - - ArgumentCaptor<Bundle> captor = ArgumentCaptor.forClass(Bundle.class); - verify(mDialog1).onSaveState(captor.capture()); - - // Old dialog doesn't animate - verify(mDialog1).dismissWithoutCallback(eq(false /* animate */)); - - // Saved state is restored into new dialog - ArgumentCaptor<Bundle> captor2 = ArgumentCaptor.forClass(Bundle.class); - verify(mDialog2).show(any(), captor2.capture()); - - // TODO: This should check all values we want to save/restore - assertEquals(captor.getValue(), captor2.getValue()); - } - - @Test - public void testConfigurationPersists_whenBiometricFallbackToCredential() { - showDialog(new int[] {1} /* sensorIds */, true /* credentialAllowed */); - verify(mDialog1).show(any(), any()); - - // Pretend that the UI is now showing device credential UI. - doAnswer(invocation -> { - Object[] args = invocation.getArguments(); - Bundle savedState = (Bundle) args[0]; - savedState.putBoolean(AuthDialog.KEY_CONTAINER_GOING_AWAY, false); - savedState.putBoolean(AuthDialog.KEY_CREDENTIAL_SHOWING, true); - return null; // onSaveState returns void - }).when(mDialog1).onSaveState(any()); - - mAuthController.onConfigurationChanged(new Configuration()); - - // Check that the new dialog was initialized to the credential UI. - ArgumentCaptor<Bundle> captor = ArgumentCaptor.forClass(Bundle.class); - verify(mDialog2).show(any(), captor.capture()); - assertEquals(Authenticators.DEVICE_CREDENTIAL, - mAuthController.mLastBiometricPromptInfo.getAuthenticators()); + verify(mDialog2).show(any()); } @Test @@ -1006,7 +945,7 @@ public class AuthControllerTest extends SysuiTestCase { REQUEST_ID); assertNull(mAuthController.mCurrentDialog); - verify(mDialog1, never()).show(any(), any()); + verify(mDialog1, never()).show(any()); } private void showDialog(int[] sensorIds, boolean credentialAllowed) { diff --git a/packages/SystemUI/tests/src/com/android/systemui/biometrics/BiometricTestExtensions.kt b/packages/SystemUI/tests/src/com/android/systemui/biometrics/BiometricTestExtensions.kt index 94244cdf271d..9f24a9f553a1 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/biometrics/BiometricTestExtensions.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/biometrics/BiometricTestExtensions.kt @@ -16,8 +16,6 @@ package com.android.systemui.biometrics -import android.annotation.IdRes -import android.content.Context import android.hardware.biometrics.BiometricManager.Authenticators import android.hardware.biometrics.ComponentInfoInternal import android.hardware.biometrics.PromptInfo @@ -27,57 +25,6 @@ import android.hardware.face.FaceSensorProperties import android.hardware.face.FaceSensorPropertiesInternal import android.hardware.fingerprint.FingerprintSensorProperties import android.hardware.fingerprint.FingerprintSensorPropertiesInternal -import android.os.Bundle -import android.testing.ViewUtils -import android.view.LayoutInflater - -/** - * Inflate the given BiometricPrompt layout and initialize it with test parameters. - * - * This attaches the view so be sure to call [destroyDialog] at the end of the test. - */ -@IdRes -internal fun <T : AuthBiometricView> Int.asTestAuthBiometricView( - context: Context, - callback: AuthBiometricView.Callback, - panelController: AuthPanelController, - allowDeviceCredential: Boolean = false, - savedState: Bundle? = null, - hideDelay: Int = 0 -): T { - val view = LayoutInflater.from(context).inflate(this, null, false) as T - view.mAnimationDurationLong = 0 - view.mAnimationDurationShort = 0 - view.mAnimationDurationHideDialog = hideDelay - view.setPromptInfo(buildPromptInfo(allowDeviceCredential)) - view.setCallback(callback) - view.restoreState(savedState) - view.setPanelController(panelController) - - ViewUtils.attachView(view) - - return view -} - -private fun buildPromptInfo(allowDeviceCredential: Boolean): PromptInfo { - val promptInfo = PromptInfo() - promptInfo.title = "Title" - var authenticators = Authenticators.BIOMETRIC_WEAK - if (allowDeviceCredential) { - authenticators = authenticators or Authenticators.DEVICE_CREDENTIAL - } else { - promptInfo.negativeButtonText = "Negative" - } - promptInfo.authenticators = authenticators - return promptInfo -} - -/** Detach the view, if needed. */ -internal fun AuthBiometricView?.destroyDialog() { - if (this != null && isAttachedToWindow) { - ViewUtils.detachView(this) - } -} /** Create [FingerprintSensorPropertiesInternal] for a test. */ internal fun fingerprintSensorPropertiesInternal( diff --git a/packages/SystemUI/tests/src/com/android/systemui/biometrics/ui/viewmodel/PromptViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/biometrics/ui/viewmodel/PromptViewModelTest.kt index 3848aad695ab..5834e31cb591 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/biometrics/ui/viewmodel/PromptViewModelTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/biometrics/ui/viewmodel/PromptViewModelTest.kt @@ -24,7 +24,6 @@ import android.view.MotionEvent import androidx.test.filters.SmallTest import com.android.internal.widget.LockPatternUtils import com.android.systemui.SysuiTestCase -import com.android.systemui.biometrics.AuthBiometricView import com.android.systemui.biometrics.data.repository.FakeFingerprintPropertyRepository import com.android.systemui.biometrics.data.repository.FakePromptRepository import com.android.systemui.biometrics.data.repository.FakeRearDisplayStateRepository @@ -37,6 +36,7 @@ import com.android.systemui.biometrics.faceSensorPropertiesInternal import com.android.systemui.biometrics.fingerprintSensorPropertiesInternal import com.android.systemui.biometrics.shared.model.BiometricModalities import com.android.systemui.biometrics.shared.model.BiometricModality +import com.android.systemui.biometrics.ui.binder.Spaghetti.BiometricState import com.android.systemui.coroutines.collectLastValue import com.android.systemui.coroutines.collectValues import com.android.systemui.display.data.repository.FakeDisplayRepository @@ -132,7 +132,7 @@ internal class PromptViewModelTest(private val testCase: TestCase) : SysuiTestCa } assertThat(message).isEqualTo(PromptMessage.Empty) assertThat(size).isEqualTo(expectedSize) - assertThat(legacyState).isEqualTo(AuthBiometricView.STATE_IDLE) + assertThat(legacyState).isEqualTo(BiometricState.STATE_IDLE) val startMessage = "here we go" viewModel.showAuthenticating(startMessage, isRetry = false) @@ -142,7 +142,7 @@ internal class PromptViewModelTest(private val testCase: TestCase) : SysuiTestCa assertThat(authenticated?.isNotAuthenticated).isTrue() assertThat(size).isEqualTo(expectedSize) assertButtonsVisible(negative = expectedSize != PromptSize.SMALL) - assertThat(legacyState).isEqualTo(AuthBiometricView.STATE_AUTHENTICATING) + assertThat(legacyState).isEqualTo(BiometricState.STATE_AUTHENTICATING) } @Test @@ -220,7 +220,7 @@ internal class PromptViewModelTest(private val testCase: TestCase) : SysuiTestCa assertThat(authenticating).isTrue() assertThat(authenticated?.isNotAuthenticated).isTrue() assertThat(size).isEqualTo(if (authWithSmallPrompt) PromptSize.SMALL else PromptSize.MEDIUM) - assertThat(legacyState).isEqualTo(AuthBiometricView.STATE_AUTHENTICATING) + assertThat(legacyState).isEqualTo(BiometricState.STATE_AUTHENTICATING) assertButtonsVisible(negative = !authWithSmallPrompt) val delay = 1000L @@ -240,9 +240,9 @@ internal class PromptViewModelTest(private val testCase: TestCase) : SysuiTestCa assertThat(legacyState) .isEqualTo( if (expectConfirmation) { - AuthBiometricView.STATE_PENDING_CONFIRMATION + BiometricState.STATE_PENDING_CONFIRMATION } else { - AuthBiometricView.STATE_AUTHENTICATED + BiometricState.STATE_AUTHENTICATED } ) assertButtonsVisible( @@ -311,7 +311,7 @@ internal class PromptViewModelTest(private val testCase: TestCase) : SysuiTestCa assertThat(size).isEqualTo(PromptSize.MEDIUM) assertThat(message).isEqualTo(PromptMessage.Error(errorMessage)) assertThat(messageVisible).isTrue() - assertThat(legacyState).isEqualTo(AuthBiometricView.STATE_ERROR) + assertThat(legacyState).isEqualTo(BiometricState.STATE_ERROR) // temporary error should disappear after a delay errorJob.join() @@ -326,11 +326,11 @@ internal class PromptViewModelTest(private val testCase: TestCase) : SysuiTestCa assertThat(legacyState) .isEqualTo( if (restart) { - AuthBiometricView.STATE_AUTHENTICATING + BiometricState.STATE_AUTHENTICATING } else if (clearIconError) { - AuthBiometricView.STATE_IDLE + BiometricState.STATE_IDLE } else { - AuthBiometricView.STATE_HELP + BiometricState.STATE_HELP } ) @@ -505,7 +505,7 @@ internal class PromptViewModelTest(private val testCase: TestCase) : SysuiTestCa assertThat(authenticating).isFalse() assertThat(authenticated?.isAuthenticated).isTrue() - assertThat(legacyState).isEqualTo(AuthBiometricView.STATE_AUTHENTICATED) + assertThat(legacyState).isEqualTo(BiometricState.STATE_AUTHENTICATED) assertThat(canTryAgain).isFalse() } @@ -531,7 +531,7 @@ internal class PromptViewModelTest(private val testCase: TestCase) : SysuiTestCa assertThat(authenticated?.isAuthenticated).isTrue() if (testCase.isFaceOnly && expectConfirmation) { - assertThat(legacyState).isEqualTo(AuthBiometricView.STATE_PENDING_CONFIRMATION) + assertThat(legacyState).isEqualTo(BiometricState.STATE_PENDING_CONFIRMATION) assertThat(size).isEqualTo(PromptSize.MEDIUM) assertButtonsVisible( @@ -543,7 +543,7 @@ internal class PromptViewModelTest(private val testCase: TestCase) : SysuiTestCa assertThat(message).isEqualTo(PromptMessage.Empty) assertButtonsVisible() } else { - assertThat(legacyState).isEqualTo(AuthBiometricView.STATE_AUTHENTICATED) + assertThat(legacyState).isEqualTo(BiometricState.STATE_AUTHENTICATED) } } @@ -580,7 +580,7 @@ internal class PromptViewModelTest(private val testCase: TestCase) : SysuiTestCa assertThat(authenticating).isFalse() assertThat(authenticated?.isAuthenticated).isTrue() - assertThat(legacyState).isEqualTo(AuthBiometricView.STATE_AUTHENTICATED) + assertThat(legacyState).isEqualTo(BiometricState.STATE_AUTHENTICATED) assertThat(canTryAgain).isFalse() } @@ -614,7 +614,7 @@ internal class PromptViewModelTest(private val testCase: TestCase) : SysuiTestCa viewModel.showHelp(helpMessage) assertThat(size).isEqualTo(PromptSize.MEDIUM) - assertThat(legacyState).isEqualTo(AuthBiometricView.STATE_HELP) + assertThat(legacyState).isEqualTo(BiometricState.STATE_HELP) assertThat(message).isEqualTo(PromptMessage.Help(helpMessage)) assertThat(messageVisible).isTrue() @@ -642,9 +642,9 @@ internal class PromptViewModelTest(private val testCase: TestCase) : SysuiTestCa assertThat(size).isEqualTo(PromptSize.MEDIUM) if (confirmationRequired == true) { - assertThat(legacyState).isEqualTo(AuthBiometricView.STATE_PENDING_CONFIRMATION) + assertThat(legacyState).isEqualTo(BiometricState.STATE_PENDING_CONFIRMATION) } else { - assertThat(legacyState).isEqualTo(AuthBiometricView.STATE_AUTHENTICATED) + assertThat(legacyState).isEqualTo(BiometricState.STATE_AUTHENTICATED) } assertThat(message).isEqualTo(PromptMessage.Help(helpMessage)) assertThat(messageVisible).isTrue() |