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 android.app.IActivityTaskManager; 20 21 import com.android.systemui.Dumpable; 22 import com.android.systemui.statusbar.StatusBarState; 23 import com.android.systemui.statusbar.policy.KeyguardStateController.Callback; 24 25 import java.io.PrintWriter; 26 27 /** 28 * Source of truth for keyguard state: If locked, occluded, has password, trusted etc. 29 */ 30 public interface KeyguardStateController extends CallbackController<Callback>, Dumpable { 31 32 /** 33 * If the device is locked or unlocked. 34 */ isUnlocked()35 default boolean isUnlocked() { 36 return !isShowing() || canDismissLockScreen(); 37 } 38 39 /** 40 * If the keyguard is visible. This is unrelated to being locked or not. 41 */ isVisible()42 default boolean isVisible() { 43 return isShowing() && !isOccluded(); 44 } 45 dump(PrintWriter pw, String[] args)46 default void dump(PrintWriter pw, String[] args) { } 47 48 /** 49 * If the keyguard is showing. This includes when it's occluded by an activity, and when 50 * the device is asleep or in always on mode, except when the screen timed out and the user 51 * can unlock by quickly pressing power. 52 * 53 * This is unrelated to being locked or not. 54 * 55 * @see #isUnlocked() 56 * @see #canDismissLockScreen() 57 */ isShowing()58 boolean isShowing(); 59 60 /** 61 * Whether the bouncer (PIN/password entry) is currently visible. 62 */ isPrimaryBouncerShowing()63 boolean isPrimaryBouncerShowing(); 64 65 /** 66 * If swiping up will unlock without asking for a password. 67 * @see #isUnlocked() 68 */ canDismissLockScreen()69 boolean canDismissLockScreen(); 70 71 /** 72 * Whether the keyguard is allowed to rotate, or needs to be locked to the default orientation. 73 */ isKeyguardScreenRotationAllowed()74 boolean isKeyguardScreenRotationAllowed(); 75 76 /** 77 * If the device has PIN/pattern/password or a lock screen at all. 78 */ isMethodSecure()79 boolean isMethodSecure(); 80 81 /** 82 * When there's an {@link android.app.Activity} on top of the keyguard, where 83 * {@link android.app.Activity#setShowWhenLocked(boolean)} is true. 84 */ isOccluded()85 boolean isOccluded(); 86 87 /** 88 * If a {@link android.service.trust.TrustAgentService} is keeping the device unlocked. 89 * {@link #canDismissLockScreen()} is better source of truth that also considers this state. 90 */ isTrusted()91 boolean isTrusted(); 92 93 /** 94 * If the keyguard dismissal animation is running. 95 * @see #isKeyguardGoingAway() 96 */ isKeyguardFadingAway()97 boolean isKeyguardFadingAway(); 98 99 /** 100 * When the keyguard challenge was successfully solved, and {@link android.app.ActivityManager} 101 * is launching the activity that will be revealed. 102 * 103 * This also includes the animation of the keyguard being dismissed, meaning that this will 104 * return {@code true} whenever {@link #isKeyguardFadingAway()} also returns {@code true}. 105 */ isKeyguardGoingAway()106 boolean isKeyguardGoingAway(); 107 108 /** 109 * Whether we're currently animating between the keyguard and the app/launcher surface behind 110 * it, or will be shortly (which happens if we started a fling to dismiss the keyguard). 111 * @see {@link KeyguardViewMediator#isAnimatingBetweenKeyguardAndSurfaceBehind()} 112 */ isAnimatingBetweenKeyguardAndSurfaceBehind()113 default boolean isAnimatingBetweenKeyguardAndSurfaceBehind() { 114 return false; 115 }; 116 117 /** 118 * @return a shortened fading away duration similar to 119 * {{@link #getKeyguardFadingAwayDuration()}} which may only span half of the duration, unless 120 * we're bypassing 121 */ getShortenedFadingAwayDuration()122 default long getShortenedFadingAwayDuration() { 123 return getKeyguardFadingAwayDuration() / 2; 124 } 125 126 /** 127 * Notifies that the Keyguard is fading away with the specified timings. 128 * @param delay the precalculated animation delay in milliseconds 129 * @param fadeoutDuration the duration of the exit animation, in milliseconds 130 */ notifyKeyguardFadingAway(long delay, long fadeoutDuratio)131 default void notifyKeyguardFadingAway(long delay, long fadeoutDuratio) { 132 } 133 134 /** 135 * If there are faces enrolled and user enabled face auth on keyguard. 136 */ isFaceEnrolledAndEnabled()137 default boolean isFaceEnrolledAndEnabled() { 138 return false; 139 } 140 141 /** 142 * If the animation that morphs a notification into an app window is playing. 143 */ isLaunchTransitionFadingAway()144 boolean isLaunchTransitionFadingAway(); 145 146 /** 147 * How long the keyguard dismissal animation should take when unlocking. 148 */ getKeyguardFadingAwayDuration()149 long getKeyguardFadingAwayDuration(); 150 151 /** 152 * Delay for {@link #getKeyguardFadingAwayDuration()}. 153 */ getKeyguardFadingAwayDelay()154 long getKeyguardFadingAwayDelay(); 155 156 /** 157 * Delay when going from {@link StatusBarState#KEYGUARD} to {@link StatusBarState#SHADE} or 158 * {@link StatusBarState#SHADE_LOCKED}. 159 */ calculateGoingToFullShadeDelay()160 long calculateGoingToFullShadeDelay(); 161 162 /** 163 * How much (from 0f to 1f) the keyguard is dismissed, either via a swipe gesture or an 164 * animation. 165 */ getDismissAmount()166 float getDismissAmount(); 167 168 /** 169 * Whether the keyguard is being dismissed due to direct user input, rather than a canned 170 * animation. 171 */ isDismissingFromSwipe()172 boolean isDismissingFromSwipe(); 173 174 /** 175 * Whether a fling animation is currently playing on the keyguard, either to dismiss it or to 176 * cancel dismissing it. 177 */ isFlingingToDismissKeyguard()178 boolean isFlingingToDismissKeyguard(); 179 180 /** 181 * Whether a fling animation is currently playing on the keyguard, either to dismiss it or to 182 * cancel dismissing it, and that animation started during a swipe gesture. Fling animations 183 * can also be started without a swipe (e.g. activity launch from lock screen notification), so 184 * this is a way to tell them apart for animation purposes. 185 */ isFlingingToDismissKeyguardDuringSwipeGesture()186 boolean isFlingingToDismissKeyguardDuringSwipeGesture(); 187 188 /** 189 * Whether a fling animation is currently playing on the keyguard to cancel dismissing it, after 190 * the user released their finger during a swipe gesture. 191 */ isSnappingKeyguardBackAfterSwipe()192 boolean isSnappingKeyguardBackAfterSwipe(); 193 194 /** **/ setLaunchTransitionFadingAway(boolean b)195 default void setLaunchTransitionFadingAway(boolean b) {} 196 /** **/ notifyKeyguardGoingAway(boolean b)197 default void notifyKeyguardGoingAway(boolean b) {} 198 /** **/ notifyKeyguardDoneFading()199 default void notifyKeyguardDoneFading() {} 200 /** **/ notifyKeyguardState(boolean showing, boolean occluded)201 default void notifyKeyguardState(boolean showing, boolean occluded) {} 202 /** **/ notifyPrimaryBouncerShowing(boolean showing)203 default void notifyPrimaryBouncerShowing(boolean showing) {} 204 205 /** 206 * Updates the keyguard state to reflect that it's in the process of being dismissed, either by 207 * a swipe gesture on the lock screen or by a canned animation. 208 * 209 * @param dismissAmount 0f means we're not dismissed at all, 1f means we have been completely 210 * swiped away. 211 * @param dismissingFromTouch True if this change was caused by direct user interaction, false 212 * if it's due to an animation. 213 */ notifyKeyguardDismissAmountChanged( float dismissAmount, boolean dismissingFromTouch)214 default void notifyKeyguardDismissAmountChanged( 215 float dismissAmount, boolean dismissingFromTouch) {} 216 217 /** 218 * Updates the keyguard state to reflect that a dismiss fling gesture has started. 219 * 220 * @param dismiss Whether we're flinging to dismiss (upward) or to cancel a dismiss gesture. 221 */ notifyPanelFlingStart(boolean dismiss)222 void notifyPanelFlingStart(boolean dismiss); 223 224 /** Updates the keyguard state to reflect that a dismiss fling gesture has ended. */ notifyPanelFlingEnd()225 void notifyPanelFlingEnd(); 226 227 /** 228 * Callback for authentication events. 229 */ 230 interface Callback { 231 /** 232 * Called when the locked state of the device changes. The lock screen might still be 233 * showing on some cases, like when a {@link android.service.trust.TrustAgentService} is 234 * active, or face auth was triggered but the user didn't swipe up to dismiss the lock 235 * screen yet. 236 */ onUnlockedChanged()237 default void onUnlockedChanged() {} 238 239 /** 240 * If the lock screen is active or not. This is different from being locked, since the lock 241 * screen can be visible but unlocked by {@link android.service.trust.TrustAgentService} or 242 * face unlock. 243 * 244 * @see #isShowing() 245 */ onKeyguardShowingChanged()246 default void onKeyguardShowingChanged() {} 247 248 /** 249 * Called when the bouncer (PIN/password entry) is shown or hidden. 250 */ onPrimaryBouncerShowingChanged()251 default void onPrimaryBouncerShowingChanged() {} 252 253 /** 254 * Triggered when the device was just unlocked and the lock screen is being dismissed. 255 */ onKeyguardFadingAwayChanged()256 default void onKeyguardFadingAwayChanged() {} 257 258 /** 259 * We've called {@link IActivityTaskManager#keyguardGoingAway}, which initiates the unlock 260 * sequence. 261 */ onKeyguardGoingAwayChanged()262 default void onKeyguardGoingAwayChanged() {} 263 264 /** 265 * Triggered when the keyguard dismiss amount has changed, via either a swipe gesture or an 266 * animation. 267 */ onKeyguardDismissAmountChanged()268 default void onKeyguardDismissAmountChanged() {} 269 270 /** 271 * Triggered when face auth becomes available or unavailable. Value should be queried with 272 * {@link KeyguardStateController#isFaceEnrolledAndEnabled()}. 273 */ onFaceEnrolledChanged()274 default void onFaceEnrolledChanged() {} 275 276 /** 277 * Triggered when the notification panel is starting or has finished 278 * fading away on transition to an app. 279 */ onLaunchTransitionFadingAwayChanged()280 default void onLaunchTransitionFadingAwayChanged() {} 281 } 282 } 283