1 /* <lambda>null2 * 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.fingerprint2.domain.interactor 18 19 import android.content.Intent 20 import android.hardware.fingerprint.FingerprintManager 21 import com.android.settings.biometrics.GatekeeperPasswordProvider 22 import com.android.settings.biometrics.fingerprint2.data.repository.UserRepo 23 import com.android.settings.biometrics.fingerprint2.lib.domain.interactor.GenerateChallengeInteractor 24 import com.android.settings.password.ChooseLockSettingsHelper 25 import kotlinx.coroutines.flow.first 26 import kotlin.coroutines.resume 27 import kotlin.coroutines.suspendCoroutine 28 29 class GenerateChallengeInteractorImpl( 30 private val fingerprintManager: FingerprintManager, 31 private val userRepo: UserRepo, 32 private val gatekeeperPasswordProvider: GatekeeperPasswordProvider, 33 ) : GenerateChallengeInteractor { 34 35 override suspend fun generateChallenge(gateKeeperPasswordHandle: Long): Pair<Long, ByteArray> { 36 val userId = userRepo.currentUser.first() 37 return suspendCoroutine { 38 val callback = 39 FingerprintManager.GenerateChallengeCallback { _, userId, challenge -> 40 val intent = Intent() 41 intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_GK_PW_HANDLE, gateKeeperPasswordHandle) 42 val challengeToken = 43 gatekeeperPasswordProvider.requestGatekeeperHat(intent, challenge, userId) 44 45 gatekeeperPasswordProvider.removeGatekeeperPasswordHandle(intent, false) 46 val p = Pair(challenge, challengeToken) 47 it.resume(p) 48 } 49 fingerprintManager.generateChallenge(userId, callback) 50 } 51 } 52 } 53