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      * A power press stopped this biometric operation.
161      * @hide
162      */
163     int BIOMETRIC_ERROR_POWER_PRESSED = 19;
164     /**
165      * This constant is only used by SystemUI. It notifies SystemUI that authentication was paused
166      * because the authentication attempt was unsuccessful.
167      * @hide
168      */
169     int BIOMETRIC_PAUSED_REJECTED = 100;
170 
171     /**
172      * @hide
173      */
174     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
175     int BIOMETRIC_ERROR_VENDOR_BASE = 1000;
176 
177     @IntDef({BIOMETRIC_SUCCESS,
178             BIOMETRIC_ERROR_HW_UNAVAILABLE,
179             BIOMETRIC_ERROR_UNABLE_TO_PROCESS,
180             BIOMETRIC_ERROR_TIMEOUT,
181             BIOMETRIC_ERROR_NO_SPACE,
182             BIOMETRIC_ERROR_CANCELED,
183             BIOMETRIC_ERROR_UNABLE_TO_REMOVE,
184             BIOMETRIC_ERROR_LOCKOUT,
185             BIOMETRIC_ERROR_VENDOR,
186             BIOMETRIC_ERROR_LOCKOUT_PERMANENT,
187             BIOMETRIC_ERROR_USER_CANCELED,
188             BIOMETRIC_ERROR_NO_BIOMETRICS,
189             BIOMETRIC_ERROR_HW_NOT_PRESENT,
190             BIOMETRIC_ERROR_NEGATIVE_BUTTON,
191             BIOMETRIC_ERROR_NO_DEVICE_CREDENTIAL,
192             BIOMETRIC_ERROR_SECURITY_UPDATE_REQUIRED,
193             BIOMETRIC_PAUSED_REJECTED})
194     @Retention(RetentionPolicy.SOURCE)
195     @interface Errors {}
196 
197     //
198     // Image acquisition messages.
199     //
200 
201     /**
202      * @hide
203      */
204     @IntDef({BIOMETRIC_ACQUIRED_GOOD,
205             BIOMETRIC_ACQUIRED_PARTIAL,
206             BIOMETRIC_ACQUIRED_INSUFFICIENT,
207             BIOMETRIC_ACQUIRED_IMAGER_DIRTY,
208             BIOMETRIC_ACQUIRED_TOO_SLOW,
209             BIOMETRIC_ACQUIRED_TOO_FAST,
210             BIOMETRIC_ACQUIRED_VENDOR})
211     @Retention(RetentionPolicy.SOURCE)
212     @interface Acquired {}
213 
214     /**
215      * The image acquired was good.
216      */
217     int BIOMETRIC_ACQUIRED_GOOD = 0;
218 
219     /**
220      * Only a partial biometric image was detected. During enrollment, the user should be informed
221      * on what needs to happen to resolve this problem, e.g. "press firmly on sensor." (for
222      * fingerprint)
223      */
224     int BIOMETRIC_ACQUIRED_PARTIAL = 1;
225 
226     /**
227      * The biometric image was too noisy to process due to a detected condition or a possibly dirty
228      * sensor (See {@link #BIOMETRIC_ACQUIRED_IMAGER_DIRTY}).
229      */
230     int BIOMETRIC_ACQUIRED_INSUFFICIENT = 2;
231 
232     /**
233      * The biometric image was too noisy due to suspected or detected dirt on the sensor.  For
234      * example, it's reasonable return this after multiple {@link #BIOMETRIC_ACQUIRED_INSUFFICIENT}
235      * or actual detection of dirt on the sensor (stuck pixels, swaths, etc.). The user is expected
236      * to take action to clean the sensor when this is returned.
237      */
238     int BIOMETRIC_ACQUIRED_IMAGER_DIRTY = 3;
239 
240     /**
241      * The biometric image was unreadable due to lack of motion.
242      */
243     int BIOMETRIC_ACQUIRED_TOO_SLOW = 4;
244 
245     /**
246      * The biometric image was incomplete due to quick motion. For example, this could also happen
247      * if the user moved during acquisition. The user should be asked to repeat the operation more
248      * slowly.
249      */
250     int BIOMETRIC_ACQUIRED_TOO_FAST = 5;
251 
252     /**
253      * Hardware vendors may extend this list if there are conditions that do not fall under one of
254      * the above categories. Vendors are responsible for providing error strings for these errors.
255      * @hide
256      */
257     int BIOMETRIC_ACQUIRED_VENDOR = 6;
258     /**
259      * @hide
260      */
261     int BIOMETRIC_ACQUIRED_VENDOR_BASE = 1000;
262 
263     //
264     // Internal messages.
265     //
266 
267     /**
268      * See {@link BiometricPrompt.Builder#setReceiveSystemEvents(boolean)}. This message is sent
269      * immediately when the user cancels authentication for example by tapping the back button or
270      * tapping the scrim. This is before {@link #BIOMETRIC_ERROR_USER_CANCELED}, which is sent when
271      * dismissal animation completes.
272      * @hide
273      */
274     int BIOMETRIC_SYSTEM_EVENT_EARLY_USER_CANCEL = 1;
275 
276     /**
277      * No lockout.
278      * @hide
279      */
280     int BIOMETRIC_LOCKOUT_NONE = 0;
281     /**
282      * The biometric is in a temporary lockout state that will expire after some time.
283      * @hide
284      */
285     int BIOMETRIC_LOCKOUT_TIMED = 1;
286     /**
287      * The biometric is locked out until a reset occurs. Resets are typically triggered by
288      * successfully authenticating via a stronger method than the one that is locked out.
289      * @hide
290      */
291     int BIOMETRIC_LOCKOUT_PERMANENT = 2;
292 
293     /**
294      * @hide
295      */
296     @Retention(RetentionPolicy.SOURCE)
297     @IntDef({BIOMETRIC_LOCKOUT_NONE, BIOMETRIC_LOCKOUT_TIMED, BIOMETRIC_LOCKOUT_PERMANENT})
298     @interface LockoutMode {}
299 }
300