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

Commit 6e6277ae authored by Chandru S's avatar Chandru S Committed by Automerger Merge Worker
Browse files

Merge "Add all the new revamped bouncer messages and the prompt reasons for...

Merge "Add all the new revamped bouncer messages and the prompt reasons for them." into udc-dev am: e159a60b

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/22863280



Change-Id: Ie1549e6fcd6631ef171e33b66d8153c779c50f13
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 66b9e871 e159a60b
Loading
Loading
Loading
Loading
+323 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2023 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.keyguard

import android.annotation.IntDef
import com.android.keyguard.KeyguardSecurityModel.SecurityMode
import com.android.keyguard.KeyguardSecurityView.PROMPT_REASON_AFTER_LOCKOUT
import com.android.keyguard.KeyguardSecurityView.PROMPT_REASON_DEFAULT
import com.android.keyguard.KeyguardSecurityView.PROMPT_REASON_DEVICE_ADMIN
import com.android.keyguard.KeyguardSecurityView.PROMPT_REASON_FACE_LOCKED_OUT
import com.android.keyguard.KeyguardSecurityView.PROMPT_REASON_FINGERPRINT_LOCKED_OUT
import com.android.keyguard.KeyguardSecurityView.PROMPT_REASON_INCORRECT_FACE_INPUT
import com.android.keyguard.KeyguardSecurityView.PROMPT_REASON_INCORRECT_FINGERPRINT_INPUT
import com.android.keyguard.KeyguardSecurityView.PROMPT_REASON_INCORRECT_PRIMARY_AUTH_INPUT
import com.android.keyguard.KeyguardSecurityView.PROMPT_REASON_NONE
import com.android.keyguard.KeyguardSecurityView.PROMPT_REASON_NON_STRONG_BIOMETRIC_TIMEOUT
import com.android.keyguard.KeyguardSecurityView.PROMPT_REASON_PREPARE_FOR_UPDATE
import com.android.keyguard.KeyguardSecurityView.PROMPT_REASON_PRIMARY_AUTH_LOCKED_OUT
import com.android.keyguard.KeyguardSecurityView.PROMPT_REASON_RESTART
import com.android.keyguard.KeyguardSecurityView.PROMPT_REASON_TIMEOUT
import com.android.keyguard.KeyguardSecurityView.PROMPT_REASON_TRUSTAGENT_EXPIRED
import com.android.keyguard.KeyguardSecurityView.PROMPT_REASON_USER_REQUEST
import com.android.systemui.R.string.bouncer_face_not_recognized
import com.android.systemui.R.string.keyguard_enter_password
import com.android.systemui.R.string.keyguard_enter_pattern
import com.android.systemui.R.string.keyguard_enter_pin
import com.android.systemui.R.string.kg_bio_too_many_attempts_password
import com.android.systemui.R.string.kg_bio_too_many_attempts_pattern
import com.android.systemui.R.string.kg_bio_too_many_attempts_pin
import com.android.systemui.R.string.kg_bio_try_again_or_password
import com.android.systemui.R.string.kg_bio_try_again_or_pattern
import com.android.systemui.R.string.kg_bio_try_again_or_pin
import com.android.systemui.R.string.kg_face_locked_out
import com.android.systemui.R.string.kg_fp_locked_out
import com.android.systemui.R.string.kg_fp_not_recognized
import com.android.systemui.R.string.kg_primary_auth_locked_out_password
import com.android.systemui.R.string.kg_primary_auth_locked_out_pattern
import com.android.systemui.R.string.kg_primary_auth_locked_out_pin
import com.android.systemui.R.string.kg_prompt_after_dpm_lock
import com.android.systemui.R.string.kg_prompt_after_user_lockdown_password
import com.android.systemui.R.string.kg_prompt_after_user_lockdown_pattern
import com.android.systemui.R.string.kg_prompt_after_user_lockdown_pin
import com.android.systemui.R.string.kg_prompt_auth_timeout
import com.android.systemui.R.string.kg_prompt_password_auth_timeout
import com.android.systemui.R.string.kg_prompt_pattern_auth_timeout
import com.android.systemui.R.string.kg_prompt_pin_auth_timeout
import com.android.systemui.R.string.kg_prompt_reason_restart_password
import com.android.systemui.R.string.kg_prompt_reason_restart_pattern
import com.android.systemui.R.string.kg_prompt_reason_restart_pin
import com.android.systemui.R.string.kg_prompt_unattended_update
import com.android.systemui.R.string.kg_too_many_failed_attempts_countdown
import com.android.systemui.R.string.kg_trust_agent_disabled
import com.android.systemui.R.string.kg_unlock_with_password_or_fp
import com.android.systemui.R.string.kg_unlock_with_pattern_or_fp
import com.android.systemui.R.string.kg_unlock_with_pin_or_fp
import com.android.systemui.R.string.kg_wrong_input_try_fp_suggestion
import com.android.systemui.R.string.kg_wrong_password_try_again
import com.android.systemui.R.string.kg_wrong_pattern_try_again
import com.android.systemui.R.string.kg_wrong_pin_try_again

