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.Activity;
20 import android.app.admin.DevicePolicyManager;
21 import android.content.ActivityNotFoundException;
22 import android.content.Context;
23 import android.content.Intent;
24 import android.hardware.fingerprint.FingerprintManager;
25 import android.graphics.Typeface;
26 import android.graphics.drawable.Drawable;
27 import android.os.Bundle;
28 import android.os.UserHandle;
29 import android.text.Annotation;
30 import android.text.SpannableString;
31 import android.text.SpannableStringBuilder;
32 import android.text.TextPaint;
33 import android.text.method.LinkMovementMethod;
34 import android.text.style.URLSpan;
35 import android.util.Log;
36 import android.view.View;
37 import android.widget.AdapterView;
39 import com.android.internal.logging.MetricsProto.MetricsEvent;
40 import com.android.settings.ChooseLockGeneric;
41 import com.android.settings.ChooseLockSettingsHelper;
42 import com.android.settings.HelpUtils;
43 import com.android.settings.R;
44 import com.android.setupwizardlib.SetupWizardItemsLayout;
45 import com.android.setupwizardlib.items.Item;
46 import com.android.setupwizardlib.items.ItemAdapter;
49 * Onboarding activity for fingerprint enrollment.
51 public class FingerprintEnrollIntroduction extends FingerprintEnrollBase
52 implements AdapterView.OnItemClickListener {
54 protected static final int CHOOSE_LOCK_GENERIC_REQUEST = 1;
55 protected static final int FINGERPRINT_FIND_SENSOR_REQUEST = 2;
56 protected static final int LEARN_MORE_REQUEST = 3;
58 private boolean mHasPassword;
61 protected void onCreate(Bundle savedInstanceState) {
62 super.onCreate(savedInstanceState);
63 setContentView(R.layout.fingerprint_enroll_introduction);
64 setHeaderText(R.string.security_settings_fingerprint_enroll_introduction_title);
65 final SetupWizardItemsLayout layout =
66 (SetupWizardItemsLayout) findViewById(R.id.setup_wizard_layout);
67 layout.getListView().setOnItemClickListener(this);
68 final ItemAdapter adapter = (ItemAdapter) layout.getAdapter();
69 Item item = (Item) adapter.findItemById(R.id.fingerprint_introduction_message);
70 item.setTitle(LearnMoreSpan.linkify(
71 getText(R.string.security_settings_fingerprint_enroll_introduction_message),
72 getString(R.string.help_url_fingerprint)));
73 updatePasswordQuality();
76 private void updatePasswordQuality() {
77 final int passwordQuality = new ChooseLockSettingsHelper(this).utils()
78 .getActivePasswordQuality(mUserId);
79 mHasPassword = passwordQuality != DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
83 protected void onNextButtonClick() {
85 // No fingerprints registered, launch into enrollment wizard.
88 // Lock thingy is already set up, launch directly into find sensor step from wizard.
89 launchFindSensor(null);
93 private void launchChooseLock() {
94 Intent intent = getChooseLockIntent();
95 long challenge = getSystemService(FingerprintManager.class).preEnroll();
96 intent.putExtra(ChooseLockGeneric.ChooseLockGenericFragment.MINIMUM_QUALITY_KEY,
97 DevicePolicyManager.PASSWORD_QUALITY_SOMETHING);
98 intent.putExtra(ChooseLockGeneric.ChooseLockGenericFragment.HIDE_DISABLED_PREFS, true);
99 intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE, true);
100 intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE, challenge);
101 intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT, true);
102 if (mUserId != UserHandle.USER_NULL) {
103 intent.putExtra(Intent.EXTRA_USER_ID, mUserId);
105 startActivityForResult(intent, CHOOSE_LOCK_GENERIC_REQUEST);
108 private void launchFindSensor(byte[] token) {
109 Intent intent = getFindSensorIntent();
111 intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, token);
113 if (mUserId != UserHandle.USER_NULL) {
114 intent.putExtra(Intent.EXTRA_USER_ID, mUserId);
116 startActivityForResult(intent, FINGERPRINT_FIND_SENSOR_REQUEST);
119 protected Intent getChooseLockIntent() {
120 return new Intent(this, ChooseLockGeneric.class);
123 protected Intent getFindSensorIntent() {
124 Intent intent = new Intent(this, FingerprintEnrollFindSensor.class);
129 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
130 final boolean isResultFinished = resultCode == RESULT_FINISHED;
131 if (requestCode == FINGERPRINT_FIND_SENSOR_REQUEST) {
132 if (isResultFinished || resultCode == RESULT_SKIP) {
133 final int result = isResultFinished ? RESULT_OK : RESULT_SKIP;
134 setResult(result, data);
138 } else if (requestCode == CHOOSE_LOCK_GENERIC_REQUEST) {
139 if (isResultFinished) {
140 updatePasswordQuality();
141 byte[] token = data.getByteArrayExtra(
142 ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN);
143 launchFindSensor(token);
147 super.onActivityResult(requestCode, resultCode, data);
151 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
152 final Item item = (Item) parent.getItemAtPosition(position);
153 switch (item.getId()) {
154 case R.id.next_button:
157 case R.id.cancel_button:
158 onCancelButtonClick();
164 protected int getMetricsCategory() {
165 return MetricsEvent.FINGERPRINT_ENROLL_INTRO;
168 protected void onCancelButtonClick() {
172 private static class LearnMoreSpan extends URLSpan {
173 private static final String TAG = "LearnMoreSpan";
174 private static final Typeface TYPEFACE_MEDIUM =
175 Typeface.create("sans-serif-medium", Typeface.NORMAL);
177 private LearnMoreSpan(String url) {
182 public void onClick(View widget) {
183 Context ctx = widget.getContext();
184 Intent intent = HelpUtils.getHelpIntent(ctx, getURL(), ctx.getClass().getName());
186 // This needs to be startActivityForResult even though we do not care about the
187 // actual result because the help app needs to know about who invoked it.
188 widget.startActivityForResult(intent, LEARN_MORE_REQUEST);
189 } catch (ActivityNotFoundException e) {
190 Log.w(LearnMoreSpan.TAG,
191 "Actvity was not found for intent, " + intent.toString());
196 public void updateDrawState(TextPaint ds) {
197 super.updateDrawState(ds);
198 ds.setUnderlineText(false);
199 ds.setTypeface(TYPEFACE_MEDIUM);
202 public static CharSequence linkify(CharSequence rawText, String uri) {
203 SpannableString msg = new SpannableString(rawText);
204 Annotation[] spans = msg.getSpans(0, msg.length(), Annotation.class);
205 SpannableStringBuilder builder = new SpannableStringBuilder(msg);
206 for (Annotation annotation : spans) {
207 int start = msg.getSpanStart(annotation);
208 int end = msg.getSpanEnd(annotation);
209 LearnMoreSpan link = new LearnMoreSpan(uri);
210 builder.setSpan(link, start, end, msg.getSpanFlags(link));