diff options
author | 2024-05-16 18:01:43 +0000 | |
---|---|---|
committer | 2024-05-30 08:15:06 +0000 | |
commit | 6978db2e5378ccc6218202d9209ade7c000998c8 (patch) | |
tree | 5032896d83ae373ca4832c623ef55c9a23bd2fb8 | |
parent | 994a418726242f72fdffee12d592c2b22499f948 (diff) |
Add logging for biometric single tap launch
Bug: 328299228
Test: Built locally & deployed
Flag: ACONFIG android.credentials.flags.credman_biometric_api_enabled NEXTFOOD
Change-Id: I994a288886a8a42653c03037b8d1d17441360868
5 files changed, 47 insertions, 28 deletions
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/common/BiometricHandler.kt b/packages/CredentialManager/src/com/android/credentialmanager/common/BiometricHandler.kt index b43b5f318cf1..373b3e8b068d 100644 --- a/packages/CredentialManager/src/com/android/credentialmanager/common/BiometricHandler.kt +++ b/packages/CredentialManager/src/com/android/credentialmanager/common/BiometricHandler.kt @@ -38,7 +38,6 @@ import com.android.credentialmanager.model.EntryInfo import com.android.credentialmanager.model.creation.CreateOptionInfo import com.android.credentialmanager.model.get.CredentialEntryInfo import com.android.credentialmanager.model.get.ProviderInfo -import java.lang.Exception /** * Aggregates common display information used for the Biometric Flow. @@ -121,11 +120,11 @@ fun runBiometricFlowForGet( getBiometricCancellationSignal: () -> CancellationSignal, getRequestDisplayInfo: RequestDisplayInfo? = null, getProviderInfoList: List<ProviderInfo>? = null, - getProviderDisplayInfo: ProviderDisplayInfo? = null, -) { + getProviderDisplayInfo: ProviderDisplayInfo? = null +): Boolean { if (getBiometricPromptState() != BiometricPromptState.INACTIVE) { // Screen is already up, do not re-launch - return + return false } onBiometricPromptStateChange(BiometricPromptState.PENDING) val biometricDisplayInfo = validateAndRetrieveBiometricGetDisplayInfo( @@ -137,7 +136,7 @@ fun runBiometricFlowForGet( if (biometricDisplayInfo == null) { onBiometricFailureFallback(BiometricFlowType.GET) - return + return false } val callback: BiometricPrompt.AuthenticationCallback = @@ -146,7 +145,7 @@ fun runBiometricFlowForGet( getBiometricPromptState) Log.d(TAG, "The BiometricPrompt API call begins for Get.") - runBiometricFlow(context, biometricDisplayInfo, callback, openMoreOptionsPage, + return runBiometricFlow(context, biometricDisplayInfo, callback, openMoreOptionsPage, onBiometricFailureFallback, BiometricFlowType.GET, onCancelFlowAndFinish, getBiometricCancellationSignal) } @@ -169,11 +168,11 @@ fun runBiometricFlowForCreate( getBiometricCancellationSignal: () -> CancellationSignal, createRequestDisplayInfo: com.android.credentialmanager.createflow .RequestDisplayInfo? = null, - createProviderInfo: EnabledProviderInfo? = null, -) { + createProviderInfo: EnabledProviderInfo? = null +): Boolean { if (getBiometricPromptState() != BiometricPromptState.INACTIVE) { // Screen is already up, do not re-launch - return + return false } onBiometricPromptStateChange(BiometricPromptState.PENDING) val biometricDisplayInfo = validateAndRetrieveBiometricCreateDisplayInfo( @@ -184,7 +183,7 @@ fun runBiometricFlowForCreate( if (biometricDisplayInfo == null) { onBiometricFailureFallback(BiometricFlowType.CREATE) - return + return false } val callback: BiometricPrompt.AuthenticationCallback = @@ -193,7 +192,7 @@ fun runBiometricFlowForCreate( getBiometricPromptState) Log.d(TAG, "The BiometricPrompt API call begins for Create.") - runBiometricFlow(context, biometricDisplayInfo, callback, openMoreOptionsPage, + return runBiometricFlow(context, biometricDisplayInfo, callback, openMoreOptionsPage, onBiometricFailureFallback, BiometricFlowType.CREATE, onCancelFlowAndFinish, getBiometricCancellationSignal) } @@ -206,19 +205,19 @@ fun runBiometricFlowForCreate( * only device credentials are requested. */ private fun runBiometricFlow( - context: Context, - biometricDisplayInfo: BiometricDisplayInfo, - callback: BiometricPrompt.AuthenticationCallback, - openMoreOptionsPage: () -> Unit, - onBiometricFailureFallback: (BiometricFlowType) -> Unit, - biometricFlowType: BiometricFlowType, - onCancelFlowAndFinish: () -> Unit, - getBiometricCancellationSignal: () -> CancellationSignal, -) { + context: Context, + biometricDisplayInfo: BiometricDisplayInfo, + callback: BiometricPrompt.AuthenticationCallback, + openMoreOptionsPage: () -> Unit, + onBiometricFailureFallback: (BiometricFlowType) -> Unit, + biometricFlowType: BiometricFlowType, + onCancelFlowAndFinish: () -> Unit, + getBiometricCancellationSignal: () -> CancellationSignal +): Boolean { try { if (!canCallBiometricPrompt(biometricDisplayInfo, context)) { onBiometricFailureFallback(biometricFlowType) - return + return false } val biometricPrompt = setupBiometricPrompt(context, biometricDisplayInfo, @@ -239,7 +238,9 @@ private fun runBiometricFlow( } catch (e: IllegalArgumentException) { Log.w(TAG, "Calling the biometric prompt API failed with: /n${e.localizedMessage}\n") onBiometricFailureFallback(biometricFlowType) + return false } + return true } private fun getCryptoOpId(biometricDisplayInfo: BiometricDisplayInfo): Int? { diff --git a/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateCredentialComponents.kt b/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateCredentialComponents.kt index 7d61f73a525b..4993a1fa0672 100644 --- a/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateCredentialComponents.kt +++ b/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateCredentialComponents.kt @@ -123,7 +123,8 @@ fun CreateCredentialScreen( onBiometricPromptStateChange = viewModel::onBiometricPromptStateChange, getBiometricCancellationSignal = - viewModel::getBiometricCancellationSignal + viewModel::getBiometricCancellationSignal, + onLog = { viewModel.logUiEvent(it) }, ) CreateScreenState.MORE_OPTIONS_SELECTION_ONLY -> MoreOptionsSelectionCard( requestDisplayInfo = createCredentialUiState.requestDisplayInfo, @@ -642,12 +643,13 @@ internal fun BiometricSelectionPage( getBiometricPromptState: () -> BiometricPromptState, onBiometricPromptStateChange: (BiometricPromptState) -> Unit, getBiometricCancellationSignal: () -> CancellationSignal, + onLog: @Composable (UiEventEnum) -> Unit ) { if (biometricEntry == null) { fallbackToOriginalFlow(BiometricFlowType.CREATE) return } - runBiometricFlowForCreate( + val biometricFlowCalled = runBiometricFlowForCreate( biometricEntry = biometricEntry, context = LocalContext.current, openMoreOptionsPage = onMoreOptionSelected, @@ -659,6 +661,9 @@ internal fun BiometricSelectionPage( createProviderInfo = enabledProviderInfo, onBiometricFailureFallback = fallbackToOriginalFlow, onIllegalStateAndFinish = onIllegalScreenStateAndFinish, - getBiometricCancellationSignal = getBiometricCancellationSignal, + getBiometricCancellationSignal = getBiometricCancellationSignal ) + if (biometricFlowCalled) { + onLog(CreateCredentialEvent.CREDMAN_CREATE_CRED_BIOMETRIC_FLOW_LAUNCHED) + } } diff --git a/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialComponents.kt b/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialComponents.kt index ba61b90fa4dc..517ad0069f85 100644 --- a/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialComponents.kt +++ b/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialComponents.kt @@ -166,7 +166,8 @@ fun GetCredentialScreen( onBiometricPromptStateChange = viewModel::onBiometricPromptStateChange, getBiometricCancellationSignal = - viewModel::getBiometricCancellationSignal + viewModel::getBiometricCancellationSignal, + onLog = { viewModel.logUiEvent(it) }, ) } else if (credmanBiometricApiEnabled() && getCredentialUiState.currentScreenState @@ -260,12 +261,13 @@ internal fun BiometricSelectionPage( getBiometricPromptState: () -> BiometricPromptState, onBiometricPromptStateChange: (BiometricPromptState) -> Unit, getBiometricCancellationSignal: () -> CancellationSignal, + onLog: @Composable (UiEventEnum) -> Unit, ) { if (biometricEntry == null) { fallbackToOriginalFlow(BiometricFlowType.GET) return } - runBiometricFlowForGet( + val biometricFlowCalled = runBiometricFlowForGet( biometricEntry = biometricEntry, context = LocalContext.current, openMoreOptionsPage = onMoreOptionSelected, @@ -280,6 +282,9 @@ internal fun BiometricSelectionPage( onBiometricFailureFallback = fallbackToOriginalFlow, getBiometricCancellationSignal = getBiometricCancellationSignal ) + if (biometricFlowCalled) { + onLog(GetCredentialEvent.CREDMAN_GET_CRED_BIOMETRIC_FLOW_LAUNCHED) + } } /** Draws the primary credential selection page, used in Android U. */ diff --git a/packages/CredentialManager/src/com/android/credentialmanager/logging/CreateCredentialEvent.kt b/packages/CredentialManager/src/com/android/credentialmanager/logging/CreateCredentialEvent.kt index daa42be020ce..39f2fcee6a0a 100644 --- a/packages/CredentialManager/src/com/android/credentialmanager/logging/CreateCredentialEvent.kt +++ b/packages/CredentialManager/src/com/android/credentialmanager/logging/CreateCredentialEvent.kt @@ -17,6 +17,7 @@ package com.android.credentialmanager.logging import com.android.internal.logging.UiEvent import com.android.internal.logging.UiEventLogger +import com.android.internal.logging.UiEventLogger.UiEventEnum.RESERVE_NEW_UI_EVENT_ID enum class CreateCredentialEvent(private val id: Int) : UiEventLogger.UiEventEnum { @@ -52,7 +53,10 @@ enum class CreateCredentialEvent(private val id: Int) : UiEventLogger.UiEventEnu CREDMAN_CREATE_CRED_EXTERNAL_ONLY_SELECTION(1327), @UiEvent(doc = "The more about passkeys intro card is visible on screen.") - CREDMAN_CREATE_CRED_MORE_ABOUT_PASSKEYS_INTRO(1328); + CREDMAN_CREATE_CRED_MORE_ABOUT_PASSKEYS_INTRO(1328), + + @UiEvent(doc = "The single tap biometric flow is launched.") + CREDMAN_CREATE_CRED_BIOMETRIC_FLOW_LAUNCHED(RESERVE_NEW_UI_EVENT_ID); override fun getId(): Int { return this.id diff --git a/packages/CredentialManager/src/com/android/credentialmanager/logging/GetCredentialEvent.kt b/packages/CredentialManager/src/com/android/credentialmanager/logging/GetCredentialEvent.kt index 8de8895e8ffc..89fd72cdc8cc 100644 --- a/packages/CredentialManager/src/com/android/credentialmanager/logging/GetCredentialEvent.kt +++ b/packages/CredentialManager/src/com/android/credentialmanager/logging/GetCredentialEvent.kt @@ -17,6 +17,7 @@ package com.android.credentialmanager.logging import com.android.internal.logging.UiEvent import com.android.internal.logging.UiEventLogger +import com.android.internal.logging.UiEventLogger.UiEventEnum.RESERVE_NEW_UI_EVENT_ID enum class GetCredentialEvent(private val id: Int) : UiEventLogger.UiEventEnum { @@ -54,7 +55,10 @@ enum class GetCredentialEvent(private val id: Int) : UiEventLogger.UiEventEnum { CREDMAN_GET_CRED_PRIMARY_SELECTION_CARD(1341), @UiEvent(doc = "The all sign in option card is visible on screen.") - CREDMAN_GET_CRED_ALL_SIGN_IN_OPTION_CARD(1342); + CREDMAN_GET_CRED_ALL_SIGN_IN_OPTION_CARD(1342), + + @UiEvent(doc = "The single tap biometric flow is launched.") + CREDMAN_GET_CRED_BIOMETRIC_FLOW_LAUNCHED(RESERVE_NEW_UI_EVENT_ID); override fun getId(): Int { return this.id |