1 /*
2  * Copyright (C) 2020 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.keyguard;
18 
19 import android.os.Bundle;
20 import android.view.View;
21 import android.view.ViewRootImpl;
22 
23 import androidx.annotation.Nullable;
24 
25 import com.android.systemui.keyguard.KeyguardViewMediator;
26 import com.android.systemui.statusbar.phone.BiometricUnlockController;
27 import com.android.systemui.statusbar.phone.KeyguardBypassController;
28 import com.android.systemui.statusbar.phone.NotificationPanelViewController;
29 import com.android.systemui.statusbar.phone.StatusBar;
30 import com.android.systemui.statusbar.phone.panelstate.PanelExpansionStateManager;
31 
32 /**
33  *  Interface to control Keyguard View. It should be implemented by KeyguardViewManagers, which
34  *  should, in turn, be injected into {@link KeyguardViewMediator}.
35  */
36 public interface KeyguardViewController {
37     /**
38      * Shows Keyguard.
39      * @param options
40      */
show(Bundle options)41     void show(Bundle options);
42 
43     /**
44      * Hides Keyguard with the fade-out animation as configured by the parameters provided.
45      *
46      * @param startTime
47      * @param fadeoutDuration
48      */
hide(long startTime, long fadeoutDuration)49     void hide(long startTime, long fadeoutDuration);
50 
51     /**
52      * Resets the state of Keyguard View.
53      * @param hideBouncerWhenShowing
54      */
reset(boolean hideBouncerWhenShowing)55     void reset(boolean hideBouncerWhenShowing);
56 
57     /**
58      * Called when the device started going to sleep.
59      */
onStartedGoingToSleep()60     default void onStartedGoingToSleep() {};
61 
62     /**
63      * Called when the device has finished going to sleep.
64      */
onFinishedGoingToSleep()65     default void onFinishedGoingToSleep() {};
66 
67     /**
68      * Called when the device started waking up.
69      */
onStartedWakingUp()70     default void onStartedWakingUp() {};
71 
72     /**
73      * Called when the device started turning on.
74      */
onScreenTurningOn()75     default void onScreenTurningOn() {};
76 
77     /**
78      * Called when the device has finished turning on.
79      */
onScreenTurnedOn()80     default void onScreenTurnedOn() {};
81 
82     /**
83      * Sets whether the Keyguard needs input.
84      * @param needsInput
85      */
setNeedsInput(boolean needsInput)86     void setNeedsInput(boolean needsInput);
87 
88     /**
89      * Called when cancel button in bouncer is pressed.
90      */
onCancelClicked()91     void onCancelClicked();
92 
93     /**
94      * Sets whether the keyguard is occluded by another window.
95      *
96      * @param occluded
97      * @param animate
98      */
setOccluded(boolean occluded, boolean animate)99     void setOccluded(boolean occluded, boolean animate);
100 
101     /**
102      * @return Whether the keyguard is showing
103      */
isShowing()104     boolean isShowing();
105 
106     /**
107      * Dismisses the keyguard by going to the next screen or making it gone.
108      */
dismissAndCollapse()109     void dismissAndCollapse();
110 
111     /**
112      * Notifies that Keyguard is just about to go away.
113      */
keyguardGoingAway()114     void keyguardGoingAway();
115 
116     /**
117      * Sets the system state depending on whether the keyguard is going away or not.
118      */
setKeyguardGoingAwayState(boolean isKeyguardGoingAway)119     void setKeyguardGoingAwayState(boolean isKeyguardGoingAway);
120 
121     /**
122      * @return Whether window animation for unlock should be disabled.
123      */
shouldDisableWindowAnimationsForUnlock()124     boolean shouldDisableWindowAnimationsForUnlock();
125 
126     /**
127      * @return Whether the keyguard is going to notification shade.
128      */
isGoingToNotificationShade()129     boolean isGoingToNotificationShade();
130 
131     /**
132      * @return Whether subtle animation should be used for unlocking the device.
133      */
isUnlockWithWallpaper()134     boolean isUnlockWithWallpaper();
135 
136     /**
137      * @return Whether subtle animation should be used for unlocking the device.
138      */
shouldSubtleWindowAnimationsForUnlock()139     boolean shouldSubtleWindowAnimationsForUnlock();
140 
141     /**
142      * Starts the animation before we dismiss Keyguard, i.e. an disappearing animation on the
143      * security view of the bouncer.
144      *
145      * @param finishRunnable the runnable to be run after the animation finished, or {@code null} if
146      *                       no action should be run
147      */
startPreHideAnimation(Runnable finishRunnable)148     void startPreHideAnimation(Runnable finishRunnable);
149 
150     /**
151      * Blocks the current touch gesture from affecting the expansion amount of the notification
152      * panel. This is used after a completed unlock gesture to ignore further dragging before an
153      * ACTION_UP.
154      */
blockPanelExpansionFromCurrentTouch()155     void blockPanelExpansionFromCurrentTouch();
156 
157     /**
158      * @return the ViewRootImpl of the View where the Keyguard is mounted.
159      */
getViewRootImpl()160     ViewRootImpl getViewRootImpl();
161 
162     /**
163      * Notifies that the user has authenticated by other means than using the bouncer, for example,
164      * fingerprint.
165      */
notifyKeyguardAuthenticated(boolean strongAuth)166     void notifyKeyguardAuthenticated(boolean strongAuth);
167 
168     /**
169      * Shows the Bouncer.
170      *
171      */
showBouncer(boolean scrimmed)172     void showBouncer(boolean scrimmed);
173 
174     /**
175      * Returns {@code true} when the bouncer is currently showing
176      */
isBouncerShowing()177     boolean isBouncerShowing();
178 
179     /**
180      * When bouncer is fully visible or it is showing but animation didn't finish yet.
181      */
bouncerIsOrWillBeShowing()182     boolean bouncerIsOrWillBeShowing();
183 
184     // TODO: Deprecate registerStatusBar in KeyguardViewController interface. It is currently
185     //  only used for testing purposes in StatusBarKeyguardViewManager, and it prevents us from
186     //  achieving complete abstraction away from where the Keyguard View is mounted.
187 
188     /**
189      * Registers the StatusBar to which this Keyguard View is mounted.
190      */
registerStatusBar(StatusBar statusBar, NotificationPanelViewController notificationPanelViewController, @Nullable PanelExpansionStateManager panelExpansionStateManager, BiometricUnlockController biometricUnlockController, View notificationContainer, KeyguardBypassController bypassController)191     void registerStatusBar(StatusBar statusBar,
192             NotificationPanelViewController notificationPanelViewController,
193             @Nullable PanelExpansionStateManager panelExpansionStateManager,
194             BiometricUnlockController biometricUnlockController,
195             View notificationContainer,
196             KeyguardBypassController bypassController);
197 }
198