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.biometrics.domain.interactor 18 19 import android.hardware.biometrics.SensorLocationInternal 20 import com.android.systemui.biometrics.data.repository.FingerprintPropertyRepository 21 import com.android.systemui.dagger.SysUISingleton 22 import javax.inject.Inject 23 import kotlinx.coroutines.flow.Flow 24 import kotlinx.coroutines.flow.MutableStateFlow 25 import kotlinx.coroutines.flow.asStateFlow 26 import kotlinx.coroutines.flow.combine 27 28 /** Business logic for SideFps overlay offsets. */ 29 interface SideFpsOverlayInteractor { 30 31 /** The displayId of the current display. */ 32 val displayId: Flow<String> 33 34 /** Overlay offsets corresponding to given displayId. */ 35 val overlayOffsets: Flow<SensorLocationInternal> 36 37 /** Called on display changes, used to keep the display state in sync */ 38 fun onDisplayChanged(displayId: String) 39 } 40 41 @SysUISingleton 42 class SideFpsOverlayInteractorImpl 43 @Inject 44 constructor(fingerprintPropertyRepository: FingerprintPropertyRepository) : 45 SideFpsOverlayInteractor { 46 47 private val _displayId: MutableStateFlow<String> = MutableStateFlow("") 48 override val displayId: Flow<String> = _displayId.asStateFlow() 49 50 override val overlayOffsets: Flow<SensorLocationInternal> = 51 combine(displayId, fingerprintPropertyRepository.sensorLocations) { displayId, offsets -> 52 offsets[displayId] ?: SensorLocationInternal.DEFAULT 53 } 54 55 override fun onDisplayChanged(displayId: String) { 56 _displayId.value = displayId 57 } 58 59 companion object { 60 private const val TAG = "SideFpsOverlayInteractorImpl" 61 } 62 } 63