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