1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.hardware.biometrics;
import android.annotation.IntDef;
import android.hardware.biometrics.BiometricPrompt.AuthenticationResultType;
import android.os.CancellationSignal;
import android.os.Parcelable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.concurrent.Executor;
/**
* This is the common interface that all biometric authentication classes should implement.
* @hide
*/
public interface BiometricAuthenticator {
/**
* No biometric methods or nothing has been enrolled.
* Move/expose these in BiometricPrompt if we ever want to allow applications to "denylist"
* modalities when calling authenticate().
* @hide
*/
int TYPE_NONE = 0;
/**
* Constant representing credential (PIN, pattern, or password).
* @hide
*/
int TYPE_CREDENTIAL = 1 << 0;
/**
* Constant representing fingerprint.
* @hide
*/
int TYPE_FINGERPRINT = 1 << 1;
/**
* Constant representing iris.
* @hide
*/
int TYPE_IRIS = 1 << 2;
/**
* Constant representing face.
* @hide
*/
int TYPE_FACE = 1 << 3;
/**
* @hide
*/
int TYPE_ANY_BIOMETRIC = TYPE_FINGERPRINT | TYPE_IRIS | TYPE_FACE;
@IntDef(flag = true, value = {
TYPE_NONE,
TYPE_CREDENTIAL,
TYPE_FINGERPRINT,
TYPE_IRIS,
TYPE_FACE
})
@Retention(RetentionPolicy.SOURCE)
@interface Modality {}
/**
* Container for biometric data
* @hide
*/
abstract class Identifier implements Parcelable {
private CharSequence mName;
private int mBiometricId;
private long mDeviceId; // physical device this is associated with
public Identifier() {}
public Identifier(CharSequence name, int biometricId, long deviceId) {
mName = name;
mBiometricId = biometricId;
mDeviceId = deviceId;
}
/**
* Gets the human-readable name for the given biometric.
* @return name given to the biometric
*/
public CharSequence getName() {
return mName;
}
/**
* Gets the device-specific biometric id. Used by Settings to map a name to a specific
* biometric template.
*/
public int getBiometricId() {
return mBiometricId;
}
/**
* Device this biometric belongs to.
*/
public long getDeviceId() {
return mDeviceId;
}
public void setName(CharSequence name) {
mName = name;
}
public void setDeviceId(long deviceId) {
mDeviceId = deviceId;
}
}
/**
* Container for callback data from {@link BiometricAuthenticator#authenticate(
* CancellationSignal, Executor, AuthenticationCallback)} and
* {@link BiometricAuthenticator#authenticate(CryptoObject, CancellationSignal, Executor,
* AuthenticationCallback)}
*/
class AuthenticationResult {
private Identifier mIdentifier;
private CryptoObject mCryptoObject;
private @AuthenticationResultType int mAuthenticationType;
private int mUserId;
/**
* @hide
*/
public AuthenticationResult() { }
/**
* Authentication result
* @param crypto
* @param authenticationType
* @param identifier
* @param userId
* @hide
*/
public AuthenticationResult(CryptoObject crypto,
@AuthenticationResultType int authenticationType, Identifier identifier,
int userId) {
mCryptoObject = crypto;
mAuthenticationType = authenticationType;
mIdentifier = identifier;
mUserId = userId;
}
/**
* Provides the crypto object associated with this transaction.
* @return The crypto object provided to {@link BiometricPrompt#authenticate(
* BiometricPrompt.CryptoObject, CancellationSignal, Executor,
* BiometricPrompt.AuthenticationCallback)}
*/
public CryptoObject getCryptoObject() {
return mCryptoObject;
}
/**
* Provides the type of authentication (e.g. device credential or biometric) that was
* requested from and successfully provided by the user.
*
* @return An integer value representing the authentication method used.
*/
public @AuthenticationResultType int getAuthenticationType() {
return mAuthenticationType;
}
/**
* Obtain the biometric identifier associated with this operation. Applications are strongly
* discouraged from associating specific identifiers with specific applications or
* operations.
* @hide
*/
public Identifier getId() {
return mIdentifier;
}
/**
* Obtain the userId for which this biometric was authenticated.
* @hide
*/
public int getUserId() {
return mUserId;
}
};
/**
* Callback structure provided to {@link BiometricAuthenticator#authenticate(CancellationSignal,
* Executor, AuthenticationCallback)} or {@link BiometricAuthenticator#authenticate(
* CryptoObject, CancellationSignal, Executor, AuthenticationCallback)}. Users must provide
* an implementation of this for listening to biometric events.
*/
abstract class AuthenticationCallback {
/**
* Called when an unrecoverable error has been encountered and the operation is complete.
* No further actions will be made on this object.
* @param errorCode An integer identifying the error message
* @param errString A human-readable error string that can be shown on an UI
*/
public void onAuthenticationError(int errorCode, CharSequence errString) {}
/**
* Called when a recoverable error has been encountered during authentication. The help
* string is provided to give the user guidance for what went wrong, such as "Sensor dirty,
* please clean it."
* @param helpCode An integer identifying the error message
* @param helpString A human-readable string that can be shown on an UI
*/
public void onAuthenticationHelp(int helpCode, CharSequence helpString) {}
/**
* Called when a biometric is valid but not recognized.
*/
public void onAuthenticationFailed() {}
/**
* Called when a biometric has been acquired, but hasn't been processed yet.
* @hide
*/
public void onAuthenticationAcquired(int acquireInfo) {}
}
}
|