1 /* 2 * Copyright (C) 2023 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.deviceentry.domain.interactor 18 19 import com.android.systemui.dagger.SysUISingleton 20 import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor 21 import com.android.systemui.keyguard.shared.model.BiometricUnlockMode 22 import com.android.systemui.keyguard.shared.model.BiometricUnlockSource 23 import com.android.systemui.util.kotlin.sample 24 import javax.inject.Inject 25 import kotlinx.coroutines.ExperimentalCoroutinesApi 26 import kotlinx.coroutines.flow.Flow 27 import kotlinx.coroutines.flow.MutableSharedFlow 28 import kotlinx.coroutines.flow.filter 29 import kotlinx.coroutines.flow.filterNotNull 30 import kotlinx.coroutines.flow.map 31 32 /** 33 * Hosts application business logic related to the source of the user entering the device. Note: The 34 * source of the user entering the device isn't equivalent to the reason the device is unlocked. 35 * 36 * For example, the user successfully enters the device when they dismiss the lockscreen via a 37 * bypass biometric or, if the device is already unlocked, by triggering an affordance that 38 * dismisses the lockscreen. 39 */ 40 @ExperimentalCoroutinesApi 41 @SysUISingleton 42 class DeviceEntrySourceInteractor 43 @Inject 44 constructor( 45 keyguardInteractor: KeyguardInteractor, 46 ) { 47 val deviceEntryFromBiometricSource: Flow<BiometricUnlockSource> = 48 keyguardInteractor.biometricUnlockState <lambda>null49 .filter { BiometricUnlockMode.dismissesKeyguard(it.mode) } <lambda>null50 .map { it.source } 51 .filterNotNull() 52 53 private val attemptEnterDeviceFromDeviceEntryIcon: MutableSharedFlow<Unit> = MutableSharedFlow() 54 val deviceEntryFromDeviceEntryIcon: Flow<Unit> = 55 attemptEnterDeviceFromDeviceEntryIcon 56 .sample(keyguardInteractor.isKeyguardDismissible) <lambda>null57 .filter { it } // only send events if the keyguard is dismissible <lambda>null58 .map {} // map to Unit 59 attemptEnterDeviceFromDeviceEntryIconnull60 suspend fun attemptEnterDeviceFromDeviceEntryIcon() { 61 attemptEnterDeviceFromDeviceEntryIcon.emit(Unit) 62 } 63 } 64