• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.KeyguardManager;
20 import android.app.settings.SettingsEnums;
21 import android.content.Intent;
22 import android.hardware.fingerprint.FingerprintManager;
23 import android.view.View;
24 
25 import com.android.settings.SetupWizardUtils;
26 import com.android.settings.Utils;
27 import com.android.settings.biometrics.BiometricUtils;
28 import com.android.settings.password.ChooseLockSettingsHelper;
29 import com.android.settings.password.SetupSkipDialog;
30 
31 public class SetupFingerprintEnrollIntroduction extends FingerprintEnrollIntroduction {
32     /**
33      * Returns the number of fingerprint enrolled.
34      */
35     public static final String EXTRA_FINGERPRINT_ENROLLED_COUNT = "fingerprint_enrolled_count";
36 
37     private static final String KEY_LOCK_SCREEN_PRESENT = "wasLockScreenPresent";
38 
39     @Override
getEnrollingIntent()40     protected Intent getEnrollingIntent() {
41         final Intent intent = new Intent(this, SetupFingerprintEnrollFindSensor.class);
42         BiometricUtils.copyMultiBiometricExtras(getIntent(), intent);
43         if (BiometricUtils.containsGatekeeperPasswordHandle(getIntent())) {
44             intent.putExtra(
45                     ChooseLockSettingsHelper.EXTRA_KEY_GK_PW_HANDLE,
46                     BiometricUtils.getGatekeeperPasswordHandle(getIntent()));
47         }
48         SetupWizardUtils.copySetupExtras(getIntent(), intent);
49         return intent;
50     }
51 
52     @Override
onActivityResult(int requestCode, int resultCode, Intent data)53     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
54         boolean hasEnrolledFace = false;
55         boolean hasEnrolledFingerprint = false;
56         if (data != null) {
57             hasEnrolledFace = data.getBooleanExtra(EXTRA_FINISHED_ENROLL_FACE, false);
58             hasEnrolledFingerprint = data.getBooleanExtra(EXTRA_FINISHED_ENROLL_FINGERPRINT, false);
59             // If we've enrolled a face, we can remove the pending intent to launch FaceEnrollIntro.
60             if (hasEnrolledFace) {
61                 removeEnrollNextBiometric();
62             }
63         }
64         if (requestCode == BIOMETRIC_FIND_SENSOR_REQUEST && isKeyguardSecure()) {
65             // Report fingerprint count if user adding a new fingerprint
66             if (resultCode == RESULT_FINISHED) {
67                 data = setFingerprintCount(data);
68             }
69 
70             if (resultCode == RESULT_CANCELED && hasEnrolledFingerprint) {
71                 // If we are coming from a back press from an already enrolled fingerprint,
72                 // we can finish this activity.
73                 setResult(resultCode, data);
74                 finish();
75                 return;
76             }
77         } else if (requestCode == ENROLL_NEXT_BIOMETRIC_REQUEST) {
78             // See if we can still enroll a fingerprint
79             boolean canEnrollFinger = checkMaxEnrolled() == 0;
80             // If we came from the next biometric flow and a user has either
81             // finished or skipped, we will also finish.
82             if (resultCode == RESULT_SKIP || resultCode == RESULT_FINISHED) {
83                 // If user skips the enroll next biometric, we will also finish
84                 setResult(RESULT_FINISHED, data);
85                 finish();
86             } else if (resultCode == RESULT_CANCELED) {
87                 // Note that result_canceled comes from onBackPressed.
88                 // If we can enroll a finger, Stay on this page, else we cannot,
89                 // and finish entirely.
90                 if (!canEnrollFinger) {
91                     finish();
92                 }
93             } else {
94                 super.onActivityResult(requestCode, resultCode, data);
95             }
96             return;
97         }
98         super.onActivityResult(requestCode, resultCode, data);
99     }
100 
setFingerprintCount(Intent data)101     private Intent setFingerprintCount(Intent data) {
102         if (data == null) {
103             data = new Intent();
104         }
105         final FingerprintManager fpm = Utils.getFingerprintManagerOrNull(this);
106         if (fpm != null) {
107             int enrolled = fpm.getEnrolledFingerprints(mUserId).size();
108             data.putExtra(EXTRA_FINGERPRINT_ENROLLED_COUNT, enrolled);
109         }
110         return data;
111     }
112 
113     @Override
onCancelButtonClick(View view)114     protected void onCancelButtonClick(View view) {
115         final int resultCode;
116         Intent data;
117         if (isKeyguardSecure()) {
118             // If the keyguard is already set up securely (maybe the user added a backup screen
119             // lock and skipped fingerprint), return RESULT_SKIP directly.
120             if (!BiometricUtils.tryStartingNextBiometricEnroll(
121                     this, ENROLL_NEXT_BIOMETRIC_REQUEST, "cancel")) {
122                 resultCode = RESULT_SKIP;
123                 setResult(resultCode);
124                 finish();
125                 return;
126             }
127         } else {
128             resultCode = SetupSkipDialog.RESULT_SKIP;
129             data = setSkipPendingEnroll(null);
130             setResult(resultCode, data);
131             finish();
132         }
133 
134         // User has explicitly canceled enroll. Don't restart it automatically.
135     }
136 
isKeyguardSecure()137     private boolean isKeyguardSecure() {
138         return getSystemService(KeyguardManager.class).isKeyguardSecure();
139     }
140 
141     @Override
getMetricsCategory()142     public int getMetricsCategory() {
143         return SettingsEnums.FINGERPRINT_ENROLL_INTRO_SETUP;
144     }
145 }
146