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