• 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.settings.SettingsEnums;
20 import android.content.Intent;
21 import android.hardware.fingerprint.FingerprintManager;
22 import android.os.Bundle;
23 import android.view.View;
24 
25 import androidx.annotation.Nullable;
26 
27 import com.android.settings.R;
28 import com.android.settings.Utils;
29 import com.android.settings.biometrics.BiometricEnrollBase;
30 import com.android.settings.biometrics.BiometricEnrollSidecar.Listener;
31 import com.android.settings.password.ChooseLockSettingsHelper;
32 
33 import com.google.android.setupcompat.template.FooterBarMixin;
34 import com.google.android.setupcompat.template.FooterButton;
35 
36 /**
37  * Activity explaining the fingerprint sensor location for fingerprint enrollment.
38  */
39 public class FingerprintEnrollFindSensor extends BiometricEnrollBase {
40 
41     @Nullable
42     private FingerprintFindSensorAnimation mAnimation;
43 
44     private FingerprintEnrollSidecar mSidecar;
45     private boolean mNextClicked;
46 
47     @Override
onCreate(Bundle savedInstanceState)48     protected void onCreate(Bundle savedInstanceState) {
49         super.onCreate(savedInstanceState);
50         setContentView(getContentView());
51         mFooterBarMixin = getLayout().getMixin(FooterBarMixin.class);
52         mFooterBarMixin.setSecondaryButton(
53                 new FooterButton.Builder(this)
54                         .setText(R.string.skip_label)
55                         .setListener(this::onSkipButtonClick)
56                         .setButtonType(FooterButton.ButtonType.SKIP)
57                         .setTheme(R.style.SudGlifButton_Secondary)
58                         .build()
59         );
60 
61         setHeaderText(R.string.security_settings_fingerprint_enroll_find_sensor_title);
62 
63 
64         startLookingForFingerprint(); // already confirmed, so start looking for fingerprint
65 
66         View animationView = findViewById(R.id.fingerprint_sensor_location_animation);
67         if (animationView instanceof FingerprintFindSensorAnimation) {
68             mAnimation = (FingerprintFindSensorAnimation) animationView;
69         } else {
70             mAnimation = null;
71         }
72     }
73 
getContentView()74     protected int getContentView() {
75         return R.layout.fingerprint_enroll_find_sensor;
76     }
77 
78     @Override
onStart()79     protected void onStart() {
80         super.onStart();
81         if (mAnimation != null) {
82             mAnimation.startAnimation();
83         }
84     }
85 
startLookingForFingerprint()86     private void startLookingForFingerprint() {
87         mSidecar = (FingerprintEnrollSidecar) getSupportFragmentManager().findFragmentByTag(
88                 FingerprintEnrollEnrolling.TAG_SIDECAR);
89         if (mSidecar == null) {
90             mSidecar = new FingerprintEnrollSidecar();
91             getSupportFragmentManager().beginTransaction()
92                     .add(mSidecar, FingerprintEnrollEnrolling.TAG_SIDECAR)
93                     .commitAllowingStateLoss();
94         }
95         mSidecar.setListener(new Listener() {
96             @Override
97             public void onEnrollmentProgressChange(int steps, int remaining) {
98                 mNextClicked = true;
99                 proceedToEnrolling(true /* cancelEnrollment */);
100             }
101 
102             @Override
103             public void onEnrollmentHelp(int helpMsgId, CharSequence helpString) {
104             }
105 
106             @Override
107             public void onEnrollmentError(int errMsgId, CharSequence errString) {
108                 if (mNextClicked && errMsgId == FingerprintManager.FINGERPRINT_ERROR_CANCELED) {
109                     mNextClicked = false;
110                     proceedToEnrolling(false /* cancelEnrollment */);
111                 }
112             }
113         });
114     }
115 
116     @Override
onStop()117     protected void onStop() {
118         super.onStop();
119         if (mAnimation != null) {
120             mAnimation.pauseAnimation();
121         }
122     }
123 
124     @Override
onDestroy()125     protected void onDestroy() {
126         super.onDestroy();
127         if (mAnimation != null) {
128             mAnimation.stopAnimation();
129         }
130     }
131 
onSkipButtonClick(View view)132     protected void onSkipButtonClick(View view) {
133         setResult(RESULT_SKIP);
134         finish();
135     }
136 
proceedToEnrolling(boolean cancelEnrollment)137     private void proceedToEnrolling(boolean cancelEnrollment) {
138         if (mSidecar != null) {
139             if (cancelEnrollment) {
140                 if (mSidecar.cancelEnrollment()) {
141                     // Enrollment cancel requested. When the cancellation is successful,
142                     // onEnrollmentError will be called with FINGERPRINT_ERROR_CANCELED, calling
143                     // this again.
144                     return;
145                 }
146             }
147             getSupportFragmentManager().beginTransaction().remove(mSidecar).
148                     commitAllowingStateLoss();
149             mSidecar = null;
150             startActivityForResult(getFingerprintEnrollingIntent(), ENROLL_REQUEST);
151         }
152     }
153 
154     @Override
onActivityResult(int requestCode, int resultCode, Intent data)155     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
156         if (requestCode == CONFIRM_REQUEST) {
157             if (resultCode == RESULT_OK && data != null) {
158                 mToken = data.getByteArrayExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN);
159                 overridePendingTransition(R.anim.sud_slide_next_in, R.anim.sud_slide_next_out);
160                 getIntent().putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, mToken);
161                 startLookingForFingerprint();
162             } else {
163                 finish();
164             }
165         } else if (requestCode == ENROLL_REQUEST) {
166             if (resultCode == RESULT_FINISHED) {
167                 setResult(RESULT_FINISHED);
168                 finish();
169             } else if (resultCode == RESULT_SKIP) {
170                 setResult(RESULT_SKIP);
171                 finish();
172             } else if (resultCode == RESULT_TIMEOUT) {
173                 setResult(RESULT_TIMEOUT);
174                 finish();
175             } else {
176                 FingerprintManager fpm = Utils.getFingerprintManagerOrNull(this);
177                 int enrolled = fpm.getEnrolledFingerprints().size();
178                 int max = getResources().getInteger(
179                         com.android.internal.R.integer.config_fingerprintMaxTemplatesPerUser);
180                 if (enrolled >= max) {
181                     finish();
182                 } else {
183                     // We came back from enrolling but it wasn't completed, start again.
184                     startLookingForFingerprint();
185                 }
186             }
187         } else {
188             super.onActivityResult(requestCode, resultCode, data);
189         }
190     }
191 
192     @Override
getMetricsCategory()193     public int getMetricsCategory() {
194         return SettingsEnums.FINGERPRINT_FIND_SENSOR;
195     }
196 }
197