diff options
| author | 2024-02-27 00:19:50 +0000 | |
|---|---|---|
| committer | 2024-03-12 02:49:41 +0000 | |
| commit | edfcbdb169a2fa604b0e73bca7d08572ab60450c (patch) | |
| tree | 82d7b6b05f63b9da15d6396db1b625e1971d0d98 | |
| parent | 87552eca0caaf15502e01c8e1e7766b1f1fc06e5 (diff) | |
Move all bouncer strings to a helper class that can be reused by both legacy and flexiglass implementations.
Other changes:
- Change the unattended update message in the new implementation
- Also update the message text to "Pin/pattern/password required for
additional security"
Bug: 299343534
Test: NA
Flag: ACONFIG com.android.systemui.revamped_bouncer_messages TRUNKFOOD
Change-Id: I818b17c793649b54ff3845cdf327a87cb4d877a6
7 files changed, 387 insertions, 345 deletions
diff --git a/packages/SystemUI/res-keyguard/values/strings.xml b/packages/SystemUI/res-keyguard/values/strings.xml index f51e1098f333..7341015e8690 100644 --- a/packages/SystemUI/res-keyguard/values/strings.xml +++ b/packages/SystemUI/res-keyguard/values/strings.xml @@ -304,6 +304,15 @@ <!-- An explanation text that the password needs to be entered since the user hasn't used strong authentication since quite some time. [CHAR LIMIT=80] --> <string name="kg_prompt_reason_timeout_password">For additional security, use password instead</string> + <!-- An explanation text that the pin needs to be provided to enter the device for security reasons. [CHAR LIMIT=70] --> + <string name="kg_prompt_added_security_pin">PIN required for additional security</string> + + <!-- An explanation text that the pattern needs to be provided to enter the device for security reasons. [CHAR LIMIT=70] --> + <string name="kg_prompt_added_security_pattern">Pattern required for additional security</string> + + <!-- An explanation text that the password needs to be provided to enter the device for security reasons. [CHAR LIMIT=70] --> + <string name="kg_prompt_added_security_password">Password required for additional security</string> + <!-- An explanation text that the credential needs to be entered because a device admin has locked the device. [CHAR LIMIT=80] --> <string name="kg_prompt_reason_device_admin">Device locked by admin</string> diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardPasswordView.java b/packages/SystemUI/src/com/android/keyguard/KeyguardPasswordView.java index 84c8ea708031..26e91b62d19a 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardPasswordView.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardPasswordView.java @@ -122,7 +122,7 @@ public class KeyguardPasswordView extends KeyguardAbsKeyInputView { case PROMPT_REASON_USER_REQUEST: return R.string.kg_prompt_after_user_lockdown_password; case PROMPT_REASON_PREPARE_FOR_UPDATE: - return R.string.kg_prompt_reason_timeout_password; + return R.string.kg_prompt_added_security_password; case PROMPT_REASON_NON_STRONG_BIOMETRIC_TIMEOUT: return R.string.kg_prompt_reason_timeout_password; case PROMPT_REASON_TRUSTAGENT_EXPIRED: diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardPatternViewController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardPatternViewController.java index bf8900da887a..caa74780538e 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardPatternViewController.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardPatternViewController.java @@ -323,7 +323,7 @@ public class KeyguardPatternViewController resId = R.string.kg_prompt_after_user_lockdown_pattern; break; case PROMPT_REASON_PREPARE_FOR_UPDATE: - resId = R.string.kg_prompt_reason_timeout_pattern; + resId = R.string.kg_prompt_added_security_pattern; break; case PROMPT_REASON_NON_STRONG_BIOMETRIC_TIMEOUT: resId = R.string.kg_prompt_reason_timeout_pattern; diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardPinBasedInputView.java b/packages/SystemUI/src/com/android/keyguard/KeyguardPinBasedInputView.java index bcab6f054dd6..fbe9edfd6680 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardPinBasedInputView.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardPinBasedInputView.java @@ -134,7 +134,7 @@ public abstract class KeyguardPinBasedInputView extends KeyguardAbsKeyInputView case PROMPT_REASON_USER_REQUEST: return R.string.kg_prompt_after_user_lockdown_pin; case PROMPT_REASON_PREPARE_FOR_UPDATE: - return R.string.kg_prompt_reason_timeout_pin; + return R.string.kg_prompt_added_security_pin; case PROMPT_REASON_NON_STRONG_BIOMETRIC_TIMEOUT: return R.string.kg_prompt_reason_timeout_pin; case PROMPT_REASON_TRUSTAGENT_EXPIRED: diff --git a/packages/SystemUI/src/com/android/systemui/bouncer/domain/interactor/BouncerMessageInteractor.kt b/packages/SystemUI/src/com/android/systemui/bouncer/domain/interactor/BouncerMessageInteractor.kt index c25e748f8668..3092defc8b0e 100644 --- a/packages/SystemUI/src/com/android/systemui/bouncer/domain/interactor/BouncerMessageInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/bouncer/domain/interactor/BouncerMessageInteractor.kt @@ -23,10 +23,12 @@ import com.android.keyguard.KeyguardSecurityModel.SecurityMode import com.android.keyguard.KeyguardUpdateMonitor import com.android.keyguard.KeyguardUpdateMonitorCallback import com.android.systemui.Flags +import com.android.systemui.authentication.shared.model.AuthenticationMethodModel import com.android.systemui.biometrics.data.repository.FacePropertyRepository import com.android.systemui.biometrics.shared.model.SensorStrength import com.android.systemui.bouncer.data.repository.BouncerMessageRepository import com.android.systemui.bouncer.shared.model.BouncerMessageModel +import com.android.systemui.bouncer.shared.model.BouncerMessageStrings import com.android.systemui.bouncer.shared.model.Message import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.qualifiers.Application @@ -35,46 +37,6 @@ import com.android.systemui.flags.SystemPropertiesHelper import com.android.systemui.keyguard.data.repository.BiometricSettingsRepository import com.android.systemui.keyguard.data.repository.DeviceEntryFingerprintAuthRepository import com.android.systemui.keyguard.data.repository.TrustRepository -import com.android.systemui.res.R.string.bouncer_face_not_recognized -import com.android.systemui.res.R.string.keyguard_enter_password -import com.android.systemui.res.R.string.keyguard_enter_pattern -import com.android.systemui.res.R.string.keyguard_enter_pin -import com.android.systemui.res.R.string.kg_bio_too_many_attempts_password -import com.android.systemui.res.R.string.kg_bio_too_many_attempts_pattern -import com.android.systemui.res.R.string.kg_bio_too_many_attempts_pin -import com.android.systemui.res.R.string.kg_bio_try_again_or_password -import com.android.systemui.res.R.string.kg_bio_try_again_or_pattern -import com.android.systemui.res.R.string.kg_bio_try_again_or_pin -import com.android.systemui.res.R.string.kg_face_locked_out -import com.android.systemui.res.R.string.kg_fp_not_recognized -import com.android.systemui.res.R.string.kg_primary_auth_locked_out_password -import com.android.systemui.res.R.string.kg_primary_auth_locked_out_pattern -import com.android.systemui.res.R.string.kg_primary_auth_locked_out_pin -import com.android.systemui.res.R.string.kg_prompt_after_adaptive_auth_lock -import com.android.systemui.res.R.string.kg_prompt_after_dpm_lock -import com.android.systemui.res.R.string.kg_prompt_after_update_password -import com.android.systemui.res.R.string.kg_prompt_after_update_pattern -import com.android.systemui.res.R.string.kg_prompt_after_update_pin -import com.android.systemui.res.R.string.kg_prompt_after_user_lockdown_password -import com.android.systemui.res.R.string.kg_prompt_after_user_lockdown_pattern -import com.android.systemui.res.R.string.kg_prompt_after_user_lockdown_pin -import com.android.systemui.res.R.string.kg_prompt_auth_timeout -import com.android.systemui.res.R.string.kg_prompt_password_auth_timeout -import com.android.systemui.res.R.string.kg_prompt_pattern_auth_timeout -import com.android.systemui.res.R.string.kg_prompt_pin_auth_timeout -import com.android.systemui.res.R.string.kg_prompt_reason_restart_password -import com.android.systemui.res.R.string.kg_prompt_reason_restart_pattern -import com.android.systemui.res.R.string.kg_prompt_reason_restart_pin -import com.android.systemui.res.R.string.kg_prompt_unattended_update -import com.android.systemui.res.R.string.kg_too_many_failed_attempts_countdown -import com.android.systemui.res.R.string.kg_trust_agent_disabled -import com.android.systemui.res.R.string.kg_unlock_with_password_or_fp -import com.android.systemui.res.R.string.kg_unlock_with_pattern_or_fp -import com.android.systemui.res.R.string.kg_unlock_with_pin_or_fp -import com.android.systemui.res.R.string.kg_wrong_input_try_fp_suggestion -import com.android.systemui.res.R.string.kg_wrong_password_try_again -import com.android.systemui.res.R.string.kg_wrong_pattern_try_again -import com.android.systemui.res.R.string.kg_wrong_pin_try_again import com.android.systemui.user.data.repository.UserRepository import com.android.systemui.util.kotlin.Quint import javax.inject.Inject @@ -130,17 +92,22 @@ constructor( repository.setMessage( when (biometricSourceType) { BiometricSourceType.FINGERPRINT -> - incorrectFingerprintInput(currentSecurityMode) + BouncerMessageStrings.incorrectFingerprintInput( + currentSecurityMode.toAuthModel() + ) + .toMessage() BiometricSourceType.FACE -> - incorrectFaceInput( - currentSecurityMode, - isFingerprintAuthCurrentlyAllowed.value - ) + BouncerMessageStrings.incorrectFaceInput( + currentSecurityMode.toAuthModel(), + isFingerprintAuthCurrentlyAllowed.value + ) + .toMessage() else -> - defaultMessage( - currentSecurityMode, - isFingerprintAuthCurrentlyAllowed.value - ) + BouncerMessageStrings.defaultMessage( + currentSecurityMode.toAuthModel(), + isFingerprintAuthCurrentlyAllowed.value + ) + .toMessage() } ) } @@ -189,45 +156,79 @@ constructor( trustOrBiometricsAvailable && flags.isPrimaryAuthRequiredAfterReboot ) { if (wasRebootedForMainlineUpdate) { - authRequiredForMainlineUpdate(currentSecurityMode) + BouncerMessageStrings.authRequiredForMainlineUpdate( + currentSecurityMode.toAuthModel() + ) + .toMessage() } else { - authRequiredAfterReboot(currentSecurityMode) + BouncerMessageStrings.authRequiredAfterReboot( + currentSecurityMode.toAuthModel() + ) + .toMessage() } } else if (trustOrBiometricsAvailable && flags.isPrimaryAuthRequiredAfterTimeout) { - authRequiredAfterPrimaryAuthTimeout(currentSecurityMode) + BouncerMessageStrings.authRequiredAfterPrimaryAuthTimeout( + currentSecurityMode.toAuthModel() + ) + .toMessage() } else if (flags.isPrimaryAuthRequiredAfterDpmLockdown) { - authRequiredAfterAdminLockdown(currentSecurityMode) + BouncerMessageStrings.authRequiredAfterAdminLockdown( + currentSecurityMode.toAuthModel() + ) + .toMessage() } else if ( trustOrBiometricsAvailable && flags.primaryAuthRequiredForUnattendedUpdate ) { - authRequiredForUnattendedUpdate(currentSecurityMode) + BouncerMessageStrings.authRequiredForUnattendedUpdate( + currentSecurityMode.toAuthModel() + ) + .toMessage() } else if (fpLockedOut) { - class3AuthLockedOut(currentSecurityMode) + BouncerMessageStrings.class3AuthLockedOut(currentSecurityMode.toAuthModel()) + .toMessage() } else if (faceLockedOut) { if (isFaceAuthClass3) { - class3AuthLockedOut(currentSecurityMode) + BouncerMessageStrings.class3AuthLockedOut(currentSecurityMode.toAuthModel()) + .toMessage() } else { - faceLockedOut(currentSecurityMode, isFingerprintAuthCurrentlyAllowed.value) + BouncerMessageStrings.faceLockedOut( + currentSecurityMode.toAuthModel(), + isFingerprintAuthCurrentlyAllowed.value + ) + .toMessage() } } else if (flags.isSomeAuthRequiredAfterAdaptiveAuthRequest) { - authRequiredAfterAdaptiveAuthRequest( - currentSecurityMode, - isFingerprintAuthCurrentlyAllowed.value - ) + BouncerMessageStrings.authRequiredAfterAdaptiveAuthRequest( + currentSecurityMode.toAuthModel(), + isFingerprintAuthCurrentlyAllowed.value + ) + .toMessage() } else if ( trustOrBiometricsAvailable && flags.strongerAuthRequiredAfterNonStrongBiometricsTimeout ) { - nonStrongAuthTimeout( - currentSecurityMode, - isFingerprintAuthCurrentlyAllowed.value - ) + BouncerMessageStrings.nonStrongAuthTimeout( + currentSecurityMode.toAuthModel(), + isFingerprintAuthCurrentlyAllowed.value + ) + .toMessage() } else if (isTrustUsuallyManaged && flags.someAuthRequiredAfterUserRequest) { - trustAgentDisabled(currentSecurityMode, isFingerprintAuthCurrentlyAllowed.value) + BouncerMessageStrings.trustAgentDisabled( + currentSecurityMode.toAuthModel(), + isFingerprintAuthCurrentlyAllowed.value + ) + .toMessage() } else if (isTrustUsuallyManaged && flags.someAuthRequiredAfterTrustAgentExpired) { - trustAgentDisabled(currentSecurityMode, isFingerprintAuthCurrentlyAllowed.value) + BouncerMessageStrings.trustAgentDisabled( + currentSecurityMode.toAuthModel(), + isFingerprintAuthCurrentlyAllowed.value + ) + .toMessage() } else if (trustOrBiometricsAvailable && flags.isInUserLockdown) { - authRequiredAfterUserLockdown(currentSecurityMode) + BouncerMessageStrings.authRequiredAfterUserLockdown( + currentSecurityMode.toAuthModel() + ) + .toMessage() } else { defaultMessage } @@ -244,7 +245,11 @@ constructor( override fun onTick(millisUntilFinished: Long) { val secondsRemaining = (millisUntilFinished / 1000.0).roundToInt() - val message = primaryAuthLockedOut(currentSecurityMode) + val message = + BouncerMessageStrings.primaryAuthLockedOut( + currentSecurityMode.toAuthModel() + ) + .toMessage() message.message?.animate = false message.message?.formatterArgs = mutableMapOf<String, Any>(Pair("count", secondsRemaining)) @@ -258,7 +263,11 @@ constructor( if (!Flags.revampedBouncerMessages()) return repository.setMessage( - incorrectSecurityInput(currentSecurityMode, isFingerprintAuthCurrentlyAllowed.value) + BouncerMessageStrings.incorrectSecurityInput( + currentSecurityMode.toAuthModel(), + isFingerprintAuthCurrentlyAllowed.value + ) + .toMessage() ) } @@ -285,7 +294,12 @@ constructor( } private val defaultMessage: BouncerMessageModel - get() = defaultMessage(currentSecurityMode, isFingerprintAuthCurrentlyAllowed.value) + get() = + BouncerMessageStrings.defaultMessage( + currentSecurityMode.toAuthModel(), + isFingerprintAuthCurrentlyAllowed.value + ) + .toMessage() fun onPrimaryBouncerUserInput() { if (!Flags.revampedBouncerMessages()) return @@ -354,283 +368,35 @@ private fun defaultMessage( return BouncerMessageModel( message = Message( - messageResId = defaultMessage(securityMode, fpAuthIsAllowed).message?.messageResId, + messageResId = + BouncerMessageStrings.defaultMessage( + securityMode.toAuthModel(), + fpAuthIsAllowed + ) + .toMessage() + .message + ?.messageResId, animate = false ), secondaryMessage = Message(message = secondaryMessage, animate = false) ) } -private fun defaultMessage( - securityMode: SecurityMode, - fpAuthIsAllowed: Boolean -): BouncerMessageModel { - return if (fpAuthIsAllowed) { - defaultMessageWithFingerprint(securityMode) - } else - 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) - }.toMessage() -} - -private fun defaultMessageWithFingerprint(securityMode: SecurityMode): BouncerMessageModel { - 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) - }.toMessage() -} - -private fun incorrectSecurityInput( - securityMode: SecurityMode, - fpAuthIsAllowed: Boolean -): BouncerMessageModel { - return if (fpAuthIsAllowed) { - incorrectSecurityInputWithFingerprint(securityMode) - } else - 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) - }.toMessage() -} - -private fun incorrectSecurityInputWithFingerprint(securityMode: SecurityMode): BouncerMessageModel { - 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) - }.toMessage() -} - -private fun incorrectFingerprintInput(securityMode: SecurityMode): BouncerMessageModel { - 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) - }.toMessage() -} - -private fun incorrectFaceInput( - securityMode: SecurityMode, - fpAuthIsAllowed: Boolean -): BouncerMessageModel { - return if (fpAuthIsAllowed) incorrectFaceInputWithFingerprintAllowed(securityMode) - else - 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) - }.toMessage() -} - -private fun incorrectFaceInputWithFingerprintAllowed( - securityMode: SecurityMode -): BouncerMessageModel { - 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) - }.toMessage() -} - -private fun biometricLockout(securityMode: SecurityMode): BouncerMessageModel { - 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) - }.toMessage() -} - -private fun authRequiredAfterReboot(securityMode: SecurityMode): BouncerMessageModel { - 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) - }.toMessage() -} - -private fun authRequiredAfterAdminLockdown(securityMode: SecurityMode): BouncerMessageModel { - 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) - }.toMessage() -} - -private fun authRequiredAfterAdaptiveAuthRequest( - securityMode: SecurityMode, - fpAuthIsAllowed: Boolean -): BouncerMessageModel { - return if (fpAuthIsAllowed) authRequiredAfterAdaptiveAuthRequestFingerprintAllowed(securityMode) - else - return when (securityMode) { - SecurityMode.Pattern -> Pair(keyguard_enter_pattern, kg_prompt_after_adaptive_auth_lock) - SecurityMode.Password -> - Pair(keyguard_enter_password, kg_prompt_after_adaptive_auth_lock) - SecurityMode.PIN -> Pair(keyguard_enter_pin, kg_prompt_after_adaptive_auth_lock) - else -> Pair(0, 0) - }.toMessage() -} - -private fun authRequiredAfterAdaptiveAuthRequestFingerprintAllowed( - securityMode: SecurityMode -): BouncerMessageModel { - return when (securityMode) { - SecurityMode.Pattern -> - Pair(kg_unlock_with_pattern_or_fp, kg_prompt_after_adaptive_auth_lock) - SecurityMode.Password -> - Pair(kg_unlock_with_password_or_fp, kg_prompt_after_adaptive_auth_lock) - SecurityMode.PIN -> Pair(kg_unlock_with_pin_or_fp, kg_prompt_after_adaptive_auth_lock) - else -> Pair(0, 0) - }.toMessage() -} - -private fun authRequiredAfterUserLockdown(securityMode: SecurityMode): BouncerMessageModel { - 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) - }.toMessage() -} - -private fun authRequiredForUnattendedUpdate(securityMode: SecurityMode): BouncerMessageModel { - 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) - }.toMessage() -} - -private fun authRequiredForMainlineUpdate(securityMode: SecurityMode): BouncerMessageModel { - return when (securityMode) { - SecurityMode.Pattern -> Pair(keyguard_enter_pattern, kg_prompt_after_update_pattern) - SecurityMode.Password -> Pair(keyguard_enter_password, kg_prompt_after_update_password) - SecurityMode.PIN -> Pair(keyguard_enter_pin, kg_prompt_after_update_pin) - else -> Pair(0, 0) - }.toMessage() -} - -private fun authRequiredAfterPrimaryAuthTimeout(securityMode: SecurityMode): BouncerMessageModel { - 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) - }.toMessage() -} - -private fun nonStrongAuthTimeout( - securityMode: SecurityMode, - fpAuthIsAllowed: Boolean -): BouncerMessageModel { - return if (fpAuthIsAllowed) { - nonStrongAuthTimeoutWithFingerprintAllowed(securityMode) - } else - 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) - }.toMessage() -} - -fun nonStrongAuthTimeoutWithFingerprintAllowed(securityMode: SecurityMode): BouncerMessageModel { - 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) - }.toMessage() -} - -private fun faceLockedOut( - securityMode: SecurityMode, - fpAuthIsAllowed: Boolean -): BouncerMessageModel { - return if (fpAuthIsAllowed) faceLockedOutButFingerprintAvailable(securityMode) - else - 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) - }.toMessage() -} - -private fun faceLockedOutButFingerprintAvailable(securityMode: SecurityMode): BouncerMessageModel { - return when (securityMode) { - SecurityMode.Pattern -> Pair(kg_unlock_with_pattern_or_fp, kg_face_locked_out) - SecurityMode.Password -> Pair(kg_unlock_with_password_or_fp, kg_face_locked_out) - SecurityMode.PIN -> Pair(kg_unlock_with_pin_or_fp, kg_face_locked_out) - else -> Pair(0, 0) - }.toMessage() -} - -private fun class3AuthLockedOut(securityMode: SecurityMode): BouncerMessageModel { - 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) - }.toMessage() -} - -private fun trustAgentDisabled( - securityMode: SecurityMode, - fpAuthIsAllowed: Boolean -): BouncerMessageModel { - return if (fpAuthIsAllowed) trustAgentDisabledWithFingerprintAllowed(securityMode) - else - 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) - }.toMessage() -} - -private fun trustAgentDisabledWithFingerprintAllowed( - securityMode: SecurityMode -): BouncerMessageModel { - 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) - }.toMessage() -} - -private fun primaryAuthLockedOut(securityMode: SecurityMode): BouncerMessageModel { - 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) - }.toMessage() -} - private fun Pair<Int, Int>.toMessage(): BouncerMessageModel { return BouncerMessageModel( message = Message(messageResId = this.first, animate = false), secondaryMessage = Message(messageResId = this.second, animate = false) ) } + +private fun SecurityMode.toAuthModel(): AuthenticationMethodModel { + return when (this) { + SecurityMode.Invalid -> AuthenticationMethodModel.None + SecurityMode.None -> AuthenticationMethodModel.None + SecurityMode.Pattern -> AuthenticationMethodModel.Pattern + SecurityMode.Password -> AuthenticationMethodModel.Password + SecurityMode.PIN -> AuthenticationMethodModel.Pin + SecurityMode.SimPin -> AuthenticationMethodModel.Sim + SecurityMode.SimPuk -> AuthenticationMethodModel.Sim + } +} diff --git a/packages/SystemUI/src/com/android/systemui/bouncer/shared/model/BouncerMessageStrings.kt b/packages/SystemUI/src/com/android/systemui/bouncer/shared/model/BouncerMessageStrings.kt new file mode 100644 index 000000000000..cb12ce50dd23 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/bouncer/shared/model/BouncerMessageStrings.kt @@ -0,0 +1,267 @@ +/* + * 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. + * 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.systemui.bouncer.shared.model + +import com.android.systemui.authentication.shared.model.AuthenticationMethodModel +import com.android.systemui.authentication.shared.model.AuthenticationMethodModel.Password +import com.android.systemui.authentication.shared.model.AuthenticationMethodModel.Pattern +import com.android.systemui.authentication.shared.model.AuthenticationMethodModel.Pin +import com.android.systemui.res.R + +typealias BouncerMessagePair = Pair<Int, Int> + +val BouncerMessagePair.primaryMessage: Int + get() = this.first + +val BouncerMessagePair.secondaryMessage: Int + get() = this.second + +object BouncerMessageStrings { + private val EmptyMessage = Pair(0, 0) + + fun defaultMessage( + securityMode: AuthenticationMethodModel, + fpAuthIsAllowed: Boolean + ): BouncerMessagePair { + return when (securityMode) { + Pattern -> Pair(patternDefaultMessage(fpAuthIsAllowed), 0) + Password -> Pair(passwordDefaultMessage(fpAuthIsAllowed), 0) + Pin -> Pair(pinDefaultMessage(fpAuthIsAllowed), 0) + else -> EmptyMessage + } + } + + fun incorrectSecurityInput( + securityMode: AuthenticationMethodModel, + fpAuthIsAllowed: Boolean + ): BouncerMessagePair { + val secondaryMessage = incorrectSecurityInputSecondaryMessage(fpAuthIsAllowed) + return when (securityMode) { + Pattern -> Pair(R.string.kg_wrong_pattern_try_again, secondaryMessage) + Password -> Pair(R.string.kg_wrong_password_try_again, secondaryMessage) + Pin -> Pair(R.string.kg_wrong_pin_try_again, secondaryMessage) + else -> EmptyMessage + } + } + + private fun incorrectSecurityInputSecondaryMessage(fpAuthIsAllowed: Boolean): Int { + return if (fpAuthIsAllowed) R.string.kg_wrong_input_try_fp_suggestion else 0 + } + + fun incorrectFingerprintInput(securityMode: AuthenticationMethodModel): BouncerMessagePair { + val primaryMessage = R.string.kg_fp_not_recognized + return when (securityMode) { + Pattern -> Pair(primaryMessage, R.string.kg_bio_try_again_or_pattern) + Password -> Pair(primaryMessage, R.string.kg_bio_try_again_or_password) + Pin -> Pair(primaryMessage, R.string.kg_bio_try_again_or_pin) + else -> EmptyMessage + } + } + + fun incorrectFaceInput( + securityMode: AuthenticationMethodModel, + fpAuthIsAllowed: Boolean + ): BouncerMessagePair { + return if (fpAuthIsAllowed) incorrectFaceInputWithFingerprintAllowed(securityMode) + else { + val primaryMessage = R.string.bouncer_face_not_recognized + when (securityMode) { + Pattern -> Pair(primaryMessage, R.string.kg_bio_try_again_or_pattern) + Password -> Pair(primaryMessage, R.string.kg_bio_try_again_or_password) + Pin -> Pair(primaryMessage, R.string.kg_bio_try_again_or_pin) + else -> EmptyMessage + } + } + } + + private fun incorrectFaceInputWithFingerprintAllowed( + securityMode: AuthenticationMethodModel + ): BouncerMessagePair { + val secondaryMsg = R.string.bouncer_face_not_recognized + return when (securityMode) { + Pattern -> Pair(patternDefaultMessage(true), secondaryMsg) + Password -> Pair(passwordDefaultMessage(true), secondaryMsg) + Pin -> Pair(pinDefaultMessage(true), secondaryMsg) + else -> EmptyMessage + } + } + + fun authRequiredAfterReboot(securityMode: AuthenticationMethodModel): BouncerMessagePair { + return when (securityMode) { + Pattern -> Pair(patternDefaultMessage(false), R.string.kg_prompt_reason_restart_pattern) + Password -> + Pair(passwordDefaultMessage(false), R.string.kg_prompt_reason_restart_password) + Pin -> Pair(pinDefaultMessage(false), R.string.kg_prompt_reason_restart_pin) + else -> EmptyMessage + } + } + + fun authRequiredAfterAdminLockdown( + securityMode: AuthenticationMethodModel + ): BouncerMessagePair { + val secondaryMsg = R.string.kg_prompt_after_dpm_lock + return when (securityMode) { + Pattern -> Pair(patternDefaultMessage(false), secondaryMsg) + Password -> Pair(passwordDefaultMessage(false), secondaryMsg) + Pin -> Pair(pinDefaultMessage(false), secondaryMsg) + else -> EmptyMessage + } + } + + fun authRequiredAfterAdaptiveAuthRequest( + securityMode: AuthenticationMethodModel, + fpAuthIsAllowed: Boolean + ): BouncerMessagePair { + val secondaryMsg = R.string.kg_prompt_after_adaptive_auth_lock + return when (securityMode) { + Pattern -> Pair(patternDefaultMessage(fpAuthIsAllowed), secondaryMsg) + Password -> Pair(passwordDefaultMessage(fpAuthIsAllowed), secondaryMsg) + Pin -> Pair(pinDefaultMessage(fpAuthIsAllowed), secondaryMsg) + else -> EmptyMessage + } + } + + fun authRequiredAfterUserLockdown(securityMode: AuthenticationMethodModel): BouncerMessagePair { + return when (securityMode) { + Pattern -> + Pair(patternDefaultMessage(false), R.string.kg_prompt_after_user_lockdown_pattern) + Password -> + Pair(passwordDefaultMessage(false), R.string.kg_prompt_after_user_lockdown_password) + Pin -> Pair(pinDefaultMessage(false), R.string.kg_prompt_after_user_lockdown_pin) + else -> EmptyMessage + } + } + + fun authRequiredForUnattendedUpdate( + securityMode: AuthenticationMethodModel + ): BouncerMessagePair { + return when (securityMode) { + Pattern -> Pair(patternDefaultMessage(false), R.string.kg_prompt_added_security_pattern) + Password -> + Pair(passwordDefaultMessage(false), R.string.kg_prompt_added_security_password) + Pin -> Pair(pinDefaultMessage(false), R.string.kg_prompt_added_security_pin) + else -> EmptyMessage + } + } + + fun authRequiredForMainlineUpdate(securityMode: AuthenticationMethodModel): BouncerMessagePair { + return when (securityMode) { + Pattern -> Pair(patternDefaultMessage(false), R.string.kg_prompt_after_update_pattern) + Password -> + Pair(passwordDefaultMessage(false), R.string.kg_prompt_after_update_password) + Pin -> Pair(pinDefaultMessage(false), R.string.kg_prompt_after_update_pin) + else -> EmptyMessage + } + } + + fun authRequiredAfterPrimaryAuthTimeout( + securityMode: AuthenticationMethodModel + ): BouncerMessagePair { + return when (securityMode) { + Pattern -> Pair(patternDefaultMessage(false), R.string.kg_prompt_pattern_auth_timeout) + Password -> + Pair(passwordDefaultMessage(false), R.string.kg_prompt_password_auth_timeout) + Pin -> Pair(pinDefaultMessage(false), R.string.kg_prompt_pin_auth_timeout) + else -> EmptyMessage + } + } + + fun nonStrongAuthTimeout( + securityMode: AuthenticationMethodModel, + fpAuthIsAllowed: Boolean + ): BouncerMessagePair { + val secondaryMsg = R.string.kg_prompt_auth_timeout + return when (securityMode) { + Pattern -> Pair(patternDefaultMessage(fpAuthIsAllowed), secondaryMsg) + Password -> Pair(passwordDefaultMessage(fpAuthIsAllowed), secondaryMsg) + Pin -> Pair(pinDefaultMessage(fpAuthIsAllowed), secondaryMsg) + else -> EmptyMessage + } + } + + fun faceLockedOut( + securityMode: AuthenticationMethodModel, + fpAuthIsAllowed: Boolean + ): BouncerMessagePair { + val secondaryMsg = R.string.kg_face_locked_out + return when (securityMode) { + Pattern -> Pair(patternDefaultMessage(fpAuthIsAllowed), secondaryMsg) + Password -> Pair(passwordDefaultMessage(fpAuthIsAllowed), secondaryMsg) + Pin -> Pair(pinDefaultMessage(fpAuthIsAllowed), secondaryMsg) + else -> EmptyMessage + } + } + + fun class3AuthLockedOut(securityMode: AuthenticationMethodModel): BouncerMessagePair { + return when (securityMode) { + Pattern -> Pair(patternDefaultMessage(false), R.string.kg_bio_too_many_attempts_pattern) + Password -> + Pair(passwordDefaultMessage(false), R.string.kg_bio_too_many_attempts_password) + Pin -> Pair(pinDefaultMessage(false), R.string.kg_bio_too_many_attempts_pin) + else -> EmptyMessage + } + } + + fun trustAgentDisabled( + securityMode: AuthenticationMethodModel, + fpAuthIsAllowed: Boolean + ): BouncerMessagePair { + val secondaryMsg = R.string.kg_trust_agent_disabled + return when (securityMode) { + Pattern -> Pair(patternDefaultMessage(fpAuthIsAllowed), secondaryMsg) + Password -> Pair(passwordDefaultMessage(fpAuthIsAllowed), secondaryMsg) + Pin -> Pair(pinDefaultMessage(fpAuthIsAllowed), secondaryMsg) + else -> EmptyMessage + } + } + + fun primaryAuthLockedOut(securityMode: AuthenticationMethodModel): BouncerMessagePair { + return when (securityMode) { + Pattern -> + Pair( + R.string.kg_too_many_failed_attempts_countdown, + R.string.kg_primary_auth_locked_out_pattern + ) + Password -> + Pair( + R.string.kg_too_many_failed_attempts_countdown, + R.string.kg_primary_auth_locked_out_password + ) + Pin -> + Pair( + R.string.kg_too_many_failed_attempts_countdown, + R.string.kg_primary_auth_locked_out_pin + ) + else -> EmptyMessage + } + } + + private fun patternDefaultMessage(fingerprintAllowed: Boolean): Int { + return if (fingerprintAllowed) R.string.kg_unlock_with_pattern_or_fp + else R.string.keyguard_enter_pattern + } + + private fun pinDefaultMessage(fingerprintAllowed: Boolean): Int { + return if (fingerprintAllowed) R.string.kg_unlock_with_pin_or_fp + else R.string.keyguard_enter_pin + } + + private fun passwordDefaultMessage(fingerprintAllowed: Boolean): Int { + return if (fingerprintAllowed) R.string.kg_unlock_with_password_or_fp + else R.string.keyguard_enter_password + } +} diff --git a/packages/SystemUI/tests/src/com/android/systemui/bouncer/domain/interactor/BouncerMessageInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/bouncer/domain/interactor/BouncerMessageInteractorTest.kt index e7963031411d..701b7039a1ed 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/bouncer/domain/interactor/BouncerMessageInteractorTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/bouncer/domain/interactor/BouncerMessageInteractorTest.kt @@ -401,7 +401,7 @@ class BouncerMessageInteractorTest : SysuiTestCase() { LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN to Pair("Enter PIN", "PIN is required after lockdown"), LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_FOR_UNATTENDED_UPDATE to - Pair("Enter PIN", "Update will install when device not in use"), + Pair("Enter PIN", "PIN required for additional security"), LockPatternUtils.StrongAuthTracker .STRONG_AUTH_REQUIRED_AFTER_NON_STRONG_BIOMETRICS_TIMEOUT to Pair( @@ -439,7 +439,7 @@ class BouncerMessageInteractorTest : SysuiTestCase() { LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN to Pair("Enter PIN", "PIN is required after lockdown"), LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_FOR_UNATTENDED_UPDATE to - Pair("Enter PIN", "Update will install when device not in use"), + Pair("Enter PIN", "PIN required for additional security"), LockPatternUtils.StrongAuthTracker .STRONG_AUTH_REQUIRED_AFTER_NON_STRONG_BIOMETRICS_TIMEOUT to Pair( @@ -481,7 +481,7 @@ class BouncerMessageInteractorTest : SysuiTestCase() { LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN to Pair("Enter PIN", "PIN is required after lockdown"), LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_FOR_UNATTENDED_UPDATE to - Pair("Enter PIN", "Update will install when device not in use"), + Pair("Enter PIN", "PIN required for additional security"), LockPatternUtils.StrongAuthTracker .STRONG_AUTH_REQUIRED_AFTER_NON_STRONG_BIOMETRICS_TIMEOUT to Pair( |