typealias BouncerMessage = Pair<Int, Int>

fun emptyBouncerMessage(): BouncerMessage = Pair(0, 0)

@Retention(AnnotationRetention.SOURCE)
@IntDef(
    PROMPT_REASON_TIMEOUT,
    PROMPT_REASON_DEVICE_ADMIN,
    PROMPT_REASON_USER_REQUEST,
    PROMPT_REASON_AFTER_LOCKOUT,
    PROMPT_REASON_PREPARE_FOR_UPDATE,
    PROMPT_REASON_NON_STRONG_BIOMETRIC_TIMEOUT,
    PROMPT_REASON_TRUSTAGENT_EXPIRED,
    PROMPT_REASON_INCORRECT_PRIMARY_AUTH_INPUT,
    PROMPT_REASON_INCORRECT_FACE_INPUT,
    PROMPT_REASON_INCORRECT_FINGERPRINT_INPUT,
    PROMPT_REASON_FACE_LOCKED_OUT,
    PROMPT_REASON_FINGERPRINT_LOCKED_OUT,
    PROMPT_REASON_DEFAULT,
    PROMPT_REASON_NONE,
    PROMPT_REASON_RESTART,
    PROMPT_REASON_PRIMARY_AUTH_LOCKED_OUT,
)
annotation class BouncerPromptReason

/**
 * Helper method that provides the relevant bouncer message that should be shown for different
 * scenarios indicated by [reason]. [securityMode] & [fpAllowedInBouncer] parameters are used to
 * provide a more specific message.
 */
@JvmOverloads
fun getBouncerMessage(
    @BouncerPromptReason reason: Int,
    securityMode: SecurityMode,
    fpAllowedInBouncer: Boolean = false
): BouncerMessage {
    return when (reason) {
        PROMPT_REASON_RESTART -> authRequiredAfterReboot(securityMode)
        PROMPT_REASON_TIMEOUT -> authRequiredAfterPrimaryAuthTimeout(securityMode)
        PROMPT_REASON_DEVICE_ADMIN -> authRequiredAfterAdminLockdown(securityMode)
        PROMPT_REASON_USER_REQUEST -> authRequiredAfterUserLockdown(securityMode)
        PROMPT_REASON_AFTER_LOCKOUT -> biometricLockout(securityMode)
        PROMPT_REASON_PREPARE_FOR_UPDATE -> authRequiredForUnattendedUpdate(securityMode)
        PROMPT_REASON_FINGERPRINT_LOCKED_OUT -> fingerprintUnlockUnavailable(securityMode)
        PROMPT_REASON_FACE_LOCKED_OUT -> faceUnlockUnavailable(securityMode)
        PROMPT_REASON_INCORRECT_PRIMARY_AUTH_INPUT ->
            if (fpAllowedInBouncer) incorrectSecurityInputWithFingerprint(securityMode)
            else incorrectSecurityInput(securityMode)
        PROMPT_REASON_NON_STRONG_BIOMETRIC_TIMEOUT ->
            if (fpAllowedInBouncer) nonStrongAuthTimeoutWithFingerprintAllowed(securityMode)
            else nonStrongAuthTimeout(securityMode)
        PROMPT_REASON_TRUSTAGENT_EXPIRED ->
            if (fpAllowedInBouncer) trustAgentDisabledWithFingerprintAllowed(securityMode)
            else trustAgentDisabled(securityMode)
        PROMPT_REASON_INCORRECT_FACE_INPUT ->
            if (fpAllowedInBouncer) incorrectFaceInputWithFingerprintAllowed(securityMode)
            else incorrectFaceInput(securityMode)
        PROMPT_REASON_INCORRECT_FINGERPRINT_INPUT -> incorrectFingerprintInput(securityMode)
        PROMPT_REASON_DEFAULT ->
            if (fpAllowedInBouncer) defaultMessageWithFingerprint(securityMode)
            else defaultMessage(securityMode)
        PROMPT_REASON_PRIMARY_AUTH_LOCKED_OUT -> primaryAuthLockedOut(securityMode)
        else -> emptyBouncerMessage()
    }
}

