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