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.systemui.bouncer.ui.viewmodel 18 19 import com.android.systemui.authentication.domain.interactor.AuthenticationInteractor 20 import com.android.systemui.bouncer.domain.interactor.PrimaryBouncerInteractor 21 import com.android.systemui.lifecycle.ExclusiveActivatable 22 import com.android.systemui.user.domain.interactor.SelectedUserInteractor 23 import dagger.assisted.AssistedFactory 24 import dagger.assisted.AssistedInject 25 import kotlinx.coroutines.awaitCancellation 26 import kotlinx.coroutines.coroutineScope 27 import com.android.app.tracing.coroutines.launchTraced as launch 28 29 class BouncerContainerViewModel 30 @AssistedInject 31 constructor( 32 private val legacyInteractor: PrimaryBouncerInteractor, 33 private val authenticationInteractor: AuthenticationInteractor, 34 private val selectedUserInteractor: SelectedUserInteractor, 35 ) : ExclusiveActivatable() { 36 37 override suspend fun onActivated(): Nothing { 38 coroutineScope { 39 launch { 40 authenticationInteractor.onAuthenticationResult.collect { authenticationSucceeded -> 41 if (authenticationSucceeded) { 42 legacyInteractor.notifyKeyguardAuthenticatedPrimaryAuth( 43 selectedUserInteractor.getSelectedUserId() 44 ) 45 } 46 } 47 } 48 awaitCancellation() 49 } 50 } 51 52 @AssistedFactory 53 interface Factory { 54 fun create(): BouncerContainerViewModel 55 } 56 } 57