1 /*
2  * Copyright (C) 2019 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.biometrics;
18 
19 import android.annotation.IntDef;
20 import android.annotation.NonNull;
21 import android.annotation.Nullable;
22 import android.os.Bundle;
23 import android.view.WindowManager;
24 
25 import java.lang.annotation.Retention;
26 import java.lang.annotation.RetentionPolicy;
27 
28 /**
29  * Interface for the biometric dialog UI.
30  */
31 public interface AuthDialog {
32 
33     String KEY_CONTAINER_STATE = "container_state";
34     String KEY_BIOMETRIC_SHOWING = "biometric_showing";
35     String KEY_CREDENTIAL_SHOWING = "credential_showing";
36 
37     String KEY_BIOMETRIC_TRY_AGAIN_VISIBILITY = "try_agian_visibility";
38     String KEY_BIOMETRIC_STATE = "state";
39     String KEY_BIOMETRIC_INDICATOR_STRING = "indicator_string"; // error / help / hint
40     String KEY_BIOMETRIC_INDICATOR_ERROR_SHOWING = "error_is_temporary";
41     String KEY_BIOMETRIC_INDICATOR_HELP_SHOWING = "hint_is_temporary";
42     String KEY_BIOMETRIC_DIALOG_SIZE = "size";
43 
44     int SIZE_UNKNOWN = 0;
45     /**
46      * Minimal UI, showing only biometric icon.
47      */
48     int SIZE_SMALL = 1;
49     /**
50      * Normal-sized biometric UI, showing title, icon, buttons, etc.
51      */
52     int SIZE_MEDIUM = 2;
53     /**
54      * Full-screen credential UI.
55      */
56     int SIZE_LARGE = 3;
57     @Retention(RetentionPolicy.SOURCE)
58     @IntDef({SIZE_UNKNOWN, SIZE_SMALL, SIZE_MEDIUM, SIZE_LARGE})
59     @interface DialogSize {}
60 
61     /**
62      * Animation duration, from small to medium dialog, including back panel, icon translation, etc
63      */
64     int ANIMATE_SMALL_TO_MEDIUM_DURATION_MS = 150;
65     /**
66      * Animation duration from medium to large dialog, including biometric fade out, back panel, etc
67      */
68     int ANIMATE_MEDIUM_TO_LARGE_DURATION_MS = 450;
69     /**
70      * Delay before notifying {@link AuthCredentialView} to start animating in.
71      */
72     int ANIMATE_CREDENTIAL_START_DELAY_MS = ANIMATE_MEDIUM_TO_LARGE_DURATION_MS * 2 / 3;
73     /**
74      * Animation duration when sliding in credential UI
75      */
76     int ANIMATE_CREDENTIAL_INITIAL_DURATION_MS = 150;
77 
78     /**
79      * Show the dialog.
80      * @param wm
81      */
show(WindowManager wm, @Nullable Bundle savedState)82     void show(WindowManager wm, @Nullable Bundle savedState);
83 
84     /**
85      * Dismiss the dialog without sending a callback.
86      */
dismissWithoutCallback(boolean animate)87     void dismissWithoutCallback(boolean animate);
88 
89     /**
90      * Dismiss the dialog. Animate away.
91      */
dismissFromSystemServer()92     void dismissFromSystemServer();
93 
94     /**
95      * Biometric authenticated. May be pending user confirmation, or completed.
96      */
onAuthenticationSucceeded()97     void onAuthenticationSucceeded();
98 
99     /**
100      * Authentication failed (reject, timeout). Dialog stays showing.
101      * @param failureReason
102      */
onAuthenticationFailed(String failureReason)103     void onAuthenticationFailed(String failureReason);
104 
105     /**
106      * Authentication rejected, or help message received.
107      * @param help
108      */
onHelp(String help)109     void onHelp(String help);
110 
111     /**
112      * Authentication failed. Dialog going away.
113      * @param error
114      */
onError(String error)115     void onError(String error);
116 
117     /**
118      * Save the current state.
119      * @param outState
120      */
onSaveState(@onNull Bundle outState)121     void onSaveState(@NonNull Bundle outState);
122 
123     /**
124      * Get the client's package name
125      */
getOpPackageName()126     String getOpPackageName();
127 
128     /**
129      * Animate to credential UI. Typically called after biometric is locked out.
130      */
animateToCredentialUI()131     void animateToCredentialUI();
132 
133     /**
134      * @return true if device credential is allowed.
135      */
isAllowDeviceCredentials()136     boolean isAllowDeviceCredentials();
137 }
138