diff options
| author | 2024-04-12 16:43:31 +0000 | |
|---|---|---|
| committer | 2024-04-12 16:43:31 +0000 | |
| commit | 1ec8d1bf7ca6152000d341d15a8cea519bc6fa97 (patch) | |
| tree | d3a426610fde134bbecb523c93037352fe49d063 | |
| parent | c96af15bc16bd179e8a290ffa207ce6739c28f12 (diff) | |
| parent | 394a2b429ec10b5fa1fc35b848e337655a9f3653 (diff) | |
Merge "Log BOUNCER_PASSWORD_SUCCESS and BOUNCER_PASSWORD_FAILURE in compose bouncer." into main
5 files changed, 104 insertions, 0 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/bouncer/domain/interactor/BouncerInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/bouncer/domain/interactor/BouncerInteractorTest.kt index b0d03b15d310..cbdb71bf9040 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/bouncer/domain/interactor/BouncerInteractorTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/bouncer/domain/interactor/BouncerInteractorTest.kt @@ -18,6 +18,7 @@ package com.android.systemui.bouncer.domain.interactor import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest +import com.android.internal.logging.uiEventLoggerFake import com.android.systemui.SysuiTestCase import com.android.systemui.authentication.data.repository.FakeAuthenticationRepository import com.android.systemui.authentication.data.repository.fakeAuthenticationRepository @@ -25,6 +26,7 @@ import com.android.systemui.authentication.domain.interactor.AuthenticationResul import com.android.systemui.authentication.domain.interactor.authenticationInteractor import com.android.systemui.authentication.shared.model.AuthenticationMethodModel import com.android.systemui.authentication.shared.model.AuthenticationPatternCoordinate +import com.android.systemui.bouncer.shared.logging.BouncerUiEvent import com.android.systemui.coroutines.collectLastValue import com.android.systemui.coroutines.collectValues import com.android.systemui.deviceentry.domain.interactor.deviceEntryFaceAuthInteractor @@ -53,6 +55,7 @@ class BouncerInteractorTest : SysuiTestCase() { private val kosmos = testKosmos().apply { fakeSceneContainerFlags.enabled = true } private val testScope = kosmos.testScope private val authenticationInteractor = kosmos.authenticationInteractor + private val uiEventLoggerFake = kosmos.uiEventLoggerFake private lateinit var underTest: BouncerInteractor @@ -83,6 +86,7 @@ class BouncerInteractorTest : SysuiTestCase() { // Thus, when auth method is sim, we expect to skip here. assertThat(underTest.authenticate(FakeAuthenticationRepository.DEFAULT_PIN)) .isEqualTo(AuthenticationResult.SKIPPED) + assertThat(uiEventLoggerFake.numLogs()).isEqualTo(0) } @Test @@ -104,6 +108,8 @@ class BouncerInteractorTest : SysuiTestCase() { // Wrong 6-digit pin assertThat(underTest.authenticate(listOf(1, 2, 3, 5, 5, 6), tryAutoConfirm = true)) .isEqualTo(AuthenticationResult.FAILED) + assertThat(uiEventLoggerFake[0].eventId) + .isEqualTo(BouncerUiEvent.BOUNCER_PASSWORD_FAILURE.id) // Correct input. assertThat( @@ -113,6 +119,9 @@ class BouncerInteractorTest : SysuiTestCase() { ) ) .isEqualTo(AuthenticationResult.SUCCEEDED) + assertThat(uiEventLoggerFake[1].eventId) + .isEqualTo(BouncerUiEvent.BOUNCER_PASSWORD_SUCCESS.id) + assertThat(uiEventLoggerFake.numLogs()).isEqualTo(2) } @Test @@ -148,6 +157,8 @@ class BouncerInteractorTest : SysuiTestCase() { // Wrong input. assertThat(underTest.authenticate("alohamora".toList())) .isEqualTo(AuthenticationResult.FAILED) + assertThat(uiEventLoggerFake[0].eventId) + .isEqualTo(BouncerUiEvent.BOUNCER_PASSWORD_FAILURE.id) // Too short input. assertThat( @@ -165,6 +176,9 @@ class BouncerInteractorTest : SysuiTestCase() { // Correct input. assertThat(underTest.authenticate("password".toList())) .isEqualTo(AuthenticationResult.SUCCEEDED) + assertThat(uiEventLoggerFake[1].eventId) + .isEqualTo(BouncerUiEvent.BOUNCER_PASSWORD_SUCCESS.id) + assertThat(uiEventLoggerFake.numLogs()).isEqualTo(2) } @Test @@ -187,6 +201,8 @@ class BouncerInteractorTest : SysuiTestCase() { assertThat(wrongPattern.size) .isAtLeast(kosmos.fakeAuthenticationRepository.minPatternLength) assertThat(underTest.authenticate(wrongPattern)).isEqualTo(AuthenticationResult.FAILED) + assertThat(uiEventLoggerFake[0].eventId) + .isEqualTo(BouncerUiEvent.BOUNCER_PASSWORD_FAILURE.id) // Too short input. val tooShortPattern = @@ -200,6 +216,9 @@ class BouncerInteractorTest : SysuiTestCase() { // Correct input. assertThat(underTest.authenticate(FakeAuthenticationRepository.PATTERN)) .isEqualTo(AuthenticationResult.SUCCEEDED) + assertThat(uiEventLoggerFake[1].eventId) + .isEqualTo(BouncerUiEvent.BOUNCER_PASSWORD_SUCCESS.id) + assertThat(uiEventLoggerFake.numLogs()).isEqualTo(2) } @Test diff --git a/packages/SystemUI/src/com/android/systemui/bouncer/domain/interactor/BouncerInteractor.kt b/packages/SystemUI/src/com/android/systemui/bouncer/domain/interactor/BouncerInteractor.kt index 02a40d93ab65..dd71bc782c1c 100644 --- a/packages/SystemUI/src/com/android/systemui/bouncer/domain/interactor/BouncerInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/bouncer/domain/interactor/BouncerInteractor.kt @@ -16,16 +16,23 @@ package com.android.systemui.bouncer.domain.interactor +import android.app.StatusBarManager.SESSION_KEYGUARD import com.android.compose.animation.scene.SceneKey +import com.android.internal.logging.UiEventLogger import com.android.systemui.authentication.domain.interactor.AuthenticationInteractor import com.android.systemui.authentication.domain.interactor.AuthenticationResult +import com.android.systemui.authentication.shared.model.AuthenticationMethodModel.Password +import com.android.systemui.authentication.shared.model.AuthenticationMethodModel.Pattern +import com.android.systemui.authentication.shared.model.AuthenticationMethodModel.Pin import com.android.systemui.authentication.shared.model.AuthenticationMethodModel.Sim import com.android.systemui.bouncer.data.repository.BouncerRepository +import com.android.systemui.bouncer.shared.logging.BouncerUiEvent import com.android.systemui.classifier.FalsingClassifier import com.android.systemui.classifier.domain.interactor.FalsingInteractor import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.qualifiers.Application import com.android.systemui.deviceentry.domain.interactor.DeviceEntryFaceAuthInteractor +import com.android.systemui.log.SessionTracker import com.android.systemui.power.domain.interactor.PowerInteractor import com.android.systemui.scene.domain.interactor.SceneInteractor import com.android.systemui.scene.shared.model.Scenes @@ -50,6 +57,8 @@ constructor( private val deviceEntryFaceAuthInteractor: DeviceEntryFaceAuthInteractor, private val falsingInteractor: FalsingInteractor, private val powerInteractor: PowerInteractor, + private val uiEventLogger: UiEventLogger, + private val sessionTracker: SessionTracker, sceneInteractor: SceneInteractor, ) { private val _onIncorrectBouncerInput = MutableSharedFlow<Unit>() @@ -162,6 +171,18 @@ constructor( ) { _onIncorrectBouncerInput.emit(Unit) } + + if (authenticationInteractor.getAuthenticationMethod() in setOf(Pin, Password, Pattern)) { + if (authResult == AuthenticationResult.SUCCEEDED) { + uiEventLogger.log(BouncerUiEvent.BOUNCER_PASSWORD_SUCCESS) + } else if (authResult == AuthenticationResult.FAILED) { + uiEventLogger.log( + BouncerUiEvent.BOUNCER_PASSWORD_FAILURE, + sessionTracker.getSessionId(SESSION_KEYGUARD) + ) + } + } + return authResult } diff --git a/packages/SystemUI/src/com/android/systemui/bouncer/shared/logging/BouncerUiEvent.kt b/packages/SystemUI/src/com/android/systemui/bouncer/shared/logging/BouncerUiEvent.kt new file mode 100644 index 000000000000..3be54992f918 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/bouncer/shared/logging/BouncerUiEvent.kt @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2024 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.bouncer.shared.logging + +import com.android.internal.logging.UiEvent +import com.android.internal.logging.UiEventLogger + +/** + * Legacy bouncer UI events {@link com.android.keyguard.KeyguardSecurityContainer.BouncerUiEvent}. + * Only contains that used by metrics. + */ +enum class BouncerUiEvent(private val _id: Int) : UiEventLogger.UiEventEnum { + @UiEvent(doc = "Bouncer is dismissed using extended security access.") + BOUNCER_DISMISS_EXTENDED_ACCESS(413), + + // PASSWORD here includes password, pattern, and pin. + @UiEvent(doc = "Bouncer is successfully unlocked using password.") + BOUNCER_PASSWORD_SUCCESS(418), + @UiEvent(doc = "An attempt to unlock bouncer using password has failed.") + BOUNCER_PASSWORD_FAILURE(419); + + override fun getId() = _id +} diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/bouncer/domain/interactor/BouncerInteractorKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/bouncer/domain/interactor/BouncerInteractorKosmos.kt index 9ce9ff2faf21..4a02f6ddbebd 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/bouncer/domain/interactor/BouncerInteractorKosmos.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/bouncer/domain/interactor/BouncerInteractorKosmos.kt @@ -16,6 +16,7 @@ package com.android.systemui.bouncer.domain.interactor +import com.android.internal.logging.uiEventLogger import com.android.systemui.authentication.domain.interactor.authenticationInteractor import com.android.systemui.bouncer.data.repository.bouncerRepository import com.android.systemui.classifier.domain.interactor.falsingInteractor @@ -23,6 +24,7 @@ import com.android.systemui.deviceentry.domain.interactor.deviceEntryFaceAuthInt import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.Kosmos.Fixture import com.android.systemui.kosmos.testScope +import com.android.systemui.log.sessionTracker import com.android.systemui.power.domain.interactor.powerInteractor import com.android.systemui.scene.domain.interactor.sceneInteractor @@ -34,6 +36,8 @@ val Kosmos.bouncerInteractor by Fixture { deviceEntryFaceAuthInteractor = deviceEntryFaceAuthInteractor, falsingInteractor = falsingInteractor, powerInteractor = powerInteractor, + uiEventLogger = uiEventLogger, + sessionTracker = sessionTracker, sceneInteractor = sceneInteractor, ) } diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/log/SessionTrackerKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/log/SessionTrackerKosmos.kt new file mode 100644 index 000000000000..eac91497dd06 --- /dev/null +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/log/SessionTrackerKosmos.kt @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2024 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.log + +import com.android.systemui.kosmos.Kosmos +import com.android.systemui.util.mockito.mock + +val Kosmos.sessionTracker: SessionTracker by Kosmos.Fixture { sessionTrackerMock } +val Kosmos.sessionTrackerMock: SessionTracker by Kosmos.Fixture { mock() } |