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.keyguard.domain.interactor 18 19 import android.graphics.Point 20 import android.view.Display 21 import com.android.systemui.dagger.SysUISingleton 22 import com.android.systemui.keyguard.data.repository.KeyguardRepository 23 import com.android.systemui.power.data.repository.PowerRepository 24 import com.android.systemui.power.shared.model.DozeScreenStateModel 25 import com.android.systemui.scene.domain.interactor.SceneInteractor 26 import com.android.systemui.scene.shared.flag.SceneContainerFlag 27 import com.android.systemui.scene.shared.model.Scenes 28 import dagger.Lazy 29 import javax.inject.Inject 30 31 @SysUISingleton 32 class DozeInteractor 33 @Inject 34 constructor( 35 private val keyguardRepository: KeyguardRepository, 36 private val powerRepository: PowerRepository, 37 // TODO(b/336364825) Remove Lazy when SceneContainerFlag is released - 38 // while the flag is off, creating this object too early results in a crash 39 private val sceneInteractor: Lazy<SceneInteractor>, 40 ) { canDozeFromCurrentScenenull41 fun canDozeFromCurrentScene(): Boolean { 42 if (SceneContainerFlag.isUnexpectedlyInLegacyMode()) { 43 return false 44 } 45 return sceneInteractor.get().currentScene.value == Scenes.Lockscreen 46 } 47 setDozeScreenStatenull48 fun setDozeScreenState(state: Int) { 49 powerRepository.dozeScreenState.value = 50 when (state) { 51 Display.STATE_UNKNOWN -> DozeScreenStateModel.UNKNOWN 52 Display.STATE_OFF -> DozeScreenStateModel.OFF 53 Display.STATE_ON -> DozeScreenStateModel.ON 54 Display.STATE_DOZE -> DozeScreenStateModel.DOZE 55 Display.STATE_DOZE_SUSPEND -> DozeScreenStateModel.DOZE_SUSPEND 56 Display.STATE_VR -> DozeScreenStateModel.VR 57 Display.STATE_ON_SUSPEND -> DozeScreenStateModel.ON_SUSPEND 58 else -> throw IllegalArgumentException("Invalid DozeScreenState: $state") 59 } 60 } 61 setAodAvailablenull62 fun setAodAvailable(value: Boolean) { 63 keyguardRepository.setAodAvailable(value) 64 } 65 setIsDozingnull66 fun setIsDozing(isDozing: Boolean) { 67 keyguardRepository.setIsDozing(isDozing) 68 } 69 setLastTapToWakePositionnull70 fun setLastTapToWakePosition(position: Point) { 71 keyguardRepository.setLastDozeTapToWakePosition(position) 72 } 73 dozeTimeTicknull74 fun dozeTimeTick() { 75 keyguardRepository.dozeTimeTick() 76 } 77 } 78