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

Commit 47a93786 authored by Hao Dong's avatar Hao Dong
Browse files

Replace Utils.CredentialType with PromptKind.

Test: just a replacement, manually check test app working well
Flag: NA
Bug: 330908557
Change-Id: I569824412b11416acd8ec1b0f52da31c5c9fa0b5
parent 7ede1a66
Loading
Loading
Loading
Loading
+6 −17
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@
package com.android.systemui.biometrics

import android.Manifest
import android.annotation.IntDef
import android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC
import android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC
import android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_COMPLEX
@@ -39,14 +38,9 @@ import android.view.WindowMetrics
import android.view.accessibility.AccessibilityEvent
import android.view.accessibility.AccessibilityManager
import com.android.internal.widget.LockPatternUtils
import java.lang.annotation.Retention
import java.lang.annotation.RetentionPolicy
import com.android.systemui.biometrics.shared.model.PromptKind

object Utils {
    const val CREDENTIAL_PIN = 1
    const val CREDENTIAL_PATTERN = 2
    const val CREDENTIAL_PASSWORD = 3

    /** Base set of layout flags for fingerprint overlay widgets. */
    const val FINGERPRINT_OVERLAY_LAYOUT_PARAM_FLAGS =
        (WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN or
@@ -91,17 +85,16 @@ object Utils {
        (promptInfo.authenticators and Authenticators.BIOMETRIC_WEAK) != 0

    @JvmStatic
    @CredentialType
    fun getCredentialType(utils: LockPatternUtils, userId: Int): Int =
    fun getCredentialType(utils: LockPatternUtils, userId: Int): PromptKind =
        when (utils.getKeyguardStoredPasswordQuality(userId)) {
            PASSWORD_QUALITY_SOMETHING -> CREDENTIAL_PATTERN
            PASSWORD_QUALITY_SOMETHING -> PromptKind.Pattern
            PASSWORD_QUALITY_NUMERIC,
            PASSWORD_QUALITY_NUMERIC_COMPLEX -> CREDENTIAL_PIN
            PASSWORD_QUALITY_NUMERIC_COMPLEX -> PromptKind.Pin
            PASSWORD_QUALITY_ALPHABETIC,
            PASSWORD_QUALITY_ALPHANUMERIC,
            PASSWORD_QUALITY_COMPLEX,
            PASSWORD_QUALITY_MANAGED -> CREDENTIAL_PASSWORD
            else -> CREDENTIAL_PASSWORD
            PASSWORD_QUALITY_MANAGED -> PromptKind.Password
            else -> PromptKind.Password
        }

    @JvmStatic
@@ -129,8 +122,4 @@ object Utils {
        return windowMetrics?.windowInsets?.getInsets(WindowInsets.Type.navigationBars())
            ?: Insets.NONE
    }

    @Retention(RetentionPolicy.SOURCE)
    @IntDef(CREDENTIAL_PIN, CREDENTIAL_PATTERN, CREDENTIAL_PASSWORD)
    annotation class CredentialType
}
+9 −5
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 * 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.
@@ -16,16 +16,20 @@

package com.android.systemui.biometrics.shared.model

import com.android.systemui.biometrics.Utils

// TODO(b/251476085): this should eventually replace Utils.CredentialType
/** Credential options for biometric prompt. Shadows [Utils.CredentialType]. */
sealed interface PromptKind {
    object None : PromptKind

    data class Biometric(
        val activeModalities: BiometricModalities = BiometricModalities(),
        // TODO(b/330908557): Use this value to decide whether to show two pane layout, instead of
        // simply depending on rotations.
        val showTwoPane: Boolean = false
    ) : PromptKind

    object Pin : PromptKind
    object Pattern : PromptKind
    object Password : PromptKind

    fun isBiometric() = this is Biometric
    fun isCredential() = (this is Pin) or (this is Pattern) or (this is Password)
}
+12 −17
Original line number Diff line number Diff line
@@ -76,6 +76,7 @@ import com.android.systemui.biometrics.AuthController.ScaleFactorProvider;
import com.android.systemui.biometrics.domain.interactor.PromptCredentialInteractor;
import com.android.systemui.biometrics.domain.interactor.PromptSelectorInteractor;
import com.android.systemui.biometrics.shared.model.BiometricModalities;
import com.android.systemui.biometrics.shared.model.PromptKind;
import com.android.systemui.biometrics.ui.BiometricPromptLayout;
import com.android.systemui.biometrics.ui.CredentialView;
import com.android.systemui.biometrics.ui.binder.BiometricViewBinder;
@@ -500,24 +501,18 @@ public class AuthContainerView extends LinearLayout
    private void addCredentialView(boolean animatePanel, boolean animateContents) {
        final LayoutInflater factory = LayoutInflater.from(mContext);

        @Utils.CredentialType final int credentialType = Utils.getCredentialType(
                mLockPatternUtils, mEffectiveUserId);

        switch (credentialType) {
            case Utils.CREDENTIAL_PATTERN:
                mCredentialView = factory.inflate(
                        R.layout.auth_credential_pattern_view, null, false);
                break;
            case Utils.CREDENTIAL_PIN:
                mCredentialView = factory.inflate(R.layout.auth_credential_pin_view, null, false);
                break;
            case Utils.CREDENTIAL_PASSWORD:
                mCredentialView = factory.inflate(
                        R.layout.auth_credential_password_view, null, false);
                break;
            default:
        PromptKind credentialType = Utils.getCredentialType(mLockPatternUtils, mEffectiveUserId);
        final int layoutResourceId;
        if (credentialType instanceof PromptKind.Pattern) {
            layoutResourceId = R.layout.auth_credential_pattern_view;
        } else if (credentialType instanceof PromptKind.Pin) {
            layoutResourceId = R.layout.auth_credential_pin_view;
        } else if (credentialType instanceof PromptKind.Password) {
            layoutResourceId = R.layout.auth_credential_password_view;
        } else {
            throw new IllegalStateException("Unknown credential type: " + credentialType);
        }
        mCredentialView = factory.inflate(layoutResourceId, null, false);

        // The background is used for detecting taps / cancelling authentication. Since the
        // credential view is full-screen and should not be canceled from background taps,
+3 −3
Original line number Diff line number Diff line
@@ -125,7 +125,7 @@ constructor(
    private val _userId: MutableStateFlow<Int?> = MutableStateFlow(null)
    override val userId = _userId.asStateFlow()

    private val _kind: MutableStateFlow<PromptKind> = MutableStateFlow(PromptKind.Biometric())
    private val _kind: MutableStateFlow<PromptKind> = MutableStateFlow(PromptKind.None)
    override val kind = _kind.asStateFlow()

    private val _opPackageName: MutableStateFlow<String?> = MutableStateFlow(null)
@@ -149,7 +149,7 @@ constructor(
    override val showBpWithoutIconForCredential = _showBpWithoutIconForCredential.asStateFlow()

    override fun setShouldShowBpWithoutIconForCredential(promptInfo: PromptInfo) {
        val hasCredentialViewShown = kind.value !is PromptKind.Biometric
        val hasCredentialViewShown = kind.value.isCredential()
        val showBpForCredential =
            Flags.customBiometricPrompt() &&
                constraintBp() &&
@@ -178,7 +178,7 @@ constructor(
        _promptInfo.value = null
        _userId.value = null
        _challenge.value = null
        _kind.value = PromptKind.Biometric()
        _kind.value = PromptKind.None
        _opPackageName.value = null
    }

+0 −40
Original line number Diff line number Diff line
@@ -16,10 +16,8 @@

package com.android.systemui.biometrics.domain.interactor

import android.hardware.biometrics.PromptInfo
import com.android.internal.widget.LockPatternView
import com.android.internal.widget.LockscreenCredential
import com.android.systemui.biometrics.Utils
import com.android.systemui.biometrics.data.repository.PromptRepository
import com.android.systemui.biometrics.domain.model.BiometricOperationInfo
import com.android.systemui.biometrics.domain.model.BiometricPromptRequest
@@ -42,12 +40,6 @@ import kotlinx.coroutines.withContext
 * Business logic for BiometricPrompt's CredentialViews, which primarily includes checking a users
 * PIN, pattern, or password credential instead of a biometric.
 *
 * This is used to cache the calling app's options that were given to the underlying authenticate
 * APIs and should be set before any UI is shown to the user.
 *
 * There can be at most one request active at a given time. Use [resetPrompt] when no request is
 * active to clear the cache.
 *
 * Views that use any biometric should use [PromptSelectorInteractor] instead.
 */
class PromptCredentialInteractor
@@ -137,28 +129,6 @@ constructor(
    private val _verificationError = MutableStateFlow<CredentialStatus.Fail?>(null)
    val verificationError: Flow<CredentialStatus.Fail?> = _verificationError.asStateFlow()

    /** Update the current request to use credential-based authentication instead of biometrics. */
    fun useCredentialsForAuthentication(
        promptInfo: PromptInfo,
        @Utils.CredentialType kind: Int,
        userId: Int,
        challenge: Long,
        opPackageName: String,
    ) {
        biometricPromptRepository.setPrompt(
            promptInfo,
            userId,
            challenge,
            kind.asBiometricPromptCredential(),
            opPackageName,
        )
    }

    /** Unset the current authentication request. */
    fun resetPrompt() {
        biometricPromptRepository.unsetPrompt()
    }

    /**
     * Check a credential and return the attestation token (HAT) if successful.
     *
@@ -231,13 +201,3 @@ constructor(
        _verificationError.value = null
    }
}

// TODO(b/251476085): remove along with Utils.CredentialType
/** Convert a [Utils.CredentialType] to the corresponding [PromptKind]. */
private fun @receiver:Utils.CredentialType Int.asBiometricPromptCredential(): PromptKind =
    when (this) {
        Utils.CREDENTIAL_PIN -> PromptKind.Pin
        Utils.CREDENTIAL_PASSWORD -> PromptKind.Password
        Utils.CREDENTIAL_PATTERN -> PromptKind.Pattern
        else -> PromptKind.Biometric()
    }
Loading