• 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.R;
25 import com.android.settings.password.ChooseLockSettingsHelper;
26 
27 import com.google.android.setupcompat.util.WizardManagerHelper;
28 
29 /**
30  * Abstract base activity which handles the actual enrolling for biometrics.
31  */
32 public abstract class BiometricsEnrollEnrolling extends BiometricEnrollBase
33         implements BiometricEnrollSidecar.Listener {
34 
35     private static final String TAG_SIDECAR = "sidecar";
36 
37     @Nullable
38     protected BiometricEnrollSidecar mSidecar;
39 
40     /**
41      * @return the intent for the finish activity
42      */
getFinishIntent()43     protected abstract Intent getFinishIntent();
44 
45     /**
46      * @return an instance of the biometric enroll sidecar
47      */
getSidecar()48     protected abstract BiometricEnrollSidecar getSidecar();
49 
50     /**
51      * @return true if enrollment should start automatically.
52      */
shouldStartAutomatically()53     protected abstract boolean shouldStartAutomatically();
54 
55     @Override
onStart()56     protected void onStart() {
57         super.onStart();
58         if (shouldStartAutomatically()) {
59             startEnrollment();
60         }
61     }
62 
63     @Override
onStop()64     protected void onStop() {
65         super.onStop();
66 
67         if (mSidecar != null) {
68             mSidecar.setListener(null);
69         }
70 
71         if (!isChangingConfigurations()) {
72             if (mSidecar != null) {
73                 mSidecar.cancelEnrollment();
74                 getSupportFragmentManager()
75                         .beginTransaction().remove(mSidecar).commitAllowingStateLoss();
76             }
77             if (!WizardManagerHelper.isAnySetupWizard(getIntent())) {
78                 setResult(RESULT_TIMEOUT);
79             }
80             finish();
81         }
82     }
83 
84     @Override
shouldFinishWhenBackgrounded()85     protected boolean shouldFinishWhenBackgrounded() {
86         // Prevent super.onStop() from finishing, since we handle this in our onStop().
87         return false;
88     }
89 
90     @Override
onBackPressed()91     public void onBackPressed() {
92         cancelEnrollment();
93         super.onBackPressed();
94     }
95 
onSkipButtonClick(View view)96     protected void onSkipButtonClick(View view) {
97         cancelEnrollment();
98         setResult(RESULT_SKIP);
99         finish();
100     }
101 
cancelEnrollment()102     public void cancelEnrollment() {
103         if (mSidecar != null) {
104             mSidecar.setListener(null);
105             mSidecar.cancelEnrollment();
106             getSupportFragmentManager()
107                     .beginTransaction().remove(mSidecar).commitAllowingStateLoss();
108             mSidecar = null;
109         }
110     }
111 
startEnrollment()112     public void startEnrollment() {
113         mSidecar = (BiometricEnrollSidecar) getSupportFragmentManager()
114                 .findFragmentByTag(TAG_SIDECAR);
115         if (mSidecar == null) {
116             mSidecar = getSidecar();
117             getSupportFragmentManager().beginTransaction().add(mSidecar, TAG_SIDECAR)
118                     .commitAllowingStateLoss();
119         }
120         mSidecar.setListener(this);
121     }
122 
launchFinish(byte[] token)123     protected void launchFinish(byte[] token) {
124         Intent intent = getFinishIntent();
125         intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT
126                 | Intent.FLAG_ACTIVITY_CLEAR_TOP
127                 | Intent.FLAG_ACTIVITY_SINGLE_TOP);
128         intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, token);
129         intent.putExtra(BiometricEnrollBase.EXTRA_KEY_SENSOR_ID, mSensorId);
130         intent.putExtra(BiometricEnrollBase.EXTRA_KEY_CHALLENGE, mChallenge);
131         intent.putExtra(EXTRA_FROM_SETTINGS_SUMMARY, mFromSettingsSummary);
132         if (mUserId != UserHandle.USER_NULL) {
133             intent.putExtra(Intent.EXTRA_USER_ID, mUserId);
134         }
135         startActivity(intent);
136         overridePendingTransition(R.anim.sud_slide_next_in, R.anim.sud_slide_next_out);
137         finish();
138     }
139 
140 }
141