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