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

Commit 0cc43597 authored by Arpan Kaphle's avatar Arpan Kaphle
Browse files

Biometric Credman Layered UI Bugfix

When the biometric diaglog was canceled, the UI underneath would remain
awake. This was the first attempted fix, where we listened to a
cancellation error code, and then upon receiving it, given it ensures
the end of a flow, we utilize a viewModel lambda that ensures the
credman UI also ends.

This fix works in practice.

Bug: 331791049
Test: Built and Tested Visually
Change-Id: I076d19e2361ca1017aa57b32150d361eac0ccb97
parent 57636844
Loading
Loading
Loading
Loading
+13 −7
Original line number Diff line number Diff line
@@ -98,7 +98,8 @@ fun runBiometricFlow(
    context: Context,
    openMoreOptionsPage: () -> Unit,
    sendDataToProvider: (EntryInfo, BiometricPrompt.AuthenticationResult) -> Unit,
    onCancelFlowAndFinish: (String) -> Unit,
    onCancelFlowAndFinish: () -> Unit,
    onIllegalStateAndFinish: (String) -> Unit,
    getRequestDisplayInfo: RequestDisplayInfo? = null,
    getProviderInfoList: List<ProviderInfo>? = null,
    getProviderDisplayInfo: ProviderDisplayInfo? = null,
@@ -131,7 +132,7 @@ fun runBiometricFlow(

    val callback: BiometricPrompt.AuthenticationCallback =
        setupBiometricAuthenticationCallback(sendDataToProvider, biometricEntry,
            onCancelFlowAndFinish)
            onCancelFlowAndFinish, onIllegalStateAndFinish)

    val cancellationSignal = CancellationSignal()
    cancellationSignal.setOnCancelListener {
@@ -211,7 +212,8 @@ private fun removeDeviceCredential(requestAllowedAuthenticators: Int): Int {
private fun setupBiometricAuthenticationCallback(
    sendDataToProvider: (EntryInfo, BiometricPrompt.AuthenticationResult) -> Unit,
    selectedEntry: EntryInfo,
    onCancelFlowAndFinish: (String) -> Unit
    onCancelFlowAndFinish: () -> Unit,
    onIllegalStateAndFinish: (String) -> Unit,
): BiometricPrompt.AuthenticationCallback {
    val callback: BiometricPrompt.AuthenticationCallback =
        object : BiometricPrompt.AuthenticationCallback() {
@@ -224,14 +226,12 @@ private fun setupBiometricAuthenticationCallback(
                    if (authResult != null) {
                        sendDataToProvider(selectedEntry, authResult)
                    } else {
                        onCancelFlowAndFinish("The biometric flow succeeded but unexpectedly " +
                        onIllegalStateAndFinish("The biometric flow succeeded but unexpectedly " +
                                "returned a null value.")
                        // TODO(b/326243754) : Propagate to provider
                    }
                } catch (e: Exception) {
                    onCancelFlowAndFinish("The biometric flow succeeded but failed on handling " +
                    onIllegalStateAndFinish("The biometric flow succeeded but failed on handling " +
                            "the result. See: \n$e\n")
                    // TODO(b/326243754) : Propagate to provider
                }
            }

@@ -245,6 +245,12 @@ private fun setupBiometricAuthenticationCallback(
            override fun onAuthenticationError(errorCode: Int, errString: CharSequence?) {
                super.onAuthenticationError(errorCode, errString)
                Log.d(TAG, "Authentication error-ed out: $errorCode and $errString")
                if (errorCode == BiometricPrompt.BIOMETRIC_ERROR_USER_CANCELED) {
                    // Note that because the biometric prompt is imbued directly
                    // into the selector, parity applies to the selector's cancellation instead
                    // of the provider's biometric prompt cancellation.
                    onCancelFlowAndFinish()
                }
                // TODO(b/326243754) : Propagate to provider
            }

+5 −2
Original line number Diff line number Diff line
@@ -148,7 +148,8 @@ fun GetCredentialScreen(
                                // activeEntry will always be what represents the single tap flow
                                biometricEntry = getCredentialUiState.activeEntry,
                                onMoreOptionSelected = viewModel::getFlowOnMoreOptionSelected,
                                onCancelFlowAndFinish = viewModel::onIllegalUiState,
                                onCancelFlowAndFinish = viewModel::onUserCancel,
                                onIllegalStateAndFinish = viewModel::onIllegalUiState,
                                requestDisplayInfo = getCredentialUiState.requestDisplayInfo,
                                providerInfoList = getCredentialUiState.providerInfoList,
                                providerDisplayInfo = getCredentialUiState.providerDisplayInfo,
@@ -212,7 +213,8 @@ fun GetCredentialScreen(
@Composable
internal fun BiometricSelectionPage(
    biometricEntry: EntryInfo?,
    onCancelFlowAndFinish: (String) -> Unit,
    onCancelFlowAndFinish: () -> Unit,
    onIllegalStateAndFinish: (String) -> Unit,
    onMoreOptionSelected: () -> Unit,
    requestDisplayInfo: RequestDisplayInfo,
    providerInfoList: List<ProviderInfo>,
@@ -230,6 +232,7 @@ internal fun BiometricSelectionPage(
        openMoreOptionsPage = onMoreOptionSelected,
        sendDataToProvider = onBiometricEntrySelected,
        onCancelFlowAndFinish = onCancelFlowAndFinish,
        onIllegalStateAndFinish = onIllegalStateAndFinish,
        getRequestDisplayInfo = requestDisplayInfo,
        getProviderInfoList = providerInfoList,
        getProviderDisplayInfo = providerDisplayInfo,