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 import com.android.compose.animation.scene.SceneKey
19 import com.android.systemui.scene.shared.model.Scenes
20 
21 /** List of all possible states to transition to/from */
22 enum class KeyguardState {
23     /**
24      * The display is completely off, as well as any sensors that would trigger the device to wake
25      * up.
26      */
27     OFF,
28     /**
29      * The device has entered a special low-power mode within SystemUI. Doze is technically a
30      * special dream service implementation. No UI is visible. In this state, a least some
31      * low-powered sensors such as lift to wake or tap to wake are enabled, or wake screen for
32      * notifications is enabled, allowing the device to quickly wake up.
33      */
34     DOZING,
35     /**
36      * A device state after the device times out, which can be from both LOCKSCREEN or GONE states.
37      * DOZING is an example of special version of this state. Dreams may be implemented by third
38      * parties to present their own UI over keyguard, like a screensaver.
39      */
40     DREAMING,
41     /**
42      * A device state after the device times out, which can be from both LOCKSCREEN or GONE states.
43      * It is a special version of DREAMING state but not DOZING. The active dream will be windowless
44      * and hosted in the lockscreen.
45      */
46     DREAMING_LOCKSCREEN_HOSTED,
47     /**
48      * The device has entered a special low-power mode within SystemUI, also called the Always-on
49      * Display (AOD). A minimal UI is presented to show critical information. If the device is in
50      * low-power mode without a UI, then it is DOZING.
51      */
52     AOD,
53     /**
54      * The security screen prompt containing UI to prompt the user to use a biometric credential
55      * (ie: fingerprint). When supported, this may show before showing the primary bouncer.
56      */
57     ALTERNATE_BOUNCER,
58     /**
59      * The security screen prompt UI, containing PIN, Password, Pattern for the user to verify their
60      * credentials.
61      */
62     PRIMARY_BOUNCER,
63     /**
64      * Device is actively displaying keyguard UI and is not in low-power mode. Device may be
65      * unlocked if SWIPE security method is used, or if face lockscreen bypass is false.
66      */
67     LOCKSCREEN,
68     /**
69      * Device is locked or on dream and user has swiped from the right edge to enter the glanceable
70      * hub UI. From this state, the user can swipe from the left edge to go back to the lock screen
71      * or dream, as well as swipe down for the notifications and up for the bouncer.
72      */
73     GLANCEABLE_HUB,
74     /**
75      * Keyguard is no longer visible. In most cases the user has just authenticated and keyguard is
76      * being removed, but there are other cases where the user is swiping away keyguard, such as
77      * with SWIPE security method or face unlock without bypass.
78      */
79     GONE,
80     /**
81      * Only used in scene framework. This means we are currently on any scene framework scene that
82      * is not Lockscreen. Transitions to and from UNDEFINED are always bound to the
83      * [SceneTransitionLayout] scene transition that either transitions to or from the Lockscreen
84      * scene. These transitions are automatically handled by [LockscreenSceneTransitionInteractor].
85      */
86     UNDEFINED,
87     /** An activity is displaying over the keyguard. */
88     OCCLUDED;
89 
mapToSceneContainerStatenull90     fun mapToSceneContainerState(): KeyguardState {
91         return when (this) {
92             OFF,
93             DOZING,
94             DREAMING,
95             DREAMING_LOCKSCREEN_HOSTED,
96             AOD,
97             ALTERNATE_BOUNCER,
98             OCCLUDED,
99             LOCKSCREEN -> this
100             GLANCEABLE_HUB,
101             PRIMARY_BOUNCER,
102             GONE,
103             UNDEFINED -> UNDEFINED
104         }
105     }
106 
mapToSceneContainerScenenull107     fun mapToSceneContainerScene(): SceneKey? {
108         return when (this) {
109             OFF,
110             DOZING,
111             DREAMING,
112             DREAMING_LOCKSCREEN_HOSTED,
113             AOD,
114             ALTERNATE_BOUNCER,
115             OCCLUDED,
116             LOCKSCREEN -> Scenes.Lockscreen
117             GLANCEABLE_HUB -> Scenes.Communal
118             PRIMARY_BOUNCER -> Scenes.Bouncer
119             GONE -> Scenes.Gone
120             UNDEFINED -> null
121         }
122     }
123 
124     companion object {
125 
126         /** Whether the lockscreen is visible when we're FINISHED in the given state. */
lockscreenVisibleInStatenull127         fun lockscreenVisibleInState(state: KeyguardState): Boolean {
128             return state != GONE
129         }
130 
131         /** Whether either of the bouncers are visible when we're FINISHED in the given state. */
132         @JvmStatic
isBouncerStatenull133         fun isBouncerState(state: KeyguardState): Boolean {
134             return state == PRIMARY_BOUNCER || state == ALTERNATE_BOUNCER
135         }
136 
137         /**
138          * Whether the device is awake ([PowerInteractor.isAwake]) when we're FINISHED in the given
139          * keyguard state.
140          */
deviceIsAwakeInStatenull141         fun deviceIsAwakeInState(state: KeyguardState): Boolean {
142             return when (state) {
143                 OFF -> false
144                 DOZING -> false
145                 DREAMING -> false
146                 DREAMING_LOCKSCREEN_HOSTED -> false
147                 GLANCEABLE_HUB -> true
148                 AOD -> false
149                 ALTERNATE_BOUNCER -> true
150                 PRIMARY_BOUNCER -> true
151                 LOCKSCREEN -> true
152                 GONE -> true
153                 OCCLUDED -> true
154                 UNDEFINED -> true
155             }
156         }
157 
158         /**
159          * Whether the device is awake ([PowerInteractor.isAsleep]) when we're FINISHED in the given
160          * keyguard state.
161          */
deviceIsAsleepInStatenull162         fun deviceIsAsleepInState(state: KeyguardState): Boolean {
163             return !deviceIsAwakeInState(state)
164         }
165     }
166 }
167