• 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.ComponentName;
21 import android.content.Intent;
22 import android.content.pm.PackageManager;
23 import android.hardware.fingerprint.FingerprintManager;
24 import android.os.Bundle;
25 import android.util.Log;
26 import android.view.View;
27 
28 import androidx.annotation.VisibleForTesting;
29 
30 import com.android.settings.R;
31 import com.android.settings.Utils;
32 import com.android.settings.biometrics.BiometricEnrollBase;
33 import com.android.settings.password.ChooseLockSettingsHelper;
34 
35 import com.google.android.setupcompat.template.FooterBarMixin;
36 import com.google.android.setupcompat.template.FooterButton;
37 import com.google.android.setupcompat.util.WizardManagerHelper;
38 
39 /**
40  * Activity which concludes fingerprint enrollment.
41  */
42 public class FingerprintEnrollFinish extends BiometricEnrollBase {
43 
44     private static final String TAG = "FingerprintEnrollFinish";
45     private static final String ACTION_FINGERPRINT_SETTINGS =
46             "android.settings.FINGERPRINT_SETTINGS";
47     @VisibleForTesting
48     static final int REQUEST_ADD_ANOTHER = 1;
49     @VisibleForTesting
50     static final String FINGERPRINT_SUGGESTION_ACTIVITY =
51             "com.android.settings.SetupFingerprintSuggestionActivity";
52 
53     @Override
onCreate(Bundle savedInstanceState)54     protected void onCreate(Bundle savedInstanceState) {
55         super.onCreate(savedInstanceState);
56         setContentView(R.layout.fingerprint_enroll_finish);
57         setHeaderText(R.string.security_settings_fingerprint_enroll_finish_title);
58         setDescriptionText(R.string.security_settings_fingerprint_enroll_finish_message);
59 
60         mFooterBarMixin = getLayout().getMixin(FooterBarMixin.class);
61         mFooterBarMixin.setSecondaryButton(
62                 new FooterButton.Builder(this)
63                         .setText(R.string.fingerprint_enroll_button_add)
64                         .setButtonType(FooterButton.ButtonType.SKIP)
65                         .setTheme(R.style.SudGlifButton_Secondary)
66                         .build()
67         );
68 
69         mFooterBarMixin.setPrimaryButton(
70                 new FooterButton.Builder(this)
71                         .setText(R.string.security_settings_fingerprint_enroll_done)
72                         .setListener(this::onNextButtonClick)
73                         .setButtonType(FooterButton.ButtonType.NEXT)
74                         .setTheme(R.style.SudGlifButton_Primary)
75                         .build()
76         );
77     }
78 
79     @Override
onBackPressed()80     public void onBackPressed() {
81         super.onBackPressed();
82 
83         updateFingerprintSuggestionEnableState();
84     }
85 
86     @Override
onResume()87     protected void onResume() {
88         super.onResume();
89 
90         FooterButton addButton = mFooterBarMixin.getSecondaryButton();
91 
92         final FingerprintManager fpm = Utils.getFingerprintManagerOrNull(this);
93         boolean hideAddAnother = false;
94         if (fpm != null) {
95             int enrolled = fpm.getEnrolledFingerprints(mUserId).size();
96             int max = getResources().getInteger(
97                     com.android.internal.R.integer.config_fingerprintMaxTemplatesPerUser);
98             hideAddAnother = enrolled >= max;
99         }
100         if (hideAddAnother) {
101             // Don't show "Add" button if too many fingerprints already added
102             addButton.setVisibility(View.INVISIBLE);
103         } else {
104             addButton.setOnClickListener(this::onAddAnotherButtonClick);
105         }
106     }
107 
108     @Override
onNextButtonClick(View view)109     protected void onNextButtonClick(View view) {
110         updateFingerprintSuggestionEnableState();
111         setResult(RESULT_FINISHED);
112         if (WizardManagerHelper.isAnySetupWizard(getIntent())) {
113             postEnroll();
114         } else if (mFromSettingsSummary) {
115             // Only launch fingerprint settings if enrollment was triggered through settings summary
116             launchFingerprintSettings();
117         }
118         finish();
119     }
120 
updateFingerprintSuggestionEnableState()121     private void updateFingerprintSuggestionEnableState() {
122         final FingerprintManager fpm = Utils.getFingerprintManagerOrNull(this);
123         if (fpm != null) {
124             int enrolled = fpm.getEnrolledFingerprints(mUserId).size();
125 
126             // Only show "Add another fingerprint" if the user already enrolled one.
127             // "Add fingerprint" will be shown in the main flow if the user hasn't enrolled any
128             // fingerprints. If the user already added more than one fingerprint, they already know
129             // to add multiple fingerprints so we don't show the suggestion.
130             int flag = (enrolled == 1) ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
131                     : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
132 
133             ComponentName componentName = new ComponentName(getApplicationContext(),
134                     FINGERPRINT_SUGGESTION_ACTIVITY);
135             getPackageManager().setComponentEnabledSetting(
136                     componentName, flag, PackageManager.DONT_KILL_APP);
137             Log.d(TAG, FINGERPRINT_SUGGESTION_ACTIVITY + " enabled state = " + (enrolled == 1));
138         }
139     }
140 
postEnroll()141     private void postEnroll() {
142         final FingerprintManager fpm = Utils.getFingerprintManagerOrNull(this);
143         if (fpm != null) {
144             fpm.revokeChallenge(mUserId, mChallenge);
145         }
146     }
147 
launchFingerprintSettings()148     private void launchFingerprintSettings() {
149         final Intent intent = new Intent(ACTION_FINGERPRINT_SETTINGS);
150         intent.setPackage(Utils.SETTINGS_PACKAGE_NAME);
151         intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, mToken);
152         intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
153         intent.putExtra(Intent.EXTRA_USER_ID, mUserId);
154         intent.putExtra(BiometricEnrollBase.EXTRA_KEY_CHALLENGE, mChallenge);
155         startActivity(intent);
156         overridePendingTransition(R.anim.sud_slide_back_in, R.anim.sud_slide_back_out);
157     }
158 
onAddAnotherButtonClick(View view)159     private void onAddAnotherButtonClick(View view) {
160         startActivityForResult(getFingerprintEnrollingIntent(), REQUEST_ADD_ANOTHER);
161     }
162 
163     @Override
onActivityResult(int requestCode, int resultCode, Intent data)164     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
165         updateFingerprintSuggestionEnableState();
166         if (requestCode == REQUEST_ADD_ANOTHER && resultCode != RESULT_CANCELED) {
167             setResult(resultCode, data);
168             finish();
169         } else {
170             super.onActivityResult(requestCode, resultCode, data);
171         }
172     }
173 
174     @Override
getMetricsCategory()175     public int getMetricsCategory() {
176         return SettingsEnums.FINGERPRINT_ENROLL_FINISH;
177     }
178 }
179