fun defaultMessage(securityMode: SecurityMode): BouncerMessage {
    return when (securityMode) {
        SecurityMode.Pattern -> Pair(keyguard_enter_pattern, 0)
        SecurityMode.Password -> Pair(keyguard_enter_password, 0)
        SecurityMode.PIN -> Pair(keyguard_enter_pin, 0)
        else -> Pair(0, 0)
    }
}

fun defaultMessageWithFingerprint(securityMode: SecurityMode): BouncerMessage {
    return when (securityMode) {
        SecurityMode.Pattern -> Pair(kg_unlock_with_pattern_or_fp, 0)
        SecurityMode.Password -> Pair(kg_unlock_with_password_or_fp, 0)
        SecurityMode.PIN -> Pair(kg_unlock_with_pin_or_fp, 0)
        else -> Pair(0, 0)
    }
}

fun incorrectSecurityInput(securityMode: SecurityMode): BouncerMessage {
    return when (securityMode) {
        SecurityMode.Pattern -> Pair(kg_wrong_pattern_try_again, 0)
        SecurityMode.Password -> Pair(kg_wrong_password_try_again, 0)
        SecurityMode.PIN -> Pair(kg_wrong_pin_try_again, 0)
        else -> Pair(0, 0)
    }
}

fun incorrectSecurityInputWithFingerprint(securityMode: SecurityMode): BouncerMessage {
    return when (securityMode) {
        SecurityMode.Pattern -> Pair(kg_wrong_pattern_try_again, kg_wrong_input_try_fp_suggestion)
        SecurityMode.Password -> Pair(kg_wrong_password_try_again, kg_wrong_input_try_fp_suggestion)
        SecurityMode.PIN -> Pair(kg_wrong_pin_try_again, kg_wrong_input_try_fp_suggestion)
        else -> Pair(0, 0)
    }
}

fun incorrectFingerprintInput(securityMode: SecurityMode): BouncerMessage {
    return when (securityMode) {
        SecurityMode.Pattern -> Pair(kg_fp_not_recognized, kg_bio_try_again_or_pattern)
        SecurityMode.Password -> Pair(kg_fp_not_recognized, kg_bio_try_again_or_password)
        SecurityMode.PIN -> Pair(kg_fp_not_recognized, kg_bio_try_again_or_pin)
        else -> Pair(0, 0)
    }
}

fun incorrectFaceInput(securityMode: SecurityMode): BouncerMessage {
    return when (securityMode) {
        SecurityMode.Pattern -> Pair(bouncer_face_not_recognized, kg_bio_try_again_or_pattern)
        SecurityMode.Password -> Pair(bouncer_face_not_recognized, kg_bio_try_again_or_password)
        SecurityMode.PIN -> Pair(bouncer_face_not_recognized, kg_bio_try_again_or_pin)
        else -> Pair(0, 0)
    }
}

fun incorrectFaceInputWithFingerprintAllowed(securityMode: SecurityMode): BouncerMessage {
    return when (securityMode) {
        SecurityMode.Pattern -> Pair(kg_unlock_with_pattern_or_fp, bouncer_face_not_recognized)
        SecurityMode.Password -> Pair(kg_unlock_with_password_or_fp, bouncer_face_not_recognized)
        SecurityMode.PIN -> Pair(kg_unlock_with_pin_or_fp, bouncer_face_not_recognized)
        else -> Pair(0, 0)
    }
}

