• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.systemui.bouncer.shared.model
18 
19 import com.android.systemui.authentication.shared.model.AuthenticationMethodModel
20 import com.android.systemui.authentication.shared.model.AuthenticationMethodModel.Password
21 import com.android.systemui.authentication.shared.model.AuthenticationMethodModel.Pattern
22 import com.android.systemui.authentication.shared.model.AuthenticationMethodModel.Pin
23 import com.android.systemui.res.R
24 
25 typealias BouncerMessagePair = Pair<Int, Int>
26 
27 val BouncerMessagePair.primaryMessage: Int
28     get() = this.first
29 
30 val BouncerMessagePair.secondaryMessage: Int
31     get() = this.second
32 
33 object BouncerMessageStrings {
34     private val EmptyMessage = Pair(0, 0)
35 
defaultMessagenull36     fun defaultMessage(
37         securityMode: AuthenticationMethodModel,
38         fpAuthIsAllowed: Boolean
39     ): BouncerMessagePair {
40         return when (securityMode) {
41             Pattern -> Pair(patternDefaultMessage(fpAuthIsAllowed), 0)
42             Password -> Pair(passwordDefaultMessage(fpAuthIsAllowed), 0)
43             Pin -> Pair(pinDefaultMessage(fpAuthIsAllowed), 0)
44             else -> EmptyMessage
45         }
46     }
47 
incorrectSecurityInputnull48     fun incorrectSecurityInput(
49         securityMode: AuthenticationMethodModel,
50         fpAuthIsAllowed: Boolean
51     ): BouncerMessagePair {
52         val secondaryMessage = incorrectSecurityInputSecondaryMessage(fpAuthIsAllowed)
53         return when (securityMode) {
54             Pattern -> Pair(R.string.kg_wrong_pattern_try_again, secondaryMessage)
55             Password -> Pair(R.string.kg_wrong_password_try_again, secondaryMessage)
56             Pin -> Pair(R.string.kg_wrong_pin_try_again, secondaryMessage)
57             else -> EmptyMessage
58         }
59     }
60 
incorrectSecurityInputSecondaryMessagenull61     private fun incorrectSecurityInputSecondaryMessage(fpAuthIsAllowed: Boolean): Int {
62         return if (fpAuthIsAllowed) R.string.kg_wrong_input_try_fp_suggestion else 0
63     }
64 
incorrectFingerprintInputnull65     fun incorrectFingerprintInput(securityMode: AuthenticationMethodModel): BouncerMessagePair {
66         val primaryMessage = R.string.kg_fp_not_recognized
67         return when (securityMode) {
68             Pattern -> Pair(primaryMessage, R.string.kg_bio_try_again_or_pattern)
69             Password -> Pair(primaryMessage, R.string.kg_bio_try_again_or_password)
70             Pin -> Pair(primaryMessage, R.string.kg_bio_try_again_or_pin)
71             else -> EmptyMessage
72         }
73     }
74 
incorrectFaceInputnull75     fun incorrectFaceInput(
76         securityMode: AuthenticationMethodModel,
77         fpAuthIsAllowed: Boolean
78     ): BouncerMessagePair {
79         return if (fpAuthIsAllowed) incorrectFaceInputWithFingerprintAllowed(securityMode)
80         else {
81             val primaryMessage = R.string.bouncer_face_not_recognized
82             when (securityMode) {
83                 Pattern -> Pair(primaryMessage, R.string.kg_bio_try_again_or_pattern)
84                 Password -> Pair(primaryMessage, R.string.kg_bio_try_again_or_password)
85                 Pin -> Pair(primaryMessage, R.string.kg_bio_try_again_or_pin)
86                 else -> EmptyMessage
87             }
88         }
89     }
90 
incorrectFaceInputWithFingerprintAllowednull91     private fun incorrectFaceInputWithFingerprintAllowed(
92         securityMode: AuthenticationMethodModel
93     ): BouncerMessagePair {
94         val secondaryMsg = R.string.bouncer_face_not_recognized
95         return when (securityMode) {
96             Pattern -> Pair(patternDefaultMessage(true), secondaryMsg)
97             Password -> Pair(passwordDefaultMessage(true), secondaryMsg)
98             Pin -> Pair(pinDefaultMessage(true), secondaryMsg)
99             else -> EmptyMessage
100         }
101     }
102 
authRequiredAfterRebootnull103     fun authRequiredAfterReboot(securityMode: AuthenticationMethodModel): BouncerMessagePair {
104         return when (securityMode) {
105             Pattern -> Pair(patternDefaultMessage(false), R.string.kg_prompt_reason_restart_pattern)
106             Password ->
107                 Pair(passwordDefaultMessage(false), R.string.kg_prompt_reason_restart_password)
108             Pin -> Pair(pinDefaultMessage(false), R.string.kg_prompt_reason_restart_pin)
109             else -> EmptyMessage
110         }
111     }
112 
authRequiredAfterAdminLockdownnull113     fun authRequiredAfterAdminLockdown(
114         securityMode: AuthenticationMethodModel
115     ): BouncerMessagePair {
116         val secondaryMsg = R.string.kg_prompt_after_dpm_lock
117         return when (securityMode) {
118             Pattern -> Pair(patternDefaultMessage(false), secondaryMsg)
119             Password -> Pair(passwordDefaultMessage(false), secondaryMsg)
120             Pin -> Pair(pinDefaultMessage(false), secondaryMsg)
121             else -> EmptyMessage
122         }
123     }
124 
authRequiredAfterAdaptiveAuthRequestnull125     fun authRequiredAfterAdaptiveAuthRequest(
126         securityMode: AuthenticationMethodModel,
127         fpAuthIsAllowed: Boolean
128     ): BouncerMessagePair {
129         val secondaryMsg = R.string.kg_prompt_after_adaptive_auth_lock
130         return when (securityMode) {
131             Pattern -> Pair(patternDefaultMessage(fpAuthIsAllowed), secondaryMsg)
132             Password -> Pair(passwordDefaultMessage(fpAuthIsAllowed), secondaryMsg)
133             Pin -> Pair(pinDefaultMessage(fpAuthIsAllowed), secondaryMsg)
134             else -> EmptyMessage
135         }
136     }
137 
authRequiredAfterUserLockdownnull138     fun authRequiredAfterUserLockdown(securityMode: AuthenticationMethodModel): BouncerMessagePair {
139         return when (securityMode) {
140             Pattern ->
141                 Pair(patternDefaultMessage(false), R.string.kg_prompt_after_user_lockdown_pattern)
142             Password ->
143                 Pair(passwordDefaultMessage(false), R.string.kg_prompt_after_user_lockdown_password)
144             Pin -> Pair(pinDefaultMessage(false), R.string.kg_prompt_after_user_lockdown_pin)
145             else -> EmptyMessage
146         }
147     }
148 
authRequiredForUnattendedUpdatenull149     fun authRequiredForUnattendedUpdate(
150         securityMode: AuthenticationMethodModel
151     ): BouncerMessagePair {
152         return when (securityMode) {
153             Pattern -> Pair(patternDefaultMessage(false), R.string.kg_prompt_added_security_pattern)
154             Password ->
155                 Pair(passwordDefaultMessage(false), R.string.kg_prompt_added_security_password)
156             Pin -> Pair(pinDefaultMessage(false), R.string.kg_prompt_added_security_pin)
157             else -> EmptyMessage
158         }
159     }
160 
authRequiredForMainlineUpdatenull161     fun authRequiredForMainlineUpdate(securityMode: AuthenticationMethodModel): BouncerMessagePair {
162         return when (securityMode) {
163             Pattern -> Pair(patternDefaultMessage(false), R.string.kg_prompt_after_update_pattern)
164             Password ->
165                 Pair(passwordDefaultMessage(false), R.string.kg_prompt_after_update_password)
166             Pin -> Pair(pinDefaultMessage(false), R.string.kg_prompt_after_update_pin)
167             else -> EmptyMessage
168         }
169     }
170 
authRequiredAfterPrimaryAuthTimeoutnull171     fun authRequiredAfterPrimaryAuthTimeout(
172         securityMode: AuthenticationMethodModel
173     ): BouncerMessagePair {
174         return when (securityMode) {
175             Pattern -> Pair(patternDefaultMessage(false), R.string.kg_prompt_pattern_auth_timeout)
176             Password ->
177                 Pair(passwordDefaultMessage(false), R.string.kg_prompt_password_auth_timeout)
178             Pin -> Pair(pinDefaultMessage(false), R.string.kg_prompt_pin_auth_timeout)
179             else -> EmptyMessage
180         }
181     }
182 
nonStrongAuthTimeoutnull183     fun nonStrongAuthTimeout(
184         securityMode: AuthenticationMethodModel,
185         fpAuthIsAllowed: Boolean
186     ): BouncerMessagePair {
187         val secondaryMsg = R.string.kg_prompt_auth_timeout
188         return when (securityMode) {
189             Pattern -> Pair(patternDefaultMessage(fpAuthIsAllowed), secondaryMsg)
190             Password -> Pair(passwordDefaultMessage(fpAuthIsAllowed), secondaryMsg)
191             Pin -> Pair(pinDefaultMessage(fpAuthIsAllowed), secondaryMsg)
192             else -> EmptyMessage
193         }
194     }
195 
faceLockedOutnull196     fun faceLockedOut(
197         securityMode: AuthenticationMethodModel,
198         fpAuthIsAllowed: Boolean
199     ): BouncerMessagePair {
200         val secondaryMsg = R.string.kg_face_locked_out
201         return when (securityMode) {
202             Pattern -> Pair(patternDefaultMessage(fpAuthIsAllowed), secondaryMsg)
203             Password -> Pair(passwordDefaultMessage(fpAuthIsAllowed), secondaryMsg)
204             Pin -> Pair(pinDefaultMessage(fpAuthIsAllowed), secondaryMsg)
205             else -> EmptyMessage
206         }
207     }
208 
class3AuthLockedOutnull209     fun class3AuthLockedOut(securityMode: AuthenticationMethodModel): BouncerMessagePair {
210         return when (securityMode) {
211             Pattern -> Pair(patternDefaultMessage(false), R.string.kg_bio_too_many_attempts_pattern)
212             Password ->
213                 Pair(passwordDefaultMessage(false), R.string.kg_bio_too_many_attempts_password)
214             Pin -> Pair(pinDefaultMessage(false), R.string.kg_bio_too_many_attempts_pin)
215             else -> EmptyMessage
216         }
217     }
218 
trustAgentDisablednull219     fun trustAgentDisabled(
220         securityMode: AuthenticationMethodModel,
221         fpAuthIsAllowed: Boolean
222     ): BouncerMessagePair {
223         val secondaryMsg = R.string.kg_trust_agent_disabled
224         return when (securityMode) {
225             Pattern -> Pair(patternDefaultMessage(fpAuthIsAllowed), secondaryMsg)
226             Password -> Pair(passwordDefaultMessage(fpAuthIsAllowed), secondaryMsg)
227             Pin -> Pair(pinDefaultMessage(fpAuthIsAllowed), secondaryMsg)
228             else -> EmptyMessage
229         }
230     }
231 
primaryAuthLockedOutnull232     fun primaryAuthLockedOut(securityMode: AuthenticationMethodModel): BouncerMessagePair {
233         return when (securityMode) {
234             Pattern ->
235                 Pair(
236                     R.string.kg_too_many_failed_attempts_countdown,
237                     R.string.kg_primary_auth_locked_out_pattern
238                 )
239             Password ->
240                 Pair(
241                     R.string.kg_too_many_failed_attempts_countdown,
242                     R.string.kg_primary_auth_locked_out_password
243                 )
244             Pin ->
245                 Pair(
246                     R.string.kg_too_many_failed_attempts_countdown,
247                     R.string.kg_primary_auth_locked_out_pin
248                 )
249             else -> EmptyMessage
250         }
251     }
252 
patternDefaultMessagenull253     private fun patternDefaultMessage(fingerprintAllowed: Boolean): Int {
254         return if (fingerprintAllowed) R.string.kg_unlock_with_pattern_or_fp
255         else R.string.keyguard_enter_pattern
256     }
257 
pinDefaultMessagenull258     private fun pinDefaultMessage(fingerprintAllowed: Boolean): Int {
259         return if (fingerprintAllowed) R.string.kg_unlock_with_pin_or_fp
260         else R.string.keyguard_enter_pin
261     }
262 
passwordDefaultMessagenull263     private fun passwordDefaultMessage(fingerprintAllowed: Boolean): Int {
264         return if (fingerprintAllowed) R.string.kg_unlock_with_password_or_fp
265         else R.string.keyguard_enter_password
266     }
267 }
268