Jim Miller | 08fa40c | 2014-04-29 18:18:47 -0700 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (C) 2014 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 | |
Jim Miller | ebbf205 | 2015-03-31 17:24:34 -0700 | [diff] [blame] | 17 | package android.hardware.fingerprint; |
Jim Miller | 08fa40c | 2014-04-29 18:18:47 -0700 | [diff] [blame] | 18 | |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 19 | import android.annotation.NonNull; |
| 20 | import android.annotation.Nullable; |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 21 | import android.annotation.RequiresPermission; |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame^] | 22 | import android.app.ActivityManager; |
Jim Miller | 08fa40c | 2014-04-29 18:18:47 -0700 | [diff] [blame] | 23 | import android.content.Context; |
Jim Miller | a7596147 | 2014-06-06 15:00:49 -0700 | [diff] [blame] | 24 | import android.os.Binder; |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 25 | import android.os.CancellationSignal; |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 26 | import android.os.CancellationSignal.OnCancelListener; |
Jim Miller | 08fa40c | 2014-04-29 18:18:47 -0700 | [diff] [blame] | 27 | import android.os.Handler; |
| 28 | import android.os.IBinder; |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 29 | import android.os.Looper; |
Jorim Jaggi | 5e35422 | 2015-09-04 14:17:58 -0700 | [diff] [blame] | 30 | import android.os.PowerManager; |
Jim Miller | 08fa40c | 2014-04-29 18:18:47 -0700 | [diff] [blame] | 31 | import android.os.RemoteException; |
| 32 | import android.os.UserHandle; |
Alex Klyubin | dcdaf87 | 2015-05-13 15:57:09 -0700 | [diff] [blame] | 33 | import android.security.keystore.AndroidKeyStoreProvider; |
Jim Miller | 08fa40c | 2014-04-29 18:18:47 -0700 | [diff] [blame] | 34 | import android.util.Log; |
Jim Miller | a7596147 | 2014-06-06 15:00:49 -0700 | [diff] [blame] | 35 | import android.util.Slog; |
Jim Miller | 08fa40c | 2014-04-29 18:18:47 -0700 | [diff] [blame] | 36 | |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 37 | import java.security.Signature; |
Jim Miller | ba67aee | 2015-02-20 16:21:26 -0800 | [diff] [blame] | 38 | import java.util.List; |
| 39 | |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 40 | import javax.crypto.Cipher; |
Jim Miller | b62dc82 | 2015-04-28 20:05:53 -0700 | [diff] [blame] | 41 | import javax.crypto.Mac; |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 42 | |
Clara Bayarri | 33fd3cf | 2016-02-19 16:54:49 +0000 | [diff] [blame] | 43 | import static android.Manifest.permission.INTERACT_ACROSS_USERS; |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 44 | import static android.Manifest.permission.USE_FINGERPRINT; |
| 45 | import static android.Manifest.permission.MANAGE_FINGERPRINT; |
| 46 | |
Jim Miller | 08fa40c | 2014-04-29 18:18:47 -0700 | [diff] [blame] | 47 | /** |
| 48 | * A class that coordinates access to the fingerprint hardware. |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 49 | * <p> |
| 50 | * Use {@link android.content.Context#getSystemService(java.lang.String)} |
| 51 | * with argument {@link android.content.Context#FINGERPRINT_SERVICE} to get |
| 52 | * an instance of this class. |
Jim Miller | 08fa40c | 2014-04-29 18:18:47 -0700 | [diff] [blame] | 53 | */ |
| 54 | |
| 55 | public class FingerprintManager { |
| 56 | private static final String TAG = "FingerprintManager"; |
Jim Miller | d08c2ac | 2014-05-14 16:30:38 -0700 | [diff] [blame] | 57 | private static final boolean DEBUG = true; |
Jim Miller | 08fa40c | 2014-04-29 18:18:47 -0700 | [diff] [blame] | 58 | private static final int MSG_ENROLL_RESULT = 100; |
Jim Miller | a7596147 | 2014-06-06 15:00:49 -0700 | [diff] [blame] | 59 | private static final int MSG_ACQUIRED = 101; |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 60 | private static final int MSG_AUTHENTICATION_SUCCEEDED = 102; |
| 61 | private static final int MSG_AUTHENTICATION_FAILED = 103; |
| 62 | private static final int MSG_ERROR = 104; |
| 63 | private static final int MSG_REMOVED = 105; |
Jim Miller | 08fa40c | 2014-04-29 18:18:47 -0700 | [diff] [blame] | 64 | |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 65 | // |
| 66 | // Error messages from fingerprint hardware during initilization, enrollment, authentication or |
| 67 | // removal. Must agree with the list in fingerprint.h |
| 68 | // |
Jim Miller | 08fa40c | 2014-04-29 18:18:47 -0700 | [diff] [blame] | 69 | |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 70 | /** |
| 71 | * The hardware is unavailable. Try again later. |
| 72 | */ |
Jim Miller | 08fa40c | 2014-04-29 18:18:47 -0700 | [diff] [blame] | 73 | public static final int FINGERPRINT_ERROR_HW_UNAVAILABLE = 1; |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 74 | |
| 75 | /** |
| 76 | * Error state returned when the sensor was unable to process the current image. |
| 77 | */ |
Jim Miller | a7596147 | 2014-06-06 15:00:49 -0700 | [diff] [blame] | 78 | public static final int FINGERPRINT_ERROR_UNABLE_TO_PROCESS = 2; |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 79 | |
| 80 | /** |
| 81 | * Error state returned when the current request has been running too long. This is intended to |
| 82 | * prevent programs from waiting for the fingerprint sensor indefinitely. The timeout is |
| 83 | * platform and sensor-specific, but is generally on the order of 30 seconds. |
| 84 | */ |
Jim Miller | 08fa40c | 2014-04-29 18:18:47 -0700 | [diff] [blame] | 85 | public static final int FINGERPRINT_ERROR_TIMEOUT = 3; |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 86 | |
| 87 | /** |
| 88 | * Error state returned for operations like enrollment; the operation cannot be completed |
| 89 | * because there's not enough storage remaining to complete the operation. |
| 90 | */ |
Jim Miller | 08fa40c | 2014-04-29 18:18:47 -0700 | [diff] [blame] | 91 | public static final int FINGERPRINT_ERROR_NO_SPACE = 4; |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 92 | |
| 93 | /** |
| 94 | * The operation was canceled because the fingerprint sensor is unavailable. For example, |
| 95 | * this may happen when the user is switched, the device is locked or another pending operation |
| 96 | * prevents or disables it. |
| 97 | */ |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 98 | public static final int FINGERPRINT_ERROR_CANCELED = 5; |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 99 | |
| 100 | /** |
| 101 | * The {@link FingerprintManager#remove(Fingerprint, RemovalCallback)} call failed. Typically |
| 102 | * this will happen when the provided fingerprint id was incorrect. |
| 103 | * |
| 104 | * @hide |
| 105 | */ |
| 106 | public static final int FINGERPRINT_ERROR_UNABLE_TO_REMOVE = 6; |
| 107 | |
Jim Miller | fe6439f | 2015-04-11 18:07:57 -0700 | [diff] [blame] | 108 | /** |
| 109 | * The operation was canceled because the API is locked out due to too many attempts. |
| 110 | */ |
| 111 | public static final int FINGERPRINT_ERROR_LOCKOUT = 7; |
| 112 | |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 113 | /** |
| 114 | * Hardware vendors may extend this list if there are conditions that do not fall under one of |
| 115 | * the above categories. Vendors are responsible for providing error strings for these errors. |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 116 | * @hide |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 117 | */ |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 118 | public static final int FINGERPRINT_ERROR_VENDOR_BASE = 1000; |
Jim Miller | 08fa40c | 2014-04-29 18:18:47 -0700 | [diff] [blame] | 119 | |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 120 | // |
| 121 | // Image acquisition messages. Must agree with those in fingerprint.h |
| 122 | // |
| 123 | |
| 124 | /** |
| 125 | * The image acquired was good. |
| 126 | */ |
Jim Miller | a7596147 | 2014-06-06 15:00:49 -0700 | [diff] [blame] | 127 | public static final int FINGERPRINT_ACQUIRED_GOOD = 0; |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 128 | |
| 129 | /** |
| 130 | * Only a partial fingerprint image was detected. During enrollment, the user should be |
| 131 | * informed on what needs to happen to resolve this problem, e.g. "press firmly on sensor." |
| 132 | */ |
Jim Miller | a7596147 | 2014-06-06 15:00:49 -0700 | [diff] [blame] | 133 | public static final int FINGERPRINT_ACQUIRED_PARTIAL = 1; |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 134 | |
| 135 | /** |
| 136 | * The fingerprint image was too noisy to process due to a detected condition (i.e. dry skin) or |
| 137 | * a possibly dirty sensor (See {@link #FINGERPRINT_ACQUIRED_IMAGER_DIRTY}). |
| 138 | */ |
Jim Miller | a7596147 | 2014-06-06 15:00:49 -0700 | [diff] [blame] | 139 | public static final int FINGERPRINT_ACQUIRED_INSUFFICIENT = 2; |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 140 | |
| 141 | /** |
| 142 | * The fingerprint image was too noisy due to suspected or detected dirt on the sensor. |
| 143 | * For example, it's reasonable return this after multiple |
| 144 | * {@link #FINGERPRINT_ACQUIRED_INSUFFICIENT} or actual detection of dirt on the sensor |
| 145 | * (stuck pixels, swaths, etc.). The user is expected to take action to clean the sensor |
| 146 | * when this is returned. |
| 147 | */ |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 148 | public static final int FINGERPRINT_ACQUIRED_IMAGER_DIRTY = 3; |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 149 | |
| 150 | /** |
| 151 | * The fingerprint image was unreadable due to lack of motion. This is most appropriate for |
| 152 | * linear array sensors that require a swipe motion. |
| 153 | */ |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 154 | public static final int FINGERPRINT_ACQUIRED_TOO_SLOW = 4; |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 155 | |
| 156 | /** |
| 157 | * The fingerprint image was incomplete due to quick motion. While mostly appropriate for |
| 158 | * linear array sensors, this could also happen if the finger was moved during acquisition. |
| 159 | * The user should be asked to move the finger slower (linear) or leave the finger on the sensor |
| 160 | * longer. |
| 161 | */ |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 162 | public static final int FINGERPRINT_ACQUIRED_TOO_FAST = 5; |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 163 | |
| 164 | /** |
| 165 | * Hardware vendors may extend this list if there are conditions that do not fall under one of |
| 166 | * the above categories. Vendors are responsible for providing error strings for these errors. |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 167 | * @hide |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 168 | */ |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 169 | public static final int FINGERPRINT_ACQUIRED_VENDOR_BASE = 1000; |
Jim Miller | a7596147 | 2014-06-06 15:00:49 -0700 | [diff] [blame] | 170 | |
Jim Miller | 08fa40c | 2014-04-29 18:18:47 -0700 | [diff] [blame] | 171 | private IFingerprintService mService; |
Jim Miller | d08c2ac | 2014-05-14 16:30:38 -0700 | [diff] [blame] | 172 | private Context mContext; |
Jim Miller | a7596147 | 2014-06-06 15:00:49 -0700 | [diff] [blame] | 173 | private IBinder mToken = new Binder(); |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 174 | private AuthenticationCallback mAuthenticationCallback; |
| 175 | private EnrollmentCallback mEnrollmentCallback; |
| 176 | private RemovalCallback mRemovalCallback; |
| 177 | private CryptoObject mCryptoObject; |
| 178 | private Fingerprint mRemovalFingerprint; |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 179 | private Handler mHandler; |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 180 | |
| 181 | private class OnEnrollCancelListener implements OnCancelListener { |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 182 | @Override |
| 183 | public void onCancel() { |
Jim Miller | fe6439f | 2015-04-11 18:07:57 -0700 | [diff] [blame] | 184 | cancelEnrollment(); |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 185 | } |
| 186 | } |
| 187 | |
| 188 | private class OnAuthenticationCancelListener implements OnCancelListener { |
| 189 | private CryptoObject mCrypto; |
| 190 | |
| 191 | public OnAuthenticationCancelListener(CryptoObject crypto) { |
| 192 | mCrypto = crypto; |
| 193 | } |
| 194 | |
| 195 | @Override |
| 196 | public void onCancel() { |
| 197 | cancelAuthentication(mCrypto); |
| 198 | } |
| 199 | } |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 200 | |
| 201 | /** |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 202 | * A wrapper class for the crypto objects supported by FingerprintManager. Currently the |
Jim Miller | b62dc82 | 2015-04-28 20:05:53 -0700 | [diff] [blame] | 203 | * framework supports {@link Signature}, {@link Cipher} and {@link Mac} objects. |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 204 | */ |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 205 | public static final class CryptoObject { |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 206 | |
Jim Miller | b62dc82 | 2015-04-28 20:05:53 -0700 | [diff] [blame] | 207 | public CryptoObject(@NonNull Signature signature) { |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 208 | mCrypto = signature; |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 209 | } |
| 210 | |
Jim Miller | b62dc82 | 2015-04-28 20:05:53 -0700 | [diff] [blame] | 211 | public CryptoObject(@NonNull Cipher cipher) { |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 212 | mCrypto = cipher; |
Jim Miller | b62dc82 | 2015-04-28 20:05:53 -0700 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | public CryptoObject(@NonNull Mac mac) { |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 216 | mCrypto = mac; |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | /** |
| 220 | * Get {@link Signature} object. |
| 221 | * @return {@link Signature} object or null if this doesn't contain one. |
| 222 | */ |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 223 | public Signature getSignature() { |
| 224 | return mCrypto instanceof Signature ? (Signature) mCrypto : null; |
| 225 | } |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 226 | |
| 227 | /** |
| 228 | * Get {@link Cipher} object. |
| 229 | * @return {@link Cipher} object or null if this doesn't contain one. |
| 230 | */ |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 231 | public Cipher getCipher() { |
| 232 | return mCrypto instanceof Cipher ? (Cipher) mCrypto : null; |
| 233 | } |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 234 | |
| 235 | /** |
Jim Miller | b62dc82 | 2015-04-28 20:05:53 -0700 | [diff] [blame] | 236 | * Get {@link Mac} object. |
| 237 | * @return {@link Mac} object or null if this doesn't contain one. |
| 238 | */ |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 239 | public Mac getMac() { |
| 240 | return mCrypto instanceof Mac ? (Mac) mCrypto : null; |
| 241 | } |
Jim Miller | b62dc82 | 2015-04-28 20:05:53 -0700 | [diff] [blame] | 242 | |
| 243 | /** |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 244 | * @hide |
| 245 | * @return the opId associated with this object or 0 if none |
| 246 | */ |
| 247 | public long getOpId() { |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 248 | return mCrypto != null ? |
| 249 | AndroidKeyStoreProvider.getKeyStoreOperationHandle(mCrypto) : 0; |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 250 | } |
| 251 | |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 252 | private final Object mCrypto; |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 253 | }; |
| 254 | |
| 255 | /** |
| 256 | * Container for callback data from {@link FingerprintManager#authenticate(CryptoObject, |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 257 | * CancellationSignal, int, AuthenticationCallback, Handler)}. |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 258 | */ |
Jim Miller | 748bc36 | 2015-07-08 19:02:28 -0700 | [diff] [blame] | 259 | public static class AuthenticationResult { |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 260 | private Fingerprint mFingerprint; |
| 261 | private CryptoObject mCryptoObject; |
Jim Miller | 837fa7e | 2016-08-08 20:16:22 -0700 | [diff] [blame] | 262 | private int mUserId; |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 263 | |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 264 | /** |
| 265 | * Authentication result |
| 266 | * |
| 267 | * @param crypto the crypto object |
| 268 | * @param fingerprint the recognized fingerprint data, if allowed. |
| 269 | * @hide |
| 270 | */ |
Jim Miller | 837fa7e | 2016-08-08 20:16:22 -0700 | [diff] [blame] | 271 | public AuthenticationResult(CryptoObject crypto, Fingerprint fingerprint, int userId) { |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 272 | mCryptoObject = crypto; |
| 273 | mFingerprint = fingerprint; |
Jim Miller | 837fa7e | 2016-08-08 20:16:22 -0700 | [diff] [blame] | 274 | mUserId = userId; |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | /** |
| 278 | * Obtain the crypto object associated with this transaction |
| 279 | * @return crypto object provided to {@link FingerprintManager#authenticate(CryptoObject, |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 280 | * CancellationSignal, int, AuthenticationCallback, Handler)}. |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 281 | */ |
| 282 | public CryptoObject getCryptoObject() { return mCryptoObject; } |
| 283 | |
| 284 | /** |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 285 | * Obtain the Fingerprint associated with this operation. Applications are strongly |
| 286 | * discouraged from associating specific fingers with specific applications or operations. |
| 287 | * |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 288 | * @hide |
| 289 | */ |
| 290 | public Fingerprint getFingerprint() { return mFingerprint; } |
Jim Miller | 837fa7e | 2016-08-08 20:16:22 -0700 | [diff] [blame] | 291 | |
| 292 | /** |
| 293 | * Obtain the userId for which this fingerprint was authenticated. |
| 294 | * @hide |
| 295 | */ |
| 296 | public int getUserId() { return mUserId; } |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 297 | }; |
| 298 | |
| 299 | /** |
| 300 | * Callback structure provided to {@link FingerprintManager#authenticate(CryptoObject, |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 301 | * CancellationSignal, int, AuthenticationCallback, Handler)}. Users of {@link |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 302 | * FingerprintManager#authenticate(CryptoObject, CancellationSignal, |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 303 | * int, AuthenticationCallback, Handler) } must provide an implementation of this for listening to |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 304 | * fingerprint events. |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 305 | */ |
| 306 | public static abstract class AuthenticationCallback { |
| 307 | /** |
| 308 | * Called when an unrecoverable error has been encountered and the operation is complete. |
| 309 | * No further callbacks will be made on this object. |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 310 | * @param errorCode An integer identifying the error message |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 311 | * @param errString A human-readable error string that can be shown in UI |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 312 | */ |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 313 | public void onAuthenticationError(int errorCode, CharSequence errString) { } |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 314 | |
| 315 | /** |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 316 | * Called when a recoverable error has been encountered during authentication. The help |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 317 | * string is provided to give the user guidance for what went wrong, such as |
| 318 | * "Sensor dirty, please clean it." |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 319 | * @param helpCode An integer identifying the error message |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 320 | * @param helpString A human-readable string that can be shown in UI |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 321 | */ |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 322 | public void onAuthenticationHelp(int helpCode, CharSequence helpString) { } |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 323 | |
| 324 | /** |
| 325 | * Called when a fingerprint is recognized. |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 326 | * @param result An object containing authentication-related data |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 327 | */ |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 328 | public void onAuthenticationSucceeded(AuthenticationResult result) { } |
| 329 | |
| 330 | /** |
| 331 | * Called when a fingerprint is valid but not recognized. |
| 332 | */ |
| 333 | public void onAuthenticationFailed() { } |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 334 | |
| 335 | /** |
| 336 | * Called when a fingerprint image has been acquired, but wasn't processed yet. |
| 337 | * |
| 338 | * @param acquireInfo one of FINGERPRINT_ACQUIRED_* constants |
| 339 | * @hide |
| 340 | */ |
| 341 | public void onAuthenticationAcquired(int acquireInfo) {} |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 342 | }; |
| 343 | |
| 344 | /** |
| 345 | * Callback structure provided to {@link FingerprintManager#enroll(long, EnrollmentCallback, |
| 346 | * CancellationSignal, int). Users of {@link #FingerprintManager()} |
| 347 | * must provide an implementation of this to {@link FingerprintManager#enroll(long, |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 348 | * CancellationSignal, int, EnrollmentCallback) for listening to fingerprint events. |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 349 | * |
| 350 | * @hide |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 351 | */ |
| 352 | public static abstract class EnrollmentCallback { |
| 353 | /** |
| 354 | * Called when an unrecoverable error has been encountered and the operation is complete. |
| 355 | * No further callbacks will be made on this object. |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 356 | * @param errMsgId An integer identifying the error message |
| 357 | * @param errString A human-readable error string that can be shown in UI |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 358 | */ |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 359 | public void onEnrollmentError(int errMsgId, CharSequence errString) { } |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 360 | |
| 361 | /** |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 362 | * Called when a recoverable error has been encountered during enrollment. The help |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 363 | * string is provided to give the user guidance for what went wrong, such as |
| 364 | * "Sensor dirty, please clean it" or what they need to do next, such as |
| 365 | * "Touch sensor again." |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 366 | * @param helpMsgId An integer identifying the error message |
| 367 | * @param helpString A human-readable string that can be shown in UI |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 368 | */ |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 369 | public void onEnrollmentHelp(int helpMsgId, CharSequence helpString) { } |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 370 | |
| 371 | /** |
| 372 | * Called as each enrollment step progresses. Enrollment is considered complete when |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 373 | * remaining reaches 0. This function will not be called if enrollment fails. See |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 374 | * {@link EnrollmentCallback#onEnrollmentError(int, CharSequence)} |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 375 | * @param remaining The number of remaining steps |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 376 | */ |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 377 | public void onEnrollmentProgress(int remaining) { } |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 378 | }; |
| 379 | |
| 380 | /** |
| 381 | * Callback structure provided to {@link FingerprintManager#remove(int). Users of |
| 382 | * {@link #FingerprintManager()} may optionally provide an implementation of this to |
| 383 | * {@link FingerprintManager#remove(int, int, RemovalCallback)} for listening to |
| 384 | * fingerprint template removal events. |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 385 | * |
| 386 | * @hide |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 387 | */ |
| 388 | public static abstract class RemovalCallback { |
| 389 | /** |
| 390 | * Called when the given fingerprint can't be removed. |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 391 | * @param fp The fingerprint that the call attempted to remove |
| 392 | * @param errMsgId An associated error message id |
| 393 | * @param errString An error message indicating why the fingerprint id can't be removed |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 394 | */ |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 395 | public void onRemovalError(Fingerprint fp, int errMsgId, CharSequence errString) { } |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 396 | |
| 397 | /** |
| 398 | * Called when a given fingerprint is successfully removed. |
| 399 | * @param fingerprint the fingerprint template that was removed. |
| 400 | */ |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 401 | public void onRemovalSucceeded(Fingerprint fingerprint) { } |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 402 | }; |
| 403 | |
| 404 | /** |
Jorim Jaggi | 3a46478 | 2015-08-28 16:59:13 -0700 | [diff] [blame] | 405 | * @hide |
| 406 | */ |
| 407 | public static abstract class LockoutResetCallback { |
| 408 | |
| 409 | /** |
| 410 | * Called when lockout period expired and clients are allowed to listen for fingerprint |
| 411 | * again. |
| 412 | */ |
| 413 | public void onLockoutReset() { } |
| 414 | }; |
| 415 | |
| 416 | /** |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 417 | * Request authentication of a crypto object. This call warms up the fingerprint hardware |
| 418 | * and starts scanning for a fingerprint. It terminates when |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 419 | * {@link AuthenticationCallback#onAuthenticationError(int, CharSequence)} or |
Jim Miller | 5f69ca3 | 2015-08-19 22:03:43 -0700 | [diff] [blame] | 420 | * {@link AuthenticationCallback#onAuthenticationSucceeded(AuthenticationResult)} is called, at |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 421 | * which point the object is no longer valid. The operation can be canceled by using the |
| 422 | * provided cancel object. |
| 423 | * |
| 424 | * @param crypto object associated with the call or null if none required. |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 425 | * @param cancel an object that can be used to cancel authentication |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 426 | * @param flags optional flags; should be 0 |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 427 | * @param callback an object to receive authentication events |
| 428 | * @param handler an optional handler to handle callback events |
Jim Miller | e4c58e4 | 2015-06-09 13:48:57 -0700 | [diff] [blame] | 429 | * |
| 430 | * @throws IllegalArgumentException if the crypto operation is not supported or is not backed |
| 431 | * by <a href="{@docRoot}training/articles/keystore.html">Android Keystore |
| 432 | * facility</a>. |
| 433 | * @throws IllegalStateException if the crypto primitive is not initialized. |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 434 | */ |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 435 | @RequiresPermission(USE_FINGERPRINT) |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 436 | public void authenticate(@Nullable CryptoObject crypto, @Nullable CancellationSignal cancel, |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 437 | int flags, @NonNull AuthenticationCallback callback, @Nullable Handler handler) { |
| 438 | authenticate(crypto, cancel, flags, callback, handler, UserHandle.myUserId()); |
Jorim Jaggi | ccdfa93 | 2015-04-13 16:29:48 -0700 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | /** |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 442 | * Use the provided handler thread for events. |
| 443 | * @param handler |
| 444 | */ |
| 445 | private void useHandler(Handler handler) { |
| 446 | if (handler != null) { |
| 447 | mHandler = new MyHandler(handler.getLooper()); |
| 448 | } else if (mHandler.getLooper() != mContext.getMainLooper()){ |
| 449 | mHandler = new MyHandler(mContext.getMainLooper()); |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | /** |
| 454 | * Per-user version |
Jorim Jaggi | ccdfa93 | 2015-04-13 16:29:48 -0700 | [diff] [blame] | 455 | * @hide |
| 456 | */ |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 457 | @RequiresPermission(USE_FINGERPRINT) |
Jorim Jaggi | ccdfa93 | 2015-04-13 16:29:48 -0700 | [diff] [blame] | 458 | public void authenticate(@Nullable CryptoObject crypto, @Nullable CancellationSignal cancel, |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 459 | int flags, @NonNull AuthenticationCallback callback, Handler handler, int userId) { |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 460 | if (callback == null) { |
| 461 | throw new IllegalArgumentException("Must supply an authentication callback"); |
| 462 | } |
| 463 | |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 464 | if (cancel != null) { |
| 465 | if (cancel.isCanceled()) { |
| 466 | Log.w(TAG, "authentication already canceled"); |
| 467 | return; |
| 468 | } else { |
| 469 | cancel.setOnCancelListener(new OnAuthenticationCancelListener(crypto)); |
| 470 | } |
| 471 | } |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 472 | |
| 473 | if (mService != null) try { |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 474 | useHandler(handler); |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 475 | mAuthenticationCallback = callback; |
| 476 | mCryptoObject = crypto; |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 477 | long sessionId = crypto != null ? crypto.getOpId() : 0; |
Svetoslav | 4af76a5 | 2015-04-29 15:29:46 -0700 | [diff] [blame] | 478 | mService.authenticate(mToken, sessionId, userId, mServiceReceiver, flags, |
| 479 | mContext.getOpPackageName()); |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 480 | } catch (RemoteException e) { |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 481 | Log.w(TAG, "Remote exception while authenticating: ", e); |
| 482 | if (callback != null) { |
| 483 | // Though this may not be a hardware issue, it will cause apps to give up or try |
| 484 | // again later. |
| 485 | callback.onAuthenticationError(FINGERPRINT_ERROR_HW_UNAVAILABLE, |
| 486 | getErrorString(FINGERPRINT_ERROR_HW_UNAVAILABLE)); |
| 487 | } |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 488 | } |
| 489 | } |
| 490 | |
| 491 | /** |
| 492 | * Request fingerprint enrollment. This call warms up the fingerprint hardware |
| 493 | * and starts scanning for fingerprints. Progress will be indicated by callbacks to the |
| 494 | * {@link EnrollmentCallback} object. It terminates when |
| 495 | * {@link EnrollmentCallback#onEnrollmentError(int, CharSequence)} or |
| 496 | * {@link EnrollmentCallback#onEnrollmentProgress(int) is called with remaining == 0, at |
| 497 | * which point the object is no longer valid. The operation can be canceled by using the |
| 498 | * provided cancel object. |
Jim Miller | fe6439f | 2015-04-11 18:07:57 -0700 | [diff] [blame] | 499 | * @param token a unique token provided by a recent creation or verification of device |
| 500 | * credentials (e.g. pin, pattern or password). |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 501 | * @param cancel an object that can be used to cancel enrollment |
| 502 | * @param flags optional flags |
Clara Bayarri | a5c1a77 | 2016-01-26 16:36:14 +0000 | [diff] [blame] | 503 | * @param userId the user to whom this fingerprint will belong to |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 504 | * @param callback an object to receive enrollment events |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 505 | * @hide |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 506 | */ |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 507 | @RequiresPermission(MANAGE_FINGERPRINT) |
| 508 | public void enroll(byte [] token, CancellationSignal cancel, int flags, |
Clara Bayarri | a5c1a77 | 2016-01-26 16:36:14 +0000 | [diff] [blame] | 509 | int userId, EnrollmentCallback callback) { |
Clara Bayarri | d1f722d | 2016-01-07 14:17:39 +0000 | [diff] [blame] | 510 | if (userId == UserHandle.USER_CURRENT) { |
| 511 | userId = getCurrentUserId(); |
| 512 | } |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 513 | if (callback == null) { |
| 514 | throw new IllegalArgumentException("Must supply an enrollment callback"); |
| 515 | } |
| 516 | |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 517 | if (cancel != null) { |
| 518 | if (cancel.isCanceled()) { |
| 519 | Log.w(TAG, "enrollment already canceled"); |
| 520 | return; |
| 521 | } else { |
Jim Miller | fe6439f | 2015-04-11 18:07:57 -0700 | [diff] [blame] | 522 | cancel.setOnCancelListener(new OnEnrollCancelListener()); |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 523 | } |
| 524 | } |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 525 | |
| 526 | if (mService != null) try { |
| 527 | mEnrollmentCallback = callback; |
Jim Miller | cb2ce6f | 2016-04-13 20:28:18 -0700 | [diff] [blame] | 528 | mService.enroll(mToken, token, userId, mServiceReceiver, flags, |
| 529 | mContext.getOpPackageName()); |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 530 | } catch (RemoteException e) { |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 531 | Log.w(TAG, "Remote exception in enroll: ", e); |
| 532 | if (callback != null) { |
| 533 | // Though this may not be a hardware issue, it will cause apps to give up or try |
| 534 | // again later. |
| 535 | callback.onEnrollmentError(FINGERPRINT_ERROR_HW_UNAVAILABLE, |
| 536 | getErrorString(FINGERPRINT_ERROR_HW_UNAVAILABLE)); |
| 537 | } |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 538 | } |
| 539 | } |
| 540 | |
| 541 | /** |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 542 | * Requests a pre-enrollment auth token to tie enrollment to the confirmation of |
| 543 | * existing device credentials (e.g. pin/pattern/password). |
| 544 | * @hide |
| 545 | */ |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 546 | @RequiresPermission(MANAGE_FINGERPRINT) |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 547 | public long preEnroll() { |
| 548 | long result = 0; |
| 549 | if (mService != null) try { |
| 550 | result = mService.preEnroll(mToken); |
| 551 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 552 | throw e.rethrowFromSystemServer(); |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 553 | } |
| 554 | return result; |
| 555 | } |
| 556 | |
| 557 | /** |
Sasha Levitskiy | e0943cf | 2015-07-08 13:22:20 -0700 | [diff] [blame] | 558 | * Finishes enrollment and cancels the current auth token. |
| 559 | * @hide |
| 560 | */ |
| 561 | @RequiresPermission(MANAGE_FINGERPRINT) |
| 562 | public int postEnroll() { |
| 563 | int result = 0; |
| 564 | if (mService != null) try { |
| 565 | result = mService.postEnroll(mToken); |
| 566 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 567 | throw e.rethrowFromSystemServer(); |
Sasha Levitskiy | e0943cf | 2015-07-08 13:22:20 -0700 | [diff] [blame] | 568 | } |
| 569 | return result; |
| 570 | } |
| 571 | |
| 572 | /** |
Clara Bayarri | d1f722d | 2016-01-07 14:17:39 +0000 | [diff] [blame] | 573 | * Sets the active user. This is meant to be used to select the current profile for enrollment |
| 574 | * to allow separate enrolled fingers for a work profile |
| 575 | * @param userId |
| 576 | * @hide |
| 577 | */ |
| 578 | @RequiresPermission(MANAGE_FINGERPRINT) |
| 579 | public void setActiveUser(int userId) { |
| 580 | if (mService != null) try { |
| 581 | mService.setActiveUser(userId); |
| 582 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 583 | throw e.rethrowFromSystemServer(); |
Clara Bayarri | d1f722d | 2016-01-07 14:17:39 +0000 | [diff] [blame] | 584 | } |
| 585 | } |
| 586 | |
| 587 | /** |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 588 | * Remove given fingerprint template from fingerprint hardware and/or protected storage. |
| 589 | * @param fp the fingerprint item to remove |
Clara Bayarri | a5c1a77 | 2016-01-26 16:36:14 +0000 | [diff] [blame] | 590 | * @param userId the user who this fingerprint belongs to |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 591 | * @param callback an optional callback to verify that fingerprint templates have been |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 592 | * successfully removed. May be null of no callback is required. |
| 593 | * |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 594 | * @hide |
| 595 | */ |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 596 | @RequiresPermission(MANAGE_FINGERPRINT) |
Clara Bayarri | a5c1a77 | 2016-01-26 16:36:14 +0000 | [diff] [blame] | 597 | public void remove(Fingerprint fp, int userId, RemovalCallback callback) { |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 598 | if (mService != null) try { |
| 599 | mRemovalCallback = callback; |
| 600 | mRemovalFingerprint = fp; |
Jim Miller | 8f2aca0 | 2016-04-20 13:34:11 -0700 | [diff] [blame] | 601 | mService.remove(mToken, fp.getFingerId(), fp.getGroupId(), userId, mServiceReceiver); |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 602 | } catch (RemoteException e) { |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 603 | Log.w(TAG, "Remote exception in remove: ", e); |
| 604 | if (callback != null) { |
| 605 | callback.onRemovalError(fp, FINGERPRINT_ERROR_HW_UNAVAILABLE, |
| 606 | getErrorString(FINGERPRINT_ERROR_HW_UNAVAILABLE)); |
| 607 | } |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 608 | } |
| 609 | } |
| 610 | |
| 611 | /** |
| 612 | * Renames the given fingerprint template |
| 613 | * @param fpId the fingerprint id |
Clara Bayarri | a5c1a77 | 2016-01-26 16:36:14 +0000 | [diff] [blame] | 614 | * @param userId the user who this fingerprint belongs to |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 615 | * @param newName the new name |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 616 | * |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 617 | * @hide |
| 618 | */ |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 619 | @RequiresPermission(MANAGE_FINGERPRINT) |
Clara Bayarri | a5c1a77 | 2016-01-26 16:36:14 +0000 | [diff] [blame] | 620 | public void rename(int fpId, int userId, String newName) { |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 621 | // Renames the given fpId |
| 622 | if (mService != null) { |
| 623 | try { |
Clara Bayarri | a5c1a77 | 2016-01-26 16:36:14 +0000 | [diff] [blame] | 624 | mService.rename(fpId, userId, newName); |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 625 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 626 | throw e.rethrowFromSystemServer(); |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 627 | } |
| 628 | } else { |
| 629 | Log.w(TAG, "rename(): Service not connected!"); |
| 630 | } |
| 631 | } |
| 632 | |
| 633 | /** |
| 634 | * Obtain the list of enrolled fingerprints templates. |
| 635 | * @return list of current fingerprint items |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 636 | * |
| 637 | * @hide |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 638 | */ |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 639 | @RequiresPermission(USE_FINGERPRINT) |
Jorim Jaggi | 2aad7ee | 2015-04-14 15:25:06 -0700 | [diff] [blame] | 640 | public List<Fingerprint> getEnrolledFingerprints(int userId) { |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 641 | if (mService != null) try { |
Svetoslav | 4af76a5 | 2015-04-29 15:29:46 -0700 | [diff] [blame] | 642 | return mService.getEnrolledFingerprints(userId, mContext.getOpPackageName()); |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 643 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 644 | throw e.rethrowFromSystemServer(); |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 645 | } |
| 646 | return null; |
| 647 | } |
| 648 | |
| 649 | /** |
Jorim Jaggi | 2aad7ee | 2015-04-14 15:25:06 -0700 | [diff] [blame] | 650 | * Obtain the list of enrolled fingerprints templates. |
| 651 | * @return list of current fingerprint items |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 652 | * |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 653 | * @hide |
| 654 | */ |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 655 | @RequiresPermission(USE_FINGERPRINT) |
Jorim Jaggi | 2aad7ee | 2015-04-14 15:25:06 -0700 | [diff] [blame] | 656 | public List<Fingerprint> getEnrolledFingerprints() { |
| 657 | return getEnrolledFingerprints(UserHandle.myUserId()); |
| 658 | } |
| 659 | |
| 660 | /** |
| 661 | * Determine if there is at least one fingerprint enrolled. |
| 662 | * |
| 663 | * @return true if at least one fingerprint is enrolled, false otherwise |
| 664 | */ |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 665 | @RequiresPermission(USE_FINGERPRINT) |
Jorim Jaggi | 2aad7ee | 2015-04-14 15:25:06 -0700 | [diff] [blame] | 666 | public boolean hasEnrolledFingerprints() { |
| 667 | if (mService != null) try { |
Clara Bayarri | 33fd3cf | 2016-02-19 16:54:49 +0000 | [diff] [blame] | 668 | return mService.hasEnrolledFingerprints( |
| 669 | UserHandle.myUserId(), mContext.getOpPackageName()); |
| 670 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 671 | throw e.rethrowFromSystemServer(); |
Clara Bayarri | 33fd3cf | 2016-02-19 16:54:49 +0000 | [diff] [blame] | 672 | } |
| 673 | return false; |
| 674 | } |
| 675 | |
| 676 | /** |
| 677 | * @hide |
| 678 | */ |
| 679 | @RequiresPermission(allOf = { |
| 680 | USE_FINGERPRINT, |
| 681 | INTERACT_ACROSS_USERS}) |
| 682 | public boolean hasEnrolledFingerprints(int userId) { |
| 683 | if (mService != null) try { |
| 684 | return mService.hasEnrolledFingerprints(userId, mContext.getOpPackageName()); |
Jorim Jaggi | 2aad7ee | 2015-04-14 15:25:06 -0700 | [diff] [blame] | 685 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 686 | throw e.rethrowFromSystemServer(); |
Jorim Jaggi | 2aad7ee | 2015-04-14 15:25:06 -0700 | [diff] [blame] | 687 | } |
| 688 | return false; |
| 689 | } |
| 690 | |
| 691 | /** |
| 692 | * Determine if fingerprint hardware is present and functional. |
| 693 | * |
| 694 | * @return true if hardware is present and functional, false otherwise. |
| 695 | */ |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 696 | @RequiresPermission(USE_FINGERPRINT) |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 697 | public boolean isHardwareDetected() { |
| 698 | if (mService != null) { |
| 699 | try { |
| 700 | long deviceId = 0; /* TODO: plumb hardware id to FPMS */ |
Svetoslav | 4af76a5 | 2015-04-29 15:29:46 -0700 | [diff] [blame] | 701 | return mService.isHardwareDetected(deviceId, mContext.getOpPackageName()); |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 702 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 703 | throw e.rethrowFromSystemServer(); |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 704 | } |
| 705 | } else { |
| 706 | Log.w(TAG, "isFingerprintHardwareDetected(): Service not connected!"); |
| 707 | } |
| 708 | return false; |
| 709 | } |
Jim Miller | 08fa40c | 2014-04-29 18:18:47 -0700 | [diff] [blame] | 710 | |
Andres Morales | 4d41a20 | 2015-04-16 14:12:38 -0700 | [diff] [blame] | 711 | /** |
| 712 | * Retrieves the authenticator token for binding keys to the lifecycle |
| 713 | * of the current set of fingerprints. Used only by internal clients. |
| 714 | * |
| 715 | * @hide |
| 716 | */ |
| 717 | public long getAuthenticatorId() { |
| 718 | if (mService != null) { |
| 719 | try { |
Svetoslav | 4af76a5 | 2015-04-29 15:29:46 -0700 | [diff] [blame] | 720 | return mService.getAuthenticatorId(mContext.getOpPackageName()); |
Andres Morales | 4d41a20 | 2015-04-16 14:12:38 -0700 | [diff] [blame] | 721 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 722 | throw e.rethrowFromSystemServer(); |
Andres Morales | 4d41a20 | 2015-04-16 14:12:38 -0700 | [diff] [blame] | 723 | } |
| 724 | } else { |
| 725 | Log.w(TAG, "getAuthenticatorId(): Service not connected!"); |
| 726 | } |
| 727 | return 0; |
| 728 | } |
| 729 | |
Jim Miller | e0507bb | 2015-08-12 20:30:34 -0700 | [diff] [blame] | 730 | /** |
| 731 | * Reset the lockout timer when asked to do so by keyguard. |
| 732 | * |
| 733 | * @param token an opaque token returned by password confirmation. |
| 734 | * |
| 735 | * @hide |
| 736 | */ |
| 737 | public void resetTimeout(byte[] token) { |
| 738 | if (mService != null) { |
| 739 | try { |
| 740 | mService.resetTimeout(token); |
| 741 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 742 | throw e.rethrowFromSystemServer(); |
Jim Miller | e0507bb | 2015-08-12 20:30:34 -0700 | [diff] [blame] | 743 | } |
| 744 | } else { |
Jorim Jaggi | 3a46478 | 2015-08-28 16:59:13 -0700 | [diff] [blame] | 745 | Log.w(TAG, "resetTimeout(): Service not connected!"); |
| 746 | } |
| 747 | } |
| 748 | |
| 749 | /** |
| 750 | * @hide |
| 751 | */ |
| 752 | public void addLockoutResetCallback(final LockoutResetCallback callback) { |
| 753 | if (mService != null) { |
| 754 | try { |
Jorim Jaggi | 5e35422 | 2015-09-04 14:17:58 -0700 | [diff] [blame] | 755 | final PowerManager powerManager = mContext.getSystemService(PowerManager.class); |
Jorim Jaggi | 3a46478 | 2015-08-28 16:59:13 -0700 | [diff] [blame] | 756 | mService.addLockoutResetCallback( |
| 757 | new IFingerprintServiceLockoutResetCallback.Stub() { |
| 758 | |
| 759 | @Override |
| 760 | public void onLockoutReset(long deviceId) throws RemoteException { |
Jorim Jaggi | 5e35422 | 2015-09-04 14:17:58 -0700 | [diff] [blame] | 761 | final PowerManager.WakeLock wakeLock = powerManager.newWakeLock( |
| 762 | PowerManager.PARTIAL_WAKE_LOCK, "lockoutResetCallback"); |
| 763 | wakeLock.acquire(); |
Jorim Jaggi | 3a46478 | 2015-08-28 16:59:13 -0700 | [diff] [blame] | 764 | mHandler.post(new Runnable() { |
| 765 | @Override |
| 766 | public void run() { |
Jorim Jaggi | 5e35422 | 2015-09-04 14:17:58 -0700 | [diff] [blame] | 767 | try { |
| 768 | callback.onLockoutReset(); |
| 769 | } finally { |
| 770 | wakeLock.release(); |
| 771 | } |
Jorim Jaggi | 3a46478 | 2015-08-28 16:59:13 -0700 | [diff] [blame] | 772 | } |
| 773 | }); |
| 774 | } |
| 775 | }); |
| 776 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 777 | throw e.rethrowFromSystemServer(); |
Jorim Jaggi | 3a46478 | 2015-08-28 16:59:13 -0700 | [diff] [blame] | 778 | } |
| 779 | } else { |
| 780 | Log.w(TAG, "addLockoutResetCallback(): Service not connected!"); |
Jim Miller | e0507bb | 2015-08-12 20:30:34 -0700 | [diff] [blame] | 781 | } |
| 782 | } |
| 783 | |
Alex Klyubin | 24e9e96 | 2015-04-30 13:30:48 -0700 | [diff] [blame] | 784 | private class MyHandler extends Handler { |
| 785 | private MyHandler(Context context) { |
| 786 | super(context.getMainLooper()); |
| 787 | } |
| 788 | |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 789 | private MyHandler(Looper looper) { |
| 790 | super(looper); |
| 791 | } |
| 792 | |
Jim Miller | e0507bb | 2015-08-12 20:30:34 -0700 | [diff] [blame] | 793 | @Override |
Jim Miller | 08fa40c | 2014-04-29 18:18:47 -0700 | [diff] [blame] | 794 | public void handleMessage(android.os.Message msg) { |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 795 | switch(msg.what) { |
| 796 | case MSG_ENROLL_RESULT: |
| 797 | sendEnrollResult((Fingerprint) msg.obj, msg.arg1 /* remaining */); |
| 798 | break; |
| 799 | case MSG_ACQUIRED: |
| 800 | sendAcquiredResult((Long) msg.obj /* deviceId */, msg.arg1 /* acquire info */); |
| 801 | break; |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 802 | case MSG_AUTHENTICATION_SUCCEEDED: |
Jim Miller | 837fa7e | 2016-08-08 20:16:22 -0700 | [diff] [blame] | 803 | sendAuthenticatedSucceeded((Fingerprint) msg.obj, msg.arg1 /* userId */); |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 804 | break; |
| 805 | case MSG_AUTHENTICATION_FAILED: |
| 806 | sendAuthenticatedFailed(); |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 807 | break; |
| 808 | case MSG_ERROR: |
| 809 | sendErrorResult((Long) msg.obj /* deviceId */, msg.arg1 /* errMsgId */); |
| 810 | break; |
| 811 | case MSG_REMOVED: |
| 812 | sendRemovedResult((Long) msg.obj /* deviceId */, msg.arg1 /* fingerId */, |
| 813 | msg.arg2 /* groupId */); |
| 814 | } |
| 815 | } |
| 816 | |
| 817 | private void sendRemovedResult(long deviceId, int fingerId, int groupId) { |
| 818 | if (mRemovalCallback != null) { |
| 819 | int reqFingerId = mRemovalFingerprint.getFingerId(); |
| 820 | int reqGroupId = mRemovalFingerprint.getGroupId(); |
Jim Miller | 8f2aca0 | 2016-04-20 13:34:11 -0700 | [diff] [blame] | 821 | if (reqFingerId != 0 && fingerId != 0 && fingerId != reqFingerId) { |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 822 | Log.w(TAG, "Finger id didn't match: " + fingerId + " != " + reqFingerId); |
Jim Miller | 8f2aca0 | 2016-04-20 13:34:11 -0700 | [diff] [blame] | 823 | return; |
Jim Miller | 08fa40c | 2014-04-29 18:18:47 -0700 | [diff] [blame] | 824 | } |
Jim Miller | 1adb4a7 | 2015-09-14 18:58:08 -0700 | [diff] [blame] | 825 | if (groupId != reqGroupId) { |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 826 | Log.w(TAG, "Group id didn't match: " + groupId + " != " + reqGroupId); |
Jim Miller | 8f2aca0 | 2016-04-20 13:34:11 -0700 | [diff] [blame] | 827 | return; |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 828 | } |
Ricky Wai | f86f986 | 2016-03-23 12:05:42 +0000 | [diff] [blame] | 829 | mRemovalCallback.onRemovalSucceeded(new Fingerprint(null, groupId, fingerId, |
| 830 | deviceId)); |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 831 | } |
| 832 | } |
| 833 | |
| 834 | private void sendErrorResult(long deviceId, int errMsgId) { |
| 835 | if (mEnrollmentCallback != null) { |
| 836 | mEnrollmentCallback.onEnrollmentError(errMsgId, getErrorString(errMsgId)); |
| 837 | } else if (mAuthenticationCallback != null) { |
| 838 | mAuthenticationCallback.onAuthenticationError(errMsgId, getErrorString(errMsgId)); |
| 839 | } else if (mRemovalCallback != null) { |
| 840 | mRemovalCallback.onRemovalError(mRemovalFingerprint, errMsgId, |
| 841 | getErrorString(errMsgId)); |
| 842 | } |
| 843 | } |
| 844 | |
| 845 | private void sendEnrollResult(Fingerprint fp, int remaining) { |
| 846 | if (mEnrollmentCallback != null) { |
| 847 | mEnrollmentCallback.onEnrollmentProgress(remaining); |
| 848 | } |
| 849 | } |
| 850 | |
Jim Miller | 837fa7e | 2016-08-08 20:16:22 -0700 | [diff] [blame] | 851 | private void sendAuthenticatedSucceeded(Fingerprint fp, int userId) { |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 852 | if (mAuthenticationCallback != null) { |
Jim Miller | 837fa7e | 2016-08-08 20:16:22 -0700 | [diff] [blame] | 853 | final AuthenticationResult result = |
| 854 | new AuthenticationResult(mCryptoObject, fp, userId); |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 855 | mAuthenticationCallback.onAuthenticationSucceeded(result); |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | private void sendAuthenticatedFailed() { |
| 860 | if (mAuthenticationCallback != null) { |
| 861 | mAuthenticationCallback.onAuthenticationFailed(); |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 862 | } |
| 863 | } |
| 864 | |
| 865 | private void sendAcquiredResult(long deviceId, int acquireInfo) { |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 866 | if (mAuthenticationCallback != null) { |
| 867 | mAuthenticationCallback.onAuthenticationAcquired(acquireInfo); |
| 868 | } |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 869 | final String msg = getAcquiredString(acquireInfo); |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 870 | if (msg == null) { |
| 871 | return; |
| 872 | } |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 873 | if (mEnrollmentCallback != null) { |
| 874 | mEnrollmentCallback.onEnrollmentHelp(acquireInfo, msg); |
| 875 | } else if (mAuthenticationCallback != null) { |
| 876 | mAuthenticationCallback.onAuthenticationHelp(acquireInfo, msg); |
| 877 | } |
| 878 | } |
Jim Miller | 08fa40c | 2014-04-29 18:18:47 -0700 | [diff] [blame] | 879 | }; |
| 880 | |
Jim Miller | 06e658f | 2014-06-17 15:59:40 -0700 | [diff] [blame] | 881 | /** |
| 882 | * @hide |
| 883 | */ |
Jim Miller | a7596147 | 2014-06-06 15:00:49 -0700 | [diff] [blame] | 884 | public FingerprintManager(Context context, IFingerprintService service) { |
Jim Miller | d08c2ac | 2014-05-14 16:30:38 -0700 | [diff] [blame] | 885 | mContext = context; |
Jim Miller | a7596147 | 2014-06-06 15:00:49 -0700 | [diff] [blame] | 886 | mService = service; |
| 887 | if (mService == null) { |
| 888 | Slog.v(TAG, "FingerprintManagerService was null"); |
Jim Miller | 08fa40c | 2014-04-29 18:18:47 -0700 | [diff] [blame] | 889 | } |
Alex Klyubin | 24e9e96 | 2015-04-30 13:30:48 -0700 | [diff] [blame] | 890 | mHandler = new MyHandler(context); |
Jim Miller | 08fa40c | 2014-04-29 18:18:47 -0700 | [diff] [blame] | 891 | } |
| 892 | |
Jim Miller | 08fa40c | 2014-04-29 18:18:47 -0700 | [diff] [blame] | 893 | private int getCurrentUserId() { |
| 894 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame^] | 895 | return ActivityManager.getService().getCurrentUser().id; |
Jim Miller | 08fa40c | 2014-04-29 18:18:47 -0700 | [diff] [blame] | 896 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 897 | throw e.rethrowFromSystemServer(); |
Jim Miller | 08fa40c | 2014-04-29 18:18:47 -0700 | [diff] [blame] | 898 | } |
| 899 | } |
| 900 | |
Jim Miller | fe6439f | 2015-04-11 18:07:57 -0700 | [diff] [blame] | 901 | private void cancelEnrollment() { |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 902 | if (mService != null) try { |
| 903 | mService.cancelEnrollment(mToken); |
| 904 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 905 | throw e.rethrowFromSystemServer(); |
Jim Miller | 08fa40c | 2014-04-29 18:18:47 -0700 | [diff] [blame] | 906 | } |
| 907 | } |
Jim Miller | a7596147 | 2014-06-06 15:00:49 -0700 | [diff] [blame] | 908 | |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 909 | private void cancelAuthentication(CryptoObject cryptoObject) { |
| 910 | if (mService != null) try { |
Svetoslav | 4af76a5 | 2015-04-29 15:29:46 -0700 | [diff] [blame] | 911 | mService.cancelAuthentication(mToken, mContext.getOpPackageName()); |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 912 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 913 | throw e.rethrowFromSystemServer(); |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 914 | } |
| 915 | } |
| 916 | |
| 917 | private String getErrorString(int errMsg) { |
| 918 | switch (errMsg) { |
| 919 | case FINGERPRINT_ERROR_UNABLE_TO_PROCESS: |
| 920 | return mContext.getString( |
| 921 | com.android.internal.R.string.fingerprint_error_unable_to_process); |
| 922 | case FINGERPRINT_ERROR_HW_UNAVAILABLE: |
| 923 | return mContext.getString( |
| 924 | com.android.internal.R.string.fingerprint_error_hw_not_available); |
| 925 | case FINGERPRINT_ERROR_NO_SPACE: |
| 926 | return mContext.getString( |
| 927 | com.android.internal.R.string.fingerprint_error_no_space); |
| 928 | case FINGERPRINT_ERROR_TIMEOUT: |
Jim Miller | fe6439f | 2015-04-11 18:07:57 -0700 | [diff] [blame] | 929 | return mContext.getString(com.android.internal.R.string.fingerprint_error_timeout); |
| 930 | case FINGERPRINT_ERROR_CANCELED: |
| 931 | return mContext.getString(com.android.internal.R.string.fingerprint_error_canceled); |
| 932 | case FINGERPRINT_ERROR_LOCKOUT: |
| 933 | return mContext.getString(com.android.internal.R.string.fingerprint_error_lockout); |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 934 | default: |
| 935 | if (errMsg >= FINGERPRINT_ERROR_VENDOR_BASE) { |
| 936 | int msgNumber = errMsg - FINGERPRINT_ERROR_VENDOR_BASE; |
| 937 | String[] msgArray = mContext.getResources().getStringArray( |
| 938 | com.android.internal.R.array.fingerprint_error_vendor); |
| 939 | if (msgNumber < msgArray.length) { |
| 940 | return msgArray[msgNumber]; |
| 941 | } |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 942 | } |
Jim Miller | ce7eb6d | 2015-04-03 19:29:13 -0700 | [diff] [blame] | 943 | return null; |
| 944 | } |
| 945 | } |
| 946 | |
| 947 | private String getAcquiredString(int acquireInfo) { |
| 948 | switch (acquireInfo) { |
| 949 | case FINGERPRINT_ACQUIRED_GOOD: |
| 950 | return null; |
| 951 | case FINGERPRINT_ACQUIRED_PARTIAL: |
| 952 | return mContext.getString( |
| 953 | com.android.internal.R.string.fingerprint_acquired_partial); |
| 954 | case FINGERPRINT_ACQUIRED_INSUFFICIENT: |
| 955 | return mContext.getString( |
| 956 | com.android.internal.R.string.fingerprint_acquired_insufficient); |
| 957 | case FINGERPRINT_ACQUIRED_IMAGER_DIRTY: |
| 958 | return mContext.getString( |
| 959 | com.android.internal.R.string.fingerprint_acquired_imager_dirty); |
| 960 | case FINGERPRINT_ACQUIRED_TOO_SLOW: |
| 961 | return mContext.getString( |
| 962 | com.android.internal.R.string.fingerprint_acquired_too_slow); |
| 963 | case FINGERPRINT_ACQUIRED_TOO_FAST: |
| 964 | return mContext.getString( |
| 965 | com.android.internal.R.string.fingerprint_acquired_too_fast); |
| 966 | default: |
| 967 | if (acquireInfo >= FINGERPRINT_ACQUIRED_VENDOR_BASE) { |
| 968 | int msgNumber = acquireInfo - FINGERPRINT_ACQUIRED_VENDOR_BASE; |
| 969 | String[] msgArray = mContext.getResources().getStringArray( |
| 970 | com.android.internal.R.array.fingerprint_acquired_vendor); |
| 971 | if (msgNumber < msgArray.length) { |
| 972 | return msgArray[msgNumber]; |
| 973 | } |
| 974 | } |
| 975 | return null; |
Jim Miller | ba67aee | 2015-02-20 16:21:26 -0800 | [diff] [blame] | 976 | } |
Jim Miller | ba67aee | 2015-02-20 16:21:26 -0800 | [diff] [blame] | 977 | } |
Jim Miller | 99d6019 | 2015-03-11 17:41:58 -0700 | [diff] [blame] | 978 | |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 979 | private IFingerprintServiceReceiver mServiceReceiver = new IFingerprintServiceReceiver.Stub() { |
| 980 | |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 981 | @Override // binder call |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 982 | public void onEnrollResult(long deviceId, int fingerId, int groupId, int remaining) { |
| 983 | mHandler.obtainMessage(MSG_ENROLL_RESULT, remaining, 0, |
| 984 | new Fingerprint(null, groupId, fingerId, deviceId)).sendToTarget(); |
Jim Miller | 99d6019 | 2015-03-11 17:41:58 -0700 | [diff] [blame] | 985 | } |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 986 | |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 987 | @Override // binder call |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 988 | public void onAcquired(long deviceId, int acquireInfo) { |
| 989 | mHandler.obtainMessage(MSG_ACQUIRED, acquireInfo, 0, deviceId).sendToTarget(); |
| 990 | } |
| 991 | |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 992 | @Override // binder call |
Jim Miller | 837fa7e | 2016-08-08 20:16:22 -0700 | [diff] [blame] | 993 | public void onAuthenticationSucceeded(long deviceId, Fingerprint fp, int userId) { |
| 994 | mHandler.obtainMessage(MSG_AUTHENTICATION_SUCCEEDED, userId, 0, fp).sendToTarget(); |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 995 | } |
| 996 | |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 997 | @Override // binder call |
| 998 | public void onAuthenticationFailed(long deviceId) { |
| 999 | mHandler.obtainMessage(MSG_AUTHENTICATION_FAILED).sendToTarget();; |
| 1000 | } |
| 1001 | |
| 1002 | @Override // binder call |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 1003 | public void onError(long deviceId, int error) { |
| 1004 | mHandler.obtainMessage(MSG_ERROR, error, 0, deviceId).sendToTarget(); |
| 1005 | } |
| 1006 | |
Jim Miller | f501b58 | 2015-06-03 16:36:31 -0700 | [diff] [blame] | 1007 | @Override // binder call |
Jim Miller | 9f0753f | 2015-03-23 23:59:22 -0700 | [diff] [blame] | 1008 | public void onRemoved(long deviceId, int fingerId, int groupId) { |
| 1009 | mHandler.obtainMessage(MSG_REMOVED, fingerId, groupId, deviceId).sendToTarget(); |
| 1010 | } |
| 1011 | }; |
| 1012 | |
Andres Morales | 4d41a20 | 2015-04-16 14:12:38 -0700 | [diff] [blame] | 1013 | } |