fun biometricLockout(securityMode: SecurityMode): BouncerMessage {
    return when (securityMode) {
        SecurityMode.Pattern -> Pair(keyguard_enter_pattern, kg_bio_too_many_attempts_pattern)
        SecurityMode.Password -> Pair(keyguard_enter_password, kg_bio_too_many_attempts_password)
        SecurityMode.PIN -> Pair(keyguard_enter_pin, kg_bio_too_many_attempts_pin)
        else -> Pair(0, 0)
    }
}

fun authRequiredAfterReboot(securityMode: SecurityMode): BouncerMessage {
    return when (securityMode) {
        SecurityMode.Pattern -> Pair(keyguard_enter_pattern, kg_prompt_reason_restart_pattern)
        SecurityMode.Password -> Pair(keyguard_enter_password, kg_prompt_reason_restart_password)
        SecurityMode.PIN -> Pair(keyguard_enter_pin, kg_prompt_reason_restart_pin)
        else -> Pair(0, 0)
    }
}

fun authRequiredAfterAdminLockdown(securityMode: SecurityMode): BouncerMessage {
    return when (securityMode) {
        SecurityMode.Pattern -> Pair(keyguard_enter_pattern, kg_prompt_after_dpm_lock)
        SecurityMode.Password -> Pair(keyguard_enter_password, kg_prompt_after_dpm_lock)
        SecurityMode.PIN -> Pair(keyguard_enter_pin, kg_prompt_after_dpm_lock)
        else -> Pair(0, 0)
    }
}

fun authRequiredAfterUserLockdown(securityMode: SecurityMode): BouncerMessage {
    return when (securityMode) {
        SecurityMode.Pattern -> Pair(keyguard_enter_pattern, kg_prompt_after_user_lockdown_pattern)
        SecurityMode.Password ->
            Pair(keyguard_enter_password, kg_prompt_after_user_lockdown_password)
        SecurityMode.PIN -> Pair(keyguard_enter_pin, kg_prompt_after_user_lockdown_pin)
        else -> Pair(0, 0)
    }
}

fun authRequiredForUnattendedUpdate(securityMode: SecurityMode): BouncerMessage {
    return when (securityMode) {
        SecurityMode.Pattern -> Pair(keyguard_enter_pattern, kg_prompt_unattended_update)
        SecurityMode.Password -> Pair(keyguard_enter_password, kg_prompt_unattended_update)
        SecurityMode.PIN -> Pair(keyguard_enter_pin, kg_prompt_unattended_update)
        else -> Pair(0, 0)
    }
}

fun authRequiredAfterPrimaryAuthTimeout(securityMode: SecurityMode): BouncerMessage {
    return when (securityMode) {
        SecurityMode.Pattern -> Pair(keyguard_enter_pattern, kg_prompt_pattern_auth_timeout)
        SecurityMode.Password -> Pair(keyguard_enter_password, kg_prompt_password_auth_timeout)
        SecurityMode.PIN -> Pair(keyguard_enter_pin, kg_prompt_pin_auth_timeout)
        else -> Pair(0, 0)
    }
}

fun nonStrongAuthTimeout(securityMode: SecurityMode): BouncerMessage {
    return when (securityMode) {
        SecurityMode.Pattern -> Pair(keyguard_enter_pattern, kg_prompt_auth_timeout)
        SecurityMode.Password -> Pair(keyguard_enter_password, kg_prompt_auth_timeout)
        SecurityMode.PIN -> Pair(keyguard_enter_pin, kg_prompt_auth_timeout)
        else -> Pair(0, 0)
    }
}

fun nonStrongAuthTimeoutWithFingerprintAllowed(securityMode: SecurityMode): BouncerMessage {
    return when (securityMode) {
        SecurityMode.Pattern -> Pair(kg_unlock_with_pattern_or_fp, kg_prompt_auth_timeout)
        SecurityMode.Password -> Pair(kg_unlock_with_password_or_fp, kg_prompt_auth_timeout)
        SecurityMode.PIN -> Pair(kg_unlock_with_pin_or_fp, kg_prompt_auth_timeout)
        else -> Pair(0, 0)
    }
}

