1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License 15 */ 16 17 package com.android.settings.biometrics.fingerprint; 18 19 import android.app.Activity; 20 import android.app.settings.SettingsEnums; 21 import android.hardware.fingerprint.FingerprintManager; 22 import android.util.Log; 23 24 import com.android.settings.R; 25 import com.android.settings.Utils; 26 import com.android.settings.biometrics.BiometricEnrollSidecar; 27 28 /** 29 * Sidecar fragment to handle the state around fingerprint enrollment. 30 */ 31 public class FingerprintEnrollSidecar extends BiometricEnrollSidecar { 32 private static final String TAG = "FingerprintEnrollSidecar"; 33 34 private FingerprintManager mFingerprintManager; 35 private @FingerprintManager.EnrollReason int mEnrollReason; 36 37 @Override onAttach(Activity activity)38 public void onAttach(Activity activity) { 39 super.onAttach(activity); 40 mFingerprintManager = Utils.getFingerprintManagerOrNull(activity); 41 } 42 43 @Override startEnrollment()44 protected void startEnrollment() { 45 super.startEnrollment(); 46 47 if (mToken == null) { 48 Log.e(TAG, "Null hardware auth token for enroll"); 49 onEnrollmentError(FingerprintManager.FINGERPRINT_ERROR_HW_UNAVAILABLE, 50 getString(R.string.fingerprint_intro_error_unknown)); 51 return; 52 } 53 54 mFingerprintManager.enroll(mToken, mEnrollmentCancel, mUserId, mEnrollmentCallback, 55 mEnrollReason); 56 } 57 setEnrollReason(@ingerprintManager.EnrollReason int enrollReason)58 public void setEnrollReason(@FingerprintManager.EnrollReason int enrollReason) { 59 mEnrollReason = enrollReason; 60 } 61 62 private FingerprintManager.EnrollmentCallback mEnrollmentCallback 63 = new FingerprintManager.EnrollmentCallback() { 64 65 @Override 66 public void onEnrollmentProgress(int remaining) { 67 FingerprintEnrollSidecar.super.onEnrollmentProgress(remaining); 68 } 69 70 @Override 71 public void onEnrollmentHelp(int helpMsgId, CharSequence helpString) { 72 FingerprintEnrollSidecar.super.onEnrollmentHelp(helpMsgId, helpString); 73 } 74 75 @Override 76 public void onEnrollmentError(int errMsgId, CharSequence errString) { 77 FingerprintEnrollSidecar.super.onEnrollmentError(errMsgId, errString); 78 } 79 }; 80 81 @Override getMetricsCategory()82 public int getMetricsCategory() { 83 return SettingsEnums.FINGERPRINT_ENROLL_SIDECAR; 84 } 85 } 86