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

Commit 6978db2e authored by Reema Bajwa's avatar Reema Bajwa
Browse files

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
parent 994a4187
Loading
Loading
Loading
Loading
+22 −21
Original line number Diff line number Diff line
@@ -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)
}
@@ -213,12 +212,12 @@ private fun runBiometricFlow(
        onBiometricFailureFallback: (BiometricFlowType) -> Unit,
        biometricFlowType: BiometricFlowType,
        onCancelFlowAndFinish: () -> Unit,
    getBiometricCancellationSignal: () -> CancellationSignal,
) {
        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? {
+8 −3
Original line number Diff line number Diff line
@@ -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)
    }
}
+7 −2
Original line number Diff line number Diff line
@@ -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. */
+5 −1
Original line number Diff line number Diff line
@@ -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
+5 −1
Original line number Diff line number Diff line
@@ -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