fun faceUnlockUnavailable(securityMode: SecurityMode): BouncerMessage {
    return when (securityMode) {
        SecurityMode.Pattern -> Pair(keyguard_enter_pattern, kg_face_locked_out)
        SecurityMode.Password -> Pair(keyguard_enter_password, kg_face_locked_out)
        SecurityMode.PIN -> Pair(keyguard_enter_pin, kg_face_locked_out)
        else -> Pair(0, 0)
    }
}

fun fingerprintUnlockUnavailable(securityMode: SecurityMode): BouncerMessage {
    return when (securityMode) {
        SecurityMode.Pattern -> Pair(keyguard_enter_pattern, kg_fp_locked_out)
        SecurityMode.Password -> Pair(keyguard_enter_password, kg_fp_locked_out)
        SecurityMode.PIN -> Pair(keyguard_enter_pin, kg_fp_locked_out)
        else -> Pair(0, 0)
    }
}

fun trustAgentDisabled(securityMode: SecurityMode): BouncerMessage {
    return when (securityMode) {
        SecurityMode.Pattern -> Pair(keyguard_enter_pattern, kg_trust_agent_disabled)
        SecurityMode.Password -> Pair(keyguard_enter_password, kg_trust_agent_disabled)
        SecurityMode.PIN -> Pair(keyguard_enter_pin, kg_trust_agent_disabled)
        else -> Pair(0, 0)
    }
}

fun trustAgentDisabledWithFingerprintAllowed(securityMode: SecurityMode): BouncerMessage {
    return when (securityMode) {
        SecurityMode.Pattern -> Pair(kg_unlock_with_pattern_or_fp, kg_trust_agent_disabled)
        SecurityMode.Password -> Pair(kg_unlock_with_password_or_fp, kg_trust_agent_disabled)
        SecurityMode.PIN -> Pair(kg_unlock_with_pin_or_fp, kg_trust_agent_disabled)
        else -> Pair(0, 0)
    }
}

fun primaryAuthLockedOut(securityMode: SecurityMode): BouncerMessage {
    return when (securityMode) {
        SecurityMode.Pattern ->
            Pair(kg_too_many_failed_attempts_countdown, kg_primary_auth_locked_out_pattern)
        SecurityMode.Password ->
            Pair(kg_too_many_failed_attempts_countdown, kg_primary_auth_locked_out_password)
        SecurityMode.PIN ->
            Pair(kg_too_many_failed_attempts_countdown, kg_primary_auth_locked_out_pin)
        else -> Pair(0, 0)
    }
}
+36 −0
Original line number Original line Diff line number Diff line
@@ -66,6 +66,42 @@ public interface KeyguardSecurityView {
     */
     */
    int PROMPT_REASON_TRUSTAGENT_EXPIRED = 8;
    int PROMPT_REASON_TRUSTAGENT_EXPIRED = 8;


    /**
     * Prompt that is shown when there is an incorrect primary authentication input.
     */
    int PROMPT_REASON_INCORRECT_PRIMARY_AUTH_INPUT = 9;

    /**
     * Prompt that is shown when there is an incorrect face biometric input.
     */
    int PROMPT_REASON_INCORRECT_FACE_INPUT = 10;

    /**
     * Prompt that is shown when there is an incorrect fingerprint biometric input.
     */
    int PROMPT_REASON_INCORRECT_FINGERPRINT_INPUT = 11;

    /**
     * Prompt that is shown when face authentication is in locked out state.
     */
    int PROMPT_REASON_FACE_LOCKED_OUT = 12;

    /**
     * Prompt that is shown when fingerprint authentication is in locked out state.
     */
    int PROMPT_REASON_FINGERPRINT_LOCKED_OUT = 13;

    /**
     * Default prompt that is shown on the bouncer.
     */
    int PROMPT_REASON_DEFAULT = 14;

    /**
     * Prompt that is shown when primary authentication is in locked out state after too many
     * attempts
     */
    int PROMPT_REASON_PRIMARY_AUTH_LOCKED_OUT = 15;

    /**
    /**
     * Reset the view and prepare to take input. This should do things like clearing the
     * Reset the view and prepare to take input. This should do things like clearing the
     * password or pattern and clear error messages.
     * password or pattern and clear error messages.