2 * Copyright (C) 2015 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
17 package com.android.settings.fingerprint;
19 import android.app.admin.DevicePolicyManager;
20 import android.content.Intent;
21 import android.hardware.fingerprint.FingerprintManager;
22 import android.os.Bundle;
23 import android.os.UserHandle;
24 import android.view.View;
26 import com.android.internal.logging.MetricsProto.MetricsEvent;
27 import com.android.settings.ChooseLockGeneric;
28 import com.android.settings.ChooseLockSettingsHelper;
29 import com.android.settings.HelpUtils;
30 import com.android.settings.R;
33 * Onboarding activity for fingerprint enrollment.
35 public class FingerprintEnrollIntroduction extends FingerprintEnrollBase {
37 private static final int CHOOSE_LOCK_GENERIC_REQUEST = 1;
38 private static final int FINGERPRINT_FIND_SENSOR_REQUEST = 2;
40 private boolean mHasPassword;
43 protected void onCreate(Bundle savedInstanceState) {
44 super.onCreate(savedInstanceState);
45 setContentView(R.layout.fingerprint_enroll_introduction);
46 setHeaderText(R.string.security_settings_fingerprint_enroll_introduction_title);
47 findViewById(R.id.cancel_button).setOnClickListener(this);
48 findViewById(R.id.learn_more_button).setOnClickListener(this);
49 updatePasswordQuality();
52 private void updatePasswordQuality() {
53 final int passwordQuality = new ChooseLockSettingsHelper(this).utils()
54 .getActivePasswordQuality(mUserId);
55 mHasPassword = passwordQuality != DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
59 protected void onNextButtonClick() {
61 // No fingerprints registered, launch into enrollment wizard.
64 // Lock thingy is already set up, launch directly into find sensor step from wizard.
65 launchFindSensor(null);
69 private void launchChooseLock() {
70 Intent intent = getChooseLockIntent();
71 long challenge = getSystemService(FingerprintManager.class).preEnroll();
72 intent.putExtra(ChooseLockGeneric.ChooseLockGenericFragment.MINIMUM_QUALITY_KEY,
73 DevicePolicyManager.PASSWORD_QUALITY_SOMETHING);
74 intent.putExtra(ChooseLockGeneric.ChooseLockGenericFragment.HIDE_DISABLED_PREFS, true);
75 intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE, true);
76 intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE, challenge);
77 intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT, true);
78 if (mUserId != UserHandle.USER_NULL) {
79 intent.putExtra(Intent.EXTRA_USER_ID, mUserId);
81 startActivityForResult(intent, CHOOSE_LOCK_GENERIC_REQUEST);
84 private void launchFindSensor(byte[] token) {
85 Intent intent = getFindSensorIntent();
87 intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, token);
89 if (mUserId != UserHandle.USER_NULL) {
90 intent.putExtra(Intent.EXTRA_USER_ID, mUserId);
92 startActivityForResult(intent, FINGERPRINT_FIND_SENSOR_REQUEST);
95 protected Intent getChooseLockIntent() {
96 return new Intent(this, ChooseLockGeneric.class);
99 protected Intent getFindSensorIntent() {
100 Intent intent = new Intent(this, FingerprintEnrollFindSensor.class);
105 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
106 final boolean isResultFinished = resultCode == RESULT_FINISHED;
107 if (requestCode == FINGERPRINT_FIND_SENSOR_REQUEST) {
108 if (isResultFinished || resultCode == RESULT_SKIP) {
109 final int result = isResultFinished ? RESULT_OK : RESULT_SKIP;
114 } else if (requestCode == CHOOSE_LOCK_GENERIC_REQUEST) {
115 if (isResultFinished) {
116 updatePasswordQuality();
117 byte[] token = data.getByteArrayExtra(
118 ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN);
119 launchFindSensor(token);
123 super.onActivityResult(requestCode, resultCode, data);
127 public void onClick(View v) {
128 if (v.getId() == R.id.cancel_button) {
131 if (v.getId() == R.id.learn_more_button) {
132 launchFingerprintHelp();
137 private void launchFingerprintHelp() {
138 Intent helpIntent = HelpUtils.getHelpIntent(this,
139 getString(R.string.help_url_fingerprint), getClass().getName());
140 startActivity(helpIntent);
144 protected int getMetricsCategory() {
145 return MetricsEvent.FINGERPRINT_ENROLL_INTRO;