1 /* <lambda>null2 * 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.biometrics.ui.viewmodel 18 19 import com.android.keyguard.logging.DeviceEntryIconLogger 20 import com.android.systemui.bouncer.domain.interactor.AlternateBouncerInteractor 21 import com.android.systemui.keyguard.ui.viewmodel.DeviceEntryIconViewModel 22 import com.android.systemui.statusbar.phone.SystemUIDialogManager 23 import com.android.systemui.statusbar.phone.hideAffordancesRequest 24 import javax.inject.Inject 25 import kotlinx.coroutines.ExperimentalCoroutinesApi 26 import kotlinx.coroutines.flow.Flow 27 import kotlinx.coroutines.flow.combine 28 import kotlinx.coroutines.flow.distinctUntilChanged 29 import kotlinx.coroutines.flow.map 30 31 /** 32 * View model for the UdfpsTouchOverlay for when UDFPS is being requested for device entry. Handles 33 * touches as long as the device entry view is visible (the lockscreen or the alternate bouncer 34 * view). 35 */ 36 @ExperimentalCoroutinesApi 37 class DeviceEntryUdfpsTouchOverlayViewModel 38 @Inject 39 constructor( 40 deviceEntryIconViewModel: DeviceEntryIconViewModel, 41 alternateBouncerInteractor: AlternateBouncerInteractor, 42 systemUIDialogManager: SystemUIDialogManager, 43 logger: DeviceEntryIconLogger, 44 ) : UdfpsTouchOverlayViewModel { 45 private val deviceEntryViewAlphaIsMostlyVisible: Flow<Boolean> = 46 deviceEntryIconViewModel.deviceEntryViewAlpha 47 .map { it > ALLOW_TOUCH_ALPHA_THRESHOLD } 48 .distinctUntilChanged() 49 override val shouldHandleTouches: Flow<Boolean> = 50 combine( 51 deviceEntryViewAlphaIsMostlyVisible, 52 alternateBouncerInteractor.isVisible, 53 systemUIDialogManager.hideAffordancesRequest, 54 ) { canTouchDeviceEntryViewAlpha, alternateBouncerVisible, hideAffordancesRequest -> 55 val shouldHandleTouches = 56 (canTouchDeviceEntryViewAlpha && !hideAffordancesRequest) || 57 alternateBouncerVisible 58 logger.logDeviceEntryUdfpsTouchOverlayShouldHandleTouches( 59 shouldHandleTouches, 60 canTouchDeviceEntryViewAlpha, 61 alternateBouncerVisible, 62 hideAffordancesRequest 63 ) 64 shouldHandleTouches 65 } 66 .distinctUntilChanged() 67 68 companion object { 69 // only allow touches if the view is still mostly visible 70 const val ALLOW_TOUCH_ALPHA_THRESHOLD = .9f 71 } 72 } 73