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 * Whether we can currently perform the shared element SmartSpace transition. This is true if 54 * we're on the lockscreen, it can be dismissed with a swipe, and the Launcher is underneath the 55 * keyguard and displaying a SmartSpace that it has registered with System UI. 56 */ canPerformSmartSpaceTransition()57 boolean canPerformSmartSpaceTransition(); 58 59 /** 60 * Whether the keyguard is allowed to rotate, or needs to be locked to the default orientation. 61 */ isKeyguardScreenRotationAllowed()62 boolean isKeyguardScreenRotationAllowed(); 63 64 /** 65 * If the device has PIN/pattern/password or a lock screen at all. 66 */ isMethodSecure()67 boolean isMethodSecure(); 68 69 /** 70 * When there's an {@link android.app.Activity} on top of the keyguard, where 71 * {@link android.app.Activity#setShowWhenLocked(boolean)} is true. 72 */ isOccluded()73 boolean isOccluded(); 74 75 /** 76 * If a {@link android.service.trust.TrustAgentService} is keeping the device unlocked. 77 * {@link #canDismissLockScreen()} is better source of truth that also considers this state. 78 */ isTrusted()79 boolean isTrusted(); 80 81 /** 82 * If the keyguard dismissal animation is running. 83 * @see #isKeyguardGoingAway() 84 */ isKeyguardFadingAway()85 boolean isKeyguardFadingAway(); 86 87 /** 88 * When the keyguard challenge was successfully solved, and {@link android.app.ActivityManager} 89 * is launching the activity that will be revealed. 90 * 91 * This also includes the animation of the keyguard being dismissed, meaning that this will 92 * return {@code true} whenever {@link #isKeyguardFadingAway()} also returns {@code true}. 93 */ isKeyguardGoingAway()94 boolean isKeyguardGoingAway(); 95 96 /** 97 * @return a shortened fading away duration similar to 98 * {{@link #getKeyguardFadingAwayDuration()}} which may only span half of the duration, unless 99 * we're bypassing 100 */ getShortenedFadingAwayDuration()101 default long getShortenedFadingAwayDuration() { 102 if (isBypassFadingAnimation()) { 103 return getKeyguardFadingAwayDuration(); 104 } else { 105 return getKeyguardFadingAwayDuration() / 2; 106 } 107 } 108 109 /** 110 * @return {@code true} if the current fading away animation is the fast bypass fading. 111 */ isBypassFadingAnimation()112 default boolean isBypassFadingAnimation() { 113 return false; 114 } 115 116 /** 117 * Notifies that the Keyguard is fading away with the specified timings. 118 * @param delay the precalculated animation delay in milliseconds 119 * @param fadeoutDuration the duration of the exit animation, in milliseconds 120 * @param isBypassFading is this a fading away animation while bypassing 121 */ notifyKeyguardFadingAway(long delay, long fadeoutDuration, boolean isBypassFading)122 default void notifyKeyguardFadingAway(long delay, long fadeoutDuration, 123 boolean isBypassFading) { 124 } 125 126 /** 127 * If there are faces enrolled and user enabled face auth on keyguard. 128 */ isFaceAuthEnabled()129 default boolean isFaceAuthEnabled() { 130 return false; 131 } 132 133 /** 134 * If the animation that morphs a notification into an app window is playing. 135 */ isLaunchTransitionFadingAway()136 boolean isLaunchTransitionFadingAway(); 137 138 /** 139 * How long the keyguard dismissal animation should take when unlocking. 140 */ getKeyguardFadingAwayDuration()141 long getKeyguardFadingAwayDuration(); 142 143 /** 144 * Delay for {@link #getKeyguardFadingAwayDuration()}. 145 */ getKeyguardFadingAwayDelay()146 long getKeyguardFadingAwayDelay(); 147 148 /** 149 * Delay when going from {@link StatusBarState#KEYGUARD} to {@link StatusBarState#SHADE} or 150 * {@link StatusBarState#SHADE_LOCKED}. 151 */ calculateGoingToFullShadeDelay()152 long calculateGoingToFullShadeDelay(); 153 154 /** 155 * How much (from 0f to 1f) the keyguard is dismissed, either via a swipe gesture or an 156 * animation. 157 */ getDismissAmount()158 float getDismissAmount(); 159 160 /** 161 * Whether the keyguard is being dismissed due to direct user input, rather than a canned 162 * animation. 163 */ isDismissingFromSwipe()164 boolean isDismissingFromSwipe(); 165 166 /** 167 * Whether a fling animation is currently playing on the keyguard, either to dismiss it or to 168 * cancel dismissing it. 169 */ isFlingingToDismissKeyguard()170 boolean isFlingingToDismissKeyguard(); 171 172 /** 173 * Whether a fling animation is currently playing on the keyguard, either to dismiss it or to 174 * cancel dismissing it, and that animation started during a swipe gesture. Fling animations 175 * can also be started without a swipe (e.g. activity launch from lock screen notification), so 176 * this is a way to tell them apart for animation purposes. 177 */ isFlingingToDismissKeyguardDuringSwipeGesture()178 boolean isFlingingToDismissKeyguardDuringSwipeGesture(); 179 180 /** 181 * Whether a fling animation is currently playing on the keyguard to cancel dismissing it, after 182 * the user released their finger during a swipe gesture. 183 */ isSnappingKeyguardBackAfterSwipe()184 boolean isSnappingKeyguardBackAfterSwipe(); 185 186 /** **/ setLaunchTransitionFadingAway(boolean b)187 default void setLaunchTransitionFadingAway(boolean b) {} 188 /** **/ notifyKeyguardGoingAway(boolean b)189 default void notifyKeyguardGoingAway(boolean b) {} 190 /** **/ notifyKeyguardDoneFading()191 default void notifyKeyguardDoneFading() {} 192 /** **/ notifyKeyguardState(boolean showing, boolean occluded)193 default void notifyKeyguardState(boolean showing, boolean occluded) {} 194 195 /** 196 * Updates the keyguard state to reflect that it's in the process of being dismissed, either by 197 * a swipe gesture on the lock screen or by a canned animation. 198 * 199 * @param dismissAmount 0f means we're not dismissed at all, 1f means we have been completely 200 * swiped away. 201 * @param dismissingFromTouch True if this change was caused by direct user interaction, false 202 * if it's due to an animation. 203 */ notifyKeyguardDismissAmountChanged( float dismissAmount, boolean dismissingFromTouch)204 default void notifyKeyguardDismissAmountChanged( 205 float dismissAmount, boolean dismissingFromTouch) {} 206 207 /** 208 * Updates the keyguard state to reflect that a dismiss fling gesture has started. 209 * 210 * @param dismiss Whether we're flinging to dismiss (upward) or to cancel a dismiss gesture. 211 */ notifyPanelFlingStart(boolean dismiss)212 void notifyPanelFlingStart(boolean dismiss); 213 214 /** Updates the keyguard state to reflect that a dismiss fling gesture has ended. */ notifyPanelFlingEnd()215 void notifyPanelFlingEnd(); 216 217 /** 218 * Callback for authentication events. 219 */ 220 interface Callback { 221 /** 222 * Called when the locked state of the device changes. The lock screen might still be 223 * showing on some cases, like when a {@link android.service.trust.TrustAgentService} is 224 * active, or face auth was triggered but the user didn't swipe up to dismiss the lock 225 * screen yet. 226 */ onUnlockedChanged()227 default void onUnlockedChanged() {} 228 229 /** 230 * If the lock screen is active or not. This is different from being locked, since the lock 231 * screen can be visible but unlocked by {@link android.service.trust.TrustAgentService} or 232 * face unlock. 233 * 234 * @see #isShowing() 235 */ onKeyguardShowingChanged()236 default void onKeyguardShowingChanged() {} 237 238 /** 239 * Triggered when the device was just unlocked and the lock screen is being dismissed. 240 */ onKeyguardFadingAwayChanged()241 default void onKeyguardFadingAwayChanged() {} 242 243 /** 244 * Triggered when the keyguard dismiss amount has changed, via either a swipe gesture or an 245 * animation. 246 */ onKeyguardDismissAmountChanged()247 default void onKeyguardDismissAmountChanged() {} 248 249 /** 250 * Triggered when face auth becomes available or unavailable. Value should be queried with 251 * {@link KeyguardStateController#isFaceAuthEnabled()}. 252 */ onFaceAuthEnabledChanged()253 default void onFaceAuthEnabledChanged() {} 254 255 /** 256 * Triggered when the notification panel is starting or has finished 257 * fading away on transition to an app. 258 */ onLaunchTransitionFadingAwayChanged()259 default void onLaunchTransitionFadingAwayChanged() {} 260 } 261 } 262