1 /*
2  * Copyright (C) 2012 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 package com.android.keyguard;
17 
18 import android.content.res.ColorStateList;
19 import android.view.MotionEvent;
20 
21 import com.android.internal.widget.LockPatternUtils;
22 
23 public interface KeyguardSecurityView {
24     static public final int SCREEN_ON = 1;
25     static public final int VIEW_REVEALED = 2;
26 
27     int PROMPT_REASON_NONE = 0;
28 
29     /**
30      * Strong auth is required because the device has just booted.
31      */
32     int PROMPT_REASON_RESTART = 1;
33 
34     /**
35      * Strong auth is required because the user hasn't used strong auth since a while.
36      */
37     int PROMPT_REASON_TIMEOUT = 2;
38 
39     /**
40      * Strong auth is required because a device admin requested it.
41      */
42     int PROMPT_REASON_DEVICE_ADMIN = 3;
43 
44     /**
45      * Some auth is required because the user force locked.
46      */
47     int PROMPT_REASON_USER_REQUEST = 4;
48 
49     /**
50      * Some auth is required because too many wrong credentials led to a lockout.
51      */
52     int PROMPT_REASON_AFTER_LOCKOUT = 5;
53 
54     /***
55      * Strong auth is require to prepare for an unattended update.
56      */
57     int PROMPT_REASON_PREPARE_FOR_UPDATE = 6;
58 
59     /**
60      * Primary auth is required because the user uses weak/convenience biometrics and hasn't used
61      * primary auth since a while
62      */
63     int PROMPT_REASON_NON_STRONG_BIOMETRIC_TIMEOUT = 7;
64 
65     /**
66      * Interface back to keyguard to tell it when security
67      * @param callback
68      */
setKeyguardCallback(KeyguardSecurityCallback callback)69     void setKeyguardCallback(KeyguardSecurityCallback callback);
70 
71     /**
72      * Set {@link LockPatternUtils} object. Useful for providing a mock interface.
73      * @param utils
74      */
setLockPatternUtils(LockPatternUtils utils)75     void setLockPatternUtils(LockPatternUtils utils);
76 
77     /**
78      * Reset the view and prepare to take input. This should do things like clearing the
79      * password or pattern and clear error messages.
80      */
reset()81     void reset();
82 
83     /**
84      * Emulate activity life cycle within the view. When called, the view should clean up
85      * and prepare to be removed.
86      */
onPause()87     void onPause();
88 
89     /**
90      * Emulate activity life cycle within this view.  When called, the view should prepare itself
91      * to be shown.
92      * @param reason the root cause of the event.
93      */
onResume(int reason)94     void onResume(int reason);
95 
96     /**
97      * Inquire whether this view requires IME (keyboard) interaction.
98      *
99      * @return true if IME interaction is required.
100      */
needsInput()101     boolean needsInput();
102 
103     /**
104      * Get {@link KeyguardSecurityCallback} for the given object
105      * @return KeyguardSecurityCallback
106      */
getCallback()107     KeyguardSecurityCallback getCallback();
108 
109     /**
110      * Show a string explaining why the security view needs to be solved.
111      *
112      * @param reason a flag indicating which string should be shown, see {@link #PROMPT_REASON_NONE}
113      *               and {@link #PROMPT_REASON_RESTART}
114      */
showPromptReason(int reason)115     void showPromptReason(int reason);
116 
117     /**
118      * Show a message on the security view with a specified color
119      *
120      * @param message the message to show
121      * @param colorState the color to use
122      */
showMessage(CharSequence message, ColorStateList colorState)123     void showMessage(CharSequence message, ColorStateList colorState);
124 
125     /**
126      * Instruct the view to show usability hints, if any.
127      *
128      */
showUsabilityHint()129     void showUsabilityHint();
130 
131     /**
132      * Starts the animation which should run when the security view appears.
133      */
startAppearAnimation()134     void startAppearAnimation();
135 
136     /**
137      * Starts the animation which should run when the security view disappears.
138      *
139      * @param finishRunnable the runnable to be run when the animation ended
140      * @return true if an animation started and {@code finishRunnable} will be run, false if no
141      *         animation started and {@code finishRunnable} will not be run
142      */
startDisappearAnimation(Runnable finishRunnable)143     boolean startDisappearAnimation(Runnable finishRunnable);
144 
145     /**
146      * The localized name of the security view, provided to accessibility. This may be the content
147      * description, but content descriptions have other implications, so the title is kept separate.
148      *
149      * @return The View's title.
150      */
getTitle()151     CharSequence getTitle();
152 
153     /**
154      * If the parent should not be allowed to intercept touch events.
155      * @param event A touch event.
156      * @return {@code true} if touch should be passed forward.
157      * @see android.view.ViewGroup#requestDisallowInterceptTouchEvent(boolean)
158      */
disallowInterceptTouch(MotionEvent event)159     default boolean disallowInterceptTouch(MotionEvent event) {
160         return false;
161     }
162 
163     /**
164      * When bouncer was visible but is being dragged down or dismissed.
165      */
onStartingToHide()166     default void onStartingToHide() {};
167 }
168