1 /* 2 * Copyright (C) 2024 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.face 18 19 import android.app.ComponentCaller 20 import android.content.Intent 21 import android.os.Bundle 22 import android.util.Log 23 import androidx.appcompat.app.AppCompatActivity 24 import com.android.settings.biometrics.BiometricEnrollBase.RESULT_FINISHED 25 import com.android.settings.biometrics.combination.CombinedBiometricStatusUtils 26 import com.android.settings.overlay.FeatureFactory.Companion.featureFactory 27 28 class FaceEnroll: AppCompatActivity() { 29 30 /** 31 * The class of the next activity to launch. This is open to allow subclasses to provide their 32 * own behavior. Defaults to the default activity class provided by the 33 * enrollActivityClassProvider. 34 */ 35 private val nextActivityClass: Class<*> 36 get() = enrollActivityProvider.next 37 38 private val enrollActivityProvider: FaceEnrollActivityClassProvider 39 get() = featureFactory.faceFeatureProvider.enrollActivityClassProvider 40 41 private var isLaunched = false 42 onCreatenull43 override fun onCreate(savedInstanceState: Bundle?) { 44 super.onCreate(savedInstanceState) 45 46 if (savedInstanceState != null) { 47 isLaunched = savedInstanceState.getBoolean(KEY_IS_LAUNCHED, isLaunched) 48 } 49 50 if (!isLaunched) { 51 /** 52 * Logs the next activity to be launched, creates an intent for that activity, 53 * adds flags to forward the result, includes any existing extras from the current intent, 54 * starts the new activity and then finishes the current one 55 */ 56 Log.d("FaceEnroll", "forward to $nextActivityClass") 57 val nextIntent = Intent(this, nextActivityClass) 58 nextIntent.putExtras(intent) 59 startActivityForResult(nextIntent, 0) 60 61 isLaunched = true 62 } 63 } 64 onSaveInstanceStatenull65 override fun onSaveInstanceState(outState: Bundle) { 66 outState.putBoolean(KEY_IS_LAUNCHED, isLaunched) 67 super.onSaveInstanceState(outState) 68 } 69 onActivityResultnull70 override fun onActivityResult( 71 requestCode: Int, 72 resultCode: Int, 73 data: Intent?, 74 caller: ComponentCaller 75 ) { 76 super.onActivityResult(requestCode, resultCode, data, caller) 77 isLaunched = false 78 if (intent.getBooleanExtra( 79 CombinedBiometricStatusUtils.EXTRA_LAUNCH_FROM_SAFETY_SOURCE_ISSUE, false) 80 && resultCode != RESULT_FINISHED) { 81 featureFactory.biometricsFeatureProvider.notifySafetyIssueActionLaunched() 82 } 83 setResult(resultCode, data) 84 finish() 85 } 86 87 private companion object { 88 const val KEY_IS_LAUNCHED = "isLaunched" 89 } 90 } 91