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.content.Intent; 20 import android.os.UserHandle; 21 import android.view.View; 22 23 import com.android.settings.R; 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 protected BiometricEnrollSidecar mSidecar; 35 36 /** 37 * @return the intent for the finish activity 38 */ getFinishIntent()39 protected abstract Intent getFinishIntent(); 40 41 /** 42 * @return an instance of the biometric enroll sidecar 43 */ getSidecar()44 protected abstract BiometricEnrollSidecar getSidecar(); 45 46 /** 47 * @return true if enrollment should start automatically. 48 */ shouldStartAutomatically()49 protected abstract boolean shouldStartAutomatically(); 50 51 @Override onStart()52 protected void onStart() { 53 super.onStart(); 54 if (shouldStartAutomatically()) { 55 startEnrollment(); 56 } 57 } 58 59 @Override onStop()60 protected void onStop() { 61 super.onStop(); 62 if (mSidecar != null) { 63 mSidecar.setListener(null); 64 } 65 66 if (!isChangingConfigurations()) { 67 if (mSidecar != null) { 68 mSidecar.cancelEnrollment(); 69 getSupportFragmentManager() 70 .beginTransaction().remove(mSidecar).commitAllowingStateLoss(); 71 } 72 finish(); 73 } 74 } 75 76 @Override onBackPressed()77 public void onBackPressed() { 78 if (mSidecar != null) { 79 mSidecar.setListener(null); 80 mSidecar.cancelEnrollment(); 81 getSupportFragmentManager() 82 .beginTransaction().remove(mSidecar).commitAllowingStateLoss(); 83 mSidecar = null; 84 } 85 super.onBackPressed(); 86 } 87 onSkipButtonClick(View view)88 protected void onSkipButtonClick(View view) { 89 setResult(RESULT_SKIP); 90 finish(); 91 } 92 startEnrollment()93 public void startEnrollment() { 94 mSidecar = (BiometricEnrollSidecar) getSupportFragmentManager() 95 .findFragmentByTag(TAG_SIDECAR); 96 if (mSidecar == null) { 97 mSidecar = getSidecar(); 98 getSupportFragmentManager().beginTransaction().add(mSidecar, TAG_SIDECAR) 99 .commitAllowingStateLoss(); 100 } 101 mSidecar.setListener(this); 102 } 103 launchFinish(byte[] token)104 protected void launchFinish(byte[] token) { 105 Intent intent = getFinishIntent(); 106 intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT 107 | Intent.FLAG_ACTIVITY_CLEAR_TOP 108 | Intent.FLAG_ACTIVITY_SINGLE_TOP); 109 intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, token); 110 intent.putExtra(EXTRA_FROM_SETTINGS_SUMMARY, mFromSettingsSummary); 111 if (mUserId != UserHandle.USER_NULL) { 112 intent.putExtra(Intent.EXTRA_USER_ID, mUserId); 113 } 114 startActivity(intent); 115 overridePendingTransition(R.anim.sud_slide_next_in, R.anim.sud_slide_next_out); 116 finish(); 117 } 118 119 } 120