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.shade.ShadeExpansionStateManager;
27 import com.android.systemui.shade.ShadeViewController;
28 import com.android.systemui.statusbar.phone.BiometricUnlockController;
29 import com.android.systemui.statusbar.phone.CentralSurfaces;
30 import com.android.systemui.statusbar.phone.KeyguardBypassController;
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 when true, hides the primary and alternate bouncers if showing.
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      * Sets whether the Keyguard needs input.
74      * @param needsInput
75      */
setNeedsInput(boolean needsInput)76     void setNeedsInput(boolean needsInput);
77 
78     /**
79      * Called when cancel button in bouncer is pressed.
80      */
onCancelClicked()81     void onCancelClicked();
82 
83     /**
84      * Sets whether the keyguard is occluded by another window.
85      *
86      * @param occluded
87      * @param animate
88      */
setOccluded(boolean occluded, boolean animate)89     void setOccluded(boolean occluded, boolean animate);
90 
91     /**
92      * Dismisses the keyguard by going to the next screen or making it gone.
93      */
dismissAndCollapse()94     void dismissAndCollapse();
95 
96     /**
97      * Notifies that Keyguard is just about to go away.
98      */
keyguardGoingAway()99     void keyguardGoingAway();
100 
101     /**
102      * Sets the system state depending on whether the keyguard is going away or not.
103      */
setKeyguardGoingAwayState(boolean isKeyguardGoingAway)104     void setKeyguardGoingAwayState(boolean isKeyguardGoingAway);
105 
106     /**
107      * @return Whether window animation for unlock should be disabled.
108      */
shouldDisableWindowAnimationsForUnlock()109     boolean shouldDisableWindowAnimationsForUnlock();
110 
111     /**
112      * @return Whether the keyguard is going to notification shade.
113      */
isGoingToNotificationShade()114     boolean isGoingToNotificationShade();
115 
116     /**
117      * @return Whether subtle animation should be used for unlocking the device.
118      */
isUnlockWithWallpaper()119     boolean isUnlockWithWallpaper();
120 
121     /**
122      * @return Whether the bouncer over dream is showing. Note that the bouncer over dream is
123      * handled independently of the rest of the notification panel. As a result, setting this state
124      * via {@link CentralSurfaces#setBouncerShowing(boolean)} leads to unintended side effects from
125      * states modified behind the dream.
126      */
isBouncerShowingOverDream()127     boolean isBouncerShowingOverDream();
128 
129     /**
130      * @return Whether subtle animation should be used for unlocking the device.
131      */
shouldSubtleWindowAnimationsForUnlock()132     boolean shouldSubtleWindowAnimationsForUnlock();
133 
134     /**
135      * Starts the animation before we dismiss Keyguard, i.e. an disappearing animation on the
136      * security view of the bouncer.
137      *
138      * @param finishRunnable the runnable to be run after the animation finished, or {@code null} if
139      *                       no action should be run
140      */
startPreHideAnimation(Runnable finishRunnable)141     void startPreHideAnimation(Runnable finishRunnable);
142 
143     /**
144      * Blocks the current touch gesture from affecting the expansion amount of the notification
145      * panel. This is used after a completed unlock gesture to ignore further dragging before an
146      * ACTION_UP.
147      */
blockPanelExpansionFromCurrentTouch()148     void blockPanelExpansionFromCurrentTouch();
149 
150     /**
151      * @return the ViewRootImpl of the View where the Keyguard is mounted.
152      */
getViewRootImpl()153     ViewRootImpl getViewRootImpl();
154 
155     /**
156      * Notifies that the user has authenticated by other means than using the bouncer, for example,
157      * fingerprint.
158      */
notifyKeyguardAuthenticated(boolean strongAuth)159     void notifyKeyguardAuthenticated(boolean strongAuth);
160 
161     /**
162      * Shows the primary bouncer.
163      */
showPrimaryBouncer(boolean scrimmed)164     void showPrimaryBouncer(boolean scrimmed);
165 
166     /**
167      * When the primary bouncer is fully visible or is showing but animation didn't finish yet.
168      */
primaryBouncerIsOrWillBeShowing()169     boolean primaryBouncerIsOrWillBeShowing();
170 
171     /**
172      * Returns {@code true} when the primary bouncer or alternate bouncer is currently showing
173      */
isBouncerShowing()174     boolean isBouncerShowing();
175 
176     /**
177      * Stop showing the alternate bouncer, if showing.
178      */
hideAlternateBouncer(boolean updateScrim)179     void hideAlternateBouncer(boolean updateScrim);
180 
181     // TODO: Deprecate registerStatusBar in KeyguardViewController interface. It is currently
182     //  only used for testing purposes in StatusBarKeyguardViewManager, and it prevents us from
183     //  achieving complete abstraction away from where the Keyguard View is mounted.
184 
185     /**
186      * Registers the CentralSurfaces to which this Keyguard View is mounted.
187      */
registerCentralSurfaces(CentralSurfaces centralSurfaces, ShadeViewController shadeViewController, @Nullable ShadeExpansionStateManager shadeExpansionStateManager, BiometricUnlockController biometricUnlockController, View notificationContainer, KeyguardBypassController bypassController)188     void registerCentralSurfaces(CentralSurfaces centralSurfaces,
189             ShadeViewController shadeViewController,
190             @Nullable ShadeExpansionStateManager shadeExpansionStateManager,
191             BiometricUnlockController biometricUnlockController,
192             View notificationContainer,
193             KeyguardBypassController bypassController);
194 }
195