• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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;
18 
19 import android.annotation.Nullable;
20 import android.content.Intent;
21 import android.os.UserHandle;
22 import android.view.View;
23 
24 import com.android.settings.password.ChooseLockSettingsHelper;
25 
26 /**
27  * Abstract base activity which handles the actual enrolling for biometrics.
28  */
29 public abstract class BiometricsEnrollEnrolling extends BiometricEnrollBase
30         implements BiometricEnrollSidecar.Listener {
31 
32     private static final String TAG_SIDECAR = "sidecar";
33 
34     @Nullable
35     protected BiometricEnrollSidecar mSidecar;
36 
37     /**
38      * @return the intent for the finish activity
39      */
getFinishIntent()40     protected abstract Intent getFinishIntent();
41 
42     /**
43      * @return an instance of the biometric enroll sidecar
44      */
getSidecar()45     protected abstract BiometricEnrollSidecar getSidecar();
46 
47     /**
48      * @return true if enrollment should start automatically.
49      */
shouldStartAutomatically()50     protected abstract boolean shouldStartAutomatically();
51 
52     @Override
onStart()53     protected void onStart() {
54         super.onStart();
55         if (shouldStartAutomatically()) {
56             startEnrollment();
57         }
58     }
59 
60     @Override
onStop()61     protected void onStop() {
62         if (mSidecar != null) {
63             mSidecar.setListener(null);
64         }
65         if (!isChangingConfigurations()) {
66             if (mSidecar != null) {
67                 mSidecar.cancelEnrollment();
68                 getSupportFragmentManager()
69                         .beginTransaction().remove(mSidecar).commitAllowingStateLoss();
70             }
71         }
72 
73         super.onStop();
74     }
75 
76     @Override
onBackPressed()77     public void onBackPressed() {
78         cancelEnrollment();
79         super.onBackPressed();
80     }
81 
onSkipButtonClick(View view)82     protected void onSkipButtonClick(View view) {
83         cancelEnrollment();
84         setResult(RESULT_SKIP);
85         finish();
86     }
87 
cancelEnrollment()88     public void cancelEnrollment() {
89         if (mSidecar != null) {
90             mSidecar.setListener(null);
91             mSidecar.cancelEnrollment();
92             getSupportFragmentManager()
93                     .beginTransaction().remove(mSidecar).commitAllowingStateLoss();
94             mSidecar = null;
95         }
96     }
97 
startEnrollment()98     public void startEnrollment() {
99         mSidecar = (BiometricEnrollSidecar) getSupportFragmentManager()
100                 .findFragmentByTag(TAG_SIDECAR);
101         if (mSidecar == null) {
102             mSidecar = getSidecar();
103             getSupportFragmentManager().beginTransaction().add(mSidecar, TAG_SIDECAR)
104                     .commitAllowingStateLoss();
105         }
106         mSidecar.setListener(this);
107     }
108 
launchFinish(byte[] token)109     protected void launchFinish(byte[] token) {
110         Intent intent = getFinishIntent();
111         intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT
112                 | Intent.FLAG_ACTIVITY_CLEAR_TOP
113                 | Intent.FLAG_ACTIVITY_SINGLE_TOP);
114         intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, token);
115         intent.putExtra(BiometricEnrollBase.EXTRA_KEY_SENSOR_ID, mSensorId);
116         intent.putExtra(BiometricEnrollBase.EXTRA_KEY_CHALLENGE, mChallenge);
117         intent.putExtra(EXTRA_FROM_SETTINGS_SUMMARY, mFromSettingsSummary);
118         if (mUserId != UserHandle.USER_NULL) {
119             intent.putExtra(Intent.EXTRA_USER_ID, mUserId);
120         }
121         startActivity(intent);
122         finish();
123     }
124 
125 }
126