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 com.android.settings.biometrics; 18 19 import android.app.settings.SettingsEnums; 20 import android.content.Intent; 21 import android.content.pm.PackageManager; 22 import android.os.Bundle; 23 import android.os.UserHandle; 24 25 import com.android.settings.SetupWizardUtils; 26 import com.android.settings.biometrics.face.FaceEnrollIntroduction; 27 import com.android.settings.biometrics.fingerprint.FingerprintEnrollFindSensor; 28 import com.android.settings.biometrics.fingerprint.FingerprintEnrollIntroduction; 29 import com.android.settings.biometrics.fingerprint.SetupFingerprintEnrollIntroduction; 30 import com.android.settings.core.InstrumentedActivity; 31 import com.android.settings.password.ChooseLockSettingsHelper; 32 33 import com.google.android.setupcompat.util.WizardManagerHelper; 34 35 /** 36 * Trampoline activity launched by the {@code android.settings.BIOMETRIC_ENROLL} action which 37 * shows the user an appropriate enrollment flow depending on the device's biometric hardware. 38 * This activity must only allow enrollment of biometrics that can be used by 39 * {@link android.hardware.biometrics.BiometricPrompt}. 40 */ 41 public class BiometricEnrollActivity extends InstrumentedActivity { 42 43 private static final String TAG = "BiometricEnrollActivity"; 44 45 public static final String EXTRA_SKIP_INTRO = "skip_intro"; 46 47 public static final class InternalActivity extends BiometricEnrollActivity {} 48 49 @Override onCreate(Bundle savedInstanceState)50 public void onCreate(Bundle savedInstanceState) { 51 super.onCreate(savedInstanceState); 52 53 final PackageManager pm = getApplicationContext().getPackageManager(); 54 Intent intent = null; 55 56 // This logic may have to be modified on devices with multiple biometrics. 57 if (pm.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)) { 58 // ChooseLockGeneric can request to start fingerprint enroll bypassing the intro screen. 59 if (getIntent().getBooleanExtra(EXTRA_SKIP_INTRO, false) 60 && this instanceof InternalActivity) { 61 intent = getFingerprintFindSensorIntent(); 62 } else { 63 intent = getFingerprintIntroIntent(); 64 } 65 } else if (pm.hasSystemFeature(PackageManager.FEATURE_FACE)) { 66 intent = getFaceIntroIntent(); 67 } 68 69 if (intent != null) { 70 intent.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT); 71 72 if (this instanceof InternalActivity) { 73 // Propagate challenge and user Id from ChooseLockGeneric. 74 final byte[] token = getIntent() 75 .getByteArrayExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN); 76 final int userId = getIntent() 77 .getIntExtra(Intent.EXTRA_USER_ID, UserHandle.USER_NULL); 78 79 intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, token); 80 intent.putExtra(Intent.EXTRA_USER_ID, userId); 81 } 82 83 startActivity(intent); 84 } 85 finish(); 86 } 87 getFingerprintFindSensorIntent()88 private Intent getFingerprintFindSensorIntent() { 89 Intent intent = new Intent(this, FingerprintEnrollFindSensor.class); 90 SetupWizardUtils.copySetupExtras(getIntent(), intent); 91 return intent; 92 } 93 getFingerprintIntroIntent()94 private Intent getFingerprintIntroIntent() { 95 if (WizardManagerHelper.isAnySetupWizard(getIntent())) { 96 Intent intent = new Intent(this, SetupFingerprintEnrollIntroduction.class); 97 WizardManagerHelper.copyWizardManagerExtras(getIntent(), intent); 98 return intent; 99 } else { 100 return new Intent(this, FingerprintEnrollIntroduction.class); 101 } 102 } 103 getFaceIntroIntent()104 private Intent getFaceIntroIntent() { 105 Intent intent = new Intent(this, FaceEnrollIntroduction.class); 106 WizardManagerHelper.copyWizardManagerExtras(getIntent(), intent); 107 return intent; 108 } 109 110 @Override getMetricsCategory()111 public int getMetricsCategory() { 112 return SettingsEnums.BIOMETRIC_ENROLL_ACTIVITY; 113 } 114 } 115