1 /*
2  * Copyright (C) 2016 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.statusbar.policy;
18 
19 import com.android.systemui.statusbar.StatusBarState;
20 import com.android.systemui.statusbar.policy.KeyguardStateController.Callback;
21 
22 /**
23  * Source of truth for keyguard state: If locked, occluded, has password, trusted etc.
24  */
25 public interface KeyguardStateController extends CallbackController<Callback> {
26 
27     /**
28      * If the device is locked or unlocked.
29      */
isUnlocked()30     default boolean isUnlocked() {
31         return !isShowing() || canDismissLockScreen();
32     }
33 
34     /**
35      * If the lock screen is visible.
36      * The keyguard is also visible when the device is asleep or in always on mode, except when
37      * the screen timed out and the user can unlock by quickly pressing power.
38      *
39      * This is unrelated to being locked or not.
40      *
41      * @see #isUnlocked()
42      * @see #canDismissLockScreen()
43      */
isShowing()44     boolean isShowing();
45 
46     /**
47      * If swiping up will unlock without asking for a password.
48      * @see #isUnlocked()
49      */
canDismissLockScreen()50     boolean canDismissLockScreen();
51 
52     /**
53      * If the device has PIN/pattern/password or a lock screen at all.
54      */
isMethodSecure()55     boolean isMethodSecure();
56 
57     /**
58      * When there's an {@link android.app.Activity} on top of the keyguard, where
59      * {@link android.app.Activity#setShowWhenLocked(boolean)} is true.
60      */
isOccluded()61     boolean isOccluded();
62 
63     /**
64      * If a {@link android.service.trust.TrustAgentService} is keeping the device unlocked.
65      * {@link #canDismissLockScreen()} is better source of truth that also considers this state.
66      */
isTrusted()67     boolean isTrusted();
68 
69     /**
70      * If the keyguard dismissal animation is running.
71      * @see #isKeyguardGoingAway()
72      */
isKeyguardFadingAway()73     boolean isKeyguardFadingAway();
74 
75     /**
76      * When the keyguard challenge was successfully solved, and {@link android.app.ActivityManager}
77      * is launching the activity that will be revealed.
78      *
79      * This also includes the animation of the keyguard being dismissed, meaning that this will
80      * return {@code true} whenever {@link #isKeyguardFadingAway()} also returns {@code true}.
81      */
isKeyguardGoingAway()82     boolean isKeyguardGoingAway();
83 
84     /**
85      * @return a shortened fading away duration similar to
86      * {{@link #getKeyguardFadingAwayDuration()}} which may only span half of the duration, unless
87      * we're bypassing
88      */
getShortenedFadingAwayDuration()89     default long getShortenedFadingAwayDuration() {
90         if (isBypassFadingAnimation()) {
91             return getKeyguardFadingAwayDuration();
92         } else {
93             return getKeyguardFadingAwayDuration() / 2;
94         }
95     }
96 
97     /**
98      * @return {@code true} if the current fading away animation is the fast bypass fading.
99      */
isBypassFadingAnimation()100     default boolean isBypassFadingAnimation() {
101         return false;
102     }
103 
104     /**
105      * Notifies that the Keyguard is fading away with the specified timings.
106      * @param delay the precalculated animation delay in milliseconds
107      * @param fadeoutDuration the duration of the exit animation, in milliseconds
108      * @param isBypassFading is this a fading away animation while bypassing
109      */
notifyKeyguardFadingAway(long delay, long fadeoutDuration, boolean isBypassFading)110     default void notifyKeyguardFadingAway(long delay, long fadeoutDuration,
111             boolean isBypassFading) {
112     }
113 
114     /**
115      * If there are faces enrolled and user enabled face auth on keyguard.
116      */
isFaceAuthEnabled()117     default boolean isFaceAuthEnabled() {
118         return false;
119     }
120 
121     /**
122      * If the animation that morphs a notification into an app window is playing.
123      */
isLaunchTransitionFadingAway()124     boolean isLaunchTransitionFadingAway();
125 
126     /**
127      * How long the keyguard dismissal animation should take when unlocking.
128      */
getKeyguardFadingAwayDuration()129     long getKeyguardFadingAwayDuration();
130 
131     /**
132      * Delay for {@link #getKeyguardFadingAwayDuration()}.
133      */
getKeyguardFadingAwayDelay()134     long getKeyguardFadingAwayDelay();
135 
136     /**
137      * Delay when going from {@link StatusBarState#KEYGUARD} to {@link StatusBarState#SHADE} or
138      * {@link StatusBarState#SHADE_LOCKED}.
139      */
calculateGoingToFullShadeDelay()140     long calculateGoingToFullShadeDelay();
141 
142     /** **/
setLaunchTransitionFadingAway(boolean b)143     default void setLaunchTransitionFadingAway(boolean b) {}
144     /** **/
notifyKeyguardGoingAway(boolean b)145     default void notifyKeyguardGoingAway(boolean b) {}
146     /** **/
notifyKeyguardDoneFading()147     default void notifyKeyguardDoneFading() {}
148     /** **/
notifyKeyguardState(boolean showing, boolean occluded)149     default void notifyKeyguardState(boolean showing, boolean occluded) {}
150 
151     /**
152      * Callback for authentication events.
153      */
154     interface Callback {
155         /**
156          * Called when the locked state of the device changes. The lock screen might still be
157          * showing on some cases, like when a {@link android.service.trust.TrustAgentService} is
158          * active, or face auth was triggered but the user didn't swipe up to dismiss the lock
159          * screen yet.
160          */
onUnlockedChanged()161         default void onUnlockedChanged() {}
162 
163         /**
164          * If the lock screen is active or not. This is different from being locked, since the lock
165          * screen can be visible but unlocked by {@link android.service.trust.TrustAgentService} or
166          * face unlock.
167          *
168          * @see #isShowing()
169          */
onKeyguardShowingChanged()170         default void onKeyguardShowingChanged() {}
171 
172         /**
173          * Triggered when the device was just unlocked and the lock screen is being dismissed.
174          */
onKeyguardFadingAwayChanged()175         default void onKeyguardFadingAwayChanged() {}
176     }
177 }
178