1 /*
2  * Copyright (C) 2022 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 package com.android.systemui.keyguard.shared.model
17 
18 /**
19  * Model [BiometricUnlockMode] with [BiometricUnlockSource].
20  *
21  * @param source can be null as a starting state or if the unlock isn't coming from a biometric (the
22  *   latter should be deprecated in the future, b/338578036)
23  */
24 data class BiometricUnlockModel(
25     val mode: BiometricUnlockMode,
26     val source: BiometricUnlockSource?,
27 )
28 
29 /** Model device wakefulness states. */
30 enum class BiometricUnlockMode {
31     /** Mode in which we don't need to wake up the device when we authenticate. */
32     NONE,
33     /**
34      * Mode in which we wake up the device, and directly dismiss Keyguard. Active when we acquire a
35      * fingerprint while the screen is off and the device was sleeping.
36      */
37     WAKE_AND_UNLOCK,
38     /**
39      * Mode in which we wake the device up, and fade out the Keyguard contents because they were
40      * already visible while pulsing in doze mode.
41      */
42     WAKE_AND_UNLOCK_PULSING,
43     /**
44      * Mode in which we wake up the device, but play the normal dismiss animation. Active when we
45      * acquire a fingerprint pulsing in doze mode.
46      */
47     SHOW_BOUNCER,
48     /**
49      * Mode in which we only wake up the device, and keyguard was not showing when we authenticated.
50      */
51     ONLY_WAKE,
52     /**
53      * Mode in which fingerprint unlocks the device or passive auth (ie face auth) unlocks the
54      * device while being requested when keyguard is occluded or showing.
55      */
56     UNLOCK_COLLAPSING,
57     /** When bouncer is visible and will be dismissed. */
58     DISMISS_BOUNCER,
59     /** Mode in which fingerprint wakes and unlocks the device from a dream. */
60     WAKE_AND_UNLOCK_FROM_DREAM;
61 
62     companion object {
63         private val wakeAndUnlockModes =
64             setOf(WAKE_AND_UNLOCK, WAKE_AND_UNLOCK_FROM_DREAM, WAKE_AND_UNLOCK_PULSING)
65         private val dismissesKeyguardModes =
66             setOf(
67                 WAKE_AND_UNLOCK,
68                 WAKE_AND_UNLOCK_PULSING,
69                 UNLOCK_COLLAPSING,
70                 WAKE_AND_UNLOCK_FROM_DREAM,
71                 DISMISS_BOUNCER
72             )
73 
isWakeAndUnlocknull74         fun isWakeAndUnlock(mode: BiometricUnlockMode): Boolean {
75             return wakeAndUnlockModes.contains(mode)
76         }
77 
dismissesKeyguardnull78         fun dismissesKeyguard(mode: BiometricUnlockMode): Boolean {
79             return dismissesKeyguardModes.contains(mode)
80         }
81     }
82 }
83