1 /*
2  * Copyright (C) 2018 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 android.hardware.biometrics;
18 
19 import static android.hardware.biometrics.BiometricManager.Authenticators;
20 
21 import android.annotation.IntDef;
22 import android.compat.annotation.UnsupportedAppUsage;
23 import android.os.Build;
24 
25 import java.lang.annotation.Retention;
26 import java.lang.annotation.RetentionPolicy;
27 
28 /**
29  * Interface containing all of the biometric modality agnostic constants.
30  *
31  * NOTE: The error messages must be consistent between BiometricConstants, Biometric*Constants,
32  *       and the frameworks/support/biometric/.../BiometricConstants files.
33  *
34  * @hide
35  */
36 public interface BiometricConstants {
37     //
38     // Error messages from biometric hardware during initilization, enrollment, authentication or
39     // removal.
40     //
41 
42     /**
43      * This was not added here since it would update BiometricPrompt API. But, is used in
44      * BiometricManager.
45      * @hide
46      */
47     int BIOMETRIC_SUCCESS = 0;
48 
49     /**
50      * The hardware is unavailable. Try again later.
51      */
52     int BIOMETRIC_ERROR_HW_UNAVAILABLE = 1;
53 
54     /**
55      * Error state returned when the sensor was unable to process the current image.
56      */
57     int BIOMETRIC_ERROR_UNABLE_TO_PROCESS = 2;
58 
59     /**
60      * Error state returned when the current request has been running too long. This is intended to
61      * prevent programs from waiting for the biometric sensor indefinitely. The timeout is platform
62      * and sensor-specific, but is generally on the order of 30 seconds.
63      */
64     int BIOMETRIC_ERROR_TIMEOUT = 3;
65 
66     /**
67      * Error state returned for operations like enrollment; the operation cannot be completed
68      * because there's not enough storage remaining to complete the operation.
69      */
70     int BIOMETRIC_ERROR_NO_SPACE = 4;
71 
72     /**
73      * The operation was canceled because the biometric sensor is unavailable. For example, this may
74      * happen when the user is switched, the device is locked or another pending operation prevents
75      * or disables it.
76      */
77     int BIOMETRIC_ERROR_CANCELED = 5;
78 
79     /**
80      * The {@link BiometricManager#remove} call failed. Typically this will happen when the provided
81      * biometric id was incorrect.
82      *
83      * @hide
84      */
85     int BIOMETRIC_ERROR_UNABLE_TO_REMOVE = 6;
86 
87     /**
88      * The operation was canceled because the API is locked out due to too many attempts.
89      * This occurs after 5 failed attempts, and lasts for 30 seconds.
90      */
91     int BIOMETRIC_ERROR_LOCKOUT = 7;
92 
93     /**
94      * OEMs should use this constant if there are conditions that do not fit under any of the other
95      * publicly defined constants, and must provide appropriate strings for these
96      * errors to the {@link BiometricPrompt.AuthenticationCallback#onAuthenticationError(int,
97      * CharSequence)} callback. OEMs should expect that the error message will be shown to users.
98      */
99     int BIOMETRIC_ERROR_VENDOR = 8;
100 
101     /**
102      * The operation was canceled because BIOMETRIC_ERROR_LOCKOUT occurred too many times.
103      * Biometric authentication is disabled until the user unlocks with strong authentication
104      * (PIN/Pattern/Password)
105      */
106     int BIOMETRIC_ERROR_LOCKOUT_PERMANENT = 9;
107 
108     /**
109      * The user canceled the operation. Upon receiving this, applications should use alternate
110      * authentication (e.g. a password). The application should also provide the means to return to
111      * biometric authentication, such as a "use <biometric>" button.
112      */
113     int BIOMETRIC_ERROR_USER_CANCELED = 10;
114 
115     /**
116      * The user does not have any biometrics enrolled.
117      */
118     int BIOMETRIC_ERROR_NO_BIOMETRICS = 11;
119 
120     /**
121      * The device does not have a biometric sensor.
122      */
123     int BIOMETRIC_ERROR_HW_NOT_PRESENT = 12;
124 
125     /**
126      * The user pressed the negative button. This is a placeholder that is currently only used
127      * by the support library.
128      * @hide
129      */
130     int BIOMETRIC_ERROR_NEGATIVE_BUTTON = 13;
131 
132     /**
133      * The device does not have pin, pattern, or password set up. See
134      * {@link BiometricPrompt.Builder#setAllowedAuthenticators(int)},
135      * {@link Authenticators#DEVICE_CREDENTIAL}, and {@link BiometricManager#canAuthenticate(int)}.
136      */
137     int BIOMETRIC_ERROR_NO_DEVICE_CREDENTIAL = 14;
138 
139     /**
140      * A security vulnerability has been discovered and the sensor is unavailable until a
141      * security update has addressed this issue. This error can be received if for example,
142      * authentication was requested with {@link Authenticators#BIOMETRIC_STRONG}, but the
143      * sensor's strength can currently only meet {@link Authenticators#BIOMETRIC_WEAK}.
144      */
145     int BIOMETRIC_ERROR_SECURITY_UPDATE_REQUIRED = 15;
146 
147     /**
148      * Authentication cannot proceed because re-enrollment is required.
149      * @hide
150      */
151     int BIOMETRIC_ERROR_RE_ENROLL = 16;
152 
153     /**
154      * The privacy setting has been enabled and will block use of the sensor.
155      * @hide
156      */
157     int BIOMETRIC_ERROR_SENSOR_PRIVACY_ENABLED = 18;
158 
159     /**
160      * This constant is only used by SystemUI. It notifies SystemUI that authentication was paused
161      * because the authentication attempt was unsuccessful.
162      * @hide
163      */
164     int BIOMETRIC_PAUSED_REJECTED = 100;
165 
166     /**
167      * @hide
168      */
169     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
170     int BIOMETRIC_ERROR_VENDOR_BASE = 1000;
171 
172     @IntDef({BIOMETRIC_SUCCESS,
173             BIOMETRIC_ERROR_HW_UNAVAILABLE,
174             BIOMETRIC_ERROR_UNABLE_TO_PROCESS,
175             BIOMETRIC_ERROR_TIMEOUT,
176             BIOMETRIC_ERROR_NO_SPACE,
177             BIOMETRIC_ERROR_CANCELED,
178             BIOMETRIC_ERROR_UNABLE_TO_REMOVE,
179             BIOMETRIC_ERROR_LOCKOUT,
180             BIOMETRIC_ERROR_VENDOR,
181             BIOMETRIC_ERROR_LOCKOUT_PERMANENT,
182             BIOMETRIC_ERROR_USER_CANCELED,
183             BIOMETRIC_ERROR_NO_BIOMETRICS,
184             BIOMETRIC_ERROR_HW_NOT_PRESENT,
185             BIOMETRIC_ERROR_NEGATIVE_BUTTON,
186             BIOMETRIC_ERROR_NO_DEVICE_CREDENTIAL,
187             BIOMETRIC_ERROR_SECURITY_UPDATE_REQUIRED,
188             BIOMETRIC_PAUSED_REJECTED})
189     @Retention(RetentionPolicy.SOURCE)
190     @interface Errors {}
191 
192     //
193     // Image acquisition messages.
194     //
195 
196     /**
197      * @hide
198      */
199     @IntDef({BIOMETRIC_ACQUIRED_GOOD,
200             BIOMETRIC_ACQUIRED_PARTIAL,
201             BIOMETRIC_ACQUIRED_INSUFFICIENT,
202             BIOMETRIC_ACQUIRED_IMAGER_DIRTY,
203             BIOMETRIC_ACQUIRED_TOO_SLOW,
204             BIOMETRIC_ACQUIRED_TOO_FAST,
205             BIOMETRIC_ACQUIRED_VENDOR})
206     @Retention(RetentionPolicy.SOURCE)
207     @interface Acquired {}
208 
209     /**
210      * The image acquired was good.
211      */
212     int BIOMETRIC_ACQUIRED_GOOD = 0;
213 
214     /**
215      * Only a partial biometric image was detected. During enrollment, the user should be informed
216      * on what needs to happen to resolve this problem, e.g. "press firmly on sensor." (for
217      * fingerprint)
218      */
219     int BIOMETRIC_ACQUIRED_PARTIAL = 1;
220 
221     /**
222      * The biometric image was too noisy to process due to a detected condition or a possibly dirty
223      * sensor (See {@link #BIOMETRIC_ACQUIRED_IMAGER_DIRTY}).
224      */
225     int BIOMETRIC_ACQUIRED_INSUFFICIENT = 2;
226 
227     /**
228      * The biometric image was too noisy due to suspected or detected dirt on the sensor.  For
229      * example, it's reasonable return this after multiple {@link #BIOMETRIC_ACQUIRED_INSUFFICIENT}
230      * or actual detection of dirt on the sensor (stuck pixels, swaths, etc.). The user is expected
231      * to take action to clean the sensor when this is returned.
232      */
233     int BIOMETRIC_ACQUIRED_IMAGER_DIRTY = 3;
234 
235     /**
236      * The biometric image was unreadable due to lack of motion.
237      */
238     int BIOMETRIC_ACQUIRED_TOO_SLOW = 4;
239 
240     /**
241      * The biometric image was incomplete due to quick motion. For example, this could also happen
242      * if the user moved during acquisition. The user should be asked to repeat the operation more
243      * slowly.
244      */
245     int BIOMETRIC_ACQUIRED_TOO_FAST = 5;
246 
247     /**
248      * Hardware vendors may extend this list if there are conditions that do not fall under one of
249      * the above categories. Vendors are responsible for providing error strings for these errors.
250      * @hide
251      */
252     int BIOMETRIC_ACQUIRED_VENDOR = 6;
253     /**
254      * @hide
255      */
256     int BIOMETRIC_ACQUIRED_VENDOR_BASE = 1000;
257 
258     //
259     // Internal messages.
260     //
261 
262     /**
263      * See {@link BiometricPrompt.Builder#setReceiveSystemEvents(boolean)}. This message is sent
264      * immediately when the user cancels authentication for example by tapping the back button or
265      * tapping the scrim. This is before {@link #BIOMETRIC_ERROR_USER_CANCELED}, which is sent when
266      * dismissal animation completes.
267      * @hide
268      */
269     int BIOMETRIC_SYSTEM_EVENT_EARLY_USER_CANCEL = 1;
270 
271